Search in sources :

Example 86 with Text

use of org.jdom2.Text in project mycore by MyCoRe-Org.

the class MCRMetaXMLTest method xmlRoundrip.

@Test
public void xmlRoundrip() throws IOException {
    MCRMetaXML mXml = new MCRMetaXML("def.heading", "complete", 0);
    Element imported = new Element("heading");
    imported.setAttribute("lang", MCRMetaDefault.DEFAULT_LANGUAGE, Namespace.XML_NAMESPACE);
    imported.setAttribute("inherited", "0");
    imported.setAttribute("type", "complete");
    imported.addContent(new Text("This is a "));
    imported.addContent(new Element("span").setText("JUnit"));
    imported.addContent(new Text("test"));
    mXml.setFromDOM(imported);
    Element exported = mXml.createXML();
    if (LOGGER.isDebugEnabled()) {
        XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat());
        StringWriter sw = new StringWriter();
        StringWriter sw2 = new StringWriter();
        try {
            xout.output(imported, sw);
            LOGGER.info(sw.toString());
            xout.output(exported, sw2);
            LOGGER.info(sw2.toString());
        } catch (IOException e) {
            LOGGER.warn("Failure printing xml result", e);
        }
    }
    try {
        assertTrue(MCRXMLHelper.deepEqual(new Document(imported), new Document(exported)));
    } catch (AssertionError e) {
        XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
        out.output(imported, System.err);
        out.output(exported, System.err);
        throw e;
    }
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) StringWriter(java.io.StringWriter) Element(org.jdom2.Element) Text(org.jdom2.Text) IOException(java.io.IOException) Document(org.jdom2.Document) Test(org.junit.Test)

Example 87 with Text

use of org.jdom2.Text in project mycore by MyCoRe-Org.

the class MCRSetElementText method setText.

public static MCRChangeData setText(Element element, String text) {
    Element clone = element.clone();
    for (Iterator<Attribute> attributes = clone.getAttributes().iterator(); attributes.hasNext(); ) {
        attributes.next();
        attributes.remove();
    }
    MCRChangeData data = new MCRChangeData("set-text", clone, 0, element);
    element.setText(text);
    return data;
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 88 with Text

use of org.jdom2.Text in project mycore by MyCoRe-Org.

the class MCRDebugTarget method handleSubmission.

@Override
public void handleSubmission(ServletContext context, MCRServletJob job, MCREditorSession session, String parameter) throws Exception {
    job.getResponse().setContentType("text/html; charset=UTF-8");
    PrintWriter out = job.getResponse().getWriter();
    out.println("<html><body>");
    Map<String, String[]> parameters = job.getRequest().getParameterMap();
    session.getSubmission().setSubmittedValues(parameters);
    Document result = session.getEditedXML().clone();
    MCRChangeTracker tracker = session.getChangeTracker().clone();
    List<Step> steps = new ArrayList<>();
    for (String label; (label = tracker.undoLastBreakpoint(result)) != null; ) steps.add(0, new Step(label, result.clone()));
    result = session.getEditedXML().clone();
    result = MCRChangeTracker.removeChangeTracking(result);
    result = session.getXMLCleaner().clean(result);
    steps.add(new Step("After cleaning", result));
    result = session.getPostProcessor().process(result);
    steps.add(new Step("After postprocessing", result));
    for (int i = 0; i < steps.size(); i++) {
        if (i == steps.size() - 3)
            outputParameters(parameters, out);
        steps.get(i).output(out);
    }
    out.println("</body></html>");
    out.close();
}
Also used : MCRChangeTracker(org.mycore.frontend.xeditor.tracker.MCRChangeTracker) ArrayList(java.util.ArrayList) Document(org.jdom2.Document) PrintWriter(java.io.PrintWriter)

Example 89 with Text

use of org.jdom2.Text in project mycore by MyCoRe-Org.

the class MCRSubselectReturnTarget method getBaseXPathForSubselect.

private String getBaseXPathForSubselect(MCREditorSession session) throws JaxenException, JDOMException {
    Document doc = session.getEditedXML();
    MCRChangeData change = session.getChangeTracker().findLastChange(doc);
    String text = change.getText();
    String xPath = text.substring(text.lastIndexOf(" ") + 1).trim();
    return bindsFirstOrMoreThanOneElement(xPath, session) ? xPath + "[1]" : xPath;
}
Also used : MCRChangeData(org.mycore.frontend.xeditor.tracker.MCRChangeData) Document(org.jdom2.Document)

Example 90 with Text

use of org.jdom2.Text in project mycore by MyCoRe-Org.

the class MCRObjectDerivate method setFromDOM.

/**
 * This methode read the XML input stream part from a DOM part for the
 * structure data of the document.
 *
 * @param derivate
 *            a list of relevant DOM elements for the derivate
 */
private void setFromDOM(org.jdom2.Element derivate) {
    // Link to Metadata part
    org.jdom2.Element linkmeta_element = derivate.getChild("linkmetas").getChild("linkmeta");
    MCRMetaLinkID link = new MCRMetaLinkID();
    link.setFromDOM(linkmeta_element);
    linkmeta = link;
    // External part
    org.jdom2.Element externalsElement = derivate.getChild("externals");
    externals.clear();
    if (externalsElement != null) {
        List<Element> externalList = externalsElement.getChildren();
        for (Element externalElement : externalList) {
            MCRMetaLink eLink = new MCRMetaLink();
            eLink.setFromDOM(externalElement);
            externals.add(eLink);
        }
    }
    // Internal part
    org.jdom2.Element internals_element = derivate.getChild("internals");
    if (internals_element != null) {
        org.jdom2.Element internal_element = internals_element.getChild("internal");
        if (internal_element != null) {
            internals = new MCRMetaIFS();
            internals.setFromDOM(internal_element);
        }
    }
    // Title part
    org.jdom2.Element titlesElement = derivate.getChild("titles");
    titles.clear();
    if (titlesElement != null) {
        List<Element> titleList = titlesElement.getChildren();
        for (Element titleElement : titleList) {
            MCRMetaLangText text = new MCRMetaLangText();
            text.setFromDOM(titleElement);
            if (text.isValid()) {
                titles.add(text);
            }
        }
    }
    // fileset part
    Element filesetElements = derivate.getChild("fileset");
    if (filesetElements != null) {
        String mainURN = filesetElements.getAttributeValue("urn");
        if (mainURN != null) {
            this.derivateURN = mainURN;
        }
        List<Element> filesInList = filesetElements.getChildren();
        if (!filesInList.isEmpty()) {
            files = new ArrayList<>(filesInList.size());
            for (Element file : filesInList) {
                files.add(new MCRFileMetadata(file));
            }
        }
    }
    String displayVal = derivate.getAttributeValue("display");
    if (displayVal != null && displayVal.length() > 3) {
        this.display = Boolean.valueOf(displayVal);
    }
}
Also used : Element(org.jdom2.Element) Element(org.jdom2.Element)

Aggregations

Element (org.jdom2.Element)83 Document (org.jdom2.Document)36 File (java.io.File)21 ProcessingInstruction (org.jdom2.ProcessingInstruction)17 IOException (java.io.IOException)14 Text (org.jdom2.Text)12 Attribute (org.jdom2.Attribute)11 XMLOutputter (org.jdom2.output.XMLOutputter)10 Test (org.junit.Test)10 HashMap (java.util.HashMap)9 XmlFile (jmri.jmrit.XmlFile)9 ArrayList (java.util.ArrayList)6 JDOMException (org.jdom2.JDOMException)6 StringWriter (java.io.StringWriter)5 NamedIcon (jmri.jmrit.catalog.NamedIcon)5 FileOutputStream (java.io.FileOutputStream)4 LinkedHashMap (java.util.LinkedHashMap)4 FileNotFoundException (java.io.FileNotFoundException)3 URL (java.net.URL)3 Locale (java.util.Locale)3