private Element text2element(String text) { try { return new SAXBuilder().build(new StringReader(text)).detachRootElement(); } catch (JDOMException | IOException ex) { throw new MCRException("Exception in text2element: " + text, ex); } }
@Override public Element fromJSON(JsonArray jsonSectionArray) { // create new document MyCoReWebPageProvider wp = new MyCoReWebPageProvider(); // parse sections for (JsonElement sectionElement : jsonSectionArray) { if (!sectionElement.isJsonObject()) { LOGGER.warn("Invalid json element in content array! {}", sectionElement); continue; } JsonObject sectionObject = sectionElement.getAsJsonObject(); String title = null; String lang = null; if (sectionObject.has(JSON_TITLE)) { title = sectionObject.get(JSON_TITLE).getAsJsonPrimitive().getAsString(); } if (sectionObject.has(JSON_LANG)) { lang = sectionObject.get(JSON_LANG).getAsJsonPrimitive().getAsString(); } String xmlAsString = sectionObject.get(JSON_DATA).getAsJsonPrimitive().getAsString(); try { wp.addSection(title, xmlAsString, lang); } catch (IOException | SAXParseException | JDOMException exc) { throw new WebApplicationException("unable to add section " + title, exc); } } wp.updateMeta(MCRSessionMgr.getCurrentSession().getUserInformation().getUserID(), null); return wp.getXML().detachRootElement(); } }
private Element fetchWorksXML(WebTarget target) throws JDOMException, IOException, SAXException { LOGGER.info("get {}", target.getUri()); Builder b = target.request().accept(MCRORCIDConstants.ORCID_XML_MEDIA_TYPE) .header("Authorization", "Bearer " + MCRReadPublicTokenFactory.getToken()); MCRContent response = new MCRStreamContent(b.get(InputStream.class)); MCRContent transformed = T_WORK2MCR.transform(response); return transformed.asXML().detachRootElement(); }
/** * Turn a list of payload into an xml jdom ocument * * @param list the payload list */ public static Document toXml(final List<IBaseDataObject> list) { final Element root = new Element("payload-list"); for (final IBaseDataObject d : list) { final Document doc = toXml(d); root.addContent(doc.detachRootElement()); logger.debug("Adding xml content for " + d.shortName() + " to document"); } final Document doc = new Document(root); return doc; }
private void sendNotificationMail(List<MCRObject> importedObjects) throws Exception { Element xml = new Element(STATUS_FLAG).setAttribute("source", this.sourceSystemID); for (MCRObject obj : importedObjects) { xml.addContent(obj.createXML().detachRootElement()); } HashMap<String, String> parameters = new HashMap<>(); parameters.put(PROPERTY_MAIL_ADDRESS, MCRConfiguration.instance().getString(PROPERTY_MAIL_ADDRESS)); MCRMailer.sendMail(new Document(xml), xsl2BuildNotificationMail, parameters); } }
/** * Converts the oaipmh pojo to a jdom representation. * * @return the oaipmh as jdom * @throws JDOMException the conversion went wrong */ private Element marshal() throws JDOMException { try { NamespaceFilter outFilter = new NamespaceFilter(); SAXHandler saxHandler = new SAXHandler(); outFilter.setContentHandler(saxHandler); Marshaller marshaller = createMarshaller(); marshaller.marshal(new JAXBElement<>(new QName(OAIConstants.NS_OAI.getURI(), OAIConstants.XML_OAI_ROOT), OAIPMHtype.class, this.oaipmh), outFilter); Element rootElement = saxHandler.getDocument().detachRootElement(); moveNamespacesUp(rootElement); return rootElement; } catch (Exception exc) { throw new JDOMException("while marshalling", exc); } }
Element u = MCRUserTransformer.buildBasicXML(user).detachRootElement(); addString(u, "realName", user.getRealName()); addString(u, "eMail", user.getEMailAddress());
@Override public void updateMetadata(MCRObject object, Deposit entry, boolean replace) throws SwordServerException, SwordError { if (!replace) { throw new SwordServerException("Operation is not supported!", new OperationNotSupportedException()); } final Document document = buildDCDocument(entry.getSwordEntry().getDublinCore()); final Document newMetadata = convertDCToMods(document); object.getMetadata().setFromDOM(newMetadata.detachRootElement()); try { MCRMetadataManager.update(object); } catch (MCRAccessException e) { throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, HttpServletResponse.SC_UNAUTHORIZED, e.getMessage()); } }
@Override public MCRObjectID ingestMetadata(Deposit entry) throws SwordError, SwordServerException { final MCRObjectID newObjectId = MCRObjectID .getNextFreeId(MCRConfiguration.instance().getString("MIR.projectid.default") + "_mods"); final Map<String, List<String>> dublinCoreMetadata = entry.getSwordEntry().getDublinCore(); Document dcDocument = buildDCDocument(dublinCoreMetadata); Document convertedDocument = convertDCToMods(dcDocument); final MCRObject mcrObject = MCRMODSWrapper.wrapMODSDocument(convertedDocument.detachRootElement(), newObjectId.getProjectId()); mcrObject.setId(newObjectId); try { MCRMetadataManager.create(mcrObject); } catch (MCRAccessException e) { throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, HttpServletResponse.SC_UNAUTHORIZED, e.getMessage()); } return newObjectId; }