Search in sources :

Example 46 with Document

use of org.jdom.Document in project vcell by virtualcell.

the class DocumentCompiler method validateTOC.

private void validateTOC() throws Exception {
    File tocSourceFile = new File(docSourceDir, tocFileName);
    // 
    // read in existing TOC file and validate it's contents
    // 
    Document doc = XmlUtil.readXML(tocSourceFile);
    Element root = doc.getRootElement();
    if (!root.getName().equals(VCellDocTags.toc_tag)) {
        throw new RuntimeException("expecting " + VCellDocTags.toc_tag + " in file " + tocSourceFile.getPath());
    }
    HashSet<DocumentPage> pagesNotYetReferenced = new HashSet<DocumentPage>(Arrays.asList(documentation.getDocumentPages()));
    readTOCItem(pagesNotYetReferenced, root);
    if (pagesNotYetReferenced.size() > 0) {
        for (DocumentPage docPage : pagesNotYetReferenced) {
            if (!documentation.isReferenced(docPage)) {
                System.err.println("ERROR: Document page '" + docPage.getTarget() + "' not referenced in either table of contents or from another document");
            }
        }
    }
    // copy the Table of Contents to the target directory.
    FileUtils.copyFile(new File(docSourceDir, tocFileName), new File(docTargetDir, tocFileName));
    // System.out.println("Calling buildHtmlIndex");
    buildHtmlIndex(root);
}
Also used : Element(org.jdom.Element) Document(org.jdom.Document) File(java.io.File) HashSet(java.util.HashSet)

Example 47 with Document

use of org.jdom.Document in project vcell by virtualcell.

the class DocumentCompiler method readDefinitionFile.

private ArrayList<DocumentDefinition> readDefinitionFile(File file) throws XmlParseException {
    ArrayList<DocumentDefinition> documentDefs = new ArrayList<DocumentDefinition>();
    Document doc = XmlUtil.readXML(file);
    Element root = doc.getRootElement();
    if (!root.getName().equals(VCellDocTags.VCellDoc_tag)) {
        throw new RuntimeException("expecting ...");
    }
    // get all definition elements
    @SuppressWarnings("unchecked") List<Object> pageElements = root.getContent();
    if (pageElements != null) {
        for (Object pageElement : pageElements) {
            if (pageElement instanceof Element && ((Element) pageElement).getName().equals(VCellDocTags.definition_tag)) {
                String target = ((Element) pageElement).getAttributeValue(VCellDocTags.target_attr);
                String label = ((Element) pageElement).getAttributeValue(VCellDocTags.definition_label_attr);
                String text = ((Element) pageElement).getText();
                DocumentDefinition documentDefinition = new DocumentDefinition(file, target, label, text);
                documentDefs.add(documentDefinition);
            }
        }
    }
    return documentDefs;
}
Also used : Element(org.jdom.Element) ArrayList(java.util.ArrayList) Document(org.jdom.Document)

Example 48 with Document

use of org.jdom.Document in project vcell by virtualcell.

the class JDOM2Model method addJDOM.

public void addJDOM(Element element, String baseURI) throws IOException, RDFParseException, RDFHandlerException {
    Document document = new Document((Element) element.clone());
    StringWriter stringWriter = new StringWriter();
    new XMLOutputter().output(document, stringWriter);
    StringReader stringReader = new StringReader(stringWriter.getBuffer().toString());
    RDFParser rdfParser = Rio.createParser(RDFFormat.RDFXML);
    rdfParser.setRDFHandler(new StatementCollector(model));
    rdfParser.parse(stringReader, baseURI);
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) StringWriter(java.io.StringWriter) StatementCollector(org.openrdf.rio.helpers.StatementCollector) StringReader(java.io.StringReader) Document(org.jdom.Document) RDFParser(org.openrdf.rio.RDFParser)

Example 49 with Document

use of org.jdom.Document in project vcell by virtualcell.

the class VisMeshUtils method writePointDataToVtu.

public static void writePointDataToVtu(File inputMeshFile, String dataName, double[] data, File outputMeshFile) throws IOException {
    Document meshDocument = XmlUtil.readXML(inputMeshFile);
    addPointDataToVtuXml(meshDocument, dataName, data);
    FileWriter fw = null;
    try {
        fw = new FileWriter(outputMeshFile);
        XMLOutputter xmlOut = new XMLOutputter();
        Format f = Format.getRawFormat();
        f.setLineSeparator("\n");
        f.setOmitEncoding(true);
        f.setExpandEmptyElements(true);
        xmlOut.setFormat(f);
        xmlOut.output(meshDocument, fw);
    } finally {
        if (fw != null) {
            fw.close();
        }
    }
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) Format(org.jdom.output.Format) FileWriter(java.io.FileWriter) Document(org.jdom.Document)

Example 50 with Document

use of org.jdom.Document in project vcell by virtualcell.

the class ExpressionMathMLPrinter method getMathML.

/**
 * Insert the method's description here.
 * Creation date: (2/8/2002 5:51:09 PM)
 * @return java.lang.String
 */
String getMathML(boolean bOnlyMathMLFragment, MathType desiredMathType) throws ExpressionException, java.io.IOException {
    org.jdom.output.XMLOutputter xmlwriter = new org.jdom.output.XMLOutputter();
    Element mathElement = new Element("math", Namespace.getNamespace("http://www.w3.org/1998/Math/MathML"));
    mathElement.addContent(getMathML(rootNode, desiredMathType));
    if (!bOnlyMathMLFragment) {
        Document mathDoc = new Document(mathElement);
        return xmlwriter.outputString(mathDoc);
    }
    return xmlwriter.outputString(mathElement);
}
Also used : Element(org.jdom.Element) Document(org.jdom.Document)

Aggregations

Document (org.jdom.Document)144 Element (org.jdom.Element)102 SAXBuilder (org.jdom.input.SAXBuilder)51 IOException (java.io.IOException)49 JDOMException (org.jdom.JDOMException)29 File (java.io.File)27 ArrayList (java.util.ArrayList)22 XMLOutputter (org.jdom.output.XMLOutputter)22 List (java.util.List)16 StringReader (java.io.StringReader)15 Format (org.jdom.output.Format)12 VCDocument (org.vcell.util.document.VCDocument)11 XPath (org.jdom.xpath.XPath)10 StringWriter (java.io.StringWriter)9 InputStream (java.io.InputStream)8 URL (java.net.URL)8 NotNull (org.jetbrains.annotations.NotNull)7 Nullable (org.jetbrains.annotations.Nullable)7 FileNotFoundException (java.io.FileNotFoundException)5 Writer (java.io.Writer)5