List of usage examples for org.dom4j Node getText
String getText();
Returns the text of this node.
From source file:org.jivesoftware.openfire.clearspace.WSUtils.java
License:Open Source License
/** * Parse REST responses of the type String[] that represent usernames, that are XML of the form: * <pre>//w w w . j a v a 2 s . c om * {@code * <something> * <return>text1</return> * <return>text2</return> * <return>text3</return> * </something> * } * </pre> * * @param element Element from REST response to be parsed. * @return An array of strings from the REST response. */ protected static List<String> parseUsernameArray(Element element) { List<String> list = new ArrayList<String>(); @SuppressWarnings("unchecked") List<Node> nodes = (List<Node>) element.selectNodes("return"); for (Node node : nodes) { String username = node.getText(); // Escape username. username = JID.escapeNode(username); list.add(username); } return list; }
From source file:org.jivesoftware.sparkimpl.plugin.viewer.PluginViewer.java
License:Open Source License
public Collection<PublicPlugin> getPluginList(InputStream response) { final List<PublicPlugin> pluginList = new ArrayList<>(); SAXReader saxReader = new SAXReader(); Document pluginXML = null;/*from ww w . j a va 2 s . c o m*/ try { pluginXML = saxReader.read(response); } catch (DocumentException e) { Log.error(e); } List<? extends Node> plugins = pluginXML.selectNodes("/plugins/plugin"); for (Node plugin1 : plugins) { PublicPlugin publicPlugin = new PublicPlugin(); String clazz; String name = null; try { Element plugin = (Element) plugin1; try { String version = plugin.selectSingleNode("minSparkVersion").getText(); if (!isGreaterOrEqual(JiveInfo.getVersion(), version)) { Log.error("Unable to load plugin " + name + " due to min version incompatibility."); continue; } } catch (Exception e) { Log.error("Unable to load plugin " + name + " due to no minSparkVersion."); continue; } name = plugin.selectSingleNode("name").getText(); clazz = plugin.selectSingleNode("class").getText(); publicPlugin.setPluginClass(clazz); publicPlugin.setName(name); try { String version = plugin.selectSingleNode("version").getText(); publicPlugin.setVersion(version); String author = plugin.selectSingleNode("author").getText(); publicPlugin.setAuthor(author); Node emailNode = plugin.selectSingleNode("email"); if (emailNode != null) { publicPlugin.setEmail(emailNode.getText()); } Node descriptionNode = plugin.selectSingleNode("description"); if (descriptionNode != null) { publicPlugin.setDescription(descriptionNode.getText()); } Node homePageNode = plugin.selectSingleNode("homePage"); if (homePageNode != null) { publicPlugin.setHomePage(homePageNode.getText()); } Node downloadNode = plugin.selectSingleNode("downloadURL"); if (downloadNode != null) { String downloadURL = downloadNode.getText(); publicPlugin.setDownloadURL(downloadURL); } Node changeLogNode = plugin.selectSingleNode("changeLog"); if (changeLogNode != null) { publicPlugin.setChangeLogURL(changeLogNode.getText()); } Node readMeNode = plugin.selectSingleNode("readme"); if (readMeNode != null) { publicPlugin.setReadMeURL(readMeNode.getText()); } Node smallIcon = plugin.selectSingleNode("smallIcon"); if (smallIcon != null) { publicPlugin.setSmallIconAvailable(true); } Node largeIcon = plugin.selectSingleNode("largeIcon"); if (largeIcon != null) { publicPlugin.setLargeIconAvailable(true); } } catch (Exception e) { Log.error("Error retrieving PluginInformation from xml.", e); } pluginList.add(publicPlugin); } catch (Exception ex) { ex.printStackTrace(); } } return pluginList; }
From source file:org.kitodo.production.plugin.importer.massimport.googlecode.fascinator.redbox.sru.NLAIdentity.java
License:Open Source License
/** * <p>/*from w ww . j a va 2 s . co m*/ * Default Constructor. Extract some basic information. * </p> * * @param node * searchResponse A parsed DOM4J Document * @throws SRUException * If any of the XML structure does not look like expected */ public NLAIdentity(Node node) throws SRUException { eac = node; // Identity List<Node> otherIds = eac.selectNodes("eac:eac-cpf/eac:control/eac:otherRecordId"); for (Node idNode : otherIds) { String otherId = idNode.getText(); if (otherId.startsWith("http://nla.gov.au")) { nlaId = otherId; } } if (nlaId == null) { throw new SRUException("Error processing Identity; Cannot find ID"); } knownIds = getSourceIdentities(); // Cosmetically we want to use the first row (should be the longest // top-level name we found) firstName = knownIds.get(0).get("firstName"); surname = knownIds.get(0).get("surname"); displayName = knownIds.get(0).get(DISPLAY_NAME); // For institution we want the first one we find that isn't NLA or // Libraries Australia for (Map<String, String> id : knownIds) { if (institution == null // But we'll settle for those in a pinch || "National Library of Australia Party Infrastructure".equals(institution) || "Libraries Australia".equals(institution)) { institution = id.get(INSTITUTION); } } }
From source file:org.kitodo.production.plugin.importer.massimport.googlecode.fascinator.redbox.sru.NLAIdentity.java
License:Open Source License
private List<Map<String, String>> getSourceIdentities() { List<Map<String, String>> returnList = new ArrayList<>(); // Top level institution Map<String, String> idMap = new HashMap<>(); Node institutionNode = eac.selectSingleNode("eac:eac-cpf/eac:control/eac:maintenanceAgency/eac:agencyName"); String institutionString = institutionNode.getText(); // Top level name Node nlaNamesNode = eac.selectSingleNode("eac:eac-cpf/eac:cpfDescription/eac:identity"); // Get all the names this ID lists List<Map<String, String>> nameList = getNames(nlaNamesNode); for (Map<String, String> name : nameList) { // Only use the longest top-level name for display purposes String oldDisplayName = idMap.get(DISPLAY_NAME); String thisDisplayName = name.get(DISPLAY_NAME); if (oldDisplayName == null || (thisDisplayName != null && thisDisplayName.length() > oldDisplayName.length())) { // Clear any old data idMap.clear();/*w ww. j a v a 2s . c o m*/ // Store this ID idMap.putAll(name); idMap.put(INSTITUTION, institutionString); } } // And add to the list returnList.add(idMap); // All name entities from contributing institutions List<Node> sourceIdentities = eac.selectNodes("eac:eac-cpf/eac:cpfDescription//eac:eac-cpf"); for (Node identity : sourceIdentities) { // Institution for this ID institutionNode = identity.selectSingleNode("*//eac:maintenanceAgency/eac:agencyName"); if (Objects.nonNull(institutionNode)) { institutionString = institutionNode.getText(); // Any names for this ID List<Node> idNodes = identity.selectNodes("*//eac:identity"); for (Node idNode : idNodes) { // A Map for each name idMap = new HashMap<>(); // Get all the names this ID lists nameList = getNames(idNode); for (Map<String, String> name : nameList) { idMap.putAll(name); } // Indicate the institution for each one idMap.put(INSTITUTION, institutionString); // And add to the list returnList.add(idMap); } } } return returnList; }
From source file:org.kitodo.production.plugin.importer.massimport.googlecode.fascinator.redbox.sru.NLAIdentity.java
License:Open Source License
private Map<String, String> getNameMap(Node name) { Map<String, String> nameMap = new HashMap<>(); String thisDisplay = null;/* ww w . j ava 2 s.c o m*/ String thisFirstName = null; String thisSurname = null; String title = null; // First name Node firstNameNode = name .selectSingleNode("eac:part[(@localType=\"forename\") " + "or (@localType=\"givenname\")]"); if (Objects.nonNull(firstNameNode)) { thisFirstName = firstNameNode.getText(); } // Surname Node surnameNode = name .selectSingleNode("eac:part[(@localType=\"surname\") " + "or (@localType=\"familyname\")]"); if (Objects.nonNull(surnameNode)) { thisSurname = surnameNode.getText(); } // Title Node titleNode = name.selectSingleNode("eac:part[@localType=\"title\"]"); if (Objects.nonNull(titleNode)) { title = titleNode.getText(); } // Display Name if (Objects.nonNull(thisSurname)) { thisDisplay = thisSurname; nameMap.put("surname", thisSurname); if (Objects.nonNull(thisFirstName)) { thisDisplay += ", " + thisFirstName; nameMap.put("firstName", thisFirstName); } if (Objects.nonNull(title)) { thisDisplay += " (" + title + ")"; } nameMap.put(DISPLAY_NAME, thisDisplay); } // Last ditch effort... we couldn't find simple name information // from recommended values. So just concatenate what we can see. if (Objects.isNull(thisDisplay)) { // Find every part List<Node> parts = name.selectNodes("eac:part"); for (Node part : parts) { String value = getValueFromPart((Element) part); // And add to the display name if (Objects.isNull(thisDisplay)) { thisDisplay = value; } else { thisDisplay += ", " + value; } } nameMap.put(DISPLAY_NAME, thisDisplay); } return nameMap; }
From source file:org.kitodo.production.plugin.importer.massimport.googlecode.fascinator.redbox.sru.SRUClient.java
License:Open Source License
/** * <p>// w w w. j a v a 2 s .c o m * Search for a record from the National Library of Australia with the * provided identifier. If multiple records match this identifier only the * first will be returned. * </p> * * @param id * The identifier to search for * @return the record matching this identifier, empty String if not found */ public String nlaGetNationalId(String id) { Node node = nlaGetRecordNodeById(id); if (node == null) { return ""; } List<Node> otherIds = node.selectNodes("eac:control/eac:otherRecordId"); for (Node idNode : otherIds) { String otherId = idNode.getText(); if (otherId.startsWith("http://nla.gov.au")) { return otherId; } } return ""; }
From source file:org.kitodo.production.plugin.importer.massimport.googlecode.fascinator.redbox.sru.SRUResponse.java
License:Open Source License
/** * <p>// www . jav a2 s. co m * Default Constructor. Extract some basic information. * </p> * * @param searchResponse * A parsed DOM4J Document * @throws SRUException * If any of the XML structure does not look like expected */ public SRUResponse(Document searchResponse) throws SRUException { // Results total Node number = searchResponse.selectSingleNode("//srw:numberOfRecords"); if (number == null) { throw new SRUException("Unable to get result numbers from response XML."); } totalRecords = Integer.parseInt(number.getText()); logger.debug("SRU Search found {} results(s)", totalRecords); // Results List if (totalRecords == 0) { resultsList = new ArrayList<>(); } else { resultsList = searchResponse.selectNodes("//srw:recordData"); } recordsReturned = resultsList.size(); }
From source file:org.kuali.kra.budget.nonpersonnel.BudgetJustificationWrapper.java
License:Educational Community License
/** * This method parses the raw budgetJustification String into the fields needed for this class * Expected format://from w ww . j a v a2 s. c o m * <budgetJustification lastUpdateBy="" lastUpdateOn=""> * <![CDATA[ * Justification text * ]]> * </justification> */ private void parse(String budgetJustificationAsXML) { if (budgetJustificationAsXML == null || budgetJustificationAsXML.trim().length() == 0) { return; } try { Document document = DocumentHelper.parseText(budgetJustificationAsXML); Node node = document.selectSingleNode("//budgetJustification"); lastUpdateUser = node.valueOf("@lastUpdateBy"); lastUpdateTime = node.valueOf("@lastUpdateOn"); justificationText = node.getText(); } catch (DocumentException e) { LOG.warn(e.getMessage(), e); } }
From source file:org.light.portlets.weather.Weather.java
License:Apache License
public void setDocument(Document document) { this.lastRefreshTime = System.currentTimeMillis(); this.document = document; Node node = document.selectSingleNode("//weather/cc/tmp"); if (node != null) { this.tmp = node.getText();//.valueOf( "@name" ); Node node1 = document.selectSingleNode("//weather/head/ut"); this.tmpUnit = node1.getText(); Node node2 = document.selectSingleNode("//weather/cc/icon"); this.icon = node2.getText(); Node node3 = document.selectSingleNode("//weather/loc/dnam"); this.location = node3.getText(); Node node4 = document.selectSingleNode("//weather/cc/lsup"); this.time = node4.getText(); if (this.time.indexOf("Local") > 0) { int index = this.time.indexOf("Local"); this.time = this.time.substring(0, index); }/*from w ww . j av a 2 s.com*/ Node node5 = document.selectSingleNode("//weather/cc/t"); this.status = node5.getText(); Node node6 = document.selectSingleNode("//weather/cc/wind/s"); this.speed = node6.getText(); Node node61 = document.selectSingleNode("//weather/head/us"); this.speedUnit = node61.getText(); Node node7 = document.selectSingleNode("//weather/cc/wind/t"); this.trend = node7.getText(); Node node8 = document.selectSingleNode("//weather/cc/hmid"); this.hmid = node8.getText(); Node node9 = document.selectSingleNode("//weather/cc/vis"); this.vis = node9.getText(); } else { this.errorFound = true; Node node1 = document.selectSingleNode("//error/err"); this.error = node1.getText(); } }
From source file:org.light.portlets.weather.WeatherLocations.java
License:Apache License
public void setDocument(Document document) { this.lastRefreshTime = System.currentTimeMillis(); this.document = document; List list = document.selectNodes("//search/loc"); if (list != null) { if (list.size() > 0) { for (Iterator iter = list.iterator(); iter.hasNext();) { Node node = (Node) iter.next(); String name = node.getText(); String id = node.valueOf("@id"); this.locations.add(new WeatherLocation(id, name)); }/*from ww w. j av a 2 s . com*/ } else { this.errorFound = true; this.error = "The location which you just input is not avaliable in The Weather Channel, please check the locaiton."; } } else { this.errorFound = true; Node node1 = document.selectSingleNode("//error/err"); this.error = node1.getText(); } }