use of org.jdom2.Content in project mycore by MyCoRe-Org.
the class MCRMetaIFS method createXML.
/**
* This method create a XML stream for all data in this class, defined by
* the MyCoRe XML MCRMetaIFS definition for the given subtag.
*
* @exception MCRException
* if the content of this class is not valid
* @return a JDOM Element with the XML MCRClassification part
*/
@Override
public final Element createXML() throws MCRException {
Element elm = super.createXML();
if (sourcepath != null) {
elm.setAttribute("sourcepath", sourcepath);
}
elm.setAttribute("maindoc", maindoc);
elm.setAttribute("ifsid", ifsid);
return elm;
}
use of org.jdom2.Content in project mycore by MyCoRe-Org.
the class MCRMetaLangText method createXML.
/**
* This method create a XML stream for all data in this class, defined by
* the MyCoRe XML MCRMetaLangText definition for the given subtag.
*
* @exception MCRException
* if the content of this class is not valid
* @return a JDOM Element with the XML MCRMetaLangText part
*/
@Override
public org.jdom2.Element createXML() throws MCRException {
Element elm = super.createXML();
if (form != null && (form = form.trim()).length() != 0) {
elm.setAttribute("form", form);
}
elm.addContent(text);
return elm;
}
use of org.jdom2.Content in project mycore by MyCoRe-Org.
the class MCRFileStoreTest method basicFunctionality.
@Test
public void basicFunctionality() throws Exception {
Date first = new Date();
synchronized (this) {
wait(1000);
}
MCRFileCollection col = getStore().create();
assertNotNull(col);
assertTrue(col.getID() > 0);
Date created = col.getLastModified();
assertFalse(first.after(created));
bzzz();
MCRFile build = col.createFile("build.xml");
assertNotNull(build);
Date modified = col.getLastModified();
assertTrue(modified.after(created));
assertEquals(1, col.getNumChildren());
assertEquals(1, col.getChildren().size());
assertEquals(0, build.getSize());
assertTrue(created.before(build.getLastModified()));
build.setContent(new MCRJDOMContent(new Element("project")));
assertTrue(build.getSize() > 0);
assertNotNull(build.getContent().asByteArray());
bzzz();
MCRDirectory dir = col.createDir("documentation");
assertEquals(2, col.getNumChildren());
assertTrue(modified.before(col.getLastModified()));
byte[] content = "Hello World!".getBytes("UTF-8");
dir.createFile("readme.txt").setContent(new MCRByteContent(content, System.currentTimeMillis()));
MCRFile child = (MCRFile) dir.getChild("readme.txt");
assertNotNull(child);
assertEquals(content.length, child.getSize());
}
use of org.jdom2.Content in project mycore by MyCoRe-Org.
the class MyCoReWebPageProviderTest method addSection.
@Test
public void addSection() throws Exception {
MyCoReWebPageProvider wp = new MyCoReWebPageProvider();
// simple test
Element content = new Element("content");
content.setText("sample text");
Element section = wp.addSection("title1", content, "de");
assertNotNull(section);
assertEquals("title1", section.getAttributeValue("title"));
assertEquals("de", section.getAttributeValue("lang", Namespace.XML_NAMESPACE));
assertEquals("sample text", section.getChild("content").getText());
// xml text surrounded by p-tag
Element section2 = wp.addSection("title2", "<p>text test</p>", "en");
assertEquals("title2", section2.getAttributeValue("title"));
assertEquals("en", section2.getAttributeValue("lang", Namespace.XML_NAMESPACE));
assertEquals("text test", section2.getChild("p").getText());
// only text
Element section3 = wp.addSection("title3", "simple text", "uk");
assertEquals("simple text", section3.getText());
// multi tags
Element section4 = wp.addSection("title4", "<b>bold</b> <i>italic</i>", "at");
assertEquals(2, section4.getChildren().size());
// check section count
assertEquals(4, wp.getXML().getRootElement().getContentSize());
// entities
wp.addSection("title5", " &äHallo", "de");
// custom tags
wp.addSection("title6", "<p><printlatestobjects /></p>", "de");
}
use of org.jdom2.Content in project mycore by MyCoRe-Org.
the class MCRAclEditorResource method transform.
protected InputStream transform(String xmlFile) throws Exception {
InputStream guiXML = getClass().getResourceAsStream(xmlFile);
if (guiXML == null) {
throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).build());
}
SAXBuilder saxBuilder = new SAXBuilder();
Document webPage = saxBuilder.build(guiXML);
XPathExpression<Object> xpath = XPathFactory.instance().compile("/MyCoReWebPage/section/div[@id='mycore-acl-editor2']");
Object node = xpath.evaluateFirst(webPage);
MCRSession mcrSession = MCRSessionMgr.getCurrentSession();
String lang = mcrSession.getCurrentLanguage();
if (node != null) {
Element mainDiv = (Element) node;
mainDiv.setAttribute("lang", lang);
String bsPath = CONFIG.getString("MCR.bootstrap.path", "");
if (!bsPath.equals("")) {
bsPath = MCRFrontendUtil.getBaseURL() + bsPath;
Element item = new Element("link").setAttribute("href", bsPath).setAttribute("rel", "stylesheet").setAttribute("type", "text/css");
mainDiv.addContent(0, item);
}
}
MCRContent content = MCRJerseyUtil.transform(webPage, request);
return content.getInputStream();
}
Aggregations