View | Details | Raw Unified | Return to bug 51134
Collapse All | Expand All

(-)src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java (-1 / +70 lines)
Lines 62-67 Link Here
62
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyles;
62
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyles;
63
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl;
63
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl;
64
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc;
64
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc;
65
import org.openxmlformats.schemas.wordprocessingml.x2006.main.NumberingDocument;
65
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CommentsDocument;
66
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CommentsDocument;
66
import org.openxmlformats.schemas.wordprocessingml.x2006.main.DocumentDocument;
67
import org.openxmlformats.schemas.wordprocessingml.x2006.main.DocumentDocument;
67
import org.openxmlformats.schemas.wordprocessingml.x2006.main.EndnotesDocument;
68
import org.openxmlformats.schemas.wordprocessingml.x2006.main.EndnotesDocument;
Lines 645-650 Link Here
645
    }
646
    }
646
647
647
    /**
648
    /**
649
     * Gets the index of the relation we're trying to create
650
     * @param relation
651
     * @return i
652
     */
653
    private int getRelationIndex(XWPFRelation relation) {
654
        List<POIXMLDocumentPart> relations = getRelations();
655
        int i = 1;
656
        for (Iterator<POIXMLDocumentPart> it = relations.iterator(); it.hasNext() ; ) {
657
           POIXMLDocumentPart item = it.next();
658
           if (item.getPackageRelationship().getRelationshipType().equals(relation.getRelation())) {
659
              i++;
660
           }
661
        }
662
        return i;
663
    }
664
665
    /**
648
     * Appends a new paragraph to this document
666
     * Appends a new paragraph to this document
649
     * @return a new paragraph
667
     * @return a new paragraph
650
     */
668
     */
Lines 654-661 Link Here
654
        paragraphs.add(p);
672
        paragraphs.add(p);
655
        return p;
673
        return p;
656
    }
674
    }
657
    
675
658
    /**
676
    /**
677
     * Creates an empty numbering if one does not already exist and sets the numbering member
678
     * @return numbering
679
     */
680
    public XWPFNumbering createNumbering() {
681
        if(numbering == null) {
682
            NumberingDocument numberingDoc = NumberingDocument.Factory.newInstance();
683
684
            XWPFRelation relation = XWPFRelation.NUMBERING;
685
            int i = getRelationIndex(relation);
686
687
            XWPFNumbering wrapper = (XWPFNumbering)createRelationship(relation, XWPFFactory.getInstance(), i);
688
            wrapper.setNumbering(numberingDoc.addNewNumbering());
689
            numbering = wrapper;
690
        }
691
692
        return numbering;
693
    }
694
695
    /**
696
     * Creates an empty styles for the document if one does not already exist
697
     * @return styles
698
     */
699
    public XWPFStyles createStyles() {
700
       if(styles == null) {
701
          StylesDocument stylesDoc = StylesDocument.Factory.newInstance();
702
703
          XWPFRelation relation = XWPFRelation.STYLES;
704
          int i = getRelationIndex(relation);
705
706
          XWPFStyles wrapper = (XWPFStyles)createRelationship(relation, XWPFFactory.getInstance(), i);
707
          wrapper.setStyles(stylesDoc.addNewStyles());
708
          styles = wrapper;
709
       }
710
711
       return styles;
712
    }
713
714
715
    public XWPFFootnote addEndnote(CTFtnEdn note) {
716
       XWPFFootnote footnote = new XWPFFootnote(this, note); 
717
       footnotes.put(note.getId().intValue(), footnote);
718
       return footnote;
719
    }
720
721
    public XWPFFootnote addFootnote(CTFtnEdn note) {
722
       XWPFFootnote endnote = new XWPFFootnote(this, note); 
723
       endnotes.put(note.getId().intValue(), endnote);
724
       return endnote;
725
    }
726
727
    /**
659
     * remove a BodyElement from bodyElements array list 
728
     * remove a BodyElement from bodyElements array list 
660
     * @param pos
729
     * @param pos
661
     * @return true if removing was successfully, else return false
730
     * @return true if removing was successfully, else return false
(-)src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java (-1 / +112 lines)
Lines 24-29 Link Here
24
import java.util.HashMap;
24
import java.util.HashMap;
25
import java.util.List;
25
import java.util.List;
26
import java.util.Map;
26
import java.util.Map;
27
import java.lang.String;
27
28
28
import javax.xml.namespace.QName;
29
import javax.xml.namespace.QName;
29
30
Lines 38-43 Link Here
38
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyles;
39
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyles;
39
import org.openxmlformats.schemas.wordprocessingml.x2006.main.StylesDocument;
40
import org.openxmlformats.schemas.wordprocessingml.x2006.main.StylesDocument;
40
41
42
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
43
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPrDefault;
44
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLanguage;
45
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts;
46
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocDefaults;
41
/**
47
/**
42
 * @author Philipp Epp
48
 * @author Philipp Epp
43
 *
49
 *
Lines 58-64 Link Here
58
		super(part, rel);
64
		super(part, rel);
59
		onDocumentRead();
65
		onDocumentRead();
60
	}
66
	}
67
61
	/**
68
	/**
69
	 * Construct XWPFStyles from scratch for a new document.
70
	 */
71
	public XWPFStyles() {
72
		listStyle = new ArrayList<XWPFStyle>();
73
	}
74
75
	/**
62
	 * Read document
76
	 * Read document
63
	 */
77
	 */
64
	 @Override
78
	 @Override
Lines 95-101 Link Here
95
	    }
109
	    }
96
110
97
	
111
	
98
112
    /**
113
     * Sets the ctStyles
114
     * @param styles
115
     */
116
    public void setStyles(CTStyles styles) {
117
       ctStyles = styles;
118
    }
99
	
119
	
100
	 /**
120
	 /**
101
	  * checks whether style with styleID exist
121
	  * checks whether style with styleID exist
Lines 173-178 Link Here
173
		return usedStyleList;
193
		return usedStyleList;
174
	}
194
	}
175
	
195
	
196
	/**
197
	 * Sets the default spelling language on ctStyles DocDefaults parameter
198
	 * @param strSpellingLanguage
199
	 */
200
	public void setSpellingLanguage(String strSpellingLanguage) {
201
		CTDocDefaults docDefaults = null;
202
		CTRPr runProps = null;
203
		CTLanguage lang = null;
204
205
		// Just making sure we use the members that have already been defined
206
		if(ctStyles.isSetDocDefaults()) {
207
			docDefaults = ctStyles.getDocDefaults();
208
			if(docDefaults.isSetRPrDefault()) {
209
				CTRPrDefault RPrDefault = docDefaults.getRPrDefault();
210
				if(RPrDefault.isSetRPr()) {
211
					runProps = RPrDefault.getRPr();
212
					if(runProps.isSetLang())
213
						lang = runProps.getLang();
214
				}
215
			}
216
		}
217
218
		if(docDefaults == null)
219
			docDefaults = ctStyles.addNewDocDefaults();
220
		if(runProps == null)
221
			runProps = docDefaults.addNewRPrDefault().addNewRPr();
222
		if(lang == null)
223
			lang = runProps.addNewLang();
224
225
		lang.setVal(strSpellingLanguage);
226
		lang.setBidi(strSpellingLanguage);
227
	}
228
229
	/**
230
	 * Sets the default East Asia spelling language on ctStyles DocDefaults parameter
231
	 * @param strEastAsia
232
	 */
233
	public void setEastAsia(String strEastAsia) {
234
		CTDocDefaults docDefaults = null;
235
		CTRPr runProps = null;
236
		CTLanguage lang = null;
237
238
		// Just making sure we use the members that have already been defined
239
		if(ctStyles.isSetDocDefaults()) {
240
			docDefaults = ctStyles.getDocDefaults();
241
			if(docDefaults.isSetRPrDefault()) {
242
				CTRPrDefault RPrDefault = docDefaults.getRPrDefault();
243
				if(RPrDefault.isSetRPr()) {
244
					runProps = RPrDefault.getRPr();
245
					if(runProps.isSetLang())
246
						lang = runProps.getLang();
247
				}
248
			}
249
		}
250
251
		if(docDefaults == null)
252
			docDefaults = ctStyles.addNewDocDefaults();
253
		if(runProps == null)
254
			runProps = docDefaults.addNewRPrDefault().addNewRPr();
255
		if(lang == null)
256
			lang = runProps.addNewLang();
257
258
		lang.setEastAsia(strEastAsia);
259
	}
260
261
	/**
262
	 * Sets the default font on ctStyles DocDefaults parameter
263
	 * @param fonts
264
	 */
265
	public void setDefaultFonts(CTFonts fonts) {
266
		CTDocDefaults docDefaults = null;
267
		CTRPr runProps = null;
268
269
		// Just making sure we use the members that have already been defined
270
		if(ctStyles.isSetDocDefaults()) {
271
			docDefaults = ctStyles.getDocDefaults();
272
			if(docDefaults.isSetRPrDefault()) {
273
				CTRPrDefault RPrDefault = docDefaults.getRPrDefault();
274
				if(RPrDefault.isSetRPr()) {
275
					runProps = RPrDefault.getRPr();
276
				}
277
			}
278
		}
279
280
		if(docDefaults == null)
281
			docDefaults = ctStyles.addNewDocDefaults();
282
		if(runProps == null)
283
			runProps = docDefaults.addNewRPrDefault().addNewRPr();
284
285
		runProps.setRFonts(fonts);
286
	}
176
	
287
	
177
	
288
	
178
	/**
289
	/**
(-)src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFNumbering.java (-4 / +38 lines)
Lines 57-64 Link Here
57
		isNew = true;
57
		isNew = true;
58
		onDocumentRead();
58
		onDocumentRead();
59
	}
59
	}
60
	
60
61
	/**
61
	/**
62
	 * create a new XWPFNumbering object for use in a new document
63
	 */
64
	public XWPFNumbering(){
65
		abstractNums = new ArrayList<XWPFAbstractNum>();
66
		nums = new ArrayList<XWPFNum>();
67
		isNew = true;
68
	}
69
70
	/**
62
	 * read numbering form an existing package
71
	 * read numbering form an existing package
63
	 */
72
	 */
64
	@Override
73
	@Override
Lines 108-113 Link Here
108
        out.close();
117
        out.close();
109
    }
118
    }
110
119
120
121
	/**
122
	 * Sets the ctNumbering
123
	 * @param numbering
124
	 */
125
	public void setNumbering(CTNumbering numbering){
126
		ctNumbering = numbering;
127
	}
111
	
128
	
112
	
129
	
113
	/**
130
	/**
Lines 149-154 Link Here
149
		return ctNum.getNumId();
166
		return ctNum.getNumId();
150
	}
167
	}
151
	
168
	
169
	/**
170
	 * Add a new num with an abstractNumID and a numID
171
	 * @param abstractNumId
172
	 * @param numID
173
	 */
174
	public void addNum(BigInteger abstractNumID, BigInteger numID){
175
		CTNum ctNum = this.ctNumbering.addNewNum();
176
		ctNum.addNewAbstractNumId();
177
		ctNum.getAbstractNumId().setVal(abstractNumID);
178
		ctNum.setNumId(numID);
179
		XWPFNum num = new XWPFNum(ctNum, this);
180
		nums.add(num);
181
	}
152
	
182
	
153
	/**
183
	/**
154
	 * get Num by NumID
184
	 * get Num by NumID
Lines 207-215 Link Here
207
	 */
237
	 */
208
	public BigInteger addAbstractNum(XWPFAbstractNum abstractNum){
238
	public BigInteger addAbstractNum(XWPFAbstractNum abstractNum){
209
		int pos = abstractNums.size();
239
		int pos = abstractNums.size();
210
		ctNumbering.addNewAbstractNum();
240
		if(abstractNum.getAbstractNum() != null){ // Use the current CTAbstractNum if it exists
211
		abstractNum.getAbstractNum().setAbstractNumId(BigInteger.valueOf(pos));
241
			ctNumbering.addNewAbstractNum().set(abstractNum.getAbstractNum());
212
		ctNumbering.setAbstractNumArray(pos, abstractNum.getAbstractNum());
242
		} else {
243
			ctNumbering.addNewAbstractNum();
244
			abstractNum.getAbstractNum().setAbstractNumId(BigInteger.valueOf(pos));
245
			ctNumbering.setAbstractNumArray(pos, abstractNum.getAbstractNum());
246
		}
213
		abstractNums.add(abstractNum);
247
		abstractNums.add(abstractNum);
214
		return abstractNum.getCTAbstractNum().getAbstractNumId();
248
		return abstractNum.getCTAbstractNum().getAbstractNumId();
215
	}
249
	}

Return to bug 51134