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;
}
}
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;
}
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();
}
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;
}
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);
}
}
Aggregations