Search in sources :

Example 41 with Content

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;
}
Also used : Element(org.jdom2.Element)

Example 42 with Content

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;
}
Also used : Element(org.jdom2.Element)

Example 43 with Content

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());
}
Also used : Element(org.jdom2.Element) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) MCRByteContent(org.mycore.common.content.MCRByteContent) Date(java.util.Date) Test(org.junit.Test)

Example 44 with Content

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", "&nbsp;&amp;&auml;Hallo", "de");
    // custom tags
    wp.addSection("title6", "<p><printlatestobjects /></p>", "de");
}
Also used : Element(org.jdom2.Element) Test(org.junit.Test)

Example 45 with Content

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();
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) MCRSession(org.mycore.common.MCRSession) WebApplicationException(javax.ws.rs.WebApplicationException) InputStream(java.io.InputStream) Element(org.jdom2.Element) JsonObject(com.google.gson.JsonObject) Document(org.jdom2.Document) MCRContent(org.mycore.common.content.MCRContent)

Aggregations

Element (org.jdom2.Element)77 Document (org.jdom2.Document)27 IOException (java.io.IOException)18 JDOMException (org.jdom2.JDOMException)16 File (java.io.File)11 MCRException (org.mycore.common.MCRException)11 Content (org.jdom2.Content)10 MCRContent (org.mycore.common.content.MCRContent)10 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)10 XMLOutputter (org.jdom2.output.XMLOutputter)9 SAXBuilder (org.jdom2.input.SAXBuilder)8 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 Attribute (org.jdom2.Attribute)6 MCRPath (org.mycore.datamodel.niofs.MCRPath)6 SAXException (org.xml.sax.SAXException)6 JsonElement (com.google.gson.JsonElement)5 Color (java.awt.Color)4 MCRDerivate (org.mycore.datamodel.metadata.MCRDerivate)4 MCRObject (org.mycore.datamodel.metadata.MCRObject)4