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);
}
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());
}
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();
}
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()));
}
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);
}
Aggregations