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.pdfsam.console.business.pdf.handlers.ConcatCmdExecutor.java
License:Open Source License
/** * given a fileset node returns the PdfFile objects * //from w w w .j a va 2 s . co m * @param fileSetNode * @param parentDir * @return a list of PdfFile objects * @throws Exception */ private List getFileNodesFromFileset(Node fileSetNode, String parentDir) throws Exception { String parentPath = null; Node useCurrentDir = fileSetNode.selectSingleNode("@usecurrentdir"); Node dir = fileSetNode.selectSingleNode("@dir"); if (dir != null && dir.getText().trim().length() > 0) { parentPath = dir.getText(); } else { if (useCurrentDir != null && Boolean.valueOf(useCurrentDir.getText()).booleanValue()) { parentPath = parentDir; } } return getPdfFileListFromNode(fileSetNode.selectNodes("file"), parentPath); }
From source file:org.pdfsam.plugin.coverfooter.GUI.CoverFooterMainGUI.java
License:Open Source License
@SuppressWarnings("unchecked") public void loadJobNode(Node arg0) throws LoadJobException { try {// ww w. ja v a 2s.co m Node coverSource = (Node) arg0.selectSingleNode("cover/@value"); if (coverSource != null && coverSource.getText().length() > 0) { Node coverPageSelection = (Node) arg0.selectSingleNode("cover/@pageselection"); Node coverFilePwd = (Node) arg0.selectSingleNode("cover/@password"); coverSelectionPanel.getLoader().addFile(new File(coverSource.getText()), (coverFilePwd != null) ? coverFilePwd.getText() : null, (coverPageSelection != null) ? coverPageSelection.getText() : null); } footerSelectionPanel.getClearButton().doClick(); Node footerSource = (Node) arg0.selectSingleNode("cover/@value"); if (footerSource != null && footerSource.getText().length() > 0) { Node footerPageSelection = (Node) arg0.selectSingleNode("cover/@pageselection"); Node footerFilePwd = (Node) arg0.selectSingleNode("cover/@password"); footerSelectionPanel.getLoader().addFile(new File(footerSource.getText()), (footerFilePwd != null) ? footerFilePwd.getText() : null, (footerPageSelection != null) ? footerPageSelection.getText() : null); } Node fileDestination = (Node) arg0.selectSingleNode("destination/@value"); if (fileDestination != null) { destinationTextField.setText(fileDestination.getText()); } Node fileOverwrite = (Node) arg0.selectSingleNode("overwrite/@value"); if (fileOverwrite != null) { overwriteCheckbox.setSelected(TRUE.equals(fileOverwrite.getText())); } Node mergeType = (Node) arg0.selectSingleNode("merge_type/@value"); if (mergeType != null) { mergeTypeCheck.setSelected(TRUE.equals(mergeType.getText())); } selectionPanel.getClearButton().doClick(); List fileList = arg0.selectNodes("filelist/file"); for (int i = 0; fileList != null && i < fileList.size(); i++) { Node fileNode = (Node) fileList.get(i); if (fileNode != null) { Node fileName = (Node) fileNode.selectSingleNode("@name"); if (fileName != null && fileName.getText().length() > 0) { Node pageSelection = (Node) fileNode.selectSingleNode("@pageselection"); Node filePwd = (Node) fileNode.selectSingleNode("@password"); selectionPanel.getLoader().addFile(new File(fileName.getText()), (filePwd != null) ? filePwd.getText() : null, (pageSelection != null) ? pageSelection.getText() : null); } } } Node fileCompressed = (Node) arg0.selectSingleNode("compressed/@value"); if (fileCompressed != null && TRUE.equals(fileCompressed.getText())) { outputCompressedCheck.doClick(); } Node pdfVersion = (Node) arg0.selectSingleNode("pdfversion/@value"); if (pdfVersion != null) { for (int i = 0; i < versionCombo.getItemCount(); i++) { if (((StringItem) versionCombo.getItemAt(i)).getId().equals(pdfVersion.getText())) { versionCombo.setSelectedIndex(i); break; } } } log.info(GettextResource.gettext(config.getI18nResourceBundle(), "Cover And Footer section loaded.")); } catch (Exception ex) { log.error(GettextResource.gettext(config.getI18nResourceBundle(), "Error: "), ex); } }
From source file:org.pdfsam.plugin.decrypt.GUI.DecryptMainGUI.java
License:Open Source License
@SuppressWarnings("unchecked") public void loadJobNode(Node arg0) throws LoadJobException { try {/* w w w .ja v a2 s. com*/ List fileList = arg0.selectNodes("filelist/file"); for (int i = 0; fileList != null && i < fileList.size(); i++) { Node fileNode = (Node) fileList.get(i); if (fileNode != null) { Node fileName = (Node) fileNode.selectSingleNode("@name"); if (fileName != null && fileName.getText().length() > 0) { Node filePwd = (Node) fileNode.selectSingleNode("@password"); selectionPanel.getLoader().addFile(new File(fileName.getText()), (filePwd != null) ? filePwd.getText() : null); } } } Node fileDestination = (Node) arg0.selectSingleNode("destination/@value"); if (fileDestination != null) { destinationTextField.setText(fileDestination.getText()); } Node fileOverwrite = (Node) arg0.selectSingleNode("overwrite/@value"); if (fileOverwrite != null) { overwriteCheckbox.setSelected(fileOverwrite.getText().equals("true")); } Node fileCompressed = (Node) arg0.selectSingleNode("compressed/@value"); if (fileCompressed != null && TRUE.equals(fileCompressed.getText())) { outputCompressedCheck.doClick(); } Node filePrefix = (Node) arg0.selectSingleNode("prefix/@value"); if (filePrefix != null) { outPrefixTextField.setText(filePrefix.getText()); } Node pdfVersion = (Node) arg0.selectSingleNode("pdfversion/@value"); if (pdfVersion != null) { for (int i = 0; i < versionCombo.getItemCount(); i++) { if (((StringItem) versionCombo.getItemAt(i)).getId().equals(pdfVersion.getText())) { versionCombo.setSelectedIndex(i); break; } } } log.info(GettextResource.gettext(config.getI18nResourceBundle(), "Decrypt section loaded.")); } catch (Exception ex) { log.error(GettextResource.gettext(config.getI18nResourceBundle(), "Error: "), ex); } }
From source file:org.pdfsam.plugin.encrypt.GUI.EncryptMainGUI.java
License:Open Source License
@SuppressWarnings("unchecked") public void loadJobNode(Node arg0) throws LoadJobException { try {// w w w .j ava2 s.c om List fileList = arg0.selectNodes("filelist/file"); for (int i = 0; fileList != null && i < fileList.size(); i++) { Node fileNode = (Node) fileList.get(i); if (fileNode != null) { Node fileName = (Node) fileNode.selectSingleNode("@name"); if (fileName != null && fileName.getText().length() > 0) { Node filePwd = (Node) fileNode.selectSingleNode("@password"); selectionPanel.getLoader().addFile(new File(fileName.getText()), (filePwd != null) ? filePwd.getText() : null); } } } Node allowAll = (Node) arg0.selectSingleNode("allowall/@value"); if (allowAll != null && TRUE.equals(allowAll.getText())) { allowAllCheck.doClick(); } else { Node permissions = (Node) arg0.selectSingleNode("permissions"); if (permissions != null) { List listEnab = permissions.selectNodes("enabled"); for (int j = 0; listEnab != null && j < listEnab.size(); j++) { Node enabledNode = (Node) listEnab.get(j); if (enabledNode != null) { permissionsCheck[Integer.parseInt(enabledNode.selectSingleNode("@value").getText())] .setSelected(true); } } } } Node encType = (Node) arg0.selectSingleNode("enctype/@value"); if (encType != null) { encryptType.setSelectedItem((String) encType.getText()); } Node userPwd = (Node) arg0.selectSingleNode("usrpwd/@value"); if (userPwd != null) { userPwdField.setText(userPwd.getText()); } Node ownerPwd = (Node) arg0.selectSingleNode("ownerpwd/@value"); if (ownerPwd != null) { ownerPwdField.setText(ownerPwd.getText()); } Node fileDestination = (Node) arg0.selectSingleNode("destination/@value"); if (fileDestination != null) { destFolderText.setText(fileDestination.getText()); } Node fileOverwrite = (Node) arg0.selectSingleNode("overwrite/@value"); if (fileOverwrite != null) { overwriteCheckbox.setSelected(TRUE.equals(fileOverwrite.getText())); } Node fileCompressed = (Node) arg0.selectSingleNode("compressed/@value"); if (fileCompressed != null && TRUE.equals(fileCompressed.getText())) { outputCompressedCheck.doClick(); } Node filePrefix = (Node) arg0.selectSingleNode("prefix/@value"); if (filePrefix != null) { outPrefixTextField.setText(filePrefix.getText()); } Node pdfVersion = (Node) arg0.selectSingleNode("pdfversion/@value"); if (pdfVersion != null) { for (int i = 0; i < versionCombo.getItemCount(); i++) { if (((StringItem) versionCombo.getItemAt(i)).getId().equals(pdfVersion.getText())) { versionCombo.setSelectedIndex(i); break; } } } log.info(GettextResource.gettext(config.getI18nResourceBundle(), "Encrypt section loaded.")); } catch (Exception ex) { log.error(GettextResource.gettext(config.getI18nResourceBundle(), "Error: "), ex); } }
From source file:org.pdfsam.plugin.merge.GUI.MergeMainGUI.java
License:Open Source License
@SuppressWarnings("unchecked") public void loadJobNode(Node arg0) throws LoadJobException { try {/* w w w. jav a2 s. c om*/ Node fileDestination = (Node) arg0.selectSingleNode("destination/@value"); if (fileDestination != null) { destinationTextField.setText(fileDestination.getText()); } Node fileOverwrite = (Node) arg0.selectSingleNode("overwrite/@value"); if (fileOverwrite != null) { overwriteCheckbox.setSelected(TRUE.equals(fileOverwrite.getText())); } Node mergeType = (Node) arg0.selectSingleNode("merge_type/@value"); if (mergeType != null) { mergeTypeCheck.setSelected(TRUE.equals(mergeType.getText())); } List fileList = arg0.selectNodes("filelist/file"); for (int i = 0; fileList != null && i < fileList.size(); i++) { Node fileNode = (Node) fileList.get(i); if (fileNode != null) { Node fileName = (Node) fileNode.selectSingleNode("@name"); if (fileName != null && fileName.getText().length() > 0) { Node pageSelection = (Node) fileNode.selectSingleNode("@pageselection"); Node filePwd = (Node) fileNode.selectSingleNode("@password"); selectionPanel.getLoader().addFile(new File(fileName.getText()), (filePwd != null) ? filePwd.getText() : null, (pageSelection != null) ? pageSelection.getText() : null); } } } Node fileCompressed = (Node) arg0.selectSingleNode("compressed/@value"); if (fileCompressed != null && TRUE.equals(fileCompressed.getText())) { outputCompressedCheck.doClick(); } Node pdfVersion = (Node) arg0.selectSingleNode("pdfversion/@value"); if (pdfVersion != null) { for (int i = 0; i < versionCombo.getItemCount(); i++) { if (((StringItem) versionCombo.getItemAt(i)).getId().equals(pdfVersion.getText())) { versionCombo.setSelectedIndex(i); break; } } } log.info(GettextResource.gettext(config.getI18nResourceBundle(), "Merge section loaded.")); } catch (Exception ex) { log.error(GettextResource.gettext(config.getI18nResourceBundle(), "Error: "), ex); } }
From source file:org.pdfsam.plugin.rotate.GUI.RotateMainGUI.java
License:Open Source License
@SuppressWarnings("unchecked") public void loadJobNode(Node arg0) throws LoadJobException { try {//www . j a va 2s . c o m List fileList = arg0.selectNodes("filelist/file"); for (int i = 0; fileList != null && i < fileList.size(); i++) { Node fileNode = (Node) fileList.get(i); if (fileNode != null) { Node fileName = (Node) fileNode.selectSingleNode("@name"); if (fileName != null && fileName.getText().length() > 0) { Node filePwd = (Node) fileNode.selectSingleNode("@password"); selectionPanel.getLoader().addFile(new File(fileName.getText()), (filePwd != null) ? filePwd.getText() : null); } } } Node rotationNode = (Node) arg0.selectSingleNode("rotation/@value"); if (rotationNode != null) { rotationBox.setSelectedItem((String) rotationNode.getText()); } Node rotationPageNode = (Node) arg0.selectSingleNode("pages/@value"); if (rotationPageNode != null) { for (int i = 0; i < rotationPagesBox.getItemCount(); i++) { if (((StringItem) rotationPagesBox.getItemAt(i)).getId().equals(rotationPageNode.getText())) { rotationPagesBox.setSelectedIndex(i); break; } } } Node fileDestination = (Node) arg0.selectSingleNode("destination/@value"); if (fileDestination != null) { destinationTextField.setText(fileDestination.getText()); } Node fileOverwrite = (Node) arg0.selectSingleNode("overwrite/@value"); if (fileOverwrite != null) { overwriteCheckbox.setSelected(fileOverwrite.getText().equals("true")); } Node fileCompressed = (Node) arg0.selectSingleNode("compressed/@value"); if (fileCompressed != null && TRUE.equals(fileCompressed.getText())) { outputCompressedCheck.doClick(); } Node filePrefix = (Node) arg0.selectSingleNode("prefix/@value"); if (filePrefix != null) { outPrefixTextField.setText(filePrefix.getText()); } Node pdfVersion = (Node) arg0.selectSingleNode("pdfversion/@value"); if (pdfVersion != null) { for (int i = 0; i < versionCombo.getItemCount(); i++) { if (((StringItem) versionCombo.getItemAt(i)).getId().equals(pdfVersion.getText())) { versionCombo.setSelectedIndex(i); break; } } } log.info(GettextResource.gettext(config.getI18nResourceBundle(), "Rotate section loaded.")); } catch (Exception ex) { log.error(GettextResource.gettext(config.getI18nResourceBundle(), "Error: "), ex); } }
From source file:org.pdfsam.plugin.unpack.GUI.UnpackMainGUI.java
License:Open Source License
@SuppressWarnings("unchecked") public void loadJobNode(Node arg0) throws LoadJobException { try {/*from w w w.ja v a 2s. co m*/ List fileList = arg0.selectNodes("filelist/file"); for (int i = 0; fileList != null && i < fileList.size(); i++) { Node fileNode = (Node) fileList.get(i); if (fileNode != null) { Node fileName = (Node) fileNode.selectSingleNode("@name"); if (fileName != null && fileName.getText().length() > 0) { Node filePwd = (Node) fileNode.selectSingleNode("@password"); selectionPanel.getLoader().addFile(new File(fileName.getText()), (filePwd != null) ? filePwd.getText() : null); } } } Node fileDestination = (Node) arg0.selectSingleNode("destination/@value"); if (fileDestination != null) { destinationTextField.setText(fileDestination.getText()); } Node fileOverwrite = (Node) arg0.selectSingleNode("overwrite/@value"); if (fileOverwrite != null) { overwriteCheckbox.setSelected(fileOverwrite.getText().equals("true")); } log.info(GettextResource.gettext(config.getI18nResourceBundle(), "Unpack section loaded.")); } catch (Exception ex) { log.error(GettextResource.gettext(config.getI18nResourceBundle(), "Error: "), ex); } }
From source file:org.pdfsam.plugin.vpagereorder.GUI.VPageReorderMainGUI.java
License:Open Source License
@SuppressWarnings("unchecked") public void loadJobNode(Node arg0) throws LoadJobException { try {/* w w w . j a va 2s. co m*/ Node fileSource = (Node) arg0.selectSingleNode("source/@value"); if (fileSource != null && fileSource.getText().length() > 0) { Node filePwd = (Node) arg0.selectSingleNode("source/@password"); String password = null; if (filePwd != null && filePwd.getText().length() > 0) { password = filePwd.getText(); } List<DocumentPage> template = null; List<Node> pages = arg0.selectNodes("source/page"); if (pages != null && pages.size() > 0) { for (Node pageNode : pages) { DocumentPage currentPage = XmlUtility.getDocumentPage(pageNode); if (currentPage != null) { if (template == null) { template = new ArrayList<DocumentPage>(); } template.add(currentPage); } } } selectionPanel.getPdfLoader().addFile(new File(fileSource.getText()), password, template); } Node fileDestination = (Node) arg0.selectSingleNode("destination/@value"); if (fileDestination != null && fileDestination.getText().length() > 0) { destinationFileText.setText(fileDestination.getText()); chooseAFileRadio.doClick(); } else { sameAsSourceRadio.doClick(); } Node fileOverwrite = (Node) arg0.selectSingleNode("overwrite/@value"); if (fileOverwrite != null) { overwriteCheckbox.setSelected(TRUE.equals(fileOverwrite.getText())); } Node fileCompressed = (Node) arg0.selectSingleNode("compressed/@value"); if (fileCompressed != null && TRUE.equals(fileCompressed.getText())) { outputCompressedCheck.doClick(); } Node pdfVersion = (Node) arg0.selectSingleNode("pdfversion/@value"); if (pdfVersion != null) { for (int i = 0; i < versionCombo.getItemCount(); i++) { if (((StringItem) versionCombo.getItemAt(i)).getId().equals(pdfVersion.getText())) { versionCombo.setSelectedIndex(i); break; } } } log.info(GettextResource.gettext(config.getI18nResourceBundle(), "Visual Reorder section loaded.")); } catch (Exception ex) { log.error(GettextResource.gettext(config.getI18nResourceBundle(), "Error: "), ex); } }
From source file:org.pentaho.cdf.NavigateComponent.java
License:Open Source License
@SuppressWarnings("unchecked") private JSONArray processTree(final Node tree, final String parentPath, boolean includeAllFiles) { final String xPathDir = "./file[@isDirectory='true']"; //$NON-NLS-1$ JSONArray array = null;//from w ww .ja v a2s . c o m try { final List nodes = tree.selectNodes(xPathDir); //$NON-NLS-1$ if (!nodes.isEmpty()) { array = new JSONArray(); } final String[] parentPathArray = parentPath.split("/"); final String solutionName = parentPathArray.length > 2 ? parentPathArray[2] : ""; final String solutionPath = parentPathArray.length > 3 ? parentPath.substring(parentPath.indexOf(solutionName) + solutionName.length() + 1, parentPath.length()) + "/" : ""; for (final Object node1 : nodes) { final Node node = (Node) node1; final JSONObject json = new JSONObject(); JSONArray children = null; String name = node.valueOf("@name"); if (parentPathArray.length > 0) { final String localizedName = node.valueOf("@localized-name"); final String description = node.valueOf("@description"); final boolean visible = node.valueOf("@visible").equals("true"); final boolean isDirectory = node.valueOf("@isDirectory").equals("true"); final String path = solutionName.length() == 0 ? "" : solutionPath + name; final String solution = solutionName.length() == 0 ? name : solutionName; json.put("id", parentPath + "/" + name); json.put("name", name); json.put("solution", solution); json.put("path", path); json.put("type", TYPE_DIR); json.put("visible", visible); json.put("title", visible ? localizedName : "Hidden"); json.put("description", description); if (visible && isDirectory) { children = processTree(node, parentPath + "/" + name, includeAllFiles); json.put("files", new JSONArray()); // Process directory wcdf/xcdf files List<Node> fileNodes; if (includeAllFiles) { fileNodes = node.selectNodes("./file[@isDirectory='false']"); } else { fileNodes = node.selectNodes( "./file[@isDirectory='false'][ends-with(string(@name),'.xcdf') or ends-with(string(@name),'.wcdf')]"); } for (final Node fileNode : fileNodes) { processFileNode(json, fileNode, "files"); } } } else { // root dir json.put("id", tree.valueOf("@path")); json.put("name", solutionName); json.put("path", solutionPath); json.put("visible", true); json.put("title", "Solution"); children = processTree(tree, tree.valueOf("@path"), includeAllFiles); } // System.out.println(" Processing getting children "); if (children != null) { json.put("folders", children); } array.put(json); } } catch (Exception e) { System.out.println("Error: " + e.getClass().getName() + " - " + e.getMessage()); logger.warn("Error: " + e.getClass().getName() + " - " + e.getMessage()); } return array; }
From source file:org.pentaho.cdf.NavigateComponent.java
License:Open Source License
private String getContentListJSON(final String _solution, final String _path) { String jsonString = null;//from ww w .j a v a2 s .com JSONArray array = null; try { final JSONObject json = new JSONObject(); final Document navDoc = getRepositoryDocument(this.userSession); final Node tree = navDoc.getRootElement(); final String xPathDir = "./file[@name='" + _solution + "']"; //$NON-NLS-1$ List nodes = tree.selectNodes(xPathDir); //$NON-NLS-1$ if (!nodes.isEmpty() && nodes.size() == 1) { // Add Folder final Node node = getDirectoryNode((Node) nodes.get(0), _path); json.put("name", node.valueOf("@name")); json.put("id", _solution + "/" + _path); json.put("solution", _solution); json.put("path", _path); json.put("type", TYPE_DIR); json.put("visible", false); json.put("title", "Hidden"); array = new JSONArray(); json.put("content", array); nodes = node.selectNodes("./file"); // Add Folder Content for (final Object fileNode : nodes) { processFileNode(json, (Node) fileNode, "content"); } } jsonString = json.toString(2); } catch (Exception e) { System.out.println("Error: " + e.getClass().getName() + " - " + e.getMessage()); logger.warn("Error: " + e.getClass().getName() + " - " + e.getMessage()); } // debug("Finished processing tree"); return jsonString; }