Search in sources :

Example 6 with MCRURLContent

use of org.mycore.common.content.MCRURLContent in project mycore by MyCoRe-Org.

the class MCRWCMSContentManager method getContent.

/**
 * Return a json object with the content of a MyCoRe webpage.
 * <p>
 * {
 *  type: "content",
 *  content: @see {@link MCRWCMSDefaultSectionProvider}
 * }
 * </p>
 * <p>
 * If an error occur (e.g. file not exist) the returning json
 * looks like:<br>
 * {
 *  type: "error",
 *  errorType: "invalidFile"
 *  webpageId: "myfolder/webpage1.xml"
 * }
 * </p>
 *
 * @param webpageId id of the webpage
 * @return json object
 * @see ErrorType
 */
public JsonObject getContent(String webpageId) throws IOException, JDOMException, SAXException {
    boolean isXML = webpageId.endsWith(".xml");
    URL resourceURL = null;
    try {
        resourceURL = MCRWebPagesSynchronizer.getURL(webpageId);
    } catch (MalformedURLException e) {
        throwError(ErrorType.invalidDirectory, webpageId);
    }
    // file is not in web application directory
    if (!isXML) {
        throwError(ErrorType.invalidFile, webpageId);
    }
    Document doc = null;
    if (resourceURL == null) {
        MyCoReWebPageProvider wpp = new MyCoReWebPageProvider();
        wpp.addSection("neuer Eintrag", new Element("p").setText("TODO"), "de");
        doc = wpp.getXML();
    } else {
        doc = new MCRURLContent(resourceURL).asXML();
    }
    Element rootElement = doc.getRootElement();
    if (!rootElement.getName().equals("MyCoReWebPage")) {
        throwError(ErrorType.notMyCoReWebPage, webpageId);
    }
    // return content
    return getContent(rootElement);
}
Also used : MalformedURLException(java.net.MalformedURLException) MyCoReWebPageProvider(org.mycore.tools.MyCoReWebPageProvider) JsonElement(com.google.gson.JsonElement) Element(org.jdom2.Element) MCRURLContent(org.mycore.common.content.MCRURLContent) Document(org.jdom2.Document) URL(java.net.URL)

Example 7 with MCRURLContent

use of org.mycore.common.content.MCRURLContent in project mycore by MyCoRe-Org.

the class MCRCategoryDAOImplTest method testClassEditorBatch.

@Test
public void testClassEditorBatch() throws Exception {
    EntityManager entityManager = MCREntityManagerProvider.getCurrentEntityManager();
    Document xml = MCRXMLParserFactory.getParser().parseXML(new MCRURLContent(new URL("http://mycore.de/classifications/nameIdentifier.xml")));
    MCRCategory nameIdentifier = MCRXMLTransformer.getCategory(xml);
    MCRCategory secondCateg = nameIdentifier.getChildren().get(1);
    DAO.addCategory(null, nameIdentifier);
    startNewTransaction();
    MCRCategLinkServiceFactory.getInstance().getLinksFromCategory(secondCateg.getId());
    assertTrue(secondCateg.getId() + " should exist.", DAO.exist(secondCateg.getId()));
    // re-set labels
    DAO.setLabels(secondCateg.getId(), secondCateg.getLabels().stream().collect(Collectors.toSet()));
    // re-set URI
    entityManager.detach(DAO.setURI(secondCateg.getId(), secondCateg.getURI()));
    // move to new index
    DAO.moveCategory(secondCateg.getId(), secondCateg.getParent().getId(), 0);
    startNewTransaction();
    MCRCategoryImpl copyOfDB = MCRCategoryDAOImpl.getByNaturalID(entityManager, secondCateg.getId());
    assertNotNull(secondCateg.getId() + " must hav a parent.", copyOfDB.getParent());
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) EntityManager(javax.persistence.EntityManager) MCRURLContent(org.mycore.common.content.MCRURLContent) Document(org.jdom2.Document) URL(java.net.URL) Test(org.junit.Test)

Example 8 with MCRURLContent

use of org.mycore.common.content.MCRURLContent in project mycore by MyCoRe-Org.

the class MCRCategoryDAOImplTest method testLicenses.

@Test
public void testLicenses() throws Exception {
    Document xml = MCRXMLParserFactory.getParser().parseXML(new MCRURLContent(new URL("http://mycore.de/classifications/mir_licenses.xml")));
    MCRCategory licenses = MCRXMLTransformer.getCategory(xml);
    DAO.addCategory(null, licenses);
    MCRCategoryID cc_30 = new MCRCategoryID(licenses.getId().getRootID(), "cc_3.0");
    DAO.deleteCategory(cc_30);
    startNewTransaction();
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRURLContent(org.mycore.common.content.MCRURLContent) Document(org.jdom2.Document) URL(java.net.URL) Test(org.junit.Test)

Example 9 with MCRURLContent

use of org.mycore.common.content.MCRURLContent in project mycore by MyCoRe-Org.

the class MCRXMLParserTest method testValidXML.

@Test
public void testValidXML() throws SAXParseException, IOException {
    MCRXMLParserFactory.getValidatingParser().parseXML(new MCRURLContent(xmlResource));
    MCRXMLParserFactory.getValidatingParser().parseXML(new MCRURLContent(xmlFile.toUri().toURL()));
}
Also used : MCRURLContent(org.mycore.common.content.MCRURLContent) Test(org.junit.Test)

Example 10 with MCRURLContent

use of org.mycore.common.content.MCRURLContent in project mycore by MyCoRe-Org.

the class MCRClassification2Commands method loadFromURL.

@MCRCommand(syntax = "load classification from url {0}", help = "The command adds a new classification from URL {0} to the system.", order = 15)
public static void loadFromURL(String fileURL) throws SAXParseException, MalformedURLException, URISyntaxException {
    Document xml = MCRXMLParserFactory.getParser().parseXML(new MCRURLContent(new URL(fileURL)));
    MCRCategory category = MCRXMLTransformer.getCategory(xml);
    DAO.addCategory(null, category);
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRURLContent(org.mycore.common.content.MCRURLContent) Document(org.jdom2.Document) URL(java.net.URL) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Aggregations

MCRURLContent (org.mycore.common.content.MCRURLContent)11 URL (java.net.URL)8 Document (org.jdom2.Document)5 Test (org.junit.Test)4 MCRCategory (org.mycore.datamodel.classifications2.MCRCategory)4 IOException (java.io.IOException)3 File (java.io.File)2 MCRContent (org.mycore.common.content.MCRContent)2 MCRFileContent (org.mycore.common.content.MCRFileContent)2 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)2 JsonElement (com.google.gson.JsonElement)1 MalformedURLException (java.net.MalformedURLException)1 EntityManager (javax.persistence.EntityManager)1 TransformerException (javax.xml.transform.TransformerException)1 SolrClient (org.apache.solr.client.solrj.SolrClient)1 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)1 Element (org.jdom2.Element)1 MCRCategoryID (org.mycore.datamodel.classifications2.MCRCategoryID)1 MCRFile (org.mycore.datamodel.ifs.MCRFile)1 MCRSolrURL (org.mycore.solr.search.MCRSolrURL)1