Changeset 301

Show
Ignore:
Timestamp:
12/01/08 17:51:00 (4 years ago)
Author:
dmisev
Message:

fixed #175

Location:
src/jomdoc/trunk/src
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • src/jomdoc/trunk/src/jomdoc/org/jomdoc/ntn/rnd/AbstractRenderer.java

    r300 r301  
    104104    public Document render(Document doc) throws XSLException, IOException, ParsingException { 
    105105        Document ret = new Document(doc); 
     106 
     107        // preprocessing the input document 
    106108        try { 
    107109            contract(ret, "OMR"); 
    108110        } 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); 
    115121        List<Element> mobjs = mobjs(ret); 
    116122         
     
    127133            } 
    128134        } 
    129          
     135 
     136        // transforming the rendered result 
    130137        if (xslt != null) { 
    131138            Log.debug("Transforming the rendered document, with " + xslt.getBaseURI()); 
  • src/jomdoc/trunk/src/jomdoc/org/jomdoc/util/etc/NtnUtil.java

    r206 r301  
    512512        RefContraction contr = new RefContraction(true); 
    513513        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())); 
    514561    } 
    515562 
  • src/jomdoc/trunk/src/test/org/jomdoc/cli/JOMDocTest.java

    r300 r301  
    66package org.jomdoc.cli; 
    77 
     8import java.io.File; 
     9import nu.xom.Document; 
    810import org.jomdoc.Paths; 
    911import org.jomdoc.util.err.ErrorCode; 
    1012import org.jomdoc.util.etc.Log; 
     13import org.jomdoc.util.etc.NtnUtil; 
    1114import org.jomdoc.util.etc.StringUtil; 
     15import org.jomdoc.util.xml.XMLUtil; 
    1216import org.junit.BeforeClass; 
    1317import org.junit.Ignore; 
     
    307311     * Ticket #167 
    308312     */ 
     313    @Ignore 
    309314    @Test 
    310315    public void testImportsAware11() { 
    311316        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"); 
    312317    } 
     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    } 
    313332}