use of org.omegat.filters3.Text in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class TextIT method setupBeforeEach.
@BeforeEach
public void setupBeforeEach() throws ClientException {
setComponentResources();
text = new Text();
setup();
}
use of org.omegat.filters3.Text in project mycore by MyCoRe-Org.
the class MCRWCMSDefaultSectionProvider method getContent.
/**
* Returns the content of an element as string. The element itself
* is ignored.
*
* @param e the element to get the content from
* @return the content as string
*/
protected String getContent(Element e) throws IOException {
XMLOutputter out = new XMLOutputter();
StringWriter writer = new StringWriter();
for (Content child : e.getContent()) {
if (child instanceof Element) {
out.output((Element) child, writer);
} else if (child instanceof Text) {
Text t = (Text) child;
String trimmedText = t.getTextTrim();
if (!trimmedText.equals("")) {
Text newText = new Text(trimmedText);
out.output(newText, writer);
}
}
}
return writer.toString();
}
use of org.omegat.filters3.Text in project mycore by MyCoRe-Org.
the class MCRMetaNumberTest method xmlRoundrip.
@Test
public void xmlRoundrip() throws IOException {
// test 0.100
MCRMetaNumber meta_number = new MCRMetaNumber();
Element imported = new Element("number");
imported.setAttribute("inherited", "0");
imported.setAttribute("dimension", "width");
imported.setAttribute("measurement", "cm");
imported.addContent(new Text("0.100"));
meta_number.setFromDOM(imported);
Element exported = meta_number.createXML();
print_data(imported, exported);
check_data(imported, exported);
}
use of org.omegat.filters3.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.omegat.filters3.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;
}
Aggregations