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

(-)src/ooxml/java/org/apache/poi/xwpf/usermodel/LineSpacingRule.java (+76 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
package org.apache.poi.xwpf.usermodel;
18
19
import java.util.HashMap;
20
import java.util.Map;
21
22
/**
23
 * Specifies the logic which shall be used to calculate the line spacing of the
24
 * parent object when it is displayed in the document.
25
 * 
26
 * @author Gisella Bronzetti
27
 */
28
public enum LineSpacingRule {
29
30
    /**
31
     * Specifies that the line spacing of the parent object shall be
32
     * automatically determined by the size of its contents, with no
33
     * predetermined minimum or maximum size.
34
     */
35
36
    AUTO(1),
37
38
    /**
39
     * Specifies that the height of the line shall be exactly the value
40
     * specified, regardless of the size of the contents If the contents are too
41
     * large for the specified height, then they shall be clipped as necessary.
42
     */
43
    EXACT(2),
44
45
    /**
46
     * Specifies that the height of the line shall be at least the value
47
     * specified, but may be expanded to fit its content as needed.
48
     */
49
    AT_LEAST(3);
50
51
    
52
    private final int value;
53
54
    private LineSpacingRule(int val) {
55
	value = val;
56
    }
57
58
    public int getValue() {
59
	return value;
60
    }
61
62
    private static Map<Integer, LineSpacingRule> imap = new HashMap<Integer, LineSpacingRule>();
63
    static {
64
	for (LineSpacingRule p : values()) {
65
	    imap.put(p.getValue(), p);
66
	}
67
    }
68
69
    public static LineSpacingRule valueOf(int type) {
70
	LineSpacingRule lineType = imap.get(type);
71
	if (lineType == null)
72
	    throw new IllegalArgumentException("Unknown line type: " + type);
73
	return lineType;
74
    }
75
76
}
(-)src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java (-257 / +294 lines)
Lines 38-43 Link Here
38
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTextAlignment;
38
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTextAlignment;
39
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder;
39
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder;
40
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STJc;
40
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STJc;
41
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STLineSpacingRule;
41
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
42
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
42
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTextAlignment;
43
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTextAlignment;
43
import org.w3c.dom.NodeList;
44
import org.w3c.dom.NodeList;
Lines 59-137 Link Here
59
    private StringBuffer pictureText = new StringBuffer();
60
    private StringBuffer pictureText = new StringBuffer();
60
61
61
    protected XWPFParagraph(CTP prgrph, XWPFDocument docRef) {
62
    protected XWPFParagraph(CTP prgrph, XWPFDocument docRef) {
62
        this.paragraph = prgrph;
63
	this.paragraph = prgrph;
63
        this.document = docRef;
64
	this.document = docRef;
64
65
65
        if (!isEmpty()) {
66
	if (!isEmpty()) {
66
            // All the runs to loop over
67
	    // All the runs to loop over
67
            // TODO - replace this with some sort of XPath expression
68
	    // TODO - replace this with some sort of XPath expression
68
            // to directly find all the CTRs, in the right order
69
	    // to directly find all the CTRs, in the right order
69
            ArrayList<CTR> rs = new ArrayList<CTR>();
70
	    ArrayList<CTR> rs = new ArrayList<CTR>();
70
            CTR[] tmp;
71
	    CTR[] tmp;
71
72
72
            // Get the main text runs
73
	    // Get the main text runs
73
            tmp = paragraph.getRArray();
74
	    tmp = paragraph.getRArray();
74
            for (int i = 0; i < tmp.length; i++) {
75
	    for (int i = 0; i < tmp.length; i++) {
75
                rs.add(tmp[i]);
76
		rs.add(tmp[i]);
76
            }
77
	    }
77
78
78
            // Not sure quite what these are, but they hold
79
	    // Not sure quite what these are, but they hold
79
            // more text runs
80
	    // more text runs
80
            CTSdtRun[] sdts = paragraph.getSdtArray();
81
	    CTSdtRun[] sdts = paragraph.getSdtArray();
81
            for (int i = 0; i < sdts.length; i++) {
82
	    for (int i = 0; i < sdts.length; i++) {
82
                CTSdtContentRun run = sdts[i].getSdtContent();
83
		CTSdtContentRun run = sdts[i].getSdtContent();
83
                tmp = run.getRArray();
84
		tmp = run.getRArray();
84
                for (int j = 0; j < tmp.length; j++) {
85
		for (int j = 0; j < tmp.length; j++) {
85
                    rs.add(tmp[j]);
86
		    rs.add(tmp[j]);
86
                }
87
		}
87
            }
88
	    }
88
89
89
            // Get text of the paragraph
90
	    // Get text of the paragraph
90
            for (int j = 0; j < rs.size(); j++) {
91
	    for (int j = 0; j < rs.size(); j++) {
91
                // Grab the text and tabs of the paragraph
92
		// Grab the text and tabs of the paragraph
92
                // Do so in a way that preserves the ordering
93
		// Do so in a way that preserves the ordering
93
                XmlCursor c = rs.get(j).newCursor();
94
		XmlCursor c = rs.get(j).newCursor();
94
                c.selectPath("./*");
95
		c.selectPath("./*");
95
                while (c.toNextSelection()) {
96
		while (c.toNextSelection()) {
96
                    XmlObject o = c.getObject();
97
		    XmlObject o = c.getObject();
97
                    if (o instanceof CTText) {
98
		    if (o instanceof CTText) {
98
                        text.append(((CTText) o).getStringValue());
99
			text.append(((CTText) o).getStringValue());
99
                    }
100
		    }
100
                    if (o instanceof CTPTab) {
101
		    if (o instanceof CTPTab) {
101
                        text.append("\t");
102
			text.append("\t");
102
                    }
103
		    }
103
                }
104
		}
104
105
105
                // Loop over pictures inside our
106
		// Loop over pictures inside our
106
                // paragraph, looking for text in them
107
		// paragraph, looking for text in them
107
                CTPicture[] picts = rs.get(j).getPictArray();
108
		CTPicture[] picts = rs.get(j).getPictArray();
108
                for (int k = 0; k < picts.length; k++) {
109
		for (int k = 0; k < picts.length; k++) {
109
                    XmlObject[] t = picts[k]
110
		    XmlObject[] t = picts[k]
110
                            .selectPath("declare namespace w='http://schemas.openxmlformats.org/wordprocessingml/2006/main' .//w:t");
111
		                          .selectPath("declare namespace w='http://schemas.openxmlformats.org/wordprocessingml/2006/main' .//w:t");
111
                    for (int m = 0; m < t.length; m++) {
112
		    for (int m = 0; m < t.length; m++) {
112
                        NodeList kids = t[m].getDomNode().getChildNodes();
113
			NodeList kids = t[m].getDomNode().getChildNodes();
113
                        for (int n = 0; n < kids.getLength(); n++) {
114
			for (int n = 0; n < kids.getLength(); n++) {
114
                            if (kids.item(n) instanceof Text) {
115
			    if (kids.item(n) instanceof Text) {
115
                                pictureText.append("\n");
116
				pictureText.append("\n");
116
                                pictureText.append(kids.item(n).getNodeValue());
117
				pictureText.append(kids.item(n).getNodeValue());
117
                            }
118
			    }
118
                        }
119
			}
119
                    }
120
		    }
120
                }
121
		}
121
            }
122
	    }
122
        }
123
	}
123
    }
124
    }
124
125
125
    public CTP getCTP() {
126
    public CTP getCTP() {
126
        return paragraph;
127
	return paragraph;
127
    }
128
    }
128
129
129
    public boolean isEmpty() {
130
    public boolean isEmpty() {
130
        return !paragraph.getDomNode().hasChildNodes();
131
	return !paragraph.getDomNode().hasChildNodes();
131
    }
132
    }
132
133
133
    public XWPFDocument getDocument() {
134
    public XWPFDocument getDocument() {
134
        return document;
135
	return document;
135
    }
136
    }
136
137
137
    /**
138
    /**
Lines 139-145 Link Here
139
     * in it.
140
     * in it.
140
     */
141
     */
141
    public String getText() {
142
    public String getText() {
142
        return getParagraphText() + getPictureText();
143
	return getParagraphText() + getPictureText();
143
    }
144
    }
144
145
145
    /**
146
    /**
Lines 147-160 Link Here
147
     * paragraph
148
     * paragraph
148
     */
149
     */
149
    public String getParagraphText() {
150
    public String getParagraphText() {
150
        return text.toString();
151
	return text.toString();
151
    }
152
    }
152
153
153
    /**
154
    /**
154
     * Returns any text from any suitable pictures in the paragraph
155
     * Returns any text from any suitable pictures in the paragraph
155
     */
156
     */
156
    public String getPictureText() {
157
    public String getPictureText() {
157
        return pictureText.toString();
158
	return pictureText.toString();
158
    }
159
    }
159
160
160
    /**
161
    /**
Lines 163-169 Link Here
163
     * @return a new text run
164
     * @return a new text run
164
     */
165
     */
165
    public XWPFRun createRun() {
166
    public XWPFRun createRun() {
166
        return new XWPFRun(paragraph.addNewR(), this);
167
	return new XWPFRun(paragraph.addNewR(), this);
167
    }
168
    }
168
169
169
    /**
170
    /**
Lines 181-189 Link Here
181
     * @return the paragraph alignment of this paragraph.
182
     * @return the paragraph alignment of this paragraph.
182
     */
183
     */
183
    public ParagraphAlignment getAlignment() {
184
    public ParagraphAlignment getAlignment() {
184
        CTPPr pr = paragraph.getPPr();
185
	CTPPr pr = getCTPPr();
185
        return pr == null || !pr.isSetJc() ? ParagraphAlignment.LEFT
186
	return pr == null || !pr.isSetJc() ? ParagraphAlignment.LEFT
186
                : ParagraphAlignment.valueOf(pr.getJc().getVal().intValue());
187
		: ParagraphAlignment.valueOf(pr.getJc().getVal().intValue());
187
    }
188
    }
188
189
189
    /**
190
    /**
Lines 201-211 Link Here
201
     * @param align the paragraph alignment to apply to this paragraph.
202
     * @param align the paragraph alignment to apply to this paragraph.
202
     */
203
     */
203
    public void setAlignment(ParagraphAlignment align) {
204
    public void setAlignment(ParagraphAlignment align) {
204
        CTPPr pr = paragraph.isSetPPr() ? paragraph.getPPr() : paragraph
205
	CTPPr pr = getCTPPr();
205
                .addNewPPr();
206
	CTJc jc = pr.isSetJc() ? pr.getJc() : pr.addNewJc();
206
        CTJc jc = pr.isSetJc() ? pr.getJc() : pr.addNewJc();
207
	STJc.Enum en = STJc.Enum.forInt(align.getValue());
207
        STJc.Enum en = STJc.Enum.forInt(align.getValue());
208
	jc.setVal(en);
208
        jc.setVal(en);
209
    }
209
    }
210
210
211
    /**
211
    /**
Lines 227-236 Link Here
227
     * @return the vertical alignment of this paragraph.
227
     * @return the vertical alignment of this paragraph.
228
     */
228
     */
229
    public TextAlignment getVerticalAlignment() {
229
    public TextAlignment getVerticalAlignment() {
230
        CTPPr pr = paragraph.getPPr();
230
	CTPPr pr = getCTPPr();
231
        return pr == null || !pr.isSetTextAlignment() ? TextAlignment.AUTO
231
	return (pr == null || !pr.isSetTextAlignment()) ? TextAlignment.AUTO
232
                : TextAlignment.valueOf(pr.getTextAlignment().getVal()
232
		: TextAlignment.valueOf(pr.getTextAlignment().getVal()
233
                .intValue());
233
			.intValue());
234
    }
234
    }
235
235
236
    /**
236
    /**
Lines 253-265 Link Here
253
     *               paragraph.
253
     *               paragraph.
254
     */
254
     */
255
    public void setVerticalAlignment(TextAlignment valign) {
255
    public void setVerticalAlignment(TextAlignment valign) {
256
        CTPPr pr = paragraph.isSetPPr() ? paragraph.getPPr() : paragraph
256
	CTPPr pr = getCTPPr();
257
                .addNewPPr();
257
	CTTextAlignment textAlignment = pr.isSetTextAlignment() ? pr
258
        CTTextAlignment textAlignment = pr.isSetTextAlignment() ? pr
258
		.getTextAlignment() : pr.addNewTextAlignment();
259
                .getTextAlignment() : pr.addNewTextAlignment();
259
		STTextAlignment.Enum en = STTextAlignment.Enum
260
        STTextAlignment.Enum en = STTextAlignment.Enum
260
		.forInt(valign.getValue());
261
                .forInt(valign.getValue());
261
		textAlignment.setVal(en);
262
        textAlignment.setVal(en);
263
    }
262
    }
264
263
265
    /**
264
    /**
Lines 290-301 Link Here
290
     * @see Borders for a list of all types of borders
289
     * @see Borders for a list of all types of borders
291
     */
290
     */
292
    public void setBorderTop(Borders border) {
291
    public void setBorderTop(Borders border) {
293
        CTPBdr ct = getCTPBrd(true);
292
	CTPBdr ct = getCTPBrd(true);
294
        CTBorder pr = ct.isSetTop() ? ct.getTop() : ct.addNewTop();
293
295
        if (border.getValue() == Borders.NONE.getValue())
294
	CTBorder pr = (ct != null && ct.isSetTop()) ? ct.getTop() : ct.addNewTop();
296
            ct.unsetTop();
295
	if (border.getValue() == Borders.NONE.getValue())
297
        else
296
	    ct.unsetTop();
298
            pr.setVal(STBorder.Enum.forInt(border.getValue()));
297
	else
298
	    pr.setVal(STBorder.Enum.forInt(border.getValue()));
299
    }
299
    }
300
300
301
    /**
301
    /**
Lines 307-320 Link Here
307
     * @see Borders a list of all types of borders
307
     * @see Borders a list of all types of borders
308
     */
308
     */
309
    public Borders getBorderTop() {
309
    public Borders getBorderTop() {
310
        CTPBdr border = getCTPBrd(false);
310
	CTPBdr border = getCTPBrd(false);
311
        CTBorder ct;
311
	CTBorder ct = null;
312
        if (border != null) {
312
	if (border != null) {
313
            ct = border.getTop();
313
	    ct = border.getTop();
314
            STBorder.Enum ptrn = ct != null ? ct.getVal() : STBorder.NONE;
314
	}
315
            return Borders.valueOf(ptrn.intValue());
315
	STBorder.Enum ptrn = (ct != null) ? ct.getVal() : STBorder.NONE;
316
        }
316
	return Borders.valueOf(ptrn.intValue());
317
        return Borders.NONE;
318
    }
317
    }
319
318
320
    /**
319
    /**
Lines 345-356 Link Here
345
     * @see Borders a list of all types of borders
344
     * @see Borders a list of all types of borders
346
     */
345
     */
347
    public void setBorderBottom(Borders border) {
346
    public void setBorderBottom(Borders border) {
348
        CTPBdr ct = getCTPBrd(true);
347
	CTPBdr ct = getCTPBrd(true);
349
        CTBorder pr = ct.isSetBottom() ? ct.getBottom() : ct.addNewBottom();
348
	CTBorder pr = ct.isSetBottom() ? ct.getBottom() : ct.addNewBottom();
350
        if (border.getValue() == Borders.NONE.getValue())
349
	if (border.getValue() == Borders.NONE.getValue())
351
            ct.unsetBottom();
350
	    ct.unsetBottom();
352
        else
351
	else
353
            pr.setVal(STBorder.Enum.forInt(border.getValue()));
352
	    pr.setVal(STBorder.Enum.forInt(border.getValue()));
354
    }
353
    }
355
354
356
    /**
355
    /**
Lines 362-374 Link Here
362
     * @see Borders a list of all types of borders
361
     * @see Borders a list of all types of borders
363
     */
362
     */
364
    public Borders getBorderBottom() {
363
    public Borders getBorderBottom() {
365
        CTPBdr border = getCTPBrd(false);
364
	CTPBdr border = getCTPBrd(false);
366
        CTBorder ct = null;
365
	CTBorder ct = null;
367
        if (border != null) {
366
	if (border != null) {
368
            ct = border.getBottom();
367
	    ct = border.getBottom();
369
        }
368
	}
370
        STBorder.Enum ptrn = ct != null ? ct.getVal() : STBorder.NONE;
369
	STBorder.Enum ptrn = ct != null ? ct.getVal() : STBorder.NONE;
371
        return Borders.valueOf(ptrn.intValue());
370
	return Borders.valueOf(ptrn.intValue());
372
    }
371
    }
373
372
374
    /**
373
    /**
Lines 394-405 Link Here
394
     * @see Borders for a list of all possible borders
393
     * @see Borders for a list of all possible borders
395
     */
394
     */
396
    public void setBorderLeft(Borders border) {
395
    public void setBorderLeft(Borders border) {
397
        CTPBdr ct = getCTPBrd(true);
396
	CTPBdr ct = getCTPBrd(true);
398
        CTBorder pr = ct.isSetLeft() ? ct.getLeft() : ct.addNewLeft();
397
	CTBorder pr = ct.isSetLeft() ? ct.getLeft() : ct.addNewLeft();
399
        if (border.getValue() == Borders.NONE.getValue())
398
	if (border.getValue() == Borders.NONE.getValue())
400
            ct.unsetLeft();
399
	    ct.unsetLeft();
401
        else
400
	else
402
            pr.setVal(STBorder.Enum.forInt(border.getValue()));
401
	    pr.setVal(STBorder.Enum.forInt(border.getValue()));
403
    }
402
    }
404
403
405
    /**
404
    /**
Lines 411-423 Link Here
411
     * @see Borders for a list of all possible borders
410
     * @see Borders for a list of all possible borders
412
     */
411
     */
413
    public Borders getBorderLeft() {
412
    public Borders getBorderLeft() {
414
        CTPBdr border = getCTPBrd(false);
413
	CTPBdr border = getCTPBrd(false);
415
        CTBorder ct = null;
414
	CTBorder ct = null;
416
        if (border != null) {
415
	if (border != null) {
417
            ct = border.getLeft();
416
	    ct = border.getLeft();
418
        }
417
	}
419
        STBorder.Enum ptrn = ct != null ? ct.getVal() : STBorder.NONE;
418
	STBorder.Enum ptrn = ct != null ? ct.getVal() : STBorder.NONE;
420
        return Borders.valueOf(ptrn.intValue());
419
	return Borders.valueOf(ptrn.intValue());
421
    }
420
    }
422
421
423
    /**
422
    /**
Lines 443-454 Link Here
443
     * @see Borders for a list of all possible borders
442
     * @see Borders for a list of all possible borders
444
     */
443
     */
445
    public void setBorderRight(Borders border) {
444
    public void setBorderRight(Borders border) {
446
        CTPBdr ct = getCTPBrd(true);
445
	CTPBdr ct = getCTPBrd(true);
447
        CTBorder pr = ct.isSetRight() ? ct.getRight() : ct.addNewRight();
446
	CTBorder pr = ct.isSetRight() ? ct.getRight() : ct.addNewRight();
448
        if (border.getValue() == Borders.NONE.getValue())
447
	if (border.getValue() == Borders.NONE.getValue())
449
            ct.unsetRight();
448
	    ct.unsetRight();
450
        else
449
	else
451
            pr.setVal(STBorder.Enum.forInt(border.getValue()));
450
	    pr.setVal(STBorder.Enum.forInt(border.getValue()));
452
    }
451
    }
453
452
454
    /**
453
    /**
Lines 460-472 Link Here
460
     * @see Borders for a list of all possible borders
459
     * @see Borders for a list of all possible borders
461
     */
460
     */
462
    public Borders getBorderRight() {
461
    public Borders getBorderRight() {
463
        CTPBdr border = getCTPBrd(false);
462
	CTPBdr border = getCTPBrd(false);
464
        CTBorder ct = null;
463
	CTBorder ct = null;
465
        if (border != null) {
464
	if (border != null) {
466
            ct = border.getRight();
465
	    ct = border.getRight();
467
        }
466
	}
468
        STBorder.Enum ptrn = ct != null ? ct.getVal() : STBorder.NONE;
467
	STBorder.Enum ptrn = ct != null ? ct.getVal() : STBorder.NONE;
469
        return Borders.valueOf(ptrn.intValue());
468
	return Borders.valueOf(ptrn.intValue());
470
    }
469
    }
471
470
472
    /**
471
    /**
Lines 496-507 Link Here
496
     * @see Borders for a list of all possible borders
495
     * @see Borders for a list of all possible borders
497
     */
496
     */
498
    public void setBorderBetween(Borders border) {
497
    public void setBorderBetween(Borders border) {
499
        CTPBdr ct = getCTPBrd(true);
498
	CTPBdr ct = getCTPBrd(true);
500
        CTBorder pr = ct.isSetBetween() ? ct.getBetween() : ct.addNewBetween();
499
	CTBorder pr = ct.isSetBetween() ? ct.getBetween() : ct.addNewBetween();
501
        if (border.getValue() == Borders.NONE.getValue())
500
	if (border.getValue() == Borders.NONE.getValue())
502
            ct.unsetBetween();
501
	    ct.unsetBetween();
503
        else
502
	else
504
            pr.setVal(STBorder.Enum.forInt(border.getValue()));
503
	    pr.setVal(STBorder.Enum.forInt(border.getValue()));
505
    }
504
    }
506
505
507
    /**
506
    /**
Lines 513-525 Link Here
513
     * @see Borders for a list of all possible borders
512
     * @see Borders for a list of all possible borders
514
     */
513
     */
515
    public Borders getBorderBetween() {
514
    public Borders getBorderBetween() {
516
        CTPBdr border = getCTPBrd(false);
515
	CTPBdr border = getCTPBrd(false);
517
        CTBorder ct = null;
516
	CTBorder ct = null;
518
        if (border != null) {
517
	if (border != null) {
519
            ct = border.getBetween();
518
	    ct = border.getBetween();
520
        }
519
	}
521
        STBorder.Enum ptrn = ct != null ? ct.getVal() : STBorder.NONE;
520
	STBorder.Enum ptrn = ct != null ? ct.getVal() : STBorder.NONE;
522
        return Borders.valueOf(ptrn.intValue());
521
	return Borders.valueOf(ptrn.intValue());
523
    }
522
    }
524
523
525
    /**
524
    /**
Lines 539-551 Link Here
539
     *                  boolean value
538
     *                  boolean value
540
     */
539
     */
541
    public void setPageBreak(boolean pageBreak) {
540
    public void setPageBreak(boolean pageBreak) {
542
        CTPPr ppr = getCTPPr();
541
	CTPPr ppr = getCTPPr();
543
        CTOnOff ct_pageBreak = ppr.isSetPageBreakBefore() ? ppr
542
	CTOnOff ct_pageBreak = ppr.isSetPageBreakBefore() ? ppr
544
                .getPageBreakBefore() : ppr.addNewPageBreakBefore();
543
		.getPageBreakBefore() : ppr.addNewPageBreakBefore();
545
        if (pageBreak)
544
		if (pageBreak)
546
            ct_pageBreak.setVal(STOnOff.TRUE);
545
		    ct_pageBreak.setVal(STOnOff.TRUE);
547
        else
546
		else
548
            ct_pageBreak.setVal(STOnOff.FALSE);
547
		    ct_pageBreak.setVal(STOnOff.FALSE);
549
    }
548
    }
550
549
551
    /**
550
    /**
Lines 564-577 Link Here
564
     * @return boolean - if page break is set
563
     * @return boolean - if page break is set
565
     */
564
     */
566
    public boolean isPageBreak() {
565
    public boolean isPageBreak() {
567
        CTPPr ppr = getCTPPr();
566
	CTPPr ppr = getCTPPr();
568
        CTOnOff ct_pageBreak = ppr.isSetPageBreakBefore() ? ppr
567
	CTOnOff ct_pageBreak = ppr.isSetPageBreakBefore() ? ppr
569
                .getPageBreakBefore() : null;
568
		.getPageBreakBefore() : null;
570
        if (ct_pageBreak != null
569
		if (ct_pageBreak != null
571
                && ct_pageBreak.getVal().intValue() == STOnOff.INT_TRUE)
570
			&& ct_pageBreak.getVal().intValue() == STOnOff.INT_TRUE)
572
            return true;
571
		    return true;
573
        else
572
		else
574
            return false;
573
		    return false;
575
    }
574
    }
576
575
577
    /**
576
    /**
Lines 586-606 Link Here
586
     *               a positive whole number, whose contents consist of a
585
     *               a positive whole number, whose contents consist of a
587
     *               measurement in twentieths of a point.
586
     *               measurement in twentieths of a point.
588
     */
587
     */
589
    public void setSpacingAfter(BigInteger spaces) {
588
    public void setSpacingAfter(int spaces) {
590
        CTSpacing spacing = getCTSpacing(true);
589
	CTSpacing spacing = getCTSpacing(true);
591
        if (spacing != null)
590
	if (spacing != null){
592
            spacing.setAfter(spaces);
591
	    BigInteger bi=new BigInteger(""+spaces);
592
	    spacing.setAfter(bi);
593
	}
594
593
    }
595
    }
594
596
595
    /**
597
    /**
596
     * Specifies the spacing that should be added after the last line in this
598
     * Specifies the spacing that should be added after the last line in this
597
     * paragraph in the document in absolute units.
599
     * paragraph in the document in absolute units.
598
     *
600
     *
599
     * @return bigInteger - value representing the spacing after the paragraph
601
     * @return int - value representing the spacing after the paragraph
600
     */
602
     */
601
    public BigInteger getSpacingAfter() {
603
    public int getSpacingAfter() {
602
        CTSpacing spacing = getCTSpacing(false);
604
	CTSpacing spacing = getCTSpacing(false);
603
        return spacing.isSetAfter() ? spacing.getAfter() : null;
605
	return (spacing != null && spacing.isSetAfter()) ? spacing.getAfter().intValue() : -1;
604
    }
606
    }
605
607
606
    /**
608
    /**
Lines 620-628 Link Here
620
     *               a positive whole number, whose contents consist of a
622
     *               a positive whole number, whose contents consist of a
621
     *               measurement in twentieths of a
623
     *               measurement in twentieths of a
622
     */
624
     */
623
    public void setSpacingAfterLines(BigInteger spaces) {
625
    public void setSpacingAfterLines(int spaces) {
624
        CTSpacing spacing = getCTSpacing(true);
626
	CTSpacing spacing = getCTSpacing(true);
625
        spacing.setAfterLines(spaces);
627
	BigInteger bi=new BigInteger(""+spaces);
628
	spacing.setAfterLines(bi);
626
    }
629
    }
627
630
628
631
Lines 633-643 Link Here
633
     * @return bigInteger - value representing the spacing after the paragraph
636
     * @return bigInteger - value representing the spacing after the paragraph
634
     * @see #setSpacingAfterLines(BigInteger)
637
     * @see #setSpacingAfterLines(BigInteger)
635
     */
638
     */
636
    public BigInteger getSpacingAfterLines() {
639
    public int getSpacingAfterLines() {
637
        CTSpacing spacing = getCTSpacing(false);
640
	CTSpacing spacing = getCTSpacing(false);
638
        return spacing.isSetAfterLines() ? spacing.getAfterLines() : null;
641
	return (spacing != null && spacing.isSetAfterLines() ) ? spacing.getAfterLines().intValue() : -1;
639
    }
642
    }
640
643
644
645
641
    /**
646
    /**
642
     * Specifies the spacing that should be added above the first line in this
647
     * Specifies the spacing that should be added above the first line in this
643
     * paragraph in the document in absolute units.
648
     * paragraph in the document in absolute units.
Lines 648-656 Link Here
648
     *
653
     *
649
     * @param spaces
654
     * @param spaces
650
     */
655
     */
651
    public void setSpacingBefore(BigInteger spaces) {
656
    public void setSpacingBefore(int spaces) {
652
        CTSpacing spacing = getCTSpacing(true);
657
	CTSpacing spacing = getCTSpacing(true);
653
        spacing.setBefore(spaces);
658
	BigInteger bi=new BigInteger(""+spaces);
659
	spacing.setBefore(bi);
654
    }
660
    }
655
661
656
    /**
662
    /**
Lines 660-668 Link Here
660
     * @return the spacing that should be added above the first line
666
     * @return the spacing that should be added above the first line
661
     * @see #setSpacingBefore(BigInteger)
667
     * @see #setSpacingBefore(BigInteger)
662
     */
668
     */
663
    public BigInteger getSpacingBefore() {
669
    public int getSpacingBefore() {
664
        CTSpacing spacing = getCTSpacing(false);
670
	CTSpacing spacing = getCTSpacing(false);
665
        return spacing.isSetBefore() ? spacing.getBefore() : null;
671
	return (spacing != null && spacing.isSetBefore()) ? spacing.getBefore().intValue() : -1;
666
    }
672
    }
667
673
668
    /**
674
    /**
Lines 677-685 Link Here
677
     *
683
     *
678
     * @param spaces
684
     * @param spaces
679
     */
685
     */
680
    public void setSpacingBeforeLines(BigInteger spaces) {
686
    public void setSpacingBeforeLines(int spaces) {
681
        CTSpacing spacing = getCTSpacing(true);
687
	CTSpacing spacing = getCTSpacing(true);
682
        spacing.setBeforeLines(spaces);
688
	BigInteger bi=new BigInteger(""+spaces);
689
	spacing.setBeforeLines(bi);
683
    }
690
    }
684
691
685
    /**
692
    /**
Lines 690-701 Link Here
690
     * @return the spacing that should be added before the first line in this paragraph
697
     * @return the spacing that should be added before the first line in this paragraph
691
     * @see #setSpacingBeforeLines(BigInteger)
698
     * @see #setSpacingBeforeLines(BigInteger)
692
     */
699
     */
693
    public BigInteger getSpacingBeforeLines() {
700
    public int getSpacingBeforeLines() {
694
        CTSpacing spacing = getCTSpacing(false);
701
	CTSpacing spacing = getCTSpacing(false);
695
        return spacing.isSetBeforeLines() ? spacing.getBeforeLines() : null;
702
	return (spacing != null && spacing.isSetBeforeLines()) ? spacing.getBeforeLines().intValue() : -1;
696
    }
703
    }
697
704
705
698
    /**
706
    /**
707
     * Specifies how the spacing between lines is calculated as stored in the
708
     * line attribute. If this attribute is omitted, then it shall be assumed to
709
     * be of a value auto if a line attribute value is present.
710
     * 
711
     * @see LineSpacingRule
712
     * @param rule
713
     */
714
    public void setSpacingLineRule(LineSpacingRule rule) {
715
	CTSpacing spacing = getCTSpacing(true);
716
	spacing.setLineRule(STLineSpacingRule.Enum.forInt(rule.getValue()));
717
    }
718
719
    /**
720
     * 
721
     * Specifies how the spacing between lines is calculated as stored in the
722
     * line attribute. If this attribute is omitted, then it shall be assumed to
723
     * be of a value auto if a line attribute value is present.
724
     * 
725
     * @see LineSpacingRule
726
     * @see #setSpacingLineRule(LineSpacingRule)
727
     * @return rule
728
     */
729
    public LineSpacingRule getSpacingLineRule() {
730
	CTSpacing spacing = getCTSpacing(false);
731
	return (spacing != null && spacing.isSetLineRule()) ? LineSpacingRule.valueOf(spacing
732
		.getLineRule().intValue()) : LineSpacingRule.AUTO;
733
    }
734
735
736
    /**
699
     * Specifies the indentation which shall be placed between the left text
737
     * Specifies the indentation which shall be placed between the left text
700
     * margin for this paragraph and the left edge of that paragraph's content
738
     * margin for this paragraph and the left edge of that paragraph's content
701
     * in a left to right paragraph, and the right text margin and the right
739
     * in a left to right paragraph, and the right text margin and the right
Lines 708-716 Link Here
708
     *
746
     *
709
     * @param indentation
747
     * @param indentation
710
     */
748
     */
711
    public void setIndentationLeft(BigInteger indentation) {
749
    public void setIndentationLeft(int indentation) {
712
        CTInd indent = getCTInd(true);
750
	CTInd indent = getCTInd(true);
713
        indent.setLeft(indentation);
751
	BigInteger bi=new BigInteger(""+indentation);
752
	indent.setLeft(bi);
714
    }
753
    }
715
754
716
    /**
755
    /**
Lines 726-735 Link Here
726
     *
765
     *
727
     * @return indentation or null if indentation is not set
766
     * @return indentation or null if indentation is not set
728
     */
767
     */
729
    public BigInteger getIndentationLeft() {
768
    public int getIndentationLeft() {
730
        CTInd indentation = getCTInd(false);
769
	CTInd indentation = getCTInd(false);
731
        return indentation.isSetLeft() ? indentation.getLeft()
770
	return (indentation != null && indentation.isSetLeft()) ? indentation.getLeft().intValue()
732
                : new BigInteger("0");
771
		: -1;
733
    }
772
    }
734
773
735
    /**
774
    /**
Lines 745-753 Link Here
745
     *
784
     *
746
     * @param indentation
785
     * @param indentation
747
     */
786
     */
748
    public void setIndentationRight(BigInteger indentation) {
787
    public void setIndentationRight(int indentation) {
749
        CTInd indent = getCTInd(true);
788
	CTInd indent = getCTInd(true);
750
        indent.setRight(indentation);
789
	BigInteger bi=new BigInteger(""+indentation);
790
	indent.setRight(bi);
751
    }
791
    }
752
792
753
    /**
793
    /**
Lines 764-773 Link Here
764
     * @return indentation or null if indentation is not set
804
     * @return indentation or null if indentation is not set
765
     */
805
     */
766
806
767
    public BigInteger getIndentationRight() {
807
    public int getIndentationRight() {
768
        CTInd indentation = getCTInd(false);
808
	CTInd indentation = getCTInd(false);
769
        return indentation.isSetRight() ? indentation.getRight()
809
	return (indentation != null && indentation.isSetRight()) ? indentation.getRight().intValue()
770
                : new BigInteger("0");
810
		: -1;
771
    }
811
    }
772
812
773
    /**
813
    /**
Lines 784-792 Link Here
784
     * @param indentation
824
     * @param indentation
785
     */
825
     */
786
826
787
    public void setIndentationHanging(BigInteger indentation) {
827
    public void setIndentationHanging(int indentation) {
788
        CTInd indent = getCTInd(true);
828
	CTInd indent = getCTInd(true);
789
        indent.setHanging(indentation);
829
	BigInteger bi=new BigInteger(""+indentation);
830
	indent.setHanging(bi);
790
    }
831
    }
791
832
792
    /**
833
    /**
Lines 802-810 Link Here
802
     *
843
     *
803
     * @return indentation or null if indentation is not set
844
     * @return indentation or null if indentation is not set
804
     */
845
     */
805
    public BigInteger getIndentationHanging() {
846
    public int getIndentationHanging() {
806
        CTInd indentation = getCTInd(false);
847
	CTInd indentation = getCTInd(false);
807
        return indentation.isSetHanging() ? indentation.getHanging() : null;
848
	return (indentation != null && indentation.isSetHanging()) ? indentation.getHanging().intValue() : -1;
808
    }
849
    }
809
850
810
    /**
851
    /**
Lines 821-829 Link Here
821
     *
862
     *
822
     * @param indentation
863
     * @param indentation
823
     */
864
     */
824
    public void setIndentationFirstLine(BigInteger indentation) {
865
    public void setIndentationFirstLine(int indentation) {
825
        CTInd indent = getCTInd(true);
866
	CTInd indent = getCTInd(true);
826
        indent.setFirstLine(indentation);
867
	BigInteger bi=new BigInteger(""+indentation);
868
	indent.setFirstLine(bi);
827
    }
869
    }
828
870
829
    /**
871
    /**
Lines 841-850 Link Here
841
     *
883
     *
842
     * @return indentation or null if indentation is not set
884
     * @return indentation or null if indentation is not set
843
     */
885
     */
844
    public BigInteger getIndentationFirstLine() {
886
    public int getIndentationFirstLine() {
845
        CTInd indentation = getCTInd(false);
887
	CTInd indentation = getCTInd(false);
846
        return indentation.isSetFirstLine() ? indentation.getFirstLine()
888
	return (indentation != null && indentation.isSetFirstLine()) ? indentation.getFirstLine().intValue()
847
                : new BigInteger("0");
889
		: -1;
848
    }
890
    }
849
891
850
    /**
892
    /**
Lines 856-867 Link Here
856
     * @param wrap - boolean
898
     * @param wrap - boolean
857
     */
899
     */
858
    public void setWordWrap(boolean wrap) {
900
    public void setWordWrap(boolean wrap) {
859
        CTOnOff wordWrap = getCTPPr().isSetWordWrap() ? getCTPPr()
901
	CTOnOff wordWrap = getCTPPr().isSetWordWrap() ? getCTPPr()
860
                .getWordWrap() : getCTPPr().addNewWordWrap();
902
		.getWordWrap() : getCTPPr().addNewWordWrap();
861
        if (wrap)
903
		if (wrap)
862
            wordWrap.setVal(STOnOff.TRUE);
904
		    wordWrap.setVal(STOnOff.TRUE);
863
        else
905
		else
864
            wordWrap.unsetVal();
906
		    wordWrap.unsetVal();
865
    }
907
    }
866
908
867
    /**
909
    /**
Lines 873-886 Link Here
873
     * @return boolean
915
     * @return boolean
874
     */
916
     */
875
    public boolean isWordWrap() {
917
    public boolean isWordWrap() {
876
        CTOnOff wordWrap = getCTPPr().isSetWordWrap() ? getCTPPr()
918
	CTOnOff wordWrap = getCTPPr().isSetWordWrap() ? getCTPPr()
877
                .getWordWrap() : null;
919
		.getWordWrap() : null;
878
        if (wordWrap != null) {
920
		if (wordWrap != null) {
879
            return (wordWrap.getVal() == STOnOff.ON
921
		    return (wordWrap.getVal() == STOnOff.ON
880
                    || wordWrap.getVal() == STOnOff.TRUE || wordWrap.getVal() == STOnOff.X_1) ? true
922
			    || wordWrap.getVal() == STOnOff.TRUE || wordWrap.getVal() == STOnOff.X_1) ? true
881
                    : false;
923
				    : false;
882
        } else
924
		} else
883
            return false;
925
		    return false;
884
    }
926
    }
885
927
886
    /**
928
    /**
Lines 888-901 Link Here
888
     * a new instance.
930
     * a new instance.
889
     */
931
     */
890
    private CTPBdr getCTPBrd(boolean create) {
932
    private CTPBdr getCTPBrd(boolean create) {
891
        CTPPr pr = getCTPPr();
933
	CTPPr pr = getCTPPr();
892
        if (pr != null) {
934
	CTPBdr ct = pr.isSetPBdr() ? pr.getPBdr() : null;
893
            CTPBdr ct = pr.isSetPBdr() ? pr.getPBdr() : null;
935
	if (create && ct == null)
894
            if (create && ct == null)
936
	    ct = pr.addNewPBdr();
895
                ct = pr.addNewPBdr();
937
	return ct;
896
            return ct;
897
        }
898
        return null;
899
    }
938
    }
900
939
901
    /**
940
    /**
Lines 903-916 Link Here
903
     * return a new instance.
942
     * return a new instance.
904
     */
943
     */
905
    private CTSpacing getCTSpacing(boolean create) {
944
    private CTSpacing getCTSpacing(boolean create) {
906
        CTPPr pr = getCTPPr();
945
	CTPPr pr = getCTPPr();
907
        if (pr != null) {
946
	CTSpacing ct = pr.getSpacing() == null ? null : pr.getSpacing();
908
            CTSpacing ct = pr.isSetSpacing() ? pr.getSpacing() : null;
947
	if (create && ct == null)
909
            if (create && ct == null)
948
	    ct = pr.addNewSpacing();
910
                ct = pr.addNewSpacing();
949
	return ct;
911
            return ct;
912
        }
913
        return null;
914
    }
950
    }
915
951
916
    /**
952
    /**
Lines 918-937 Link Here
918
     * a new instance.
954
     * a new instance.
919
     */
955
     */
920
    private CTInd getCTInd(boolean create) {
956
    private CTInd getCTInd(boolean create) {
921
        CTPPr pr = getCTPPr();
957
	CTPPr pr = getCTPPr();
922
        if (pr != null) {
958
	CTInd ct = pr.getInd() == null ? null : pr.getInd();
923
            CTInd ct = pr.isSetInd() ? pr.getInd() : null;
959
	if (create && ct == null)
924
            if (create && ct == null)
960
	    ct = pr.addNewInd();
925
                ct = pr.addNewInd();
961
	return ct;
926
            return ct;
927
        }
928
        return null;
929
    }
962
    }
930
963
964
    /**
965
     * Get a <b>copy</b> of the currently used CTPPr, if none is used, return
966
     * a new instance.
967
     */
931
    private CTPPr getCTPPr() {
968
    private CTPPr getCTPPr() {
932
        CTPPr pr = paragraph.getPPr() == null ? paragraph.addNewPPr()
969
	CTPPr pr = paragraph.getPPr() == null ? paragraph.addNewPPr()
933
                : paragraph.getPPr();
970
		: paragraph.getPPr();
934
        return pr;
971
	return pr;
935
    }
972
    }
936
973
937
}
974
}
(-)src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java (-17 / +65 lines)
Lines 21-27 Link Here
21
21
22
import junit.framework.TestCase;
22
import junit.framework.TestCase;
23
23
24
import org.openxmlformats.schemas.officeDocument.x2006.math.STSpacingRule;
24
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder;
25
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder;
26
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTInd;
25
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTJc;
27
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTJc;
26
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff;
28
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff;
27
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
29
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
Lines 31-39 Link Here
31
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTextAlignment;
33
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTextAlignment;
32
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder;
34
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder;
33
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STJc;
35
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STJc;
36
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STLineSpacingRule;
34
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
37
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
35
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTextAlignment;
38
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTextAlignment;
36
import org.apache.poi.POIXMLDocument;
37
39
38
/**
40
/**
39
 * Tests for XWPF Paragraphs
41
 * Tests for XWPF Paragraphs
Lines 44-50 Link Here
44
     */
46
     */
45
    private XWPFDocument xml;
47
    private XWPFDocument xml;
46
    private File file;
48
    private File file;
47
49
/*
48
    protected void setUp() throws Exception {
50
    protected void setUp() throws Exception {
49
        super.setUp();
51
        super.setUp();
50
52
Lines 55-64 Link Here
55
        assertTrue(file.exists());
57
        assertTrue(file.exists());
56
        xml = new XWPFDocument(POIXMLDocument.openPackage(file.toString()));
58
        xml = new XWPFDocument(POIXMLDocument.openPackage(file.toString()));
57
    }
59
    }
58
60
*/
59
    /**
61
    /**
60
     * Check that we get the right paragraph from the header
62
     * Check that we get the right paragraph from the header
61
     */
63
     */
64
    /*
62
    public void testHeaderParagraph() throws Exception {
65
    public void testHeaderParagraph() throws Exception {
63
        XWPFHeader hdr = xml.getHeaderFooterPolicy().getDefaultHeader();
66
        XWPFHeader hdr = xml.getHeaderFooterPolicy().getDefaultHeader();
64
        assertNotNull(hdr);
67
        assertNotNull(hdr);
Lines 71-80 Link Here
71
        assertEquals("First header column!\tMid header\tRight header!", p
74
        assertEquals("First header column!\tMid header\tRight header!", p
72
                .getText());
75
                .getText());
73
    }
76
    }
74
77
*/
75
    /**
78
    /**
76
     * Check that we get the right paragraphs from the document
79
     * Check that we get the right paragraphs from the document
77
     */
80
     */
81
    /*
78
    public void testDocumentParagraph() throws Exception {
82
    public void testDocumentParagraph() throws Exception {
79
        XWPFParagraph[] ps = xml.getParagraphs();
83
        XWPFParagraph[] ps = xml.getParagraphs();
80
        assertEquals(10, ps.length);
84
        assertEquals(10, ps.length);
Lines 96-115 Link Here
96
        assertFalse(ps[4].isEmpty());
100
        assertFalse(ps[4].isEmpty());
97
        assertEquals("More on page one", ps[4].getText());
101
        assertEquals("More on page one", ps[4].getText());
98
    }
102
    }
99
103
*/
100
    public void testSetGetBorderTop() {
104
    public void testSetGetBorderTop() {
101
        //new clean instance of paragraph
105
        //new clean instance of paragraph
102
        XWPFDocument doc = new XWPFDocument();
106
        XWPFDocument doc = new XWPFDocument();
103
        XWPFParagraph p = doc.createParagraph();
107
        XWPFParagraph p = doc.createParagraph();
104
108
109
        assertEquals(STBorder.NONE.intValue(), p.getBorderTop().getValue());
110
        
105
        CTP ctp = p.getCTP();
111
        CTP ctp = p.getCTP();
106
        CTPPr ppr = ctp.addNewPPr();
112
        CTPPr ppr = ctp.getPPr()== null? ctp.addNewPPr() : ctp.getPPr();
113
        
107
        //bordi
114
        //bordi
108
        CTPBdr bdr = ppr.addNewPBdr();
115
        CTPBdr bdr = ppr.addNewPBdr();
109
        CTBorder borderTop = bdr.addNewTop();
116
        CTBorder borderTop = bdr.addNewTop();
110
        borderTop.setVal(STBorder.APPLES);
117
        borderTop.setVal(STBorder.DOUBLE);
111
        bdr.setTop(borderTop);
118
        bdr.setTop(borderTop);
112
        assertEquals(Borders.APPLES, p.getBorderTop());
119
        
120
        assertEquals(Borders.DOUBLE, p.getBorderTop());
113
        p.setBorderTop(Borders.SINGLE);
121
        p.setBorderTop(Borders.SINGLE);
114
        assertEquals(STBorder.SINGLE, borderTop.getVal());
122
        assertEquals(STBorder.SINGLE, borderTop.getVal());
115
    }
123
    }
Lines 119-126 Link Here
119
        XWPFDocument doc = new XWPFDocument();
127
        XWPFDocument doc = new XWPFDocument();
120
        XWPFParagraph p = doc.createParagraph();
128
        XWPFParagraph p = doc.createParagraph();
121
129
130
        assertEquals(STJc.LEFT.intValue(), p.getAlignment().getValue());
131
        
122
        CTP ctp = p.getCTP();
132
        CTP ctp = p.getCTP();
123
        CTPPr ppr = ctp.addNewPPr();
133
        CTPPr ppr = ctp.getPPr()== null? ctp.addNewPPr() : ctp.getPPr();
124
134
125
        CTJc align = ppr.addNewJc();
135
        CTJc align = ppr.addNewJc();
126
        align.setVal(STJc.CENTER);
136
        align.setVal(STJc.CENTER);
Lines 130-158 Link Here
130
        assertEquals(STJc.BOTH, ppr.getJc().getVal());
140
        assertEquals(STJc.BOTH, ppr.getJc().getVal());
131
    }
141
    }
132
142
143
    
133
    public void testSetGetSpacing() {
144
    public void testSetGetSpacing() {
134
        XWPFDocument doc = new XWPFDocument();
145
        XWPFDocument doc = new XWPFDocument();
135
        XWPFParagraph p = doc.createParagraph();
146
        XWPFParagraph p = doc.createParagraph();
136
147
137
        CTP ctp = p.getCTP();
148
        CTP ctp = p.getCTP();
138
        CTPPr ppr = ctp.addNewPPr();
149
        CTPPr ppr = ctp.getPPr()== null? ctp.addNewPPr() : ctp.getPPr();
139
150
140
        //TEST ALL OTHERS POSSIBLE COMBINATIONS
151
        assertEquals(-1, p.getSpacingAfter());
152
        
141
        CTSpacing spacing = ppr.addNewSpacing();
153
        CTSpacing spacing = ppr.addNewSpacing();
142
        spacing.setAfter(new BigInteger("10"));
154
        spacing.setAfter(new BigInteger("10"));
143
        assertEquals(10, p.getSpacingAfter().longValue());
155
        assertEquals(10, p.getSpacingAfter());
144
156
145
        p.setSpacingAfter(new BigInteger("100"));
157
        p.setSpacingAfter(100);
146
        assertEquals(100, spacing.getAfter().longValue());
158
        assertEquals(100, spacing.getAfter().intValue());
147
    }
159
    }
148
160
161
    public void testSetGetSpacingLineRule() {
162
        XWPFDocument doc = new XWPFDocument();
163
        XWPFParagraph p = doc.createParagraph();
164
165
        CTP ctp = p.getCTP();
166
        CTPPr ppr = ctp.getPPr()== null? ctp.addNewPPr() : ctp.getPPr();
167
168
        assertEquals(STLineSpacingRule.INT_AUTO, p.getSpacingLineRule().getValue());
169
        
170
        CTSpacing spacing = ppr.addNewSpacing();
171
        spacing.setLineRule(STLineSpacingRule.AT_LEAST);
172
        assertEquals(LineSpacingRule.AT_LEAST, p.getSpacingLineRule());
173
174
        p.setSpacingAfter(100);
175
        assertEquals(100, spacing.getAfter().intValue());
176
    }
177
    
178
    public void testSetGetIndentation() {
179
        XWPFDocument doc = new XWPFDocument();
180
        XWPFParagraph p = doc.createParagraph();
181
182
        assertEquals(-1, p.getIndentationLeft());
183
        
184
        CTP ctp = p.getCTP();
185
        CTPPr ppr = ctp.getPPr()== null? ctp.addNewPPr() : ctp.getPPr();
186
187
        assertEquals(-1, p.getIndentationLeft());
188
        
189
        CTInd ind = ppr.addNewInd();
190
        ind.setLeft(new BigInteger("10"));
191
        assertEquals(10, p.getIndentationLeft());
192
193
        p.setIndentationLeft(100);
194
        assertEquals(100, ind.getLeft().intValue());
195
    }
196
    
149
    public void testSetGetVerticalAlignment() {
197
    public void testSetGetVerticalAlignment() {
150
        //new clean instance of paragraph
198
        //new clean instance of paragraph
151
        XWPFDocument doc = new XWPFDocument();
199
        XWPFDocument doc = new XWPFDocument();
152
        XWPFParagraph p = doc.createParagraph();
200
        XWPFParagraph p = doc.createParagraph();
153
201
154
        CTP ctp = p.getCTP();
202
        CTP ctp = p.getCTP();
155
        CTPPr ppr = ctp.addNewPPr();
203
        CTPPr ppr = ctp.getPPr()== null? ctp.addNewPPr() : ctp.getPPr();
156
204
157
        CTTextAlignment txtAlign = ppr.addNewTextAlignment();
205
        CTTextAlignment txtAlign = ppr.addNewTextAlignment();
158
        txtAlign.setVal(STTextAlignment.CENTER);
206
        txtAlign.setVal(STTextAlignment.CENTER);
Lines 167-173 Link Here
167
        XWPFParagraph p = doc.createParagraph();
215
        XWPFParagraph p = doc.createParagraph();
168
216
169
        CTP ctp = p.getCTP();
217
        CTP ctp = p.getCTP();
170
        CTPPr ppr = ctp.addNewPPr();
218
        CTPPr ppr = ctp.getPPr()== null? ctp.addNewPPr() : ctp.getPPr();
171
219
172
        CTOnOff wordWrap = ppr.addNewWordWrap();
220
        CTOnOff wordWrap = ppr.addNewWordWrap();
173
        wordWrap.setVal(STOnOff.FALSE);
221
        wordWrap.setVal(STOnOff.FALSE);
Lines 183-189 Link Here
183
        XWPFParagraph p = doc.createParagraph();
231
        XWPFParagraph p = doc.createParagraph();
184
232
185
        CTP ctp = p.getCTP();
233
        CTP ctp = p.getCTP();
186
        CTPPr ppr = ctp.addNewPPr();
234
        CTPPr ppr = ctp.getPPr()== null? ctp.addNewPPr() : ctp.getPPr();
187
235
188
        CTOnOff pageBreak = ppr.addNewPageBreakBefore();
236
        CTOnOff pageBreak = ppr.addNewPageBreakBefore();
189
        pageBreak.setVal(STOnOff.FALSE);
237
        pageBreak.setVal(STOnOff.FALSE);

Return to bug 46300