use of com.adobe.cq.wcm.core.components.it.seljup.util.components.text.v2.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 com.adobe.cq.wcm.core.components.it.seljup.util.components.text.v2.Text in project mycore by MyCoRe-Org.
the class MCRXSL2XMLTransformer method getDocument.
private Document getDocument(JDOMResult result) {
Document resultDoc = result.getDocument();
if (resultDoc == null) {
// Sometimes a transformation produces whitespace strings
// JDOM would produce a empty document if it detects those
// So we remove them, if they exists.
List<Content> transformResult = result.getResult();
int origSize = transformResult.size();
Iterator<Content> iterator = transformResult.iterator();
while (iterator.hasNext()) {
Content content = iterator.next();
if (content instanceof Text) {
String trimmedText = ((Text) content).getTextTrim();
if (trimmedText.length() == 0) {
iterator.remove();
}
}
}
if (transformResult.size() < origSize) {
JDOMFactory f = result.getFactory();
if (f == null) {
f = new DefaultJDOMFactory();
}
resultDoc = f.document(null);
resultDoc.setContent(transformResult);
}
}
return resultDoc;
}
use of com.adobe.cq.wcm.core.components.it.seljup.util.components.text.v2.Text in project mycore by MyCoRe-Org.
the class MCRTransferPackageUtil method getMCRObjects.
/**
* Gets the list of mycore object identifiers from the given directory.
*
* @param targetDirectory directory where the *.tar was unpacked
* @return list of object which lies within the directory
*/
public static List<String> getMCRObjects(Path targetDirectory) throws JDOMException, IOException {
Path order = targetDirectory.resolve(MCRTransferPackage.IMPORT_CONFIG_FILENAME);
Document xml = new SAXBuilder().build(order.toFile());
Element config = xml.getRootElement();
XPathExpression<Text> exp = MCRConstants.XPATH_FACTORY.compile("order/object/text()", Filters.text());
return exp.evaluate(config).stream().map(Text::getText).collect(Collectors.toList());
}
use of com.adobe.cq.wcm.core.components.it.seljup.util.components.text.v2.Text in project mycore by MyCoRe-Org.
the class MCRURNObjectXPathMetadataManager method getIdentifier.
@Override
public Optional<MCRPersistentIdentifier> getIdentifier(MCRBase obj, String additional) throws MCRPersistentIdentifierException {
String xpath = getProperties().get("Xpath");
Document xml = obj.createXML();
XPathFactory xpfac = XPathFactory.instance();
XPathExpression<Text> xp = xpfac.compile(xpath, Filters.text());
List<Text> evaluate = xp.evaluate(xml);
if (evaluate.size() > 1) {
throw new MCRPersistentIdentifierException("Got " + evaluate.size() + " matches for " + obj.getId() + " with xpath " + xpath + "");
}
if (evaluate.size() == 0) {
return Optional.empty();
}
Text identifierText = evaluate.listIterator().next();
String identifierString = identifierText.getTextNormalize();
Optional<MCRDNBURN> parsedIdentifierOptional = PARSER.parse(identifierString);
return parsedIdentifierOptional.map(MCRPersistentIdentifier.class::cast);
}
Aggregations