Changeset 301
- Timestamp:
- 12/01/08 17:51:00 (4 years ago)
- Location:
- src/jomdoc/trunk/src
- Files:
-
- 3 modified
-
jomdoc/org/jomdoc/ntn/rnd/AbstractRenderer.java (modified) (2 diffs)
-
jomdoc/org/jomdoc/util/etc/NtnUtil.java (modified) (1 diff)
-
test/org/jomdoc/cli/JOMDocTest.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/jomdoc/trunk/src/jomdoc/org/jomdoc/ntn/rnd/AbstractRenderer.java
r300 r301 104 104 public Document render(Document doc) throws XSLException, IOException, ParsingException { 105 105 Document ret = new Document(doc); 106 107 // preprocessing the input document 106 108 try { 107 109 contract(ret, "OMR"); 108 110 } catch (Exception ex) { 109 Log.error("Error contracting OMR elements in the document", ex); 110 } 111 112 Log.debug("Started rendering document: " + doc.getBaseURI().toString(), 113 ntnCollector.toString(), ctxCollector.toString()); 114 111 Log.warn("Error contracting OMR elements in the document", ex); 112 } 113 try { 114 nestOMATTR(doc); 115 } catch (Exception ex) { 116 Log.warn("Error nesting OMATTR key -> value lists", ex); 117 } 118 119 // rendering 120 Log.debug("Started rendering document: " + doc.getBaseURI(), ntnCollector, ctxCollector); 115 121 List<Element> mobjs = mobjs(ret); 116 122 … … 127 133 } 128 134 } 129 135 136 // transforming the rendered result 130 137 if (xslt != null) { 131 138 Log.debug("Transforming the rendered document, with " + xslt.getBaseURI()); -
src/jomdoc/trunk/src/jomdoc/org/jomdoc/util/etc/NtnUtil.java
r206 r301 512 512 RefContraction contr = new RefContraction(true); 513 513 contr.evaluate(e, 0); 514 } 515 516 public static void nestOMATTR(Document doc) { 517 DFSTraversor traversor = new DFSTraversor(new Filter() { 518 519 public boolean evaluate(Object node, int depth) { 520 if (!(node instanceof Element)) { 521 return false; 522 } 523 524 Element e = (Element) node; 525 if (!e.getLocalName().equals(LABEL_OMATTR)) { 526 return false; 527 } 528 529 int omatpChildren = 0; 530 Element nest = new Element(LABEL_OMATTR, NAMESPACE_OPENMATH); 531 for (int i = 0; i < e.getChildCount(); i++) { 532 Node n = e.getChild(i); 533 if (omatpChildren == 2) { 534 n.detach(); 535 nest.appendChild(n); 536 } else if (n instanceof Element) { 537 Element c = (Element) n; 538 539 if (omatpChildren < 2) { 540 if (c.getLocalName().equals(LABEL_OMATP)) { 541 ++omatpChildren; 542 if (omatpChildren == 2) { 543 c.detach(); 544 nest.appendChild(c); 545 } 546 } else { 547 break; 548 } 549 } 550 } 551 } 552 if (omatpChildren == 2) { 553 e.appendChild(nest); 554 } 555 556 return false; 557 } 558 }); 559 560 traversor.traverse(new TraversableXOM(doc.getRootElement())); 514 561 } 515 562 -
src/jomdoc/trunk/src/test/org/jomdoc/cli/JOMDocTest.java
r300 r301 6 6 package org.jomdoc.cli; 7 7 8 import java.io.File; 9 import nu.xom.Document; 8 10 import org.jomdoc.Paths; 9 11 import org.jomdoc.util.err.ErrorCode; 10 12 import org.jomdoc.util.etc.Log; 13 import org.jomdoc.util.etc.NtnUtil; 11 14 import org.jomdoc.util.etc.StringUtil; 15 import org.jomdoc.util.xml.XMLUtil; 12 16 import org.junit.BeforeClass; 13 17 import org.junit.Ignore; … … 307 311 * Ticket #167 308 312 */ 313 @Ignore 309 314 @Test 310 315 public void testImportsAware11() { 311 316 render("-t", "/home/dimitar/kwarc/omdoc/examples/varia/fitch-proof.omdoc", "-o", "/home/dimitar/out.xhtml", "-v", "-x", "/home/dimitar/kwarc/jomdoc/xsl2/omdoc2pmml-copymobj.xsl"); 312 317 } 318 319 /** 320 * Ticket #175 321 */ 322 @Test 323 public void testOmattrNesting() { 324 try { 325 Document doc = XMLUtil.buildDocument(new File(IN + "nesting-omattr.omdoc")); 326 NtnUtil.nestOMATTR(doc); 327 System.out.println(XMLUtil.serialize(doc)); 328 } catch (Exception ex) { 329 ex.printStackTrace(); 330 } 331 } 313 332 }
