Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
import java.util.Set;
import java.util.Stack;

import org.apache.poi.xwpf.usermodel.XWPFAbstractNum;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFNum;
import org.apache.poi.xwpf.usermodel.XWPFNumbering;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.URIConverter;
Expand Down Expand Up @@ -61,7 +63,6 @@
import org.obeonetwork.m2doc.element.impl.MTableImpl.MCellImpl;
import org.obeonetwork.m2doc.element.impl.MTableImpl.MRowImpl;
import org.obeonetwork.m2doc.element.impl.MTextImpl;
import org.obeonetwork.m2doc.services.PaginationServices;
import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STOnOff;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTAbstractNum;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDecimalNumber;
Expand All @@ -71,7 +72,6 @@
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLvl;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNum;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNumFmt;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNumbering;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STJc;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STMultiLevelType;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STNumberFormat;
Expand Down Expand Up @@ -1985,19 +1985,30 @@ private void setOrderedListNumbering(Context context, Element element) {
* the {@link Context}
*/
private void createNumbering(Context context) {
final CTAbstractNum res;
final XWPFNumbering numbering = destinationDocument.createNumbering();
final CTNumbering ctNumbering = PaginationServices.getCTNumbering(numbering);
res = ctNumbering.addNewAbstractNum();

// Create CTAbstractNum using the factory to avoid duplicate when creating XWPFAbstractNum
CTAbstractNum res = CTAbstractNum.Factory.newInstance();
res.addNewMultiLevelType().setVal(STMultiLevelType.HYBRID_MULTILEVEL);
BigInteger id = BigInteger.valueOf(ctNumbering.sizeOfAbstractNumArray() - 1);
res.setAbstractNumId(id);
final CTNum ctNum = ctNumbering.addNewNum();
ctNum.setNumId(BigInteger.valueOf(ctNumbering.sizeOfNumArray()));
ctNum.addNewAbstractNumId().setVal(id);
BigInteger abstractNumId = BigInteger.valueOf(numbering.getAbstractNums().size());
res.setAbstractNumId(abstractNumId);
XWPFAbstractNum newAbstractNum = new XWPFAbstractNum(res);
BigInteger finalAbsId = numbering.addAbstractNum(newAbstractNum);

// Update the reference (that was changed through addAbstractNum)
res = newAbstractNum.getCTAbstractNum();
newAbstractNum.setNumbering(numbering);

final CTNum ctNum = CTNum.Factory.newInstance();
ctNum.addNewAbstractNumId().setVal(finalAbsId);
BigInteger numId = BigInteger.valueOf(numbering.getNums().size() + 1);
ctNum.setNumId(numId);
XWPFNum newNum = new XWPFNum(ctNum);
newNum.setNumbering(numbering);
numbering.addNum(newNum);

context.numbering = res;
context.numberingID = ctNum.getNumId();
context.numberingID = numId;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016, 2024 Obeo.
* Copyright (c) 2016, 2026 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -39,6 +39,7 @@
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFFootnote;
import org.apache.poi.xwpf.usermodel.XWPFHeaderFooter;
import org.apache.poi.xwpf.usermodel.XWPFNumbering;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import org.apache.poi.xwpf.usermodel.XWPFSDT;
Expand Down Expand Up @@ -367,16 +368,24 @@ private XWPFParagraph copyParagraph(final IBody outputBody, final Map<String, St
@SuppressWarnings("resource")
private BigInteger copyNumID(IBody inputBody, IBody outputBody, BigInteger inputNumID) {
final XWPFDocument inputDocument = inputBody.getXWPFDocument();
final XWPFDocument ouptutDocument = outputBody.getXWPFDocument();
final XWPFDocument outputDocument = outputBody.getXWPFDocument();

final XWPFAbstractNum inputNum = inputDocument.getNumbering()
.getAbstractNum(inputNumID.subtract(BigInteger.ONE));
final XWPFNumbering inputNumbering = inputDocument.getNumbering();
BigInteger numId = null;
if (inputNumbering != null) {
numId = inputDocument.getNumbering().getAbstractNumID(inputNumID);
}
if (inputNumbering == null || numId == null) {
// If it's not found in the template, check in the generated document (implicit numbering from template constructs)
return outputDocument.getNumbering().getAbstractNumID(inputNumID);
}
final XWPFAbstractNum inputNum = inputDocument.getNumbering().getAbstractNum(numId);

final XWPFAbstractNum outputNum = new XWPFAbstractNum((CTAbstractNum) inputNum.getCTAbstractNum().copy());
final BigInteger newID = BigInteger.valueOf(ouptutDocument.getNumbering().getAbstractNums().size());
final BigInteger newID = BigInteger.valueOf(outputDocument.getNumbering().getAbstractNums().size());
outputNum.getAbstractNum().setAbstractNumId(newID);
BigInteger outputNumID = ouptutDocument.getNumbering().addAbstractNum(outputNum);
ouptutDocument.getNumbering().addNum(outputNumID);
BigInteger outputNumID = outputDocument.getNumbering().addAbstractNum(outputNum);
outputDocument.getNumbering().addNum(outputNumID);
return outputNumID;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="anydsl" nsURI="http://www.eclipse.org/acceleo/anydsl" nsPrefix="anydsl">
<eClassifiers xsi:type="ecore:EClass" name="World">
<eAnnotations source="http://www.obeo.fr/dsl/dnc/archetype">
<details key="archetype" value="MomentInterval"/>
</eAnnotations>
<eStructuralFeatures xsi:type="ecore:EReference" name="companies" upperBound="-1"
eType="#//Company" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="foods" upperBound="-1"
eType="#//Food" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="sources" upperBound="-1"
eType="#//Source" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="MultiNamedElement" abstract="true" interface="true">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" upperBound="-1" eType="#//SingleString"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="NamedElement" abstract="true" interface="true">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="#//SingleString"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Producer" eSuperTypes="#//NamedElement">
<eStructuralFeatures xsi:type="ecore:EReference" name="adress" eType="#//Adress"
containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="company" eType="#//Company"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="foods" upperBound="-1"
eType="#//Food" eOpposite="#//Food/producers"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Adress">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="zipCode" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="city" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="country" eType="#//CountryData"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Company" abstract="true" interface="true"
eSuperTypes="#//NamedElement">
<eStructuralFeatures xsi:type="ecore:EReference" name="adress" eType="#//Adress"
containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="world" eType="#//World"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="ProductionCompany" eSuperTypes="#//Company">
<eStructuralFeatures xsi:type="ecore:EReference" name="producers" upperBound="-1"
eType="#//Producer" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Restaurant" eSuperTypes="#//Company">
<eStructuralFeatures xsi:type="ecore:EReference" name="chefs" upperBound="-1"
eType="#//Chef" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="menu" upperBound="-1" eType="#//EStringToRecipeMap"
containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Chef" eSuperTypes="#//NamedElement">
<eStructuralFeatures xsi:type="ecore:EReference" name="adress" eType="#//Adress"
containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="recipes" upperBound="-1"
eType="#//Recipe" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Recipe" eSuperTypes="#//NamedElement">
<eStructuralFeatures xsi:type="ecore:EReference" name="ingredients" upperBound="-1"
eType="#//Food"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Food" eSuperTypes="#//NamedElement">
<eOperations name="ripen" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean">
<eParameters name="color" eType="#//Color"/>
</eOperations>
<eOperations name="preferredColor" eType="#//Color"/>
<eOperations name="newFood" eType="#//Food"/>
<eOperations name="setColor">
<eParameters name="food" eType="#//Food"/>
<eParameters name="newColor" eType="#//Color"/>
</eOperations>
<eOperations name="setCaliber">
<eParameters name="food" eType="#//Food"/>
<eParameters name="newCaliber" upperBound="-1" eType="#//Caliber"/>
</eOperations>
<eOperations name="acceptedCaliber" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean">
<eParameters name="caliber" eType="#//Caliber"/>
</eOperations>
<eOperations name="label">
<eParameters name="text" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eOperations>
<eOperations name="preferredLabel" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString">
<eParameters name="text" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eOperations>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="color" upperBound="-1"
eType="#//Color"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="caliber" eType="#//Caliber"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="relatedFoods" upperBound="-1"
eType="#//Food"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="group" eType="#//Group"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="label" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="source" eType="#//Source"
eOpposite="#//Source/foods"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="producers" upperBound="-1"
eType="#//Producer" eOpposite="#//Producer/foods"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Source" abstract="true" interface="true"
eSuperTypes="#//MultiNamedElement">
<eStructuralFeatures xsi:type="ecore:EReference" name="foods" upperBound="-1"
eType="#//Food" eOpposite="#//Food/source"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="origin" upperBound="-1"
eType="#//CountryData"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Plant" eSuperTypes="#//Source">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="kind" eType="#//Kind"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Animal" eSuperTypes="#//Source">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="part" upperBound="-1" eType="#//Part"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EEnum" name="Color">
<eLiterals name="black"/>
<eLiterals name="red" value="1"/>
<eLiterals name="green" value="2"/>
<eLiterals name="yellow" value="3"/>
<eLiterals name="orange" value="4"/>
<eLiterals name="brown" value="5"/>
<eLiterals name="pink" value="6"/>
<eLiterals name="palPink" value="7" literal="palPink"/>
<eLiterals name="veryYellow" value="8"/>
<eLiterals name="white" value="9"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EEnum" name="Caliber">
<eLiterals name="S"/>
<eLiterals name="M" value="1"/>
<eLiterals name="L" value="2"/>
<eLiterals name="XL" value="3"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EEnum" name="Group">
<eLiterals name="Water"/>
<eLiterals name="Dairy" value="1"/>
<eLiterals name="Fruit" value="2"/>
<eLiterals name="Grain" value="3"/>
<eLiterals name="Protein" value="4"/>
<eLiterals name="Sweet" value="5"/>
<eLiterals name="Vegetable" value="6"/>
<eLiterals name="Alcohol" value="7"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EEnum" name="Continent">
<eLiterals name="Europe"/>
<eLiterals name="Asia" value="1"/>
<eLiterals name="Africa" value="2"/>
<eLiterals name="America" value="3"/>
<eLiterals name="Australia" value="4"/>
<eLiterals name="Antarctica" value="5"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EEnum" name="Kind">
<eLiterals name="Other"/>
<eLiterals name="Seed" value="1"/>
<eLiterals name="Oilseed" value="2"/>
<eLiterals name="Tree" value="3"/>
<eLiterals name="Root" value="4"/>
<eLiterals name="Bulb" value="5"/>
<eLiterals name="Leaf" value="6"/>
<eLiterals name="Stem" value="7"/>
<eLiterals name="Flower" value="8"/>
<eLiterals name="Inflorescence" value="9"/>
<eLiterals name="Spice" value="10"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EEnum" name="Part">
<eLiterals name="Other"/>
<eLiterals name="Muscle" value="1"/>
<eLiterals name="Organ" value="2"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EDataType" name="CountryData" instanceClassName="anydsl.Country"/>
<eClassifiers xsi:type="ecore:EDataType" name="SingleString" instanceClassName="java.lang.String"/>
<eClassifiers xsi:type="ecore:EClass" name="EStringToRecipeMap" instanceClassName="java.util.Map$Entry">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="key" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="value" eType="#//Recipe"/>
</eClassifiers>
</ecore:EPackage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

=== HEADER ===

=== BODY ===

A simple demonstration of a query :
[query: .fromHTMLBodyString('<ol> \n\t<li>Coffee</li> \n\t<li>Tea</li>\n\t<li>Milk</li>\n</ol>')]
[query: .MyTemplate('')]
End of demonstration.
=== FOOTER ===

=== TEMPLATES ===

template MyTemplate (any : java.lang.String)
[query: .fromHTMLBodyString('<ol> \n\t<li>Coffee</li> \n\t<li>Tea</li>\n\t<li>Milk</li>\n</ol>')]
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<genconf:Generation xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:genconf="http://www.obeonetwork.org/m2doc/genconf/1.0" name="fromHTMLBodyString" templateFileName="bug559-bulletlistfromhtml-both-template.docx" resultFileName="bug559-bulletlistfromhtml-both-actual-generation.docx" validationFileName="bug559-bulletlistfromhtml-both-actual-validation.docx">
<options name="UpdateFields" value="false"/>
<options name="IgnoreVersionCheck" value="false"/>
</genconf:Generation>
Loading
Loading