List of usage examples for org.w3c.dom Element getNodeName
public String getNodeName();
From source file:org.apache.openaz.xacml.util.XACMLPolicyScanner.java
/** * readPolicy - does the work to read in policy data from a file. * * @param policy - The path to the policy file. * @return - The policy data object. This *should* be either a PolicySet or a Policy. *///from w w w. java2 s .c o m public static Object readPolicy(InputStream is) { try { // // Parse the policy file // DocumentBuilder db = DOMUtil.getDocumentBuilder(); Document doc = db.parse(is); // // Because there is no root defined in xacml, // find the first element // NodeList nodes = doc.getChildNodes(); Node node = nodes.item(0); Element e = null; if (node.getNodeType() == Node.ELEMENT_NODE) { e = (Element) node; // // Is it a 3.0 policy? // if (e.getNamespaceURI().equals("urn:oasis:names:tc:xacml:3.0:core:schema:wd-17")) { // // A policyset or policy could be the root // if (e.getNodeName().endsWith("Policy")) { // // Now we can create the context for the policy set // and unmarshall the policy into a class. // JAXBContext context = JAXBContext.newInstance(PolicyType.class); Unmarshaller um = context.createUnmarshaller(); JAXBElement<PolicyType> root = um.unmarshal(e, PolicyType.class); // // Here is our policy set class // return root.getValue(); } else if (e.getNodeName().endsWith("PolicySet")) { // // Now we can create the context for the policy set // and unmarshall the policy into a class. // JAXBContext context = JAXBContext.newInstance(PolicySetType.class); Unmarshaller um = context.createUnmarshaller(); JAXBElement<PolicySetType> root = um.unmarshal(e, PolicySetType.class); // // Here is our policy set class // return root.getValue(); } else { if (logger.isDebugEnabled()) { logger.debug("Not supported yet: " + e.getNodeName()); } } } else { logger.warn("unsupported namespace: " + e.getNamespaceURI()); } } else { if (logger.isDebugEnabled()) { logger.debug("No root element contained in policy " + " Name: " + node.getNodeName() + " type: " + node.getNodeType() + " Value: " + node.getNodeValue()); } } } catch (Exception e) { logger.error(e.getMessage()); } return null; }
From source file:org.apache.openejb.server.axis.assembler.CommonsSchemaLoader.java
private void addImportsFromDefinition(Definition definition) throws OpenEJBException { Types types = definition.getTypes(); if (types != null) { for (Object extensibilityElement : types.getExtensibilityElements()) { if (extensibilityElement instanceof Schema) { Schema unknownExtensibilityElement = (Schema) extensibilityElement; QName elementType = unknownExtensibilityElement.getElementType(); if (new QName("http://www.w3.org/2001/XMLSchema", "schema").equals(elementType)) { Element element = unknownExtensibilityElement.getElement(); xmlSchemaCollection.read(element); }/*from www. j a v a 2 s . c o m*/ } else if (extensibilityElement instanceof UnknownExtensibilityElement) { //This is allegedly obsolete as of axis-wsdl4j-1.2-RC3.jar which includes the Schema extension above. //The change notes imply that imported schemas should end up in Schema elements. They don't, so this is still needed. UnknownExtensibilityElement unknownExtensibilityElement = (UnknownExtensibilityElement) extensibilityElement; Element element = unknownExtensibilityElement.getElement(); String elementNamespace = element.getNamespaceURI(); String elementLocalName = element.getNodeName(); if ("http://www.w3.org/2001/XMLSchema".equals(elementNamespace) && "schema".equals(elementLocalName)) { xmlSchemaCollection.read(element); } } } } //noinspection unchecked Map<String, List<Import>> imports = definition.getImports(); if (imports != null) { for (Map.Entry<String, List<Import>> entry : imports.entrySet()) { String namespaceURI = entry.getKey(); List<Import> importList = entry.getValue(); for (Import anImport : importList) { //according to the 1.1 jwsdl mr shcema imports are supposed to show up here, //but according to the 1.0 spec there is supposed to be no Definition. Definition importedDef = anImport.getDefinition(); if (importedDef != null) { addImportsFromDefinition(importedDef); } else { log.warn("Missing definition in import for namespace " + namespaceURI); } } } } }
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.jav a2 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.apache.rave.portal.service.impl.DefaultOmdlService.java
private void parseOmdlFile(Document xml, OmdlInputAdapter omdlInputAdapter) throws BadOmdlXmlFormatException { Element rootEl = xml.getDocumentElement(); String rootNodename = rootEl.getNodeName(); String namespace = rootEl.getNamespaceURI(); if (rootNodename != WORKSPACE) { throw new BadOmdlXmlFormatException("Root node must be <" + WORKSPACE + ">"); }//from ww w . java 2 s . co m // TODO - which is it - spec examples show both? if (namespace != NAMESPACE && namespace != NAMESPACE + "/") { throw new BadOmdlXmlFormatException("Default xml namespace must be " + NAMESPACE); } //child <identifier> - omit //child <goal> - omit //child <status> - omit //child <description> - omit //child <creator> - omit //child <date> - omit // Try to get the page name (title in omdl) String title = null; NodeList nodeList = rootEl.getElementsByTagNameNS(namespace, TITLE); if (nodeList.getLength() > 0) { Node node = rootEl.getElementsByTagNameNS(namespace, TITLE).item(0); if (node.getTextContent() != null) { title = node.getTextContent(); } } // store this if found, although at present it will be overwritten by the users page name omdlInputAdapter.setName(title); String layoutCode = null; // Try to get the layoutCode nodeList = rootEl.getElementsByTagNameNS(namespace, LAYOUT); if (nodeList.getLength() > 0) { Node node = rootEl.getElementsByTagNameNS(namespace, LAYOUT).item(0); if (node.getTextContent() != null) { layoutCode = node.getTextContent(); } } // Next try to find all the <app> elements (widgets) nodeList = rootEl.getElementsByTagNameNS(namespace, APP); if (nodeList != null && nodeList.getLength() > 0) { for (int i = 0; i < nodeList.getLength(); i++) { Element appElement = (Element) nodeList.item(i); String id = appElement.getAttribute(ID_ATTRIBUTE); if (id != null) { String position = null; String hrefLink = null; String hrefType = null; Node positionNode = appElement.getElementsByTagNameNS(namespace, POSITION).item(0); if (positionNode != null) { Element positionElement = (Element) positionNode; position = positionElement.getTextContent(); } Node linkNode = appElement.getElementsByTagNameNS(namespace, LINK).item(0); if (linkNode != null) { Element linkElement = (Element) linkNode; hrefLink = linkElement.getAttribute(HREF); hrefType = linkElement.getAttribute(TYPE_ATTRIBUTE); } omdlInputAdapter.addToAppMap(new OmdlWidgetReference(id, hrefLink, hrefType), position); } } } // store the string found in the xml file omdlInputAdapter.setLayoutCode(layoutCode); // update this string into a RAVE layout omdlInputAdapter.setLayoutCode(OmdlModelUtils.getRaveLayoutForImport(omdlInputAdapter)); }
From source file:org.apache.servicemix.http.HttpURITest.java
public void testResolveEndpoint() throws Exception { HttpComponent http = new HttpComponent(); HttpEndpoint ep = new HttpEndpoint(); ep.setRole(MessageExchange.Role.CONSUMER); ep.setService(ReceiverComponent.SERVICE); ep.setEndpoint(ReceiverComponent.ENDPOINT); ep.setLocationURI("http://localhost:8192/"); ep.setDefaultMep(MessageExchangeSupport.IN_ONLY); http.setEndpoints(new HttpEndpoint[] { ep }); jbi.activateComponent(http, "servicemix-http"); ReceiverComponent receiver = new ReceiverComponent(); jbi.activateComponent(receiver, "receiver"); DefaultServiceMixClient client = new DefaultServiceMixClient(jbi); DocumentFragment epr = URIResolver.createWSAEPR("http://localhost:8192/?http.soap=true"); ServiceEndpoint se = client.getContext().resolveEndpointReference(epr); assertNotNull(se);// ww w . j ava2 s.c o m InOnly inonly = client.createInOnlyExchange(); inonly.setEndpoint(se); inonly.getInMessage().setContent(new StringSource("<hello>world</hello>")); client.sendSync(inonly); assertEquals(ExchangeStatus.DONE, inonly.getStatus()); receiver.getMessageList().assertMessagesReceived(1); List msgs = receiver.getMessageList().flushMessages(); NormalizedMessage msg = (NormalizedMessage) msgs.get(0); Element elem = new SourceTransformer().toDOMElement(msg); assertEquals("http://www.w3.org/2003/05/soap-envelope", elem.getNamespaceURI()); assertEquals("env:Envelope", elem.getNodeName()); logger.info(new SourceTransformer().contentToString(msg)); }
From source file:org.apache.servicemix.jbi.runtime.impl.utils.DOMUtil.java
/** * Build a QName from the element name//from www .j a va 2 s .c o m * @param el * @return */ public static QName getQName(Element el) { if (el == null) { return null; } else if (el.getNamespaceURI() == null) { return new QName(el.getNodeName()); } else if (el.getPrefix() != null) { return new QName(el.getNamespaceURI(), el.getLocalName(), el.getPrefix()); } else { return new QName(el.getNamespaceURI(), el.getLocalName()); } }
From source file:org.apache.servicemix.jms.JmsURITest.java
public void testResolveEndpoint() throws Exception { JmsComponent jms = new JmsComponent(); jms.getConfiguration().setConnectionFactory(connectionFactory); JmsEndpoint ep = new JmsEndpoint(); ep.setRole(MessageExchange.Role.CONSUMER); ep.setService(ReceiverComponent.SERVICE); ep.setEndpoint(ReceiverComponent.ENDPOINT); ep.setDefaultMep(JbiConstants.IN_ONLY); ep.setJmsProviderDestinationName("foo.bar.myqueue"); ep.setDestinationStyle(AbstractJmsProcessor.STYLE_QUEUE); ep.setServiceUnit(new DefaultServiceUnit(jms)); jms.setEndpoints(new JmsEndpoint[] { ep }); container.activateComponent(jms, "servicemix-jms"); ReceiverComponent receiver = new ReceiverComponent(); container.activateComponent(receiver, "receiver"); DefaultServiceMixClient client = new DefaultServiceMixClient(container); DocumentFragment epr = URIResolver.createWSAEPR("jms://queue/foo.bar.myqueue?jms.soap=true"); ServiceEndpoint se = client.getContext().resolveEndpointReference(epr); assertNotNull(se);// w w w . jav a 2 s .c om InOnly inonly = client.createInOnlyExchange(); inonly.setEndpoint(se); inonly.getInMessage().setContent(new StringSource("<hello>world</hello>")); client.sendSync(inonly); assertEquals(ExchangeStatus.DONE, inonly.getStatus()); receiver.getMessageList().assertMessagesReceived(1); List msgs = receiver.getMessageList().flushMessages(); NormalizedMessage msg = (NormalizedMessage) msgs.get(0); Element elem = new SourceTransformer().toDOMElement(msg); assertEquals("http://www.w3.org/2003/05/soap-envelope", elem.getNamespaceURI()); assertEquals("env:Envelope", elem.getNodeName()); logger.info(new SourceTransformer().contentToString(msg)); // Wait for DONE status Thread.sleep(50); }
From source file:org.apache.shindig.gadgets.rewrite.ResourceMutateVisitor.java
/** * {@inheritDoc}/*from w w w . j av a 2s.c om*/ */ public boolean revisit(Gadget gadget, List<Node> nodes) throws RewritingException { Collection<Pair<Node, Uri>> proxiedUris = mutateUris(gadget, nodes); boolean mutated = false; for (Pair<Node, Uri> proxyPair : proxiedUris) { if (proxyPair.two == null) { continue; } Element element = (Element) proxyPair.one; String nodeName = element.getNodeName().toLowerCase(); element.setAttribute(resourceTags.get(nodeName), proxyPair.two.toString()); mutated = true; } return mutated; }
From source file:org.apache.sling.its.servlets.ItsImportServlet.java
/** * Store the global rule.//from ww w.ja v a2 s. c o m * * @param element * an Element from the Document object. * @param resourceType * resource type * @param itsEng * the ITSEngine */ private void storeGlobalRule(final Element element, final String resourceType, final ITraversal itsEng) { if (StringUtils.isNotBlank(resourceType)) { String globalPath = SlingItsConstants.getGlobalRules().get(element.getLocalName()) + resourceType; if (element.getPrefix() != null) { globalPath += String.format("/%s(%d)", element.getLocalName(), getCounter(globalPath + "/" + element.getLocalName())); element.setAttribute(SlingItsConstants.NODE_PREFIX, element.getPrefix()); } else { globalPath += String.format("/%s(%d)", element.getNodeName(), getCounter(globalPath + "/" + element.getNodeName())); } output(globalPath, null, null); if (element.getLocalName().equals("param")) { output(globalPath, null, element.getTextContent()); } else if (element.getLocalName().equals(SlingItsConstants.ITS_LOCNOTE_RULE) && element.hasChildNodes()) { final Element locNoteElement = (Element) XmlNodeUtils.getChildNodeByLocalName(element, SlingItsConstants.ITS_LOCNOTE); if (locNoteElement != null) { element.setAttribute(SlingItsConstants.ITS_NOTE, locNoteElement.getTextContent()); } } setAttributes(element, globalPath); } skipChildren(element, itsEng); }
From source file:org.apache.sling.its.servlets.ItsImportServlet.java
/** * Store the element and its attribute. The child node of global rules are * specially handled so they will not be traversed. * * @param path//from w w w.j av a 2s . c o m * the target path * @param resourceType * the resourceType * @param doc * the document * @param file * the file. * @param isExternalDoc * true if this is for storing global rules for external documents */ private void store(String path, final String resourceType, final Document doc, final File file, final boolean isExternalDoc) { final ITraversal itsEng = applyITSRules(doc, file, null, false); itsEng.startTraversal(); Node node; while ((node = itsEng.nextNode()) != null) { switch (node.getNodeType()) { case Node.ELEMENT_NODE: final Element element = (Element) node; // Use !backTracking() to get to the elements only once // and to include the empty elements (for attributes). if (itsEng.backTracking()) { if (!SlingItsConstants.getGlobalRules().containsKey(element.getLocalName())) { path = backTrack(path); } } else { if (element.isSameNode(doc.getDocumentElement()) && !isExternalDoc) { path += "/" + element.getNodeName(); output(path, null, null); setAttributes(element, path); } else if (SlingItsConstants.getGlobalRules().containsKey(element.getLocalName())) { storeGlobalRule(element, resourceType, itsEng); } else if (!isExternalDoc && !SlingItsConstants.getGlobalRules().containsKey(element.getLocalName()) && !(element.getParentNode().getLocalName().equals(SlingItsConstants.ITS_RULES) && element.getParentNode().getPrefix() != null)) { if (element.getLocalName().equals(SlingItsConstants.ITS_RULES) && element.getPrefix() != null) { this.hasGlobalRules = true; } if (element.getPrefix() != null) { path += String.format("/%s(%d)", element.getLocalName(), getCounter(path + "/" + element.getLocalName())); element.setAttribute(SlingItsConstants.NODE_PREFIX, element.getPrefix()); } else if (element.getNodeName().equals("link") && StringUtils.endsWith(element.getAttribute("rel"), "-rules")) { path += String.format("/%s(%d)", SlingItsConstants.ITS_RULES, getCounter(path + "/" + SlingItsConstants.ITS_RULES)); final String prefix = StringUtils.substringBefore(element.getAttribute("rel"), "-rules"); element.setAttribute(SlingItsConstants.NODE_PREFIX, prefix); element.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, SlingItsConstants.XMLNS + prefix, Namespaces.ITS_NS_URI); element.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:h", Namespaces.HTML_NS_URI); element.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:jcr", NamespaceRegistry.NAMESPACE_JCR); this.hasGlobalRules = true; } else { path += String.format("/%s(%d)", element.getNodeName(), getCounter(path + "/" + element.getNodeName())); } output(path, null, null); setAttributes(element, path); if (!element.hasChildNodes()) // Empty elements: { path = backTrack(path); } } } break; case Node.TEXT_NODE: if (StringUtils.isNotBlank(node.getNodeValue()) && !isExternalDoc) { path += String.format("/%s(%d)", SlingItsConstants.TEXT_CONTENT_NODE, getCounter(path + "/" + SlingItsConstants.TEXT_CONTENT_NODE)); output(path, null, node.getNodeValue()); path = backTrack(path); } break; default: break; } } }