List of usage examples for org.dom4j Node asXML
String asXML();
asXML
returns the textual XML representation of this node.
From source file:org.ednovo.gooru.infrastructure.persistence.hibernate.taxonomy.TaxonomyRepositoryHibernate.java
License:Open Source License
@Override public String findTaxonomyTree(String taxonomyCode, String format) throws Exception { Code code = (Code) get(Code.class, new Integer(taxonomyCode));// (taxonomyCode); CodeType codetype = (CodeType) super.get(CodeType.class, code.getCodeType().getTypeId()); Document taxonomyXML = null;//from ww w .j a v a 2 s.c o m SAXReader reader = new SAXReader(); taxonomyXML = reader.read(configProperties.getTaxonomyRepositoryPath().get("taxonomy.repository") + "/" + codetype.getCodeId() + ".xml"); Node nodeTree = null; if (taxonomyXML.getRootElement().attribute("code").getText().equals(code.getCode())) { nodeTree = taxonomyXML.getRootElement(); } else { @SuppressWarnings("unchecked") List<Node> nodes = taxonomyXML.selectNodes("//node"); for (Node node : nodes) { Element parent = (Element) node; String att = parent.attribute("code").getText(); if (att.equals(code.getCode())) { nodeTree = node; break; } } } if (format.equalsIgnoreCase("json")) { TaxonomyNode taxonomyNode = convertXmlToJson(nodeTree); JSONObject jsonObject = new JSONObject(); String nodeJson = new JSONSerializer().exclude("*.class").deepSerialize(taxonomyNode) .replace("\"node\":null,", "").replace("\"order\":null,", "") .replace("\"taxonomyImageUrl\":null,", "").replace("\"label\":null,", ""); jsonObject.put("node", new JSONObject(nodeJson)); return jsonObject.toString(); } return nodeTree.asXML(); }
From source file:org.esupportail.lecture.domain.model.Source.java
/** * Make Items objects in fonction of itemXPath, xsltURL, xmlStream. * @throws ComputeItemsException /*from w w w . ja v a 2 s . com*/ */ @SuppressWarnings("unchecked") synchronized private void computeItems() throws ComputeItemsException { if (LOG.isDebugEnabled()) { LOG.debug("id=" + this.profileId + " - computeItems()"); } if (!itemComputed) { try { //create dom4j document Document document = DocumentHelper.parseText(xmlStream); // get encoding String encoding = document.getXMLEncoding(); //lauch Xpath find String x = getItemXPath(); XPath xpath = document.createXPath(x); xpath.setNamespaceURIs(getXPathNameSpaces()); List<Node> list = xpath.selectNodes(document); //List<Node> list = document.selectNodes(getItemXPath()); Iterator<Node> iter = list.iterator(); while (iter.hasNext()) { Node node = iter.next(); Item item = new Item(this); StringBuffer xml = new StringBuffer("<?xml version=\"1.0\" encoding=\""); xml.append(encoding); xml.append("\" ?>"); xml.append(node.asXML()); String xmlAsString = xml.toString(); String htmlContent = xml2html(xmlAsString, getXsltURL(), encoding); item.setHtmlContent(htmlContent); String MobileHtmlContent = xml2html(xmlAsString, getMobileXsltURL(), encoding); item.setMobileHtmlContent(MobileHtmlContent); //find MD5 of item content for his ID byte[] hash = MessageDigest.getInstance("MD5").digest(xmlAsString.getBytes()); StringBuffer hashString = new StringBuffer(); for (int i = 0; i < hash.length; ++i) { String hex = Integer.toHexString(hash[i]); if (hex.length() == 1) { hashString.append('0'); hashString.append(hex.charAt(hex.length() - 1)); } else { hashString.append(hex.substring(hex.length() - 2)); } } item.setId(hashString.toString()); items.add(item); } } catch (DocumentException e) { String errorMsg = "Error parsing XML content of the source"; LOG.error(errorMsg, e); throw new ComputeItemsException(errorMsg, e); } catch (NoSuchAlgorithmException e) { String errorMsg = "MD5 algorithm not supported"; LOG.error(errorMsg, e); throw new ComputeItemsException(errorMsg, e); } catch (XPathException e) { String errorMsg = "Xpath with NameSpace not specified in mappings.xml"; LOG.error(errorMsg, e); throw new ComputeItemsException(errorMsg, e); } catch (MappingNotFoundException e) { String errorMsg = "Impossible to get itemXPath,XPathNameSpaces and xsltURL"; LOG.error(errorMsg, e); throw new ComputeItemsException(errorMsg, e); } catch (Xml2HtmlException e) { String errorMsg = "Impossible to make html content"; LOG.error(errorMsg, e); throw new ComputeItemsException(errorMsg, e); } itemComputed = true; } }
From source file:org.infoglue.cms.controllers.kernel.impl.simple.ShortcutController.java
License:Open Source License
/** * Returns a list of all available shortcuts defined in the system including personal * @param userPrincipal a user principal * @return a list ShortcutVOs representing available shortcuts *//*from w w w . ja v a 2 s . c o m*/ public List getAvailableShortcutVOList(InfoGluePrincipal userPrincipal) throws SystemException { List availableShortcutVOList = new ArrayList(); try { Map args = new HashMap(); args.put("globalKey", "infoglue"); PropertySet propertySet = PropertySetManager.getInstance("jdbc", args); String xml = getDataPropertyValue(propertySet, "serverNode_-1_shortcuts"); logger.info("xml:" + xml); if (xml != null) { DOMBuilder domBuilder = new DOMBuilder(); Document document = domBuilder.getDocument(xml); List nodes = document.getRootElement().selectNodes("shortcut"); logger.info("nodes:" + nodes.size()); Iterator nodesIterator = nodes.iterator(); while (nodesIterator.hasNext()) { Node node = (Node) nodesIterator.next(); logger.info("Node:" + node.asXML()); Node nameNode = node.selectSingleNode("name"); Node urlNode = node.selectSingleNode("url"); Node popupNode = node.selectSingleNode("popup"); String name = nameNode.getStringValue(); String url = urlNode.getStringValue(); String popup = popupNode.getStringValue(); ShortcutVO shortcut = new ShortcutVO(name, url, Boolean.valueOf(popup).booleanValue()); availableShortcutVOList.add(shortcut); } } } catch (Exception e) { logger.error("An error occurred when reading shortcuts:" + e.getMessage(), e); } return availableShortcutVOList; }
From source file:org.infoglue.igide.cms.connection.InfoglueProxy.java
License:Open Source License
private static ContentVersion deserializeContentVersion(String xml, boolean headonly) throws DocumentException, UnsupportedEncodingException { SAXReader reader = new SAXReader(); Logger.logConsole("Parsing XML:" + xml); Document document = reader.read(new java.io.ByteArrayInputStream(xml.getBytes("UTF-8"))); //Document document = reader.read(new StringBufferInputStream(xml)); Logger.logConsole("document:" + document); ContentVersion contentVersion = new ContentVersion(); String value = ""; Node node = document.selectSingleNode("/contentVersion/head"); System.out.println("Creating contentVersion of: " + node.asXML()); contentVersion.setId(toInteger(node.valueOf("@id"))); contentVersion.setLanguageId(toInteger(node.valueOf("@languageId"))); contentVersion.setContentId(toInteger(node.valueOf("@contentId"))); contentVersion.setStateId(toInteger(node.valueOf("@activeVersionStateId"))); contentVersion.setVersionModifier(node.valueOf("@activeVersionModifier")); contentVersion.setLanguageName(node.valueOf("@languageName")); try {// w w w. j a va2s.com contentVersion.setMod(new Date(new Long(node.valueOf("@mod")).longValue())); } catch (Exception e) { System.out.println("failed to set date: " + node.valueOf("@mod")); } contentVersion.setActive(node.valueOf("@isActive").equalsIgnoreCase("true")); if (!headonly) { Node val = document.selectSingleNode("/contentVersion/value"); value = val.getStringValue(); if (enableCompression) { Base64Encoder decoder = new Base64Encoder(); byte[] b_value = decoder.decode(value); CompressionHelper zip = new CompressionHelper(); String decoded = zip.decompress(b_value); contentVersion.setValue(decoded); } else { contentVersion.setValue(URLDecoder.decode(value, "UTF-8")); } } return contentVersion; }
From source file:org.jboss.jaxr.servlet.SAAJServlet.java
License:LGPL
public Object getRequestObject(String rootElement, Node message) throws RegistryException { Class reqType = null;//from w ww .j a v a 2 s . c o m Object req = null; try { if (rootElement.equals("AdhocQueryRequest")) { reqType = org.oasis.ebxml.registry.bindings.query.AdhocQueryRequest.class; } else if (rootElement.equals("GetContentRequest")) { reqType = org.oasis.ebxml.registry.bindings.query.GetContentRequest.class; } else if (rootElement.equals("ApproveObjectsRequest")) { reqType = org.oasis.ebxml.registry.bindings.rs.ApproveObjectsRequest.class; } else if (rootElement.equals("DeprecateObjectsRequest")) { reqType = org.oasis.ebxml.registry.bindings.rs.DeprecateObjectsRequest.class; } else if (rootElement.equals("AddSlotsRequest")) { reqType = org.oasis.ebxml.registry.bindings.rs.AddSlotsRequest.class; } else if (rootElement.equals("RemoveObjectsRequest")) { reqType = org.oasis.ebxml.registry.bindings.rs.RemoveObjectsRequest.class; } else if (rootElement.equals("RemoveSlotsRequest")) { reqType = org.oasis.ebxml.registry.bindings.rs.RemoveSlotsRequest.class; } else if (rootElement.equals("SubmitObjectsRequest")) { reqType = SubmitObjectsRequest.class; } else if (rootElement.equals("UpdateObjectsRequest")) { reqType = org.oasis.ebxml.registry.bindings.rs.UpdateObjectsRequest.class; } else { throw new RegistryException("InvalidRequest: Unknown element " + rootElement); } Unmarshaller unmarshaller = new Unmarshaller(reqType); StringReader sr = new StringReader(message.asXML()); req = unmarshaller.unmarshal(sr); } catch (org.exolab.castor.xml.MarshalException e) { throw new RegistryException(e); } catch (org.exolab.castor.xml.ValidationException e) { throw new RegistryException(e); } return req; }
From source file:org.mskcc.cbio.oncokb.quest.VariantAnnotationXMLV2.java
private static void handleCNA(Node cnaNode, Map<Alteration, String> mapAlterationXml, String diagnosis) { Gene gene = parseGene(cnaNode, "gene"); if (gene == null) { return;//from w w w.j a v a 2 s .c om } String type = cnaNode.selectSingleNode("type").getText(); Alteration alteration = new Alteration(); alteration.setGene(gene); alteration.setAlteration(type); alteration.setAlterationType(AlterationType.MUTATION); // TODO: this needs to be fixed StringBuilder sb = new StringBuilder(); sb.append("<variant_type>copy_number_alteration</variant_type>\n"); sb.append(cnaNode.asXML()).append("\n"); sb.append(VariantAnnotationXML.annotate(alteration, diagnosis)); mapAlterationXml.put(alteration, sb.toString()); }
From source file:org.mskcc.cbio.oncokb.quest.VariantAnnotationXMLV2.java
private static void handleFusion(Node fusionNode, Map<Alteration, String> mapAlterationXml, String diagnosis) { StringBuilder sb = new StringBuilder(); sb.append("<variant_type>fusion_gene</variant_type>\n"); sb.append(fusionNode.asXML()).append("\n"); Gene gene1 = parseGene(fusionNode, "gene_1"); Gene gene2 = parseGene(fusionNode, "gene_2"); // String type = fusionNode.selectSingleNode("type").getText(); String fusion = gene1.getHugoSymbol() + "-" + gene2.getHugoSymbol() + " fusion"; Alteration alteration = new Alteration(); alteration.setGene(gene2);// www . jav a 2 s. co m alteration.setAlteration(fusion); alteration.setAlterationType(AlterationType.MUTATION); // TODO: this needs to be fixed sb.append(VariantAnnotationXML.annotate(alteration, diagnosis)); mapAlterationXml.put(alteration, sb.toString()); }
From source file:org.pentaho.di.trans.steps.getxmldata.GetXMLData.java
License:Apache License
private Object[] processPutRow(Node node) throws KettleException { // Create new row... Object[] outputRowData = buildEmptyRow(); // Create new row or clone if (meta.isInFields()) { System.arraycopy(data.readrow, 0, outputRowData, 0, data.nrReadRow); }/* w ww . ja v a 2 s. com*/ try { data.nodenr++; // Read fields... for (int i = 0; i < data.nrInputFields; i++) { // Get field GetXMLDataField xmlDataField = meta.getInputFields()[i]; // Get the Path to look for String XPathValue = xmlDataField.getResolvedXPath(); if (meta.isuseToken()) { // See if user use Token inside path field // The syntax is : @_Fieldname- // PDI will search for Fieldname value and replace it // Fieldname must be defined before the current node XPathValue = substituteToken(XPathValue, outputRowData); if (isDetailed()) { logDetailed(XPathValue); } } // Get node value String nodevalue; // Handle namespaces if (meta.isNamespaceAware()) { XPath xpathField = node.createXPath(addNSPrefix(XPathValue, data.PathValue)); xpathField.setNamespaceURIs(data.NAMESPACE); if (xmlDataField.getResultType() == GetXMLDataField.RESULT_TYPE_VALUE_OF) { nodevalue = xpathField.valueOf(node); } else { // nodevalue=xpathField.selectSingleNode(node).asXML(); Node n = xpathField.selectSingleNode(node); if (n != null) { nodevalue = n.asXML(); } else { nodevalue = ""; } } } else { if (xmlDataField.getResultType() == GetXMLDataField.RESULT_TYPE_VALUE_OF) { nodevalue = node.valueOf(XPathValue); } else { // nodevalue=node.selectSingleNode(XPathValue).asXML(); Node n = node.selectSingleNode(XPathValue); if (n != null) { nodevalue = n.asXML(); } else { nodevalue = ""; } } } // Do trimming switch (xmlDataField.getTrimType()) { case GetXMLDataField.TYPE_TRIM_LEFT: nodevalue = Const.ltrim(nodevalue); break; case GetXMLDataField.TYPE_TRIM_RIGHT: nodevalue = Const.rtrim(nodevalue); break; case GetXMLDataField.TYPE_TRIM_BOTH: nodevalue = Const.trim(nodevalue); break; default: break; } // Do conversions // ValueMetaInterface targetValueMeta = data.outputRowMeta.getValueMeta(data.totalpreviousfields + i); ValueMetaInterface sourceValueMeta = data.convertRowMeta.getValueMeta(data.totalpreviousfields + i); outputRowData[data.totalpreviousfields + i] = targetValueMeta.convertData(sourceValueMeta, nodevalue); // Do we need to repeat this field if it is null? if (meta.getInputFields()[i].isRepeated()) { if (data.previousRow != null && Utils.isEmpty(nodevalue)) { outputRowData[data.totalpreviousfields + i] = data.previousRow[data.totalpreviousfields + i]; } } } // End of loop over fields... int rowIndex = data.totalpreviousfields + data.nrInputFields; // See if we need to add the filename to the row... if (meta.includeFilename() && !Utils.isEmpty(meta.getFilenameField())) { outputRowData[rowIndex++] = data.filename; } // See if we need to add the row number to the row... if (meta.includeRowNumber() && !Utils.isEmpty(meta.getRowNumberField())) { outputRowData[rowIndex++] = data.rownr; } // Possibly add short filename... if (meta.getShortFileNameField() != null && meta.getShortFileNameField().length() > 0) { outputRowData[rowIndex++] = data.shortFilename; } // Add Extension if (meta.getExtensionField() != null && meta.getExtensionField().length() > 0) { outputRowData[rowIndex++] = data.extension; } // add path if (meta.getPathField() != null && meta.getPathField().length() > 0) { outputRowData[rowIndex++] = data.path; } // Add Size if (meta.getSizeField() != null && meta.getSizeField().length() > 0) { outputRowData[rowIndex++] = data.size; } // add Hidden if (meta.isHiddenField() != null && meta.isHiddenField().length() > 0) { outputRowData[rowIndex++] = Boolean.valueOf(data.path); } // Add modification date if (meta.getLastModificationDateField() != null && meta.getLastModificationDateField().length() > 0) { outputRowData[rowIndex++] = data.lastModificationDateTime; } // Add Uri if (meta.getUriField() != null && meta.getUriField().length() > 0) { outputRowData[rowIndex++] = data.uriName; } // Add RootUri if (meta.getRootUriField() != null && meta.getRootUriField().length() > 0) { outputRowData[rowIndex] = data.rootUriName; } RowMetaInterface irow = getInputRowMeta(); if (irow == null) { data.previousRow = outputRowData; } else { // clone to previously allocated array to make sure next step doesn't // change it in between... System.arraycopy(outputRowData, 0, this.prevRow, 0, outputRowData.length); // Pick up everything else that needs a real deep clone data.previousRow = irow.cloneRow(outputRowData, this.prevRow); } } catch (Exception e) { if (getStepMeta().isDoingErrorHandling()) { // Simply add this row to the error row putError(data.outputRowMeta, outputRowData, 1, e.toString(), null, "GetXMLData001"); data.errorInRowButContinue = true; return null; } else { logError(e.toString()); throw new KettleException(e.toString()); } } return outputRowData; }
From source file:org.pentaho.di.ui.trans.steps.getxmldata.GetXMLDataDialog.java
License:Open Source License
private void ChildNode(Node node, String realXPath, String realXPathCleaned) { Element ce = (Element) node; // List child for (int j = 0; j < ce.nodeCount(); j++) { Node cnode = ce.node(j); if (!Const.isEmpty(cnode.getName())) { Element cce = (Element) cnode; if (cce.nodeCount() > 1) { if (Const.getOccurenceString(cnode.asXML(), "/>") <= 1) { // We do not have child nodes ... setNodeField(cnode, realXPathCleaned); } else { // let's get child nodes ChildNode(cnode, realXPath, realXPathCleaned); }/* w w w .j av a 2 s . com*/ } else { setNodeField(cnode, realXPathCleaned); } } } }
From source file:org.pentaho.platform.engine.services.actionsequence.SequenceDefinition.java
License:Open Source License
private int parseResourceDefinitions(final Node actionRootNode, final ILogger logger) { resourceDefinitions = new ListOrderedMap(); try {/* w w w . jav a 2s . c o m*/ List resources = actionRootNode.selectNodes("resources/*"); //$NON-NLS-1$ // TODO create objects to represent the types // TODO need source variable list Iterator resourcesIterator = resources.iterator(); Node resourceNode; String resourceName; String resourceTypeName; String resourceMimeType; int resourceType; ActionSequenceResource resource; Node typeNode, mimeNode; while (resourcesIterator.hasNext()) { resourceNode = (Node) resourcesIterator.next(); typeNode = resourceNode.selectSingleNode("./*"); //$NON-NLS-1$ if (typeNode != null) { resourceName = resourceNode.getName(); resourceTypeName = typeNode.getName(); resourceType = ActionSequenceResource.getResourceType(resourceTypeName); String resourceLocation = XmlDom4JHelper.getNodeText("location", typeNode); //$NON-NLS-1$ if ((resourceType == IActionSequenceResource.SOLUTION_FILE_RESOURCE) || (resourceType == IActionSequenceResource.FILE_RESOURCE)) { if (resourceLocation == null) { logger.error(Messages.getInstance().getErrorString( "SequenceDefinition.ERROR_0008_RESOURCE_NO_LOCATION", resourceName)); //$NON-NLS-1$ continue; } } else if (resourceType == IActionSequenceResource.STRING) { resourceLocation = XmlDom4JHelper.getNodeText("string", resourceNode); //$NON-NLS-1$ } else if (resourceType == IActionSequenceResource.XML) { //resourceLocation = XmlHelper.getNodeText("xml", resourceNode); //$NON-NLS-1$ Node xmlNode = typeNode.selectSingleNode("./location/*"); //$NON-NLS-1$ // Danger, we have now lost the character encoding of the XML in this node // see BISERVER-895 resourceLocation = (xmlNode == null) ? "" : xmlNode.asXML(); //$NON-NLS-1$ } mimeNode = typeNode.selectSingleNode("mime-type"); //$NON-NLS-1$ if (mimeNode != null) { resourceMimeType = mimeNode.getText(); if ((resourceType == IActionSequenceResource.SOLUTION_FILE_RESOURCE) || (resourceType == IActionSequenceResource.FILE_RESOURCE)) { resourceLocation = FilenameUtils.separatorsToUnix(resourceLocation); if (!resourceLocation.startsWith("/")) { //$NON-NLS-1$ String parentDir = FilenameUtils.getFullPathNoEndSeparator(xactionPath); if (parentDir.length() == 0) { parentDir = RepositoryFile.SEPARATOR; } resourceLocation = FilenameUtils .separatorsToUnix(FilenameUtils.concat(parentDir, resourceLocation)); } } resource = new ActionSequenceResource(resourceName, resourceType, resourceMimeType, resourceLocation); resourceDefinitions.put(resourceName, resource); } else { logger.error(Messages.getInstance().getErrorString( "SequenceDefinition.ERROR_0007_RESOURCE_NO_MIME_TYPE", resourceName)); //$NON-NLS-1$ } } // input = new ActionParameter( resourceName, resourceType, null // ); // resourceDefinitions.put( inputName, input ); } return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_OK; } catch (Exception e) { logger.error(Messages.getInstance().getErrorString("SequenceDefinition.ERROR_0006_PARSING_RESOURCE"), //$NON-NLS-1$ e); } return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_INVALID_ACTION_DOC; }