use of org.jdom2.JDOMException in project mycore by MyCoRe-Org.
the class MCRIdentifierXSLUtils method getPIServiceInformation.
/**
* Gets all available services which are configured.
* e.g.
* <ul>
* <li><service id="service1" inscribed="false" permission="true" type="urn" /></li>
* <li><service id="service2" inscribed="true" permission="false" type="doi" /></li>
* </ul>
*
* @param objectID the object
* @return a Nodelist
* @throws JDOMException
*/
public static NodeList getPIServiceInformation(String objectID) throws JDOMException {
Element e = new Element("list");
MCRBase obj = MCRMetadataManager.retrieve(MCRObjectID.getInstance(objectID));
MCRConfiguration.instance().getPropertiesMap("MCR.PI.Registration.").keySet().stream().map(s -> s.substring("MCR.PI.Registration.".length())).filter(id -> !id.contains(".")).map((serviceID) -> MCRPIRegistrationServiceManager.getInstance().getRegistrationService(serviceID)).map((rs -> {
Element service = new Element("service");
service.setAttribute("id", rs.getRegistrationServiceID());
// Check if the inscriber of this service can read a PI
try {
if (rs.getMetadataManager().getIdentifier(obj, "").isPresent()) {
service.setAttribute("inscribed", "true");
} else {
service.setAttribute("inscribed", "false");
}
} catch (MCRPersistentIdentifierException e1) {
LOGGER.warn("Error happened while try to read PI from object: {}", objectID, e1);
service.setAttribute("inscribed", "false");
}
// rights
String permission = "register-" + rs.getRegistrationServiceID();
Boolean canRegister = MCRAccessManager.checkPermission(objectID, "writedb") && MCRAccessManager.checkPermission(obj.getId(), permission);
service.setAttribute("permission", canRegister.toString().toLowerCase(Locale.ROOT));
// add the type
service.setAttribute("type", rs.getType());
return service;
})).forEach(e::addContent);
return new DOMOutputter().output(e).getElementsByTagName("service");
}
use of org.jdom2.JDOMException 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.jdom2.JDOMException in project mycore by MyCoRe-Org.
the class MCRViewerResource method buildResponseDocument.
/**
* Builds the jdom configuration response document.
*
* @param config the mycore configuration object
* @return jdom configuration object
*/
private static Document buildResponseDocument(MCRViewerConfiguration config) throws JDOMException, IOException, SAXException, JAXBException {
String configJson = config.toJSON();
Element startIviewClientElement = new Element("IViewConfig");
Element configElement = new Element(JSON_CONFIG_ELEMENT_NAME);
startIviewClientElement.addContent(configElement);
startIviewClientElement.addContent(config.toXML().asXML().getRootElement().detach());
configElement.addContent(configJson);
return new Document(startIviewClientElement);
}
use of org.jdom2.JDOMException in project mycore by MyCoRe-Org.
the class MCRWCMSUtil method convertToOldFormat.
/**
* Converts the navigation.xml to the old format.
*/
private static byte[] convertToOldFormat(byte[] xml) throws JDOMException, IOException {
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(new ByteArrayInputStream(xml));
Element rootElement = doc.getRootElement();
rootElement.setAttribute("href", rootElement.getName());
List<org.jdom2.Element> children = rootElement.getChildren();
for (Element menu : children) {
String id = menu.getAttributeValue("id");
menu.setName(id);
menu.setAttribute("href", id);
menu.removeAttribute("id");
}
XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
ByteArrayOutputStream bout = new ByteArrayOutputStream(xml.length);
out.output(doc, bout);
return bout.toByteArray();
}
use of org.jdom2.JDOMException in project mycore by MyCoRe-Org.
the class MCRXEditorTransformer method createEmptyDocumentFromXPath.
private void createEmptyDocumentFromXPath(String xPath) throws JaxenException, JDOMException {
Element root = createRootElement(xPath);
editorSession.setEditedXML(new Document(root));
editorSession.setBreakpoint("Starting with empty XML document");
}
Aggregations