use of org.jdom2.Text in project gocd by gocd.
the class ProjectStatus method addBreakers.
private void addBreakers(Element element) {
Element messages = new Element("messages");
Element message = new Element("message");
String breakerNames = StringUtils.join(breakers, ", ");
message.setAttribute("text", breakerNames);
message.setAttribute("kind", "Breakers");
messages.addContent(message);
element.addContent(messages);
}
use of org.jdom2.Text in project archi by archimatetool.
the class JDOMUtilsTests method testReadXMLString.
@Test
public void testReadXMLString() throws Exception {
String testString = "<root> <element att=\"hello\">Some text</element> </root>";
Document doc = JDOMUtils.readXMLString(testString);
assertNotNull(doc);
assertTrue(doc.hasRootElement());
}
use of org.jdom2.Text in project jspwiki by apache.
the class JSPWikiMarkupParser method makeLink.
private Element makeLink(int type, String link, String text, String section, Iterator attributes) {
Element el = null;
if (text == null)
text = link;
text = callMutatorChain(m_linkMutators, text);
section = (section != null) ? ("#" + section) : "";
if (link.length() == 0) {
type = EMPTY;
}
ResourceBundle rb = Preferences.getBundle(m_context, InternationalizationManager.CORE_BUNDLE);
switch(type) {
case READ:
el = createAnchor(READ, m_context.getURL(WikiContext.VIEW, link), text, section);
break;
case EDIT:
el = createAnchor(EDIT, m_context.getURL(WikiContext.EDIT, link), text, "");
el.setAttribute("title", MessageFormat.format(rb.getString("markupparser.link.create"), link));
break;
case EMPTY:
el = new Element("u").addContent(text);
break;
//
case LOCALREF:
el = createAnchor(LOCALREF, "#ref-" + m_context.getName() + "-" + link, "[" + text + "]", "");
break;
case LOCAL:
el = new Element("a").setAttribute("class", CLASS_FOOTNOTE);
el.setAttribute("name", "ref-" + m_context.getName() + "-" + link.substring(1));
el.addContent("[" + text + "]");
break;
//
case IMAGE:
el = new Element("img").setAttribute("class", "inline");
el.setAttribute("src", link);
el.setAttribute("alt", text);
break;
case IMAGELINK:
el = new Element("img").setAttribute("class", "inline");
el.setAttribute("src", link);
el.setAttribute("alt", text);
el = createAnchor(IMAGELINK, text, "", "").addContent(el);
break;
case IMAGEWIKILINK:
String pagelink = m_context.getURL(WikiContext.VIEW, text);
el = new Element("img").setAttribute("class", "inline");
el.setAttribute("src", link);
el.setAttribute("alt", text);
el = createAnchor(IMAGEWIKILINK, pagelink, "", "").addContent(el);
break;
case EXTERNAL:
el = createAnchor(EXTERNAL, link, text, section);
if (m_useRelNofollow)
el.setAttribute("rel", "nofollow");
break;
case INTERWIKI:
el = createAnchor(INTERWIKI, link, text, section);
break;
case ATTACHMENT:
String attlink = m_context.getURL(WikiContext.ATTACH, link);
String infolink = m_context.getURL(WikiContext.INFO, link);
String imglink = m_context.getURL(WikiContext.NONE, "images/attachment_small.png");
el = createAnchor(ATTACHMENT, attlink, text, "");
pushElement(el);
popElement(el.getName());
if (m_useAttachmentImage) {
el = new Element("img").setAttribute("src", imglink);
el.setAttribute("border", "0");
el.setAttribute("alt", "(info)");
el = new Element("a").setAttribute("href", infolink).addContent(el);
el.setAttribute("class", "infolink");
} else {
el = null;
}
break;
default:
break;
}
if (el != null && attributes != null) {
while (attributes.hasNext()) {
Attribute attr = (Attribute) attributes.next();
if (attr != null) {
el.setAttribute(attr);
}
}
}
if (el != null) {
flushPlainText();
m_currentElement.addContent(el);
}
return el;
}
use of org.jdom2.Text in project jspwiki by apache.
the class LinkParser method parse.
// ............
/**
* Processes incoming link text, separating out the link text, the link
* URI, and then any specified attributes.
*
* @param linktext the wiki link text to be parsed
* @return a Link object containing the link text, reference, and any valid Attributes
* @throws ParseException if the parameter is null
*/
public Link parse(String linktext) throws ParseException {
if (linktext == null) {
throw new ParseException("null value passed to link parser");
}
Link link = null;
try {
// establish link text and link ref
int cut1 = linktext.indexOf('|');
if (cut1 == -1) {
// link form 1: [Acme]
return new Link(linktext);
}
int cut2 = cut1 + 1 < linktext.length() ? linktext.indexOf('|', cut1 + 1) : -1;
if (cut2 == -1) {
// link form 2: [Acme | http://www.acme.com/]
// text = Acme
String text = linktext.substring(0, cut1).trim();
// ref = http://www.acme.com/
String ref = linktext.substring(cut1 + 1).trim();
return new Link(text, ref);
}
// link form 3: [Acme | http://www.acme.com/ | id='foo' rel='Next']
String text = linktext.substring(0, cut1).trim();
String ref = linktext.substring(cut1 + 1, cut2).trim();
// attribs = id='foo' rel='Next'
String attribs = linktext.substring(cut2 + 1).trim();
link = new Link(text, ref);
// contains "='" that looks like attrib spec
if (attribs.indexOf(EQSQUO) != -1) {
try {
StringTokenizer tok = new StringTokenizer(attribs, DELIMS, true);
while (tok.hasMoreTokens()) {
// get attribute name token
String token = tok.nextToken(DELIMS).trim();
while (isSpace(token) && tok.hasMoreTokens()) {
// remove all whitespace
token = tok.nextToken(DELIMS).trim();
}
// eat '=', break after '='
require(tok, EQ);
// eat opening delim
require(tok, SQUO);
// using existing delim
String value = tok.nextToken(SQUO);
// eat closing delim
require(tok, SQUO);
if (token != null && value != null) {
if (Arrays.binarySearch(PERMITTED_ATTRIBUTES, token) >= 0) {
// _blank _self _parent _top
if (!token.equals(TARGET) || Arrays.binarySearch(PERMITTED_TARGET_VALUES, value) >= 0) {
Attribute a = new Attribute(token, value);
link.addAttribute(a);
} else {
throw new ParseException("unknown target attribute value='" + value + "' on link");
}
} else {
throw new ParseException("unknown attribute name '" + token + "' on link");
}
} else {
throw new ParseException("unable to parse link attributes '" + attribs + "'");
}
}
} catch (ParseException pe) {
log.warn("syntax error parsing link attributes '" + attribs + "': " + pe.getMessage());
} catch (NoSuchElementException nse) {
log.warn("expected more tokens while parsing link attributes '" + attribs + "'");
}
}
} catch (Exception e) {
log.warn(e.getClass().getName() + " thrown by link parser: " + e.getMessage());
}
return link;
}
use of org.jdom2.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("/%");
}
}
}
}
}
Aggregations