use of org.jdom2.Content in project jspwiki by apache.
the class RSS10Feed method addItemList.
private void addItemList(Element root) {
SimpleDateFormat iso8601fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
WikiEngine engine = m_wikiContext.getEngine();
for (Entry entry : m_entries) {
String url = entry.getURL();
Element item = new Element("item", NS_XMNLS);
item.setAttribute("about", url, NS_RDF);
item.addContent(new Element("title", NS_XMNLS).addContent(entry.getTitle()));
item.addContent(new Element("link", NS_XMNLS).addContent(url));
Element content = new Element("description", NS_XMNLS);
// TODO: Add a size limiter here
content.addContent(entry.getContent());
item.addContent(content);
WikiPage p = entry.getPage();
if (p.getVersion() != -1) {
item.addContent(new Element("version", NS_WIKI).addContent(Integer.toString(p.getVersion())));
}
if (p.getVersion() > 1) {
item.addContent(new Element("diff", NS_WIKI).addContent(engine.getURL(WikiContext.DIFF, p.getName(), "r1=-1", true)));
}
//
// Modification date.
Calendar cal = Calendar.getInstance();
cal.setTime(p.getLastModified());
cal.add(Calendar.MILLISECOND, -(cal.get(Calendar.ZONE_OFFSET) + (cal.getTimeZone().inDaylightTime(p.getLastModified()) ? cal.get(Calendar.DST_OFFSET) : 0)));
item.addContent(new Element("date", NS_DC).addContent(iso8601fmt.format(cal.getTime())));
//
// Author
String author = entry.getAuthor();
if (author == null) {
author = "unknown";
}
Element contributor = new Element("creator", NS_DC);
item.addContent(contributor);
/*
Element description = new Element("Description", NS_RDF);
if( m_wikiContext.getEngine().pageExists(author) ) {
description.setAttribute( "link", engine.getURL( WikiContext.VIEW, author, null, true ), NS_XMNLS );
}
description.addContent( new Element("value", NS_XMNLS).addContent( author) );
contributor.addContent( description );
*/
// Not too many aggregators seem to like this. Therefore we're just adding the name here.
contributor.addContent(author);
//
// PageHistory
item.addContent(new Element("history", NS_WIKI).addContent(engine.getURL(WikiContext.INFO, p.getName(), null, true)));
//
// Add to root
root.addContent(item);
}
}
use of org.jdom2.Content in project jspwiki by apache.
the class IndexPlugin method getLink.
private Element getLink(String href, String content) {
Element a = new Element("a", xmlns_XHTML);
a.setAttribute("href", href);
a.addContent(content);
return a;
}
use of org.jdom2.Content in project mycore by MyCoRe-Org.
the class MCRXMLHelperTest method testList.
@Test
public void testList() throws Exception {
Element child1 = new Element("child").setText("Hallo Welt");
Element child2 = new Element("child").setText("hello world");
Element child3 = new Element("child").setText("Bonjour le monde");
List<Content> l1 = new ArrayList<>();
l1.add(child1);
l1.add(child2);
l1.add(child3);
Element root = new Element("root");
root.addContent(l1);
String formattedXML = "<root>\n<child>Hallo Welt</child>\n" + "<child>hello world</child>" + "<child>Bonjour le monde</child>\n</root>";
SAXBuilder b = new SAXBuilder();
Document doc = b.build(new ByteArrayInputStream(formattedXML.getBytes(Charset.forName("UTF-8"))));
assertEquals("Elements should be equal", true, MCRXMLHelper.deepEqual(root, doc.getRootElement()));
}
use of org.jdom2.Content 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.jdom2.Content in project mycore by MyCoRe-Org.
the class MCRWCMSContentManager method save.
/**
* Saves the content of the given items.
*
* Returns a json object, if everything is ok:
* <p>
* { type: "saveDone" }
* </p>
*
* <p>
* If one or more files could'nt be saved because of an error the returning
* json looks like:<br>
* {
* type: "error",
* errorArray: [
* {type: "error", errorType: "invalidDirectory", webpageId: "abc.xml"},
* {type: "error", errorType: "invalidFile", webpageId: "abc2.xml"}
* ...
* ]
* }
* </p>
*/
public void save(JsonArray items) {
XMLOutputter out = new XMLOutputter(Format.getRawFormat().setEncoding("UTF-8"));
for (JsonElement e : items) {
if (!e.isJsonObject()) {
LOGGER.warn("Invalid json element in items {}", e);
continue;
}
JsonObject item = e.getAsJsonObject();
if (!item.has("dirty") || !item.get("dirty").getAsBoolean()) {
continue;
}
JsonElement webpageIdElement = item.has("href") ? item.get("href") : (item.has("hrefStartingPage") ? item.get("hrefStartingPage") : null);
if (webpageIdElement == null || !webpageIdElement.isJsonPrimitive()) {
continue;
}
// trotzdem umgeschrieben werden -> check auf file exists
if (!item.has("content") || !item.get("content").isJsonArray()) {
continue;
}
String webpageId = webpageIdElement.getAsString();
if (!webpageId.endsWith(".xml")) {
throwError(ErrorType.invalidFile, webpageId);
}
JsonArray content = item.get("content").getAsJsonArray();
Element mycoreWebpage = this.sectionProvider.fromJSON(content);
// save
try (OutputStream fout = MCRWebPagesSynchronizer.getOutputStream(webpageId)) {
out.output(new Document(mycoreWebpage), fout);
} catch (Exception exc) {
LOGGER.error("Error while saving {}", webpageId, exc);
throwError(ErrorType.couldNotSave, webpageId);
}
}
}
Aggregations