Example usage for org.jdom2 Document Document

List of usage examples for org.jdom2 Document Document

Introduction

In this page you can find the example usage for org.jdom2 Document Document.

Prototype

public Document() 

Source Link

Document

Creates a new empty document.

Usage

From source file:pt.ist.socialsoftware.edition.export.ExpertEditionTEIExport.java

License:Creative Commons License

private Element generateCorpus() {
    this.jdomDoc = new Document();
    Element rootElement = new Element("teiCorpus");

    rootElement.setNamespace(this.xmlns);

    rootElement.addNamespaceDeclaration(Namespace.getNamespace("svg", "http://www.w3.org/2000/svg"));

    rootElement.addNamespaceDeclaration(Namespace.getNamespace("xi", "http://www.w3.org/2001/XInclude"));

    this.jdomDoc.setRootElement(rootElement);
    return rootElement;
}

From source file:pt.ist.socialsoftware.edition.visitors.TEIGenerator.java

License:Creative Commons License

private Element generateCorpus() {
    jdomDoc = new Document();
    Element rootElement = new Element("teiCorpus");

    rootElement.setNamespace(xmlns);/*from w  w  w  .  jav a2  s  . co  m*/

    rootElement.addNamespaceDeclaration(Namespace.getNamespace("svg", "http://www.w3.org/2000/svg"));

    rootElement.addNamespaceDeclaration(Namespace.getNamespace("xi", "http://www.w3.org/2001/XInclude"));

    jdomDoc.setRootElement(rootElement);
    return rootElement;
}

From source file:qtiscoringengine.itembody.QTIItemBody.java

License:Open Source License

public static QTIItemBody fromXml(String source, XmlReader reader, ValidationLog log) {
    if (reader == null)
        return null;

    Document doc = new Document();
    try {/*from   w ww . j  ava 2s.  c  om*/
        doc = reader.getDocument();
    } catch (Exception e) {
        log.addMessage(null, "Failed to load document. Message: " + e.getMessage());
        return null;
    }

    // Create an XmlNamespaceManager for resolving namespaces.
    XmlNamespaceManager nsmgr = new XmlNamespaceManager(/* doc.NameTable */);
    nsmgr.addNamespace("qti", "http://www.imsglobal.org/xsd/imsqti_v2p1");

    Element foo = doc.getRootElement();
    Element itemBody = new XmlElement(foo).selectSingleNode(ItemBodyConstants.ItemBody, nsmgr);
    if (itemBody == null) {
        log.addMessage(null, "No ItemBody node is present in the rubric");
        return new QTIItemBody(source, null);
    }
    List<Interaction> interactionList = new ArrayList<Interaction>();

    List<Element> choiceInteractions = new XmlElement(itemBody).selectNodes(ItemBodyConstants.ChoiceInteraction,
            nsmgr);
    for (Element node : choiceInteractions) {
        ChoiceInteraction ci = ChoiceInteraction.fromXml(node, nsmgr, log);
        if (ci != null)
            interactionList.add(ci);
    }

    List<Element> associateInteraction = new XmlElement(itemBody)
            .selectNodes(ItemBodyConstants.AssociateInteraction, nsmgr);
    for (Element node : associateInteraction) {
        AssociateInteraction ai = AssociateInteraction.fromXml(node, nsmgr, log);
        if (ai != null)
            interactionList.add(ai);
    }

    List<Element> gapMatchInteraction = new XmlElement(itemBody)
            .selectNodes(ItemBodyConstants.GapMatchInteraction, nsmgr);
    for (Element node : gapMatchInteraction) {
        GapMatchInteraction gmi = GapMatchInteraction.fromXml(node, nsmgr, log);
        if (gmi != null)
            interactionList.add(gmi);
    }

    List<Element> graphAssocInteraction = new XmlElement(itemBody)
            .selectNodes(ItemBodyConstants.GraphicAssociateInteraction, nsmgr);
    for (Element node : graphAssocInteraction) {
        GraphicAssociateInteraction gai = GraphicAssociateInteraction.fromXml(node, nsmgr, log);
        if (gai != null)
            interactionList.add(gai);
    }

    List<Element> graphGapMatchInteraction = new XmlElement(itemBody)
            .selectNodes(ItemBodyConstants.GraphicGapMatchInteraction, nsmgr);
    for (Element node : graphGapMatchInteraction) {
        GraphicGapMatchInteraction ggmi = GraphicGapMatchInteraction.fromXml(node, nsmgr, log);
        if (ggmi != null)
            interactionList.add(ggmi);
    }

    List<Element> graphOrderInteraction = new XmlElement(itemBody)
            .selectNodes(ItemBodyConstants.GraphicOrderInteraction, nsmgr);
    for (Element node : graphOrderInteraction) {
        GraphicOrderInteraction goi = GraphicOrderInteraction.fromXml(node, nsmgr, log);
        if (goi != null)
            interactionList.add(goi);
    }

    List<Element> hotspotInteraction = new XmlElement(itemBody)
            .selectNodes(ItemBodyConstants.HotspotInteraction, nsmgr);
    for (Element node : hotspotInteraction) {
        HotspotInteraction hsi = HotspotInteraction.fromXml(node, nsmgr, log);
        if (hsi != null)
            interactionList.add(hsi);
    }

    List<Element> hottextInteraction = new XmlElement(itemBody)
            .selectNodes(ItemBodyConstants.HottextInteraction, nsmgr);
    for (Element node : hottextInteraction) {
        HottextInteraction hti = HottextInteraction.fromXml(node, nsmgr, log);
        if (hti != null)
            interactionList.add(hti);
    }

    List<Element> matchInteraction = new XmlElement(itemBody).selectNodes(ItemBodyConstants.MatchInteraction,
            nsmgr);
    for (Element node : matchInteraction) {
        MatchInteraction mi = MatchInteraction.fromXml(node, nsmgr, log);
        if (mi != null)
            interactionList.add(mi);
    }

    List<Element> orderInteraction = new XmlElement(itemBody).selectNodes(ItemBodyConstants.OrderInteraction,
            nsmgr);
    for (Element node : orderInteraction) {
        OrderInteraction oi = OrderInteraction.fromXml(node, nsmgr, log);
        if (oi != null)
            interactionList.add(oi);
    }

    List<Element> selectPointInteraction = new XmlElement(itemBody)
            .selectNodes(ItemBodyConstants.SelectPointInteraction, nsmgr);
    for (Element node : selectPointInteraction) {
        SelectPointInteraction spi = SelectPointInteraction.fromXml(node, nsmgr, log);
        if (spi != null)
            interactionList.add(spi);
    }

    List<Element> sliderInteraction = new XmlElement(itemBody).selectNodes(ItemBodyConstants.SliderInteraction,
            nsmgr);
    for (Element node : sliderInteraction) {
        SliderInteraction si = SliderInteraction.fromXml(node, nsmgr, log);
        if (si != null)
            interactionList.add(si);
    }

    if (interactionList.size() == 0) {
        log.addMessage(null, "No valid Interaction nodes found in ItemBody node");
        return new QTIItemBody(source, null);
    }

    return new QTIItemBody(source, interactionList);
}

From source file:qtiscoringengine.QTIUtility.java

License:Open Source License

static Element getXMLFromURL(String url, XmlNamespaceManager nsmgr)
        throws MalformedURLException, QTIScoringException {
    // C:\Projects\QTISpec\qtiv2p1pd2\rptemplates
    // Uri uri = new Uri(url);
    // string[] chunks = uri.
    // int count = uri.Segments.Length;

    // string filename = uri.Segments[count-1];

    // string place =
    // string.Format("file:///C:\\Projects\\QTISpec\\qtiv2p1pd2\\rptemplates\\{0}.xml",
    // filename);
    Document doc = new Document();

    URL _url = new URL(url);
    try (InputStream is = _url.openStream()) {
        doc = new SAXBuilder().build(is);
    } catch (JDOMException | IOException e) {
        e.printStackTrace();//from w w w  .  j a  v  a 2 s .  c o m
        throw new QTIScoringException(e);
    }
    // return XPathFactory.instance ().compile
    // (QTIXmlConstants.ResponseProcessing, Filters.element (), null,
    // nsmgr).evaluateFirst (doc);
    return new XmlElement(doc.getRootElement()).selectSingleNode(QTIXmlConstants.ResponseProcessing, nsmgr);
}

From source file:Report.Report.java

License:Open Source License

public Report() {
    jdomDoc = new Document();
    Element rootElement = new Element("SatPlan");
    jdomDoc.setRootElement(rootElement);
    lazy = new ArrayList<>();
    init();/*ww w  . j av  a2 s . com*/
}

From source file:rezeptsuperpos.IngredientArchive.java

License:Open Source License

public IngredientArchive() {
    documentPathFile = "db/ingredients.xml";
    JDom jdom = new JDom();
    try {/*www  .  j a va2s. co  m*/
        document = jdom.readXML(documentPathFile);
    } catch (Exception ex) {
        document = new Document();
        document.addContent(new Element("ingredients"));
        try {
            saveIngredients();
        } catch (FileNotFoundException | UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
    for (Element ingredient : document.getRootElement().getChildren())
        documentArr.add(ingredient);
}

From source file:Servico.ArgoUMLtoAstahXML.java

public void ToXmi(UmlModel model) throws InterruptedException, IOException {
    Document doc = new Document();
    Element Emodel = new Element(model.getClass().getName());
    Emodel.setAttribute("id", model.getId() + "");
    Emodel.setAttribute("name", model.getName() + "");
    doc.setRootElement(Emodel);//from   w  w  w  .j  ava2  s  .  c o  m
    for (UmlDiagram diagram : model.getDiagrams()) {
        Element EDiagram = new Element(diagram.getClass().getName());
        EDiagram.setAttribute("id", diagram.getId() + "");
        EDiagram.setAttribute("name", diagram.getName() + "");

        for (UmlBase umlObject : diagram.getUmlObjects()) {
            //verificar o conteudo para a tag tdaction e substituir
            String action = umlObject.getTaggedValues().get("TDACTION");
            if (action != null) {
                action = action.replaceAll("%", "%25");
                umlObject.getTaggedValues().put("TDACTION", action);
            }

            Element EUmlObject = getElement(umlObject);
            EDiagram.addContent(EUmlObject);

        }
        Emodel.addContent(EDiagram);
        //doc.setRootElement(EDiagram);
    }

    //Imprimindo o XML
    File out = File.createTempFile("IntermediateFile", ".xml");//, new File(Configuration.getInstance().getProperty("workspacepath")));

    try (FileWriter arquivo = new FileWriter(out)) {
        XMLOutputter xout = new XMLOutputter();
        xout.output(doc, arquivo);
    } catch (Exception e) {
        throw new IllegalAccessError("No foi possivel escrever o arquivo xml.");
    }
}

From source file:tinygrscoringengine.TinyGR.java

License:Open Source License

public static List<String> getObjectStrings(String answerSet) throws TinyGRException {
    try {/* w  w w .j  a v  a 2 s.c  o  m*/
        List<String> objects = new ArrayList<String>();
        StringReader sr = new StringReader(answerSet);
        XmlReader reader = new XmlReader(sr);
        Document doc = new Document();
        doc = reader.getDocument();
        XmlElement objectSet = new XmlElement(new XmlElement(doc.getRootElement())
                .selectSingleNode("//AnswerSet/Question/QuestionPart/ObjectSet"));
        for (Element child : objectSet.getChildNodes()) {
            GRObject obj = GRObject.createFromNode(child);
            objects.add(obj.getXmlString());
            if (child.getName().equals("RegionGroupObject")) {
                for (Element region : child.getChildren()) {
                    outputObjectString(region, objects);
                }
            }
        }
        return objects;
    } catch (Exception exp) {
        throw new TinyGRException(exp);
    }
}

From source file:tinygrscoringengine.TinyGRExpression.java

License:Open Source License

public static DEPoint pointFromXml(String xml) throws TinyGRException {
    try {//  w  w  w.  ja  v  a 2s  . co  m
        String text = "";
        StringReader sr = new StringReader(xml);

        XmlReader reader = new XmlReader(sr);
        Document doc = new Document();
        doc = reader.getDocument();
        if ("Point".equals(doc.getRootElement().getName()))
            text = doc.getRootElement().getText();

        if (StringUtils.isEmpty(text)) {
            return null;
        }

        int locationOfX = text.indexOf('(');
        int locationOfXC = text.indexOf(',');
        int endOfPair = text.indexOf(')');

        String xText = text.substring(locationOfX + 1, locationOfXC).trim();
        String yText = text.substring(locationOfXC + 1, endOfPair).trim();

        _Ref<Integer> x = new _Ref<Integer>(0);
        _Ref<Integer> y = new _Ref<Integer>(0);
        boolean status = JavaPrimitiveUtils.intTryParse(xText, x);

        if (status)
            status = JavaPrimitiveUtils.intTryParse(yText, y);

        if (status) {
            return new DEPoint(x.get(), y.get());
        } else {
            return null;
        }
    } catch (Exception exp) {
        throw new TinyGRException(exp);
    }
}

From source file:tinytablescoringengine.TableObject.java

License:Open Source License

public Element toXml() {
    return toXml(new Document());
}