You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2011/05/13 14:22:24 UTC
svn commit: r1102691 - in /poi/trunk/src/ooxml:
java/org/apache/poi/xwpf/usermodel/ testcases/org/apache/poi/xwpf/
Author: nick
Date: Fri May 13 12:22:24 2011
New Revision: 1102691
URL: http://svn.apache.org/viewvc?rev=1102691&view=rev
Log:
Autoboxing tweaks from bug #51175, and make the paragraph/table finding code generic
Modified:
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/BreakClear.java
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/BreakType.java
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/LineSpacingRule.java
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/ParagraphAlignment.java
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/TextAlignment.java
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/UnderlinePatterns.java
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/VerticalAlign.java
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/BreakClear.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/BreakClear.java?rev=1102691&r1=1102690&r2=1102691&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/BreakClear.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/BreakClear.java Fri May 13 12:22:24 2011
@@ -86,26 +86,25 @@ public enum BreakClear {
private final int value;
private BreakClear(int val) {
- value = val;
+ value = val;
}
public int getValue() {
- return value;
+ return value;
}
private static Map<Integer, BreakClear> imap = new HashMap<Integer, BreakClear>();
static {
- for (BreakClear p : values()) {
- imap.put(p.getValue(), p);
- }
+ for (BreakClear p : values()) {
+ imap.put(new Integer(p.getValue()), p);
+ }
}
public static BreakClear valueOf(int type) {
- BreakClear bType = imap.get(type);
- if (bType == null)
- throw new IllegalArgumentException("Unknown break clear type: "
- + type);
- return bType;
+ BreakClear bType = imap.get(new Integer(type));
+ if (bType == null)
+ throw new IllegalArgumentException("Unknown break clear type: "
+ + type);
+ return bType;
}
-
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/BreakType.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/BreakType.java?rev=1102691&r1=1102690&r2=1102691&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/BreakType.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/BreakType.java Fri May 13 12:22:24 2011
@@ -59,26 +59,25 @@ public enum BreakType {
private final int value;
private BreakType(int val) {
- value = val;
+ value = val;
}
public int getValue() {
- return value;
+ return value;
}
private static Map<Integer, BreakType> imap = new HashMap<Integer, BreakType>();
static {
- for (BreakType p : values()) {
- imap.put(p.getValue(), p);
- }
+ for (BreakType p : values()) {
+ imap.put(new Integer(p.getValue()), p);
+ }
}
public static BreakType valueOf(int type) {
- BreakType bType = imap.get(type);
- if (bType == null)
- throw new IllegalArgumentException("Unknown break type: "
- + type);
- return bType;
+ BreakType bType = imap.get(new Integer(type));
+ if (bType == null)
+ throw new IllegalArgumentException("Unknown break type: "
+ + type);
+ return bType;
}
-
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/LineSpacingRule.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/LineSpacingRule.java?rev=1102691&r1=1102690&r2=1102691&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/LineSpacingRule.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/LineSpacingRule.java Fri May 13 12:22:24 2011
@@ -52,25 +52,24 @@ public enum LineSpacingRule {
private final int value;
private LineSpacingRule(int val) {
- value = val;
+ value = val;
}
public int getValue() {
- return value;
+ return value;
}
private static Map<Integer, LineSpacingRule> imap = new HashMap<Integer, LineSpacingRule>();
static {
- for (LineSpacingRule p : values()) {
- imap.put(p.getValue(), p);
- }
+ for (LineSpacingRule p : values()) {
+ imap.put(new Integer(p.getValue()), p);
+ }
}
public static LineSpacingRule valueOf(int type) {
- LineSpacingRule lineType = imap.get(type);
- if (lineType == null)
- throw new IllegalArgumentException("Unknown line type: " + type);
- return lineType;
+ LineSpacingRule lineType = imap.get(new Integer(type));
+ if (lineType == null)
+ throw new IllegalArgumentException("Unknown line type: " + type);
+ return lineType;
}
-
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/ParagraphAlignment.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/ParagraphAlignment.java?rev=1102691&r1=1102690&r2=1102691&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/ParagraphAlignment.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/ParagraphAlignment.java Fri May 13 12:22:24 2011
@@ -53,12 +53,12 @@ public enum ParagraphAlignment {
private static Map<Integer, ParagraphAlignment> imap = new HashMap<Integer, ParagraphAlignment>();
static{
for (ParagraphAlignment p : values()) {
- imap.put(p.getValue(), p);
+ imap.put(new Integer(p.getValue()), p);
}
}
public static ParagraphAlignment valueOf(int type){
- ParagraphAlignment err = imap.get(type);
+ ParagraphAlignment err = imap.get(new Integer(type));
if(err == null) throw new IllegalArgumentException("Unknown paragraph alignment: " + type);
return err;
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/TextAlignment.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/TextAlignment.java?rev=1102691&r1=1102690&r2=1102691&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/TextAlignment.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/TextAlignment.java Fri May 13 12:22:24 2011
@@ -59,20 +59,19 @@ public enum TextAlignment {
}
public int getValue(){
- return value;
+ return value;
}
private static Map<Integer, TextAlignment> imap = new HashMap<Integer, TextAlignment>();
static{
- for (TextAlignment p : values()) {
- imap.put(p.getValue(), p);
- }
+ for (TextAlignment p : values()) {
+ imap.put(new Integer(p.getValue()), p);
+ }
}
public static TextAlignment valueOf(int type){
- TextAlignment align = imap.get(type);
- if(align == null) throw new IllegalArgumentException("Unknown text alignment: " + type);
- return align;
+ TextAlignment align = imap.get(new Integer(type));
+ if(align == null) throw new IllegalArgumentException("Unknown text alignment: " + type);
+ return align;
}
-
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/UnderlinePatterns.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/UnderlinePatterns.java?rev=1102691&r1=1102690&r2=1102691&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/UnderlinePatterns.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/UnderlinePatterns.java Fri May 13 12:22:24 2011
@@ -138,26 +138,25 @@ public enum UnderlinePatterns {
private final int value;
private UnderlinePatterns(int val) {
- value = val;
+ value = val;
}
public int getValue() {
- return value;
+ return value;
}
private static Map<Integer, UnderlinePatterns> imap = new HashMap<Integer, UnderlinePatterns>();
static {
- for (UnderlinePatterns p : values()) {
- imap.put(p.getValue(), p);
- }
+ for (UnderlinePatterns p : values()) {
+ imap.put(new Integer(p.getValue()), p);
+ }
}
public static UnderlinePatterns valueOf(int type) {
- UnderlinePatterns align = imap.get(type);
- if (align == null)
- throw new IllegalArgumentException("Unknown underline pattern: "
- + type);
- return align;
+ UnderlinePatterns align = imap.get(new Integer(type));
+ if (align == null)
+ throw new IllegalArgumentException("Unknown underline pattern: "
+ + type);
+ return align;
}
-
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/VerticalAlign.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/VerticalAlign.java?rev=1102691&r1=1102690&r2=1102691&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/VerticalAlign.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/VerticalAlign.java Fri May 13 12:22:24 2011
@@ -50,26 +50,25 @@ public enum VerticalAlign {
private final int value;
private VerticalAlign(int val) {
- value = val;
+ value = val;
}
public int getValue() {
- return value;
+ return value;
}
private static Map<Integer, VerticalAlign> imap = new HashMap<Integer, VerticalAlign>();
static {
- for (VerticalAlign p : values()) {
- imap.put(p.getValue(), p);
- }
+ for (VerticalAlign p : values()) {
+ imap.put(new Integer(p.getValue()), p);
+ }
}
public static VerticalAlign valueOf(int type) {
- VerticalAlign align = imap.get(type);
- if (align == null)
- throw new IllegalArgumentException("Unknown vertical alignment: "
- + type);
- return align;
+ VerticalAlign align = imap.get(new Integer(type));
+ if (align == null)
+ throw new IllegalArgumentException("Unknown vertical alignment: "
+ + type);
+ return align;
}
-
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java?rev=1102691&r1=1102690&r2=1102691&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java Fri May 13 12:22:24 2011
@@ -583,35 +583,39 @@ public class XWPFDocument extends POIXML
return false;
}
+
+ private int getPosOfBodyElement(IBodyElement needle) {
+ BodyElementType type = needle.getElementType();
+ IBodyElement current;
+ for(int i=0; i<bodyElements.size(); i++) {
+ current = bodyElements.get(i);
+ if(current.getElementType() == type) {
+ if(current.equals(needle)) {
+ return i;
+ }
+ }
+ }
+ return -1;
+ }
/**
- * get position of the paragraph
- * @param p
+ * Get the position of the paragraph, within the list
+ * of all the body elements.
+ * @param p The paragraph to find
+ * @return The location, or -1 if the paragraph couldn't be found
*/
- public Integer getPosOfParagraph(XWPFParagraph p){
- int i, pos = 0;
- for (i = 0 ; i < bodyElements.size() ; i++) {
- if (bodyElements.get(i) instanceof XWPFParagraph){
- if (bodyElements.get(i).equals(p)){
- return pos;
- }
- pos++;
- }
- }
- return null;
+ public int getPosOfParagraph(XWPFParagraph p){
+ return getPosOfBodyElement(p);
}
- public Integer getPosOfTable(XWPFTable t){
- int i, pos = 0;
- for(i = 0; i < bodyElements.size(); i++){
- if(bodyElements.get(i).getElementType() == BodyElementType.TABLE){
- if (bodyElements.get(i) == t){
- return pos;
- }
- pos++;
- }
- }
- return null;
+ /**
+ * Get the position of the table, within the list of
+ * all the body elements.
+ * @param t The table to find
+ * @return The location, or -1 if the table couldn't be found
+ */
+ public int getPosOfTable(XWPFTable t){
+ return getPosOfBodyElement(t);
}
/**
@@ -728,7 +732,7 @@ public class XWPFDocument extends POIXML
String parStyle = par.getStyle();
if (parStyle != null && parStyle.substring(0, 7).equals("Heading")) {
try {
- int level = Integer.valueOf(parStyle.substring("Heading".length()));
+ int level = Integer.valueOf(parStyle.substring("Heading".length())).intValue();
toc.addRow(level, par.getText(), 1, "112723803");
}
catch (NumberFormatException e) {
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java?rev=1102691&r1=1102690&r2=1102691&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java Fri May 13 12:22:24 2011
@@ -105,6 +105,9 @@ public final class TestXWPFDocument exte
XWPFParagraph p = doc.createParagraph();
assertEquals(p, doc.getParagraphs().get(3));
assertEquals(4, doc.getParagraphs().size());
+
+ assertEquals(3, doc.getParagraphPos(3));
+ assertEquals(3, doc.getPosOfParagraph(p));
CTP ctp = p.getCTP();
XWPFParagraph newP = doc.getParagraph(ctp);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org