List of usage examples for org.w3c.dom Element getNamespaceURI
public String getNamespaceURI();
null
if it is unspecified (see ). From source file:io.personium.core.model.impl.fs.DavCmpFsImpl.java
@Override @SuppressWarnings("unchecked") public Multistatus proppatch(final Propertyupdate propUpdate, final String url) { long now = new Date().getTime(); String reqUri = url;//from w w w . ja v a 2 s .c o m Multistatus ms = this.of.createMultistatus(); Response res = this.of.createResponse(); res.getHref().add(reqUri); // Lock Lock lock = this.lock(); // ? try { this.load(); // ?? if (!this.exists()) { // ?(??)?????404?? throw getNotFoundException().params(this.getUrl()); } Map<String, Object> propsJson = (Map<String, Object>) this.metaFile.getProperties(); List<Prop> propsToSet = propUpdate.getPropsToSet(); for (Prop prop : propsToSet) { if (null == prop) { throw PersoniumCoreException.Dav.XML_CONTENT_ERROR; } List<Element> lpe = prop.getAny(); for (Element elem : lpe) { res.setProperty(elem, HttpStatus.SC_OK); String key = elem.getLocalName() + "@" + elem.getNamespaceURI(); String value = PersoniumCoreUtils.nodeToString(elem); log.debug("key: " + key); log.debug("val: " + value); propsJson.put(key, value); } } List<Prop> propsToRemove = propUpdate.getPropsToRemove(); for (Prop prop : propsToRemove) { if (null == prop) { throw PersoniumCoreException.Dav.XML_CONTENT_ERROR; } List<Element> lpe = prop.getAny(); for (Element elem : lpe) { String key = elem.getLocalName() + "@" + elem.getNamespaceURI(); String v = (String) propsJson.get(key); log.debug("Removing key: " + key); if (v == null) { res.setProperty(elem, HttpStatus.SC_NOT_FOUND); } else { propsJson.remove(key); res.setProperty(elem, HttpStatus.SC_OK); } } } // set the last updated date this.metaFile.setProperties((JSONObject) propsJson); this.metaFile.setUpdated(now); this.metaFile.save(); } finally { lock.release(); } ms.getResponse().add(res); return ms; }
From source file:de.betterform.xml.xforms.model.submission.Submission.java
private void destroyembeddedModels(Element targetElem) throws XFormsException { NodeList childNodes = targetElem.getChildNodes(); for (int index = 0; index < childNodes.getLength(); index++) { Node node = childNodes.item(index); if (node.getNodeType() == Node.ELEMENT_NODE) { Element elementImpl = (Element) node; String name = elementImpl.getLocalName(); String uri = elementImpl.getNamespaceURI(); if (NamespaceConstants.XFORMS_NS.equals(uri) && name.equals(XFormsConstants.MODEL)) { Model model = (Model) elementImpl.getUserData(""); if (LOGGER.isDebugEnabled()) { LOGGER.debug("dispatch 'model-destruct' event to embedded model: " + model.getId()); }/* www .j a v a2s . co m*/ String modelId = model.getId(); // do not dispatch model-destruct to avoid problems in lifecycle // TODO: review: this.container.dispatch(model.getTarget(), XFormsEventNames.MODEL_DESTRUCT, null); model.dispose(); this.container.removeModel(model); model = null; if (Config.getInstance().getProperty("betterform.debug-allowed").equals("true")) { Map contextInfo = new HashMap(1); contextInfo.put("modelId", modelId); this.container.dispatch(this.target, BetterFormEventNames.MODEL_REMOVED, contextInfo); } } else { destroyembeddedModels(elementImpl); } } } }
From source file:iristk.flow.FlowCompiler.java
private String stateClass(Element elem) { return elem.getNamespaceURI() + "." + elem.getLocalName(); }
From source file:it.cnr.icar.eric.server.profile.ws.wsdl.cataloger.WSDLCatalogerEngine.java
/** * Catalogs XMLSchema when submitted as an ExtrinsicObject - RepositoryItem pair. * *//*from w w w . j a v a 2 s . co m*/ private void catalogXMLSchemaExtrinsicObject(RegistryObjectType ro, InputSource source) throws CatalogingException { try { registryObjects.add(ro); Document document = parseXML(source); Element schemaElement = document.getDocumentElement(); String documentLocalName = schemaElement.getLocalName(); String documentNamespaceURI = schemaElement.getNamespaceURI(); if (documentLocalName.equalsIgnoreCase("schema") && documentNamespaceURI.endsWith("XMLSchema")) { Attr attribute = schemaElement.getAttributeNode("targetNamespace"); String namespaceURI = attribute.getValue(); // Set the id for the XMLSchema EO updateRegistryObjectId(namespaceURI, ro, false); // Check if this XSD file imports another file (usually XSD) NodeList nodeList = schemaElement.getChildNodes(); int length = nodeList.getLength(); for (int i = 0; i < length; i++) { Node node = nodeList.item(i); String localName = node.getLocalName(); if (localName != null && localName.equalsIgnoreCase("import")) { // This XSD imports another file NamedNodeMap importNamedNodeMap = node.getAttributes(); Node namespaceNode = importNamedNodeMap.getNamedItem("namespace"); String importNamespace = null; if (namespaceNode != null) { importNamespace = namespaceNode.getNodeValue(); } String schemaLocation = null; Node schemaLocationNode = importNamedNodeMap.getNamedItem("schemaLocation"); if (schemaLocationNode != null) { schemaLocation = schemaLocationNode.getNodeValue(); } RegistryObjectType importedObject = catalogImportStatement(ro, importNamespace, schemaLocation); createImportsAssociation(ro, importedObject); } } } } catch (CatalogingException e) { throw e; } catch (Exception e) { log.error(e, e); CatalogingException ce = new CatalogingException(e); throw ce; } }
From source file:iristk.flow.FlowCompiler.java
private Map<String, String> getParameters(Map<QName, String> attributes, List<Object> content, Object parent) throws FlowCompilerException { Map<String, String> result = new HashMap<String, String>(); for (QName attr : attributes.keySet()) { if (attr.getNamespaceURI() != null && attr.getNamespaceURI().equals("http://www.w3.org/2000/xmlns/")) continue; String name = attr.getLocalPart(); String value = formatAttrExpr(attributes.get(attr)); result.put(name, value);//from www . jav a2 s. c om } if (content.size() > 0) { ListMap<String, String> paramList = new ListMap<>(); for (Object child : content) { if (child instanceof Element) { Element elem = (Element) child; if (elem.getNamespaceURI().equals("iristk.flow.param")) { String key = elem.getLocalName(); List<Object> paramChildren = new ArrayList<Object>(); for (int j = 0; j < elem.getChildNodes().getLength(); j++) { paramChildren.add(elem.getChildNodes().item(j)); } String text = createExpression(paramChildren, elem); paramList.add(key, text); } } } if (paramList.size() == 0) { paramList.add("text", createExpression(content, parent)); } for (String key : paramList.keySet()) { if (paramList.get(key).size() > 1) { result.put(key, "java.util.Arrays.asList(" + listToString(paramList.get(key)) + ")"); } else { result.put(key, paramList.get(key).get(0)); } } } return result; }
From source file:com.fujitsu.dc.core.model.impl.es.DavCmpEsImpl.java
/** * ???./*from w ww . j a v a 2s . c o m*/ */ @SuppressWarnings("unchecked") public final void load() { DcGetResponse res = getNode(); if (res == null) { // Box???id????Dav???????? throw DcCoreException.Dav.DAV_INCONSISTENCY_FOUND; } this.version = res.version(); this.davNode = DavNode.createFromJsonString(res.getId(), res.sourceAsString()); if (this.davNode != null) { // Map<String, Object> aclObj = (Map<String, Object>) json.get("acl"); // TODO JSONParse?????. JSON Parse?????????. String jsonStr = res.sourceAsString(); JSONParser parser = new JSONParser(); try { JSONObject jo = (JSONObject) parser.parse(jsonStr); JSONObject aclObj = (JSONObject) jo.get(DavNode.KEY_ACL); if (aclObj != null) { log.debug(aclObj.toJSONString()); // principal?href ? ID__id?URL??? // base:xml? String baseUrlStr = createBaseUrlStr(); roleIdToName(aclObj.get(KEY_ACE), baseUrlStr); // ConfidentialLevel??? this.confidentialLevel = (String) aclObj.get(KEY_REQUIRE_SCHEMA_AUTHZ); this.acl = Acl.fromJson(aclObj.toJSONString()); this.acl.setBase(baseUrlStr); log.debug(this.acl.toJSON()); } Map<String, String> props = (Map<String, String>) jo.get(DavNode.KEY_PROPS); if (props != null) { for (Map.Entry<String, String> entry : props.entrySet()) { String key = entry.getKey(); String val = entry.getValue(); int idx = key.indexOf("@"); String elementName = key.substring(0, idx); String namespace = key.substring(idx + 1); QName keyQName = new QName(namespace, elementName); Element element = parseProp(val); String elementNameSpace = element.getNamespaceURI(); // ownerRepresentativeAccounts??? if (Key.PROP_KEY_OWNER_REPRESENTIVE_ACCOUNTS.equals(keyQName)) { NodeList accountNodeList = element.getElementsByTagNameNS(elementNameSpace, Key.PROP_KEY_OWNER_REPRESENTIVE_ACCOUNT.getLocalPart()); for (int i = 0; i < accountNodeList.getLength(); i++) { this.ownerRepresentativeAccounts .add(accountNodeList.item(i).getTextContent().trim()); } } } } } catch (ParseException e) { // ES?JSON??? throw DcCoreException.Dav.FS_INCONSISTENCY_FOUND.reason(e); } } }
From source file:eu.semaine.util.XMLTool.java
/** * Create an XML document from the given XPath expression. * The given string is interpreted as a limited subset of XPath expressions and split into parts. * Each part except the last one is expected to follow precisely the following form: * <code>"/" ( prefix ":" ) ? localname ( "[" "@" attName "=" "'" attValue "'" "]" ) ?</code> * The last part must be either//w w w. j a va2 s .c o m * <code> "/" "text()"</code> * or * </code> "/" "@" attributeName </code>. * @param xpathExpression an xpath expression from which the given document can be created. must not be null. * @param value the value to insert at the location identified by the xpath expression. if this is null, the empty string is added. * @param namespaceContext the namespace context to use for resolving namespace prefixes. * If this is null, the namespace context returned by {@link #getDefaultNamespaceContext()} will be used. * @param document if not null, the xpath expression + value pair will be added to the document. * If null, a new document will be created from the xpathExpression and value pair. * @return a document containing the given information * @throws NullPointerException if xpathExpression is null. * @throws IllegalArgumentException if the xpath expression is not valid, or if the xpath expression is incompatible with the given document (e.g., different root node) */ public static Document xpath2doc(String xpathExpression, String value, NamespaceContext namespaceContext, Document document) throws NullPointerException, IllegalArgumentException { if (xpathExpression == null) { throw new NullPointerException("null argument"); } if (value == null) { value = ""; } if (namespaceContext == null) { namespaceContext = getDefaultNamespaceContext(); } String[][] parts = splitXPathIntoParts(xpathExpression); Element currentElt = null; for (int i = 0; i < parts.length - 1; i++) { String[] part = parts[i]; assert part != null; assert part.length == 4; String prefix = part[0]; String localName = part[1]; String attName = part[2]; String attValue = part[3]; String namespaceURI = prefix != null ? namespaceContext.getNamespaceURI(prefix) : null; if (prefix != null && namespaceURI.equals("")) { throw new IllegalArgumentException("Unknown prefix: " + prefix); } // Now traverse to or create element defined by prefix, localName and namespaceURI if (currentElt == null) { // at top level if (document == null) { // create a new document try { document = XMLTool.newDocument(localName, namespaceURI); } catch (DOMException de) { throw new IllegalArgumentException("Cannot create document for localname '" + localName + "' and namespaceURI '" + namespaceURI + "'", de); } currentElt = document.getDocumentElement(); currentElt.setPrefix(prefix); } else { currentElt = document.getDocumentElement(); if (!currentElt.getLocalName().equals(localName)) { throw new IllegalArgumentException( "Incompatible root node specification: expression requests '" + localName + "', but document already has '" + currentElt.getLocalName() + "'!"); } String currentNamespaceURI = currentElt.getNamespaceURI(); if (!(currentNamespaceURI == null && namespaceURI == null || currentNamespaceURI != null && currentNamespaceURI.equals(namespaceURI))) { throw new IllegalArgumentException( "Incompatible root namespace specification: expression requests '" + namespaceURI + "', but document already has '" + currentNamespaceURI + "'!"); } } } else { // somewhere in the tree // First check if the requested child already exists List<Element> sameNameChildren = XMLTool.getChildrenByLocalNameNS(currentElt, localName, namespaceURI); boolean found = false; if (attName == null) { if (sameNameChildren.size() > 0) { currentElt = sameNameChildren.get(0); found = true; } } else { for (Element c : sameNameChildren) { if (c.hasAttribute(attName)) { if (attValue == null || attValue.equals(c.getAttribute(attName))) { currentElt = c; found = true; break; } } } } if (!found) { // need to create it currentElt = XMLTool.appendChildElement(currentElt, localName, namespaceURI); if (prefix != null) currentElt.setPrefix(prefix); if (attName != null) { currentElt.setAttribute(attName, attValue != null ? attValue : ""); } } } } if (currentElt == null) { throw new IllegalArgumentException( "No elements or no final part created from XPath expression '" + xpathExpression + "'"); } String[] lastPart = parts[parts.length - 1]; assert lastPart.length <= 1; if (lastPart.length == 0) { // text content of the given node currentElt.setTextContent(value); } else { String attName = lastPart[0]; currentElt.setAttribute(attName, value); } return document; }
From source file:com.fujitsu.dc.core.model.impl.es.DavCmpEsImpl.java
@Override @SuppressWarnings("unchecked") public Multistatus proppatch(final Propertyupdate propUpdate, final String url) { long now = new Date().getTime(); String reqUri = url;//from ww w . j ava2 s. c o m Multistatus ms = this.of.createMultistatus(); Response res = this.of.createResponse(); res.getHref().add(reqUri); // Lock lock = this.lock(); // ? try { this.load(); // ?? Map<String, Object> propsJson = (Map<String, Object>) this.davNode.getProperties(); List<Prop> propsToSet = propUpdate.getPropsToSet(); for (Prop prop : propsToSet) { if (null == prop) { throw DcCoreException.Dav.XML_CONTENT_ERROR; } List<Element> lpe = prop.getAny(); for (Element elem : lpe) { res.setProperty(elem, HttpStatus.SC_OK); String key = elem.getLocalName() + "@" + elem.getNamespaceURI(); String value = DcCoreUtils.nodeToString(elem); log.debug("key: " + key); log.debug("val: " + value); propsJson.put(key, value); } } List<Prop> propsToRemove = propUpdate.getPropsToRemove(); for (Prop prop : propsToRemove) { if (null == prop) { throw DcCoreException.Dav.XML_CONTENT_ERROR; } List<Element> lpe = prop.getAny(); for (Element elem : lpe) { String key = elem.getLocalName() + "@" + elem.getNamespaceURI(); String v = (String) propsJson.get(key); log.debug("Removing key: " + key); if (v == null) { res.setProperty(elem, HttpStatus.SC_NOT_FOUND); } else { propsJson.remove(key); res.setProperty(elem, HttpStatus.SC_OK); } } } // this.davNode.setUpdated(now); // JSON??? setPropToJson(propsJson); DcIndexResponse resp = updateNodeWithVersion(); // ETAG??Version?? this.version = resp.version(); } finally { // lock.release(); } ms.getResponse().add(res); return ms; }
From source file:it.cnr.icar.eric.server.profile.ws.wsdl.cataloger.WSDLCatalogerEngine.java
private void resolveTypeImports(Element portTypeElement, RegistryObjectType wsdlEO) throws CatalogingException { try {/*from w ww . j a v a 2 s . c o m*/ String id = getPortTypeId(portTypeElement); if (idToRIMMap.get(id) == null) { processPortType(portTypeElement); } @SuppressWarnings("unused") ExtrinsicObjectType rimPortType = (ExtrinsicObjectType) idToRIMMap.get(id); List<Element> typeElements = resolveTypes(wsdlDocument); Iterator<?> schemaItr = resolveSchemaExtensions(typeElements); while (schemaItr.hasNext()) { Element schemaElement = (Element) schemaItr.next(); Iterator<?> schemaAttributeItr = wsdlDocument.getAttributes(schemaElement).iterator(); String location = null; @SuppressWarnings("unused") String localName = schemaElement.getLocalName(); String namespace = schemaElement.getNamespaceURI(); while (schemaAttributeItr.hasNext()) { Attr schemaAttribute = (Attr) schemaAttributeItr.next(); String localAttrName = schemaAttribute.getLocalName(); if (localAttrName.equalsIgnoreCase("namespace")) { namespace = schemaAttribute.getValue(); } else if (localAttrName.equalsIgnoreCase("schemaLocation")) { location = schemaAttribute.getValue(); } } RegistryObjectType importedObject = catalogImportStatement(wsdlEO, namespace, location); if (importedObject != null) { AssociationType1 ebAssociationType = bu.createAssociationType(wsdlEO.getId(), importedObject.getId(), CanonicalConstants.CANONICAL_ASSOCIATION_TYPE_ID_Imports); //May need a more deterministic algorithm for setting this id?? ebAssociationType.setId(wsdlEO.getId() + ":Imports:" + importedObject.getId()); registryObjects.add(ebAssociationType); } } } catch (CatalogingException e) { throw e; } catch (Exception e) { throw new CatalogingException(e); } }
From source file:org.bedework.util.dav.DavUtil.java
private DavChild makeDavResponse(final Element resp) throws Throwable { /* <!ELEMENT response (href, ((href*, status)|(propstat+)), responsedescription?) >//from w w w .j av a2s.co m */ final Iterator<Element> elit = getChildren(resp).iterator(); Node nd = elit.next(); final DavChild dc = new DavChild(); if (!XmlUtil.nodeMatches(nd, WebdavTags.href)) { throw new Exception("Bad response. Expected href found " + nd); } dc.uri = URLDecoder.decode(getElementContent((Element) nd), HTTP.UTF_8); // href should be escaped while (elit.hasNext()) { nd = elit.next(); if (XmlUtil.nodeMatches(nd, WebdavTags.status)) { dc.status = httpStatus((Element) nd); continue; } dc.status = HttpServletResponse.SC_OK; if (!XmlUtil.nodeMatches(nd, WebdavTags.propstat)) { throw new Exception("Bad response. Expected propstat found " + nd); } /* <!ELEMENT propstat (prop, status, responsedescription?) > */ Iterator<Element> propstatit = getChildren(nd).iterator(); Node propnd = propstatit.next(); if (!XmlUtil.nodeMatches(propnd, WebdavTags.prop)) { throw new Exception("Bad response. Expected prop found " + propnd); } if (!propstatit.hasNext()) { throw new Exception("Bad response. Expected propstat/status"); } final int st = httpStatus(propstatit.next()); if (propstatit.hasNext()) { Node rdesc = propstatit.next(); if (!XmlUtil.nodeMatches(rdesc, WebdavTags.responseDescription)) { throw new Exception("Bad response, expected null or " + "responsedescription. Found: " + rdesc); } } /* process each property with this status */ Collection<Element> respProps = getChildren(propnd); for (Element pr : respProps) { /* XXX This needs fixing to handle content that is xml */ if (XmlUtil.nodeMatches(pr, WebdavTags.resourcetype)) { Collection<Element> rtypeProps = getChildren(pr); for (Element rtpr : rtypeProps) { if (XmlUtil.nodeMatches(rtpr, WebdavTags.collection)) { dc.isCollection = true; } dc.resourceTypes.add(XmlUtil.fromNode(rtpr)); } } else { DavProp dp = new DavProp(); dc.propVals.add(dp); dp.name = new QName(pr.getNamespaceURI(), pr.getLocalName()); dp.status = st; dp.element = pr; if (XmlUtil.nodeMatches(pr, WebdavTags.displayname)) { dc.displayName = getElementContent(pr); } } } } return dc; }