List of usage examples for org.w3c.dom Element getNodeValue
public String getNodeValue() throws DOMException;
From source file:org.apache.pdfbox.pdmodel.fdf.FDFDictionary.java
/** * This will create an FDF dictionary from an XFDF XML document. * * @param fdfXML The XML document that contains the XFDF data. * @throws IOException If there is an error reading from the dom. *///from w ww . j a v a 2 s. c om public FDFDictionary(Element fdfXML) { this(); NodeList nodeList = fdfXML.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node instanceof Element) { Element child = (Element) node; if (child.getTagName().equals("f")) { PDSimpleFileSpecification fs = new PDSimpleFileSpecification(); fs.setFile(child.getAttribute("href")); setFile(fs); } else if (child.getTagName().equals("ids")) { COSArray ids = new COSArray(); String original = child.getAttribute("original"); String modified = child.getAttribute("modified"); try { ids.add(COSString.parseHex(original)); } catch (IOException e) { LOG.warn("Error parsing ID entry for attribute 'original' [" + original + "]. ID entry ignored.", e); } try { ids.add(COSString.parseHex(modified)); } catch (IOException e) { LOG.warn("Error parsing ID entry for attribute 'modified' [" + modified + "]. ID entry ignored.", e); } setID(ids); } else if (child.getTagName().equals("fields")) { NodeList fields = child.getChildNodes(); List<FDFField> fieldList = new ArrayList<FDFField>(); for (int f = 0; f < fields.getLength(); f++) { Node currentNode = fields.item(f); if (currentNode instanceof Element && ((Element) currentNode).getTagName().equals("field")) { try { fieldList.add(new FDFField((Element) fields.item(f))); } catch (IOException e) { LOG.warn("Error parsing field entry [" + currentNode.getNodeValue() + "]. Field ignored.", e); } } } setFields(fieldList); } else if (child.getTagName().equals("annots")) { NodeList annots = child.getChildNodes(); List<FDFAnnotation> annotList = new ArrayList<FDFAnnotation>(); for (int j = 0; j < annots.getLength(); j++) { Node annotNode = annots.item(j); if (annotNode instanceof Element) { // the node name defines the annotation type Element annot = (Element) annotNode; String annotationName = annot.getNodeName(); try { if (annotationName.equals("text")) { annotList.add(new FDFAnnotationText(annot)); } else if (annotationName.equals("caret")) { annotList.add(new FDFAnnotationCaret(annot)); } else if (annotationName.equals("freetext")) { annotList.add(new FDFAnnotationFreeText(annot)); } else if (annotationName.equals("fileattachment")) { annotList.add(new FDFAnnotationFileAttachment(annot)); } else if (annotationName.equals("highlight")) { annotList.add(new FDFAnnotationHighlight(annot)); } else if (annotationName.equals("ink")) { annotList.add(new FDFAnnotationInk(annot)); } else if (annotationName.equals("line")) { annotList.add(new FDFAnnotationLine(annot)); } else if (annotationName.equals("link")) { annotList.add(new FDFAnnotationLink(annot)); } else if (annotationName.equals("circle")) { annotList.add(new FDFAnnotationCircle(annot)); } else if (annotationName.equals("square")) { annotList.add(new FDFAnnotationSquare(annot)); } else if (annotationName.equals("polygon")) { annotList.add(new FDFAnnotationPolygon(annot)); } else if (annotationName.equals("polyline")) { annotList.add(new FDFAnnotationPolyline(annot)); } else if (annotationName.equals("sound")) { annotList.add(new FDFAnnotationSound(annot)); } else if (annotationName.equals("squiggly")) { annotList.add(new FDFAnnotationSquiggly(annot)); } else if (annotationName.equals("stamp")) { annotList.add(new FDFAnnotationStamp(annot)); } else if (annotationName.equals("strikeout")) { annotList.add(new FDFAnnotationStrikeOut(annot)); } else if (annotationName.equals("underline")) { annotList.add(new FDFAnnotationUnderline(annot)); } else { LOG.warn("Unknown or unsupported annotation type '" + annotationName + "'"); } } catch (IOException e) { LOG.warn("Error parsing annotation information [" + annot.getNodeValue() + "]. Annotation ignored", e); } } } setAnnotations(annotList); } } } }
From source file:org.infoglue.cms.applications.structuretool.actions.ViewSiteNodePageComponentsAction.java
/** * This method shows the user a list of Components(HTML Templates). *///w w w. j av a 2 s . c o m public List getComponentBindings() throws Exception { List bindings = new ArrayList(); try { Integer siteNodeId = new Integer(this.getRequest().getParameter("siteNodeId")); Integer languageId = new Integer(this.getRequest().getParameter("languageId")); Integer contentId = new Integer(this.getRequest().getParameter("contentId")); String supplementingEntityType = this.getRequest().getParameter("supplementingEntityType"); String propertyName = this.getRequest().getParameter("propertyName"); //logger.info("**********************************************************************************"); //logger.info("siteNodeId:" + siteNodeId); //logger.info("languageId:" + languageId); //logger.info("contentId:" + contentId); //logger.info("**********************************************************************************"); //String templateString = getPageTemplateString(templateController, siteNodeId, languageId, contentId); String componentXML = getPageComponentsString(siteNodeId, this.masterLanguageVO.getId()); //logger.info("componentXML:" + componentXML); Document document = XMLHelper.readDocumentFromByteArray(componentXML.getBytes("UTF-8")); String componentXPath = "//component[@id=" + this.componentId + "]/properties/property[@name='" + propertyName + "']/binding"; //logger.info("componentXPath:" + componentXPath); NodeList anl = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(), componentXPath); //logger.info("anl:" + anl.getLength()); // We can not get a fresh path for external bindings to we look at the current path stored on the property. String[] externalBindingPath = null; for (int i = 0; i < anl.getLength(); i++) { Element component = (Element) anl.item(i); String entityName = component.getAttribute("entity"); String entityId = component.getAttribute("entityId"); String assetKey = component.getAttribute("assetKey"); NodeList supplementingEntities = component.getElementsByTagName("supplementing-binding"); try { String path = "Undefined"; if (entityName.equalsIgnoreCase("SiteNode")) { SiteNodeVO siteNodeVO = SiteNodeController.getController() .getSiteNodeVOWithId(new Integer(entityId)); path = siteNodeVO.getName(); } else if (entityName.equalsIgnoreCase("Content")) { ContentVO contentVO = ContentController.getContentController() .getContentVOWithId(new Integer(entityId)); path = contentVO.getName(); } else if (entityName.equalsIgnoreCase("External")) { if (externalBindingPath == null) { Element parent = (Element) component.getParentNode(); String propertyPath = parent.getAttribute("path"); if (propertyPath != null) { externalBindingPath = propertyPath.split(", "); if (externalBindingPath.length != anl.getLength()) { logger.error( "The number of items in the current path value does not match the current number of bindings. This should be fixed! Component id " + this.componentId + " and property: " + propertyName); externalBindingPath = new String[0]; } } } if (externalBindingPath != null && externalBindingPath.length > 0) { path = externalBindingPath[i]; } else { path = "Out of sync"; logger.warn("An external binding was found to be out of sync. SiteNodeId: " + siteNodeId + ". PropertyName" + propertyName); } } Map binding = new HashMap(); binding.put("entityName", entityName); binding.put("entityId", entityId); binding.put("assetKey", assetKey); binding.put("path", path); if (supplementingEntityType != null && !"".equals(supplementingEntityType)) { Map<String, String> supplementingBinding = new HashMap<String, String>(); supplementingBinding.put("entityType", supplementingEntityType); if (supplementingEntities != null && supplementingEntities.getLength() > 0) { Node supplementingEntity = supplementingEntities.item(0); if (supplementingEntity instanceof Element) { String supplementingEntityIdString = null; try { Element supplementingElement = (Element) supplementingEntity; supplementingEntityIdString = supplementingElement.getAttribute("entityId"); Integer supplementingEntityId = Integer.parseInt(supplementingEntityIdString); ContentVO supplementingContentVO = ContentController.getContentController() .getContentVOWithId(supplementingEntityId); if (supplementingContentVO != null) { supplementingBinding.put("entityId", supplementingContentVO.getContentId().toString()); String supplementingAssetKey = supplementingElement .getAttribute("assetKey"); supplementingAssetKey = StringEscapeUtils .unescapeXml(supplementingAssetKey); supplementingBinding.put("assetKey", supplementingAssetKey); } } catch (NumberFormatException ex) { logger.error( "Failed to parse entity id for supplementing entity id. Entity-id: " + supplementingEntityIdString + ". Message: " + ex.getMessage()); logger.warn("Failed to parse entity id for supplementing entity id.", ex); } catch (SystemException ex) { logger.warn( "Exception when verifying existence of supplementing entity. Assuming removed entity, will ignore. Entity-id: " + supplementingEntityIdString + ". Message: " + ex.getMessage()); logger.debug( "Exception when verifying existence of supplementing entity. Entity-id: " + supplementingEntityIdString, ex); } } else { logger.warn( "SupplementingBinding was not of type Element. Really Weired. Node value of component:" + component.getNodeValue()); } } binding.put("supplementingBinding", supplementingBinding); } bindings.add(binding); } catch (Exception e) { logger.warn("There was " + entityName + " bound to property '" + propertyName + "' on siteNode " + siteNodeId + " which appears to have been deleted."); } } } catch (Exception e) { e.printStackTrace(); } return bindings; }
From source file:org.safehaus.penrose.log.log4j.Log4jConfigReader.java
public void print(int level, Element node) { for (int i = 0; i < level; i++) { System.out.print(" "); }// w w w . j a va 2s .co m if (node instanceof Text) { System.out.println("Text: " + node.getNodeValue()); } else { System.out.println(node.getNodeName() + ": " + node.getNodeValue()); } NamedNodeMap map = node.getAttributes(); for (int i = 0; map != null && i < map.getLength(); i++) { Node n = map.item(i); System.out.println(" - " + n.getNodeName() + ": " + n.getNodeValue()); } NodeList list = node.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { print(level + 1, (Element) list.item(i)); } }
From source file:org.wso2.carbon.repository.core.config.RepositoryConfiguration.java
/** * Initialize the repository configuration with carbon.xml provided the carbon.xml path as * an argument./*ww w. ja v a 2 s . co m*/ * * @param carbonXMLPath the path of the carbon.xml * * @throws RepositoryException throws if the construction failed */ public RepositoryConfiguration(String carbonXMLPath) throws RepositoryException { try { File carbonXML = new File(carbonXMLPath); String carbonXMLNS = "http://wso2.org/projects/carbon/carbon.xml"; DocumentBuilderFactory documentFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentFactory.newDocumentBuilder(); Document doc = documentBuilder.parse(carbonXML); doc.getDocumentElement().normalize(); NodeList nodeList = doc.getElementsByTagNameNS(carbonXMLNS, REGISTRY_CONFIG); int numberOfElements; if ((numberOfElements = nodeList.getLength()) > 0) { if (numberOfElements == 1) { Node node = nodeList.item(0); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; registryConfiguration.put(element.getNodeName(), element.getNodeValue()); } } else { throw new RepositoryConfigurationException( "Only one registry element should exist in carbon.xml"); } } if (registryConfiguration.get(TYPE) == null) { registryConfiguration.put(TYPE, EMBEDDED_REGISTRY); } validate(); } catch (Exception e) { throw new RepositoryConfigurationException("Error occurred while initialization on reading carbon.xml", e); } }