List of usage examples for org.dom4j Element getStringValue
String getStringValue();
From source file:org.apache.poi.openxml4j.opc.internal.unmarshallers.PackagePropertiesUnmarshaller.java
License:Apache License
private String loadLastPrinted(Document xmlDoc) { Element el = xmlDoc.getRootElement().element(new QName(KEYWORD_LAST_PRINTED, namespaceCP)); if (el == null) { return null; }// w w w . java 2 s. co m return el.getStringValue(); }
From source file:org.apache.poi.openxml4j.opc.internal.unmarshallers.PackagePropertiesUnmarshaller.java
License:Apache License
private String loadModified(Document xmlDoc) { Element el = xmlDoc.getRootElement().element(new QName(KEYWORD_MODIFIED, namespaceDcTerms)); if (el == null) { return null; }/*w w w .jav a 2 s .c om*/ return el.getStringValue(); }
From source file:org.apache.poi.openxml4j.opc.internal.unmarshallers.PackagePropertiesUnmarshaller.java
License:Apache License
private String loadRevision(Document xmlDoc) { Element el = xmlDoc.getRootElement().element(new QName(KEYWORD_REVISION, namespaceCP)); if (el == null) { return null; }//from www .j a va 2s.co m return el.getStringValue(); }
From source file:org.apache.poi.openxml4j.opc.internal.unmarshallers.PackagePropertiesUnmarshaller.java
License:Apache License
private String loadSubject(Document xmlDoc) { Element el = xmlDoc.getRootElement().element(new QName(KEYWORD_SUBJECT, namespaceDC)); if (el == null) { return null; }//from w w w . ja va 2 s. co m return el.getStringValue(); }
From source file:org.apache.poi.openxml4j.opc.internal.unmarshallers.PackagePropertiesUnmarshaller.java
License:Apache License
private String loadTitle(Document xmlDoc) { Element el = xmlDoc.getRootElement().element(new QName(KEYWORD_TITLE, namespaceDC)); if (el == null) { return null; }//from ww w .ja v a2 s .c o m return el.getStringValue(); }
From source file:org.apache.poi.openxml4j.opc.internal.unmarshallers.PackagePropertiesUnmarshaller.java
License:Apache License
private String loadVersion(Document xmlDoc) { Element el = xmlDoc.getRootElement().element(new QName(KEYWORD_VERSION, namespaceCP)); if (el == null) { return null; }//from ww w . j a va 2 s. c o m return el.getStringValue(); }
From source file:org.cgiar.ccafs.ap.util.ClientRepository.java
License:Open Source License
public JSONObject getMetadata(String linkRequest, String id) { JSONObject jo = new JSONObject(); try {//from w w w . j a v a 2 s . c o m /* * OaiPmhServer server = new OaiPmhServer(linkRequest); * Record record = server.getRecord(id, "oai_dc"); */ String handleUrl = CGSPACEHANDLE.replace("{0}", id.replace("oai:cgspace.cgiar.org:", "")); Element elementHandle = this.getXmlRestClient(handleUrl); id = elementHandle.element("id").getStringValue(); linkRequest = linkRequest.replace("{0}", id); Element metadata = this.getXmlRestClient(linkRequest); List<Element> elements = metadata.elements(); for (Element element : elements) { Element key = element.element("key"); Element value = element.element("value"); String keyValue = key.getStringValue(); keyValue = keyValue.substring(3); if (jo.has(keyValue)) { jo.put(keyValue, jo.get(keyValue) + "," + value.getStringValue()); } else { jo.put(keyValue, value.getStringValue()); } } } catch (Exception e) { e.printStackTrace(); jo = null; e.printStackTrace(); } return jo; }
From source file:org.cgiar.ccafs.marlo.rest.services.deliverables.CGSpaceClientAPI.java
License:Open Source License
@Override public MetadataModel getMetadata(String link) { MetadataModel metadataModel = null;//from w w w.java 2 s.c om JSONObject jo = new JSONObject(); try { Element metadata = xmlReaderConnectionUtil.getXmlRestClient(link); List<Author> authors = new ArrayList<Author>(); List<Element> elements = metadata.elements(); for (Element element : elements) { Element key = element.element("key"); Element value = element.element("value"); String keyValue = key.getStringValue(); keyValue = keyValue.substring(3); if (keyValue.equals("contributor.author")) { Author author = new Author(value.getStringValue()); String names[] = author.getFirstName().split(", "); if (names.length == 2) { author.setFirstName(names[1]); author.setLastName(names[0]); } authors.add(author); } else { if (keyValue.equals("identifier.status")) { if (value.getStringValue().equals("Open Access")) { jo.put("openAccess", "true"); } else { jo.put("openAccess", "false"); } } if (jo.has(keyValue)) { jo.put(keyValue, jo.get(keyValue) + "," + value.getStringValue()); } else { jo.put(keyValue, value.getStringValue()); } } } GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(Date.class, new DateTypeAdapter()); Gson gson = gsonBuilder.create(); String data = jo.toString(); for (String key : coverterAtrributes.keySet()) { data = data.replace(key, coverterAtrributes.get(key)); } metadataModel = gson.fromJson(data, MetadataModel.class); Author[] authorsArr = new Author[authors.size()]; authorsArr = authors.toArray(authorsArr); metadataModel.setAuthors(authorsArr); } catch (Exception e) { e.printStackTrace(); LOG.error(e.getLocalizedMessage()); } return metadataModel; }
From source file:org.cgiar.ccafs.marlo.rest.services.deliverables.CIMMYTDspaceClientAPI.java
License:Open Source License
@Override public MetadataModel getMetadata(String link) { MetadataModel metadataModel = null;/*from w ww . ja v a2s. co m*/ JSONObject jo = new JSONObject(); try { Element metadata = xmlReaderConnectionUtil.getXmlRestClient(link); List<Author> authors = new ArrayList<Author>(); List<Element> elements = metadata.elements(); for (Element element : elements) { // get recordOAI Element recordOAI = element.element("record"); if (recordOAI != null) { // get metadataOAI Element metadataOAI = recordOAI.element("metadata"); if (metadataOAI != null) { // get oai_dc:dc List<Element> elements2 = metadataOAI.elements(); for (Element oai_dc : elements2) { // get title if (oai_dc.element("title") != null) { Element titleElement = oai_dc.element("title"); String titleValue = titleElement.getStringValue(); jo.put(titleElement.getName(), titleValue); } // get authors if (oai_dc.elements("creator") != null) { List<Element> authorsElements = oai_dc.elements("creator"); if (authorsElements != null && authorsElements.size() > 0) { for (Element value : authorsElements) { Author author = new Author(value.getStringValue().replaceAll(",", "")); String names[] = author.getFirstName().split(" "); // Name validations if (names.length > 0) { if (names.length == 1) { author.setFirstName(names[0]); authors.add(author); } else if (names.length == 2) { author.setFirstName(names[0]); author.setLastName(names[1]); authors.add(author); } else if (names.length == 3) { if (names[1].contains(".")) { author.setFirstName(names[0] + " " + names[1]); author.setLastName(names[2]); authors.add(author); } else { author.setFirstName(names[0]); author.setLastName(names[1] + " " + names[2]); authors.add(author); } } else { author.setFirstName(names[0] + " " + names[1]); String lastName = ""; for (int i = 2; i < names.length; i++) { if (i + 1 == names.length) { lastName += names[i]; } else { lastName += names[i] + " "; } } author.setLastName(lastName); authors.add(author); } } } } } // get keywords if (oai_dc.elements("subject") != null) { List<Element> subjectsElements = oai_dc.elements("subject"); if (subjectsElements != null && subjectsElements.size() > 0) { String keyWords = ""; for (Element subjectElement : subjectsElements) { if (keyWords.isEmpty()) { keyWords += subjectElement.getStringValue(); } else { keyWords += " " + subjectElement.getStringValue(); } } jo.put(subjectsElements.get(0).getName(), keyWords); } } // get description if (oai_dc.element("description") != null) { Element descriptionElement = oai_dc.element("description"); String descriptionValue = descriptionElement.getStringValue(); jo.put(descriptionElement.getName(), descriptionValue); } // get date if (oai_dc.element("date") != null) { List<Element> dateElements = oai_dc.elements("date"); if (dateElements != null && dateElements.size() > 0) { dateElements = dateElements.stream().sorted((e1, e2) -> Integer .compare(e1.getStringValue().length(), e2.getStringValue().length())) .collect(Collectors.toList()); Element dateElement = dateElements.get(0); Calendar cal = Calendar.getInstance(); cal.set(Integer.parseInt(dateElement.getStringValue()), 0, 1, 0, 0, 0); Date date = cal.getTime(); jo.put("publicationDate", date); } } // get rights if (oai_dc.element("rights") != null) { Element rightsElement = oai_dc.element("rights"); String rightsValue = rightsElement.getStringValue(); jo.put(rightsElement.getName(), rightsValue); } // get handle if (this.getId() != null) { jo.put("handle", this.getId()); } // get language if (oai_dc.element("language") != null) { Element languageElement = oai_dc.element("language"); String languageValue = languageElement.getStringValue(); jo.put(languageElement.getName(), languageValue); } } } } } GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(Date.class, new DateTypeAdapter()); Gson gson = gsonBuilder.create(); String data = jo.toString(); for (String key : coverterAtrributes.keySet()) { data = data.replace(key, coverterAtrributes.get(key)); } metadataModel = gson.fromJson(data, MetadataModel.class); Author[] authorsArr = new Author[authors.size()]; authorsArr = authors.toArray(authorsArr); metadataModel.setAuthors(authorsArr); } catch (Exception e) { e.printStackTrace(); LOG.error(e.getLocalizedMessage()); } return metadataModel; }
From source file:org.cgiar.ccafs.marlo.utils.ClientRepository.java
License:Open Source License
public JSONObject getMetadata(String linkRequest, String id) { Gson gson = new Gson(); JSONObject jo = new JSONObject(); try {//from w ww . j a va2 s . c o m /* * OaiPmhServer server = new OaiPmhServer(linkRequest); * Record record = server.getRecord(id, "oai_dc"); */ String handleUrl = CGSPACEHANDLE.replace("{0}", id.replace("oai:cgspace.cgiar.org:", "")); RestConnectionUtil connection = new RestConnectionUtil(); Element elementHandle = connection.getXmlRestClient(handleUrl); id = elementHandle.element("id").getStringValue(); linkRequest = linkRequest.replace("{0}", id); Element metadata = this.getXmlRestClient(linkRequest); List<String> authors = new ArrayList<String>(); List<Element> elements = metadata.elements(); for (Element element : elements) { Element key = element.element("key"); Element value = element.element("value"); String keyValue = key.getStringValue(); keyValue = keyValue.substring(3); if (keyValue.equals("contributor.author")) { authors.add(value.getStringValue()); } else { if (jo.has(keyValue)) { jo.put(keyValue, jo.get(keyValue) + "," + value.getStringValue()); } else { jo.put(keyValue, value.getStringValue()); } } } jo.put("contributor.author", authors); } catch (Exception e) { e.printStackTrace(); jo = null; e.printStackTrace(); } return jo; }