use of com.adobe.cq.wcm.core.components.it.seljup.util.components.text.v2.Text in project jspwiki by apache.
the class XHtmlElementToWikiTranslator method print.
private void print(Object element) throws IOException, JDOMException {
if (element instanceof Text) {
Text t = (Text) element;
String s = t.getText();
if (m_preStack.isPreMode()) {
m_out.print(s);
} else {
// remove all "line terminator" characters
s = s.replaceAll("[\\r\\n\\f\\u0085\\u2028\\u2029]", "");
m_out.print(s);
}
} else if (element instanceof Element) {
Element base = (Element) element;
String n = base.getName().toLowerCase();
if ("imageplugin".equals(base.getAttributeValue("class"))) {
printImage(base);
} else if ("wikiform".equals(base.getAttributeValue("class"))) {
// only print the children if the div's class="wikiform", but not the div itself.
printChildren(base);
} else {
boolean bold = false;
boolean italic = false;
boolean monospace = false;
String cssSpecial = null;
String cssClass = base.getAttributeValue("class");
// accomodate a FCKeditor bug with Firefox: when a link is removed, it becomes <span class="wikipage">text</span>.
boolean ignoredCssClass = cssClass != null && cssClass.matches("wikipage|createpage|external|interwiki|attachment");
Map styleProps = null;
// handled as an AugmentedWikiLink instead.
if (!n.equals("a")) {
styleProps = getStylePropertiesLowerCase(base);
}
if (styleProps != null) {
String fontFamily = (String) styleProps.get("font-family");
String whiteSpace = (String) styleProps.get("white-space");
if (fontFamily != null && (fontFamily.indexOf("monospace") >= 0 && whiteSpace != null && whiteSpace.indexOf("pre") >= 0)) {
styleProps.remove("font-family");
styleProps.remove("white-space");
monospace = true;
}
String weight = (String) styleProps.remove("font-weight");
String style = (String) styleProps.remove("font-style");
if (n.equals("p")) {
// change it so we can print out the css styles for <p>
n = "div";
}
italic = "oblique".equals(style) || "italic".equals(style);
bold = "bold".equals(weight) || "bolder".equals(weight);
if (!styleProps.isEmpty()) {
cssSpecial = propsToStyleString(styleProps);
}
}
if (cssClass != null && !ignoredCssClass) {
if (n.equals("div")) {
m_out.print("\n%%" + cssClass + " \n");
} else if (n.equals("span")) {
m_out.print("%%" + cssClass + " ");
}
}
if (bold) {
m_out.print("__");
}
if (italic) {
m_out.print("''");
}
if (monospace) {
m_out.print("{{{");
m_preStack.push();
}
if (cssSpecial != null) {
if (n.equals("div")) {
m_out.print("\n%%(" + cssSpecial + " )\n");
} else {
m_out.print("%%(" + cssSpecial + " )");
}
}
printChildren(base);
if (cssSpecial != null) {
if (n.equals("div")) {
m_out.print("\n/%\n");
} else {
m_out.print("/%");
}
}
if (monospace) {
m_preStack.pop();
m_out.print("}}}");
}
if (italic) {
m_out.print("''");
}
if (bold) {
m_out.print("__");
}
if (cssClass != null && !ignoredCssClass) {
if (n.equals("div")) {
m_out.print("\n/%\n");
} else if (n.equals("span")) {
m_out.print("/%");
}
}
}
}
}
use of com.adobe.cq.wcm.core.components.it.seljup.util.components.text.v2.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 com.adobe.cq.wcm.core.components.it.seljup.util.components.text.v2.Text in project omegat by omegat-org.
the class DefaultXMLDialect method constructShortcuts.
/**
* {@inheritDoc}
*/
@Override
public String constructShortcuts(List<Element> elements, List<ProtectedPart> protectedParts) {
protectedParts.clear();
StringBuilder r = new StringBuilder();
for (Element el : elements) {
String shortcut = el.toShortcut();
r.append(shortcut);
if (!(el instanceof Text)) {
ProtectedPart pp = new ProtectedPart();
pp.setTextInSourceSegment(shortcut);
pp.setDetailsFromSourceFile(el.toOriginal());
if (StatisticsSettings.isCountingStandardTags()) {
pp.setReplacementWordsCountCalculation(el.toSafeCalcShortcut());
} else {
pp.setReplacementWordsCountCalculation(StaticUtils.TAG_REPLACEMENT);
}
pp.setReplacementUniquenessCalculation(StaticUtils.TAG_REPLACEMENT);
pp.setReplacementMatchCalculation(StaticUtils.TAG_REPLACEMENT);
protectedParts.add(pp);
}
}
return r.toString();
}
use of com.adobe.cq.wcm.core.components.it.seljup.util.components.text.v2.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 com.adobe.cq.wcm.core.components.it.seljup.util.components.text.v2.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);
}
Aggregations