List of usage examples for org.dom4j Node selectNodes
List<Node> selectNodes(String xpathExpression);
selectNodes
evaluates an XPath expression and returns the result as a List
of Node
instances or String
instances depending on the XPath expression.
From source file:org.saiku.plugin.resources.PentahoRepositoryResource2.java
License:Apache License
private List<IRepositoryObject> processTree(final Node tree, final String parentPath, String fileType) { final String xPathDir = "./file"; //$NON-NLS-1$ List<IRepositoryObject> repoObjects = new ArrayList<IRepositoryObject>(); List<AclMethod> defaultAcls = new ArrayList<AclMethod>(); defaultAcls.add(AclMethod.READ);/* www .j a v a 2 s . c o m*/ List<IPentahoAclEntry> adminAcl = new ArrayList<IPentahoAclEntry>(); try { List nodes = tree.selectNodes(xPathDir); for (final Object node1 : nodes) { final Node node = (Node) node1; String name = node.valueOf("@name"); final String localizedName = node.valueOf("@localized-name"); final boolean visible = node.valueOf("@visible").equals("true"); final boolean isDirectory = node.valueOf("@isDirectory").equals("true"); final String path = StringUtils.isNotBlank(parentPath) ? parentPath + "/" + name : name; if (visible && isDirectory) { List<IRepositoryObject> children = new ArrayList<IRepositoryObject>(); // List<Node> fileNodes; // if (StringUtils.isBlank(fileType)) { // fileNodes = node.selectNodes("./file[@isDirectory='false']"); // } // else { // fileNodes = node.selectNodes("./file[@isDirectory='false'][ends-with(string(@name),'." + fileType + "') or ends-with(string(@name),'." + fileType + "')]"); // } // for (final Node fileNode : fileNodes) // { // boolean vis = fileNode.valueOf("@visible").equals("true"); // String t = fileNode.valueOf("@localized-name"); // String n = fileNode.valueOf("@name"); // if (vis) { // List<AclMethod> acls = getAcl(path, false); // children.add(new RepositoryFileObject(t, "#" + path + "/" + n, fileType, path + "/" + n, acls)); // } // } children.addAll(processTree(node, path, fileType)); List<AclMethod> acls = getAcl(path, true); repoObjects.add(new RepositoryFolderObject(localizedName, "#" + path, path, acls, children)); } else if (visible && !isDirectory) { if (StringUtils.isBlank(fileType) || name.endsWith(fileType)) { List<AclMethod> acls = getAcl(path, false); repoObjects.add(new RepositoryFileObject(localizedName, "#" + path, fileType, path, acls)); } } } } catch (Exception e) { e.printStackTrace(); } return repoObjects; }
From source file:org.sipfoundry.sipxconfig.vm.DistributionListsReader.java
License:Contributor Agreement License
@Override public DistributionList[] readObject(Document doc) { Node root = doc.getRootElement(); List<Element> nodeLists = root.selectNodes("//distributions/list"); DistributionList[] lists = DistributionList.createBlankList(); for (int i = 0; i < nodeLists.size(); i++) { Node listNode = nodeLists.get(i); DistributionList list = new DistributionList(); List<Node> extensionsNodes = listNode.selectNodes("destination"); String[] extensions = new String[extensionsNodes.size()]; for (int j = 0; j < extensionsNodes.size(); j++) { extensions[j] = extensionsNodes.get(j).getText(); }//w ww .ja v a 2s.co m list.setExtensions(extensions); int position = Integer.parseInt(listNode.valueOf("index/text()")); lists[position] = list; } return lists; }
From source file:org.sipfoundry.sipxconfig.vm.MailboxPreferencesReader.java
License:Contributor Agreement License
@Override public MailboxPreferences readObject(Document doc) { MailboxPreferences prefs = new MailboxPreferences(); Node root = doc.getRootElement(); String greetingId = root.valueOf("activegreeting"); MailboxPreferences.ActiveGreeting greeting = MailboxPreferences.ActiveGreeting.fromId(greetingId); prefs.setActiveGreeting(greeting);/*from w w w . j a v a2s.c o m*/ List<Element> contacts = root.selectNodes("notification/contact"); String emailAddress = getEmailAddress(0, contacts); if (StringUtils.isNotBlank(emailAddress)) { prefs.setEmailAddress(emailAddress); prefs.setAttachVoicemailToEmail(AttachType.YES); prefs.setIncludeAudioAttachment(getAttachVoicemail(0, contacts)); } String alternateEmailAdress = getEmailAddress(1, contacts); if (StringUtils.isNotBlank(alternateEmailAdress)) { prefs.setAlternateEmailAddress(alternateEmailAdress); prefs.setVoicemailToAlternateEmailNotification(AttachType.YES); prefs.setIncludeAudioAttachmentAlternateEmail(getAttachVoicemail(1, contacts)); } return prefs; }
From source file:org.sonar.report.pdf.entity.Project.java
License:Open Source License
private void initMostViolatedRulesFromNode(Node mostViolatedNode, SonarAccess sonarAccess) throws HttpException, ReportException, IOException, DocumentException { List<Node> measures = mostViolatedNode.selectNodes(ALL_MEASURES); Iterator<Node> it = measures.iterator(); if (!it.hasNext()) { Logger.warn("There is not result on select //resources/resource/msr"); }/*from ww w . j ava 2s . c om*/ while (it.hasNext()) { Node measure = it.next(); if (!measure.selectSingleNode(MEASURE_FRMT_VAL).getText().equals("0")) { Rule rule = Rule.initFromNode(measure); if (PDFReporter.reportType.equals("workbook")) { rule.loadViolatedResources(sonarAccess, this.key); } this.mostViolatedRules.add(rule); } } }
From source file:org.talend.core.nexus.NexusServerManager.java
License:Open Source License
private static void search(String nexusUrl, String userName, String password, String repositoryId, String groupIdToSearch, String versionToSearch, int searchFrom, int searchCount, List<MavenArtifact> artifacts) throws BusinessException { HttpURLConnection urlConnection = null; int totalCount = 0; try {/* w w w . j a v a 2s .co m*/ String service = NexusConstants.SERVICES_SEARCH + getSearchQuery(versionToSearch, repositoryId, groupIdToSearch, searchFrom, searchCount); urlConnection = getHttpURLConnection(nexusUrl, service, userName, password); SAXReader saxReader = new SAXReader(); InputStream inputStream = urlConnection.getInputStream(); Document document = saxReader.read(inputStream); Node countNode = document.selectSingleNode("/searchNGResponse/totalCount"); if (countNode != null) { try { totalCount = Integer.parseInt(countNode.getText()); } catch (NumberFormatException e) { totalCount = 0; } } List<Node> list = document.selectNodes("/searchNGResponse/data/artifact");//$NON-NLS-1$ for (Node arNode : list) { MavenArtifact artifact = new MavenArtifact(); artifacts.add(artifact); artifact.setGroupId(arNode.selectSingleNode("groupId").getText());//$NON-NLS-1$ artifact.setArtifactId(arNode.selectSingleNode("artifactId").getText());//$NON-NLS-1$ artifact.setVersion(arNode.selectSingleNode("version").getText());//$NON-NLS-1$ Node descNode = arNode.selectSingleNode("description");//$NON-NLS-1$ if (descNode != null) { artifact.setDescription(descNode.getText()); } Node urlNode = arNode.selectSingleNode("url");//$NON-NLS-1$ if (urlNode != null) { artifact.setUrl(urlNode.getText()); } Node licenseNode = arNode.selectSingleNode("license");//$NON-NLS-1$ if (licenseNode != null) { artifact.setLicense(licenseNode.getText()); } Node licenseUrlNode = arNode.selectSingleNode("licenseUrl");//$NON-NLS-1$ if (licenseUrlNode != null) { artifact.setLicenseUrl(licenseUrlNode.getText()); } Node distributionNode = arNode.selectSingleNode("distribution");//$NON-NLS-1$ if (distributionNode != null) { artifact.setDistribution(distributionNode.getText()); } List<Node> artLinks = arNode.selectNodes("artifactHits/artifactHit/artifactLinks/artifactLink");//$NON-NLS-1$ for (Node link : artLinks) { Node extensionElement = link.selectSingleNode("extension");//$NON-NLS-1$ String extension = null; String classifier = null; if (extensionElement != null) { if ("pom".equals(extensionElement.getText())) {//$NON-NLS-1$ continue; } extension = extensionElement.getText(); } Node classifierElement = link.selectSingleNode("classifier");//$NON-NLS-1$ if (classifierElement != null) { classifier = classifierElement.getText(); } artifact.setType(extension); artifact.setClassifier(classifier); } } int searchDone = searchFrom + searchCount; int count = MAX_SEARCH_COUNT; if (searchDone < totalCount) { if (totalCount - searchDone < MAX_SEARCH_COUNT) { count = totalCount - searchDone; } search(nexusUrl, userName, password, repositoryId, groupIdToSearch, versionToSearch, searchDone + 1, count, artifacts); } } catch (Exception e) { if (e instanceof ConnectException) { throw new BusinessException("Can not connect to nexus server ,please contact the administrator", nexusUrl); } else { throw new BusinessException(e); } } finally { if (null != urlConnection) { urlConnection.disconnect(); } } }
From source file:org.talend.core.nexus.NexusServerUtils.java
License:Open Source License
private static void search(String nexusUrl, final String userName, final String password, String repositoryId, String groupIdToSearch, String artifactId, String versionToSearch, int searchFrom, int searchCount, List<MavenArtifact> artifacts) throws Exception { HttpURLConnection urlConnection = null; int totalCount = 0; final Authenticator defaultAuthenticator = NetworkUtil.getDefaultAuthenticator(); if (userName != null && !"".equals(userName)) { Authenticator.setDefault(new Authenticator() { @Override/*from www.j av a 2s . c o m*/ protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(userName, password.toCharArray()); } }); } try { String service = NexusConstants.SERVICES_SEARCH + getSearchQuery(repositoryId, groupIdToSearch, artifactId, versionToSearch, searchFrom, searchCount); urlConnection = getHttpURLConnection(nexusUrl, service, userName, password); SAXReader saxReader = new SAXReader(); InputStream inputStream = urlConnection.getInputStream(); Document document = saxReader.read(inputStream); Node countNode = document.selectSingleNode("/searchNGResponse/totalCount"); if (countNode != null) { try { totalCount = Integer.parseInt(countNode.getText()); } catch (NumberFormatException e) { totalCount = 0; } } List<Node> list = document.selectNodes("/searchNGResponse/data/artifact");//$NON-NLS-1$ for (Node arNode : list) { MavenArtifact artifact = new MavenArtifact(); artifacts.add(artifact); artifact.setGroupId(arNode.selectSingleNode("groupId").getText());//$NON-NLS-1$ artifact.setArtifactId(arNode.selectSingleNode("artifactId").getText());//$NON-NLS-1$ artifact.setVersion(arNode.selectSingleNode("version").getText());//$NON-NLS-1$ Node descNode = arNode.selectSingleNode("description");//$NON-NLS-1$ if (descNode != null) { artifact.setDescription(descNode.getText()); } Node urlNode = arNode.selectSingleNode("url");//$NON-NLS-1$ if (urlNode != null) { artifact.setUrl(urlNode.getText()); } Node licenseNode = arNode.selectSingleNode("license");//$NON-NLS-1$ if (licenseNode != null) { artifact.setLicense(licenseNode.getText()); } Node licenseUrlNode = arNode.selectSingleNode("licenseUrl");//$NON-NLS-1$ if (licenseUrlNode != null) { artifact.setLicenseUrl(licenseUrlNode.getText()); } List<Node> artLinks = arNode.selectNodes("artifactHits/artifactHit/artifactLinks/artifactLink");//$NON-NLS-1$ for (Node link : artLinks) { Node extensionElement = link.selectSingleNode("extension");//$NON-NLS-1$ String extension = null; String classifier = null; if (extensionElement != null) { if ("pom".equals(extensionElement.getText())) {//$NON-NLS-1$ continue; } extension = extensionElement.getText(); } Node classifierElement = link.selectSingleNode("classifier");//$NON-NLS-1$ if (classifierElement != null) { classifier = classifierElement.getText(); } artifact.setType(extension); artifact.setClassifier(classifier); } } int searchDone = searchFrom + searchCount; int count = MAX_SEARCH_COUNT; if (searchDone < totalCount) { if (totalCount - searchDone < MAX_SEARCH_COUNT) { count = totalCount - searchDone; } search(nexusUrl, userName, password, repositoryId, groupIdToSearch, artifactId, versionToSearch, searchDone + 1, count, artifacts); } } finally { Authenticator.setDefault(defaultAuthenticator); if (null != urlConnection) { urlConnection.disconnect(); } } }
From source file:org.waarp.ftp.simpleimpl.config.FileBasedConfiguration.java
License:Open Source License
/** * Initiate the configuration from the xml file * /*from www.ja v a 2s. c o m*/ * @param filename * @return True if OK */ @SuppressWarnings("unchecked") public boolean setConfigurationFromXml(String filename) { Document document = null; // Open config file try { document = new SAXReader().read(filename); } catch (DocumentException e) { logger.error("Unable to read the XML Config file: " + filename, e); return false; } if (document == null) { logger.error("Unable to read the XML Config file: " + filename); return false; } Node nodebase, node = null; node = document.selectSingleNode(XML_SERVER_PASSWD); if (node == null) { logger.error("Unable to find Password in Config file: " + filename); return false; } String passwd = node.getText(); setPassword(passwd); node = document.selectSingleNode(XML_SERVER_PORT); int port = 21; if (node != null) { port = Integer.parseInt(node.getText()); } setServerPort(port); node = document.selectSingleNode(XML_SERVER_ADDRESS); String address = null; if (node != null) { address = node.getText(); } setServerAddress(address); node = document.selectSingleNode(XML_SERVER_HOME); if (node == null) { logger.error("Unable to find Home in Config file: " + filename); return false; } String path = node.getText(); File file = new File(path); try { setBaseDirectory(FilesystemBasedDirImpl.normalizePath(file.getCanonicalPath())); } catch (IOException e1) { logger.error("Unable to set Home in Config file: " + filename); return false; } if (!file.isDirectory()) { logger.error("Home is not a directory in Config file: " + filename); return false; } node = document.selectSingleNode(XML_SERVER_THREAD); if (node != null) { SERVER_THREAD = Integer.parseInt(node.getText()); } node = document.selectSingleNode(XML_CLIENT_THREAD); if (node != null) { CLIENT_THREAD = Integer.parseInt(node.getText()); } if (SERVER_THREAD == 0 || CLIENT_THREAD == 0) { computeNbThreads(); } node = document.selectSingleNode(XML_LIMITGLOBAL); if (node != null) { serverGlobalReadLimit = Long.parseLong(node.getText()); if (serverGlobalReadLimit <= 0) { serverGlobalReadLimit = 0; } serverGlobalWriteLimit = serverGlobalReadLimit; logger.warn("Global Limit: {}", serverGlobalReadLimit); } node = document.selectSingleNode(XML_LIMITSESSION); if (node != null) { serverChannelReadLimit = Long.parseLong(node.getText()); if (serverChannelReadLimit <= 0) { serverChannelReadLimit = 0; } serverChannelWriteLimit = serverChannelReadLimit; logger.warn("SessionInterface Limit: {}", serverChannelReadLimit); } delayLimit = AbstractTrafficShapingHandler.DEFAULT_CHECK_INTERVAL; node = document.selectSingleNode(XML_TIMEOUTCON); if (node != null) { TIMEOUTCON = Integer.parseInt(node.getText()); } node = document.selectSingleNode(XML_DELETEONABORT); if (node != null) { deleteOnAbort = Integer.parseInt(node.getText()) == 1 ? true : false; } node = document.selectSingleNode(XML_USENIO); if (node != null) { FilesystemBasedFileParameterImpl.useNio = Integer.parseInt(node.getText()) == 1 ? true : false; } node = document.selectSingleNode(XML_USEFASTMD5); if (node != null) { FilesystemBasedDigest.useFastMd5 = Integer.parseInt(node.getText()) == 1 ? true : false; } else { FilesystemBasedDigest.useFastMd5 = false; } node = document.selectSingleNode(XML_BLOCKSIZE); if (node != null) { BLOCKSIZE = Integer.parseInt(node.getText()); } node = document.selectSingleNode(XML_RANGE_PORT_MIN); int min = 100; if (node != null) { min = Integer.parseInt(node.getText()); } node = document.selectSingleNode(XML_RANGE_PORT_MAX); int max = 65535; if (node != null) { max = Integer.parseInt(node.getText()); } CircularIntValue rangePort = new CircularIntValue(min, max); setRangePort(rangePort); // We use Apache Commons IO FilesystemBasedDirJdkAbstract.ueApacheCommonsIo = true; node = document.selectSingleNode(XML_AUTHENTIFICATION_FILE); if (node == null) { logger.error("Unable to find Authentication file in Config file: " + filename); return false; } String fileauthent = node.getText(); document = null; try { document = new SAXReader().read(fileauthent); } catch (DocumentException e) { logger.error("Unable to read the XML Authentication file: " + fileauthent, e); return false; } if (document == null) { logger.error("Unable to read the XML Authentication file: " + fileauthent); return false; } List<Node> list = document.selectNodes(XML_AUTHENTIFICATION_BASED); Iterator<Node> iterator = list.iterator(); while (iterator.hasNext()) { nodebase = iterator.next(); node = nodebase.selectSingleNode(XML_AUTHENTIFICATION_USER); if (node == null) { continue; } String user = node.getText(); node = nodebase.selectSingleNode(XML_AUTHENTIFICATION_PASSWD); if (node == null) { continue; } String userpasswd = node.getText(); node = nodebase.selectSingleNode(XML_AUTHENTIFICATION_ADMIN); boolean isAdmin = false; if (node != null) { isAdmin = node.getText().equals("1") ? true : false; } List<Node> listaccount = nodebase.selectNodes(XML_AUTHENTIFICATION_ACCOUNT); String[] account = null; if (!listaccount.isEmpty()) { account = new String[listaccount.size()]; int i = 0; Iterator<Node> iteratoraccount = listaccount.iterator(); while (iteratoraccount.hasNext()) { node = iteratoraccount.next(); account[i] = node.getText(); // logger.debug("User: {} Acct: {}", user, account[i]); i++; } } SimpleAuth auth = new SimpleAuth(user, userpasswd, account); auth.setAdmin(isAdmin); authentications.put(user, auth); } document = null; return true; }
From source file:pt.webdetails.cdb.exporters.ExporterEngine.java
License:Open Source License
public String listExporters() { JSONArray arr = new JSONArray(); Document doc = getConfigFile(); List<Node> exporters = doc.selectNodes("//exporter"); for (Node exporter : exporters) { String id = exporter.selectSingleNode("@id").getText(); try {/*from w w w .ja v a 2 s . c o m*/ JSONObject jsonExporter = new JSONObject(); JSONObject jsonModes = new JSONObject(); jsonExporter.put("id", id); jsonExporter.put("label", exporter.selectSingleNode("@label").getText()); List<Node> modes = exporter.selectNodes(".//mode"); for (Node mode : modes) { jsonModes.put(mode.selectSingleNode("@type").getText(), true); } jsonExporter.put("modes", jsonModes); arr.put(jsonExporter); } catch (JSONException e) { logger.error("Failed to list exporter " + id + ". Reason: " + e); } } try { return arr.toString(2); } catch (JSONException e) { return null; } }
From source file:pt.webdetails.cdv.notifications.EmailOutlet.java
License:Open Source License
private static Map<String, String> getSettingsFromNode(Node settings) { Map<String, String> out = new HashMap<String, String>(); for (Node node : (List<Node>) settings.selectNodes(".//property")) { String key = node.selectSingleNode("./@name").getText(); String val = node.selectSingleNode("./@value").getText(); out.put(key, val); }/* w w w . j av a2s. c o m*/ return out; }
From source file:pt.webdetails.cdv.notifications.NotificationEngine.java
License:Open Source License
private void listAlerts(Document doc) { alerts = new HashMap<NotificationKey, List<NotificationOutlet>>(); List<Node> alertNodes = doc.selectNodes("//alerts/alert"); for (Node alertNode : alertNodes) { String outletName = ""; try {/* ww w . j av a2s . c om*/ outletName = alertNode.selectSingleNode("./@outlet").getStringValue(); Class outletClass = outlets.get(outletName); if (outletClass == null) { throw new ClassNotFoundException(); } List<Node> groups = alertNode.selectNodes("./groups/group"); for (Node group : groups) { Constructor cons = outletClass.getConstructor(Node.class); NotificationOutlet outlet = (NotificationOutlet) cons.newInstance(alertNode); String minLevel = group.selectSingleNode("./@threshold").getStringValue(); if (minLevel.equals("*")) { minLevel = "ALL"; } String groupName = group.selectSingleNode("./@name").getStringValue(); Level level; try { level = Level.valueOf(minLevel.toUpperCase()); } catch (Exception ex) { level = Level.WARN; } NotificationKey key = new NotificationKey(level, groupName); if (!alerts.containsKey(key)) { alerts.put(key, new ArrayList<NotificationOutlet>()); } alerts.get(key).add(outlet); } } catch (InstantiationException e) { logger.error("Failed to instantiate " + outletName, e); } catch (ClassNotFoundException ex) { logger.error("Failed to get class for outlet " + outletName, ex); } catch (NoSuchMethodException ex) { logger.error("Class " + outletName + " doesn't provide the necessary interface"); logger.error(ex); } catch (InvocationTargetException ex) { logger.error("Failed to set defaults on " + outletName); logger.error(ex); } catch (IllegalAccessException ex) { logger.error("Failed to set defaults on " + outletName); logger.error(ex); } } }