Changeset 1745 for trunk/docx4j/src/main/java/org
- Timestamp:
- 01/10/12 11:46:36 (5 months ago)
- Location:
- trunk/docx4j/src/main/java/org/docx4j/model/listnumbering
- Files:
-
- 3 edited
-
AbstractListNumberingDefinition.java (modified) (1 diff)
-
ListLevel.java (modified) (15 diffs)
-
ListNumberingDefinition.java (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/docx4j/src/main/java/org/docx4j/model/listnumbering/AbstractListNumberingDefinition.java
r1298 r1745 98 98 import org.docx4j.wml.PPrBase.NumPr; 99 99 100 /** 101 * Represents: 102 * 103 <w:abstractNum w:abstractNumId="0"> 104 <w:nsid w:val="2DD860C0"/> 105 <w:multiLevelType w:val="multilevel"/> 106 <w:tmpl w:val="0409001D"/> 107 <w:lvl w:ilvl="0"> 108 <w:start w:val="1"/> 109 <w:numFmt w:val="decimal"/> 110 <w:lvlText w:val="%1)"/> 111 <w:lvlJc w:val="left"/> 112 <w:pPr> 113 <w:ind w:left="360" w:hanging="360"/> 114 </w:pPr> 115 </w:lvl> 116 <w:lvl w:ilvl="1"> 117 <w:start w:val="1"/> 118 <w:numFmt w:val="lowerLetter"/> 119 <w:lvlText w:val="%2)"/> 120 <w:lvlJc w:val="left"/> 121 <w:pPr> 122 <w:ind w:left="720" w:hanging="360"/> 123 </w:pPr> 124 </w:lvl> 125 etc 126 127 (layered on top of the JAXB object representing same) 128 129 */ 100 130 public class AbstractListNumberingDefinition { 101 131 -
trunk/docx4j/src/main/java/org/docx4j/model/listnumbering/ListLevel.java
r1435 r1745 103 103 * for each story! 104 104 * 105 * 2012 01 10: numbering set up on a per-part basis 106 * seems the most sensible approach. 107 * 105 108 */ 106 109 … … 117 120 } 118 121 122 /** 123 * The counter is kept at the abstract level, since 124 * each instance definition shares a single counter. 125 * 126 */ 127 private Counter counter; 128 129 private boolean encounteredAlready = false; 130 131 132 /** 133 * Constructor for a ListLevel in an abstract definition. 134 */ 119 135 public ListLevel(Lvl levelNode) 120 136 { … … 122 138 123 139 this.id = levelNode.getIlvl().toString(); 140 141 counter = new Counter(); 124 142 125 143 Lvl.Start startValueNode = levelNode.getStart(); … … 129 147 // Start value is one less than the user set it to, 130 148 // since whenever we fetch the number, we first increment it. 131 this.counter = this.startValue;149 counter.setCurrentValue(this.startValue); 132 150 } 133 151 … … 163 181 } 164 182 165 /** copy constructor 166 * 167 * @param masterCopy 183 /** 184 * Constructor for a ListLevel in an instance definition. 168 185 */ 169 186 public ListLevel(ListLevel masterCopy) … … 174 191 this.levelText = masterCopy.levelText; 175 192 this.startValue = masterCopy.startValue; 176 this.counter = this.startValue; 193 //this.counter = this.startValue; 194 this.counter = masterCopy.counter; // reference the abstract one, since this is shared 177 195 this.font = masterCopy.font; 178 196 this.isBullet = masterCopy.isBullet; … … 191 209 if (startValueNode != null) 192 210 { 193 this.startValue = startValueNode.getVal(); 194 } 195 this.counter = this.startValue; 211 this.startValue = startValueNode.getVal().subtract(BigInteger.ONE); 212 // Start value is one less than the user set it to, 213 // since whenever we fetch the number, we first increment it. 214 counter.setCurrentValue(this.startValue); 215 } 196 216 197 217 Lvl.LvlText levelTextNode = levelNode.getLvlText(); … … 238 258 private BigInteger startValue = BigInteger.ZERO; 239 259 240 /** 260 public void setStartValue(BigInteger startValue) { 261 this.startValue = startValue; 262 } 263 264 /** 241 265 * start value of that level 242 266 * @return … … 247 271 } 248 272 249 private BigInteger counter;250 251 /**252 * returns the current count of list items of that level253 * @return254 */255 public BigInteger getCurrentValueRaw()256 {257 return this.counter;258 }259 273 260 274 /** … … 286 300 287 301 if (numFmt.equals( NumberFormat.DECIMAL ) ) { 288 return this.counter. toString();302 return this.counter.getCurrentValue().toString(); 289 303 } 290 304 … … 301 315 } 302 316 303 int current = this.counter. intValue();317 int current = this.counter.getCurrentValue().intValue(); 304 318 305 319 if (numFmt.equals( NumberFormat.UPPER_ROMAN ) ) { … … 321 335 322 336 log.error("Unhandled numFmt: " + numFmt.name() ); 323 return this.counter. toString();337 return this.counter.getCurrentValue().toString(); 324 338 } 325 339 … … 330 344 public void IncrementCounter() 331 345 { 332 this.counter = this.counter.add(BigInteger.ONE); 346 if (!encounteredAlready) { 347 // Defer setting the startValue until the list 348 // is actually encountered in the main document part, 349 // since otherwise earlier numbering (using the 350 // same abstract number) would use this startValue 351 counter.setCurrentValue(this.startValue); 352 encounteredAlready = true; 353 } 354 355 356 counter.IncrementCounter(); 333 357 334 log.debug("counter now: " + this.counter.toString() );335 336 358 } 337 359 … … 341 363 public void ResetCounter() 342 364 { 343 this.counter = this.startValue;365 counter.setCurrentValue(this.startValue); 344 366 } 345 367 … … 387 409 return this.isBullet; 388 410 } 411 412 protected class Counter { 413 414 private BigInteger currentValue; 415 416 Counter() { 417 currentValue = BigInteger.ZERO; 418 } 419 420 public void setCurrentValue(BigInteger currentValue) { 421 this.currentValue = currentValue; 422 } 423 424 /** 425 * returns the current count of list items of that level 426 * @return 427 */ 428 public BigInteger getCurrentValue() 429 { 430 log.debug("counter: " + currentValue.intValue() ); 431 return this.currentValue; 432 } 433 434 /** 435 * increments the current count of list items of that level 436 */ 437 public void IncrementCounter() 438 { 439 setCurrentValue( currentValue.add(BigInteger.ONE)); 440 441 log.debug("counter now: " + currentValue.intValue() ); 442 443 } 444 445 } 389 446 390 447 } -
trunk/docx4j/src/main/java/org/docx4j/model/listnumbering/ListNumberingDefinition.java
r1298 r1745 84 84 package org.docx4j.model.listnumbering; 85 85 86 import java.math.BigInteger; 86 87 import java.util.HashMap; 87 88 import java.util.Iterator; … … 90 91 91 92 import org.apache.log4j.Logger; 93 import org.docx4j.XmlUtils; 92 94 import org.docx4j.wml.Lvl; 93 95 import org.docx4j.wml.Numbering; 94 96 import org.docx4j.wml.Numbering.Num.LvlOverride.StartOverride; 97 98 /** 99 * Represents: 100 * 101 <w:num w:numId="1"> 102 <w:abstractNumId w:val="0"/> 103 </w:num> 104 105 or 106 107 <w:num w:numId="2"> 108 <w:abstractNumId w:val="0"/> 109 <w:lvlOverride w:ilvl="0"> 110 <w:startOverride w:val="10"/> 111 </w:lvlOverride> 112 </w:num> 113 114 (layered on top of the JAXB object representing same) 115 116 */ 95 117 public class ListNumberingDefinition { 96 97 /* There should be only one Emulator object per 98 * WordprocessingML package. It is set on the 99 * numbering part. 100 */ 101 118 102 119 // The underlying JAXB object 103 120 private Numbering.Num numNode; … … 108 125 protected static Logger log = Logger.getLogger(ListNumberingDefinition.class); 109 126 110 /// <summary> 111 /// constructor 112 /// </summary> 113 /// <param name="numNode"></param> 114 /// <param name="nsm"></param> 115 /// <param name="abstractListDefinitions"></param> 127 /** 128 * @param numNode 129 * @param abstractListDefinitions 130 */ 116 131 public ListNumberingDefinition(Numbering.Num numNode, 117 132 HashMap<String, AbstractListNumberingDefinition> abstractListDefinitions) … … 120 135 121 136 this.listNumberId = numNode.getNumId().toString(); //getAttributeValue(numNode, "w:numId"); 137 log.debug("Constructing model for numId=" + listNumberId); 122 138 123 139 //XmlNode abstractNumNode = numNode.SelectSingleNode("./w:abstractNumId", nsm); … … 146 162 if (levelOverrideNodes != null) 147 163 { 164 /* 165 * <w:lvlOverride w:ilvl="0"> 166 <w:startOverride w:val="10"/> 167 </w:lvlOverride> 168 */ 148 169 for (Numbering.Num.LvlOverride overrideNode : levelOverrideNodes) 149 170 { 150 //XmlNode node = overrideNode.SelectSingleNode("./w:lvl", nsm); 151 Lvl node = overrideNode.getLvl(); 152 if (node != null) 171 log.debug("found LvlOverride " + XmlUtils.marshaltoString(overrideNode, true)); 172 if (overrideNode.getIlvl() != null) 153 173 { 154 String overrideLevelId = node.getIlvl().toString(); //getAttributeValue(node, "w:ilvl"); 155 156 if (overrideLevelId!=null && !overrideLevelId.equals("") ) 157 { 158 this.levels.get(overrideLevelId).SetOverrides(node); 174 String overrideLevelId = overrideNode.getIlvl().toString(); //getAttributeValue(node, "w:ilvl"); 175 log.debug(".. " + overrideLevelId ); 176 177 if (!overrideLevelId.equals("") ) 178 { 179 // Is there a w:startOverride? 180 // This is given effect the first time the instance is encountered in the document 181 StartOverride startOverride = overrideNode.getStartOverride(); 182 if (startOverride!=null 183 && startOverride.getVal()!=null) { 184 this.levels.get(overrideLevelId).setStartValue(startOverride.getVal().subtract(BigInteger.ONE)); 185 log.debug("level " + overrideLevelId + "starts at " + startOverride.getVal() ); 186 } 159 187 } 160 188 } 189 // Lvl ilvl = overrideNode.getLvl(); 190 // if (ilvl != null) 191 // { 192 // this.levels.get(overrideLevelId).SetOverrides(overrideLevelId); 193 // } 161 194 } 162 195 } … … 181 214 public void IncrementCounter(String level) 182 215 { 216 183 217 log.debug("Increment level " + level); 184 218 this.levels.get(level).IncrementCounter();
Note: See TracChangeset
for help on using the changeset viewer.
