List of usage examples for javax.xml XMLConstants XMLNS_ATTRIBUTE
String XMLNS_ATTRIBUTE
To view the source code for javax.xml XMLConstants XMLNS_ATTRIBUTE.
Click Source Link
From source file:ch.entwine.weblounge.bridge.oaipmh.util.XmlGen.java
private Element appendNs(Element e, List<Namespace> namespaces) { for (Namespace n : namespaces) { e.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, XMLConstants.XMLNS_ATTRIBUTE + ":" + n.getPrefix(), n.getNamespace()); }/*from w w w . j ava 2 s. c om*/ return e; }
From source file:InlineSchemaValidator.java
public Iterator getPrefixes(String namespaceURI) { if (namespaceURI == null) { throw new IllegalArgumentException("Namespace URI cannot be null."); } else if (XMLConstants.XML_NS_URI.equals(namespaceURI)) { return new Iterator() { boolean more = true; public boolean hasNext() { return more; }/*w w w .j a v a 2 s. com*/ public Object next() { if (!hasNext()) { throw new NoSuchElementException(); } more = false; return XMLConstants.XML_NS_PREFIX; } public void remove() { throw new UnsupportedOperationException(); } }; } else if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(namespaceURI)) { return new Iterator() { boolean more = true; public boolean hasNext() { return more; } public Object next() { if (!hasNext()) { throw new NoSuchElementException(); } more = false; return XMLConstants.XMLNS_ATTRIBUTE; } public void remove() { throw new UnsupportedOperationException(); } }; } else if (fURIToPrefixMappings != null) { HashSet prefixes = (HashSet) fURIToPrefixMappings.get(namespaceURI); if (prefixes != null && prefixes.size() > 0) { return prefixes.iterator(); } } return Collections.EMPTY_LIST.iterator(); }
From source file:de.fau.cs.osr.hddiff.perfsuite.RunFcDiff.java
private boolean compareAttributes(Collection<Wom3Attribute> a, Collection<Wom3Attribute> b) { final int size = a.size(); Wom3Attribute[] aa = a.toArray(new Wom3Attribute[size]); Wom3Attribute[] ba = b.toArray(new Wom3Attribute[b.size()]); Comparator<Wom3Attribute> cmp = new Comparator<Wom3Attribute>() { @Override//w w w .j a v a 2 s . c o m public int compare(Wom3Attribute o1, Wom3Attribute o2) { return o1.getName().compareTo(o2.getName()); } }; Arrays.sort(aa, cmp); Arrays.sort(ba, cmp); for (int i = 0, j = 0; i < aa.length && j < ba.length;) { Wom3Attribute attrA = aa[i]; Wom3Attribute attrB = ba[i]; if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(attrA.getNamespaceURI()) && XMLConstants.XMLNS_ATTRIBUTE.equals(attrA.getName())) { ++i; continue; } if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(attrB.getNamespaceURI()) && XMLConstants.XMLNS_ATTRIBUTE.equals(attrB.getName())) { ++j; continue; } if (!cmpStr(attrA.getName(), attrB.getName())) { return false; } if (!cmpStr(attrA.getValue(), attrB.getValue())) { return false; } ++i; ++j; } return true; }
From source file:no.ntnu.okse.protocol.wsn.WSNotificationServer.java
/** * This interface method must take in an instance of Message, which contains the appropriate references * and flags needed to distribute the message to consumers. Implementation specific details can vary from * protocol to protocol, but the end result of a method call to sendMessage is that the message is delivered, * or an error is logged.//from ww w . jav a 2s . c om * * @param message An instance of Message containing the required data to distribute a message. */ @Override public void sendMessage(Message message) { log.debug("WSNServer received message for distribution"); if (!message.getOriginProtocol().equals(protocolServerType) || message.getAttribute("duplicate") != null) { log.debug("The message originated from other protocol than WSNotification"); WSNTools.NotifyWithContext notifywrapper = WSNTools.buildNotifyWithContext(message.getMessage(), message.getTopic(), null, null); // If it contained XML, we need to create properly marshalled jaxb node structure if (message.getMessage().contains("<") || message.getMessage().contains(">")) { // Unmarshal from raw XML Notify notify = WSNTools.createNotify(message); // If it was malformed, or maybe just a message containing < or >, build it as generic content element if (notify == null) { WSNTools.injectMessageContentIntoNotify( WSNTools.buildGenericContentElement(message.getMessage()), notifywrapper.notify); // Else inject the unmarshalled XML nodes into the Notify message attribute } else { WSNTools.injectMessageContentIntoNotify(WSNTools.extractMessageContentFromNotify(notify), notifywrapper.notify); } } /* Start to resolve recipients. The reason we cannot re-use the WSNCommandProxy's sendNotification method is that it will inject the message to the MessageService for relay thus creating duplicate messages. */ NuNamespaceContextResolver namespaceContextResolver = notifywrapper.nuNamespaceContextResolver; // bind namespaces to topics for (NotificationMessageHolderType holderType : notifywrapper.notify.getNotificationMessage()) { // Extract the topic TopicExpressionType topic = holderType.getTopic(); if (holderType.getTopic() != null) { NuNamespaceContextResolver.NuResolvedNamespaceContext context = namespaceContextResolver .resolveNamespaceContext(topic); if (context == null) { continue; } context.getAllPrefixes().forEach(prefix -> { // check if this is the default xmlns attribute if (!prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) { // add namespace context to the expression node topic.getOtherAttributes().put(new QName("xmlns:" + prefix), context.getNamespaceURI(prefix)); } }); } } // For all valid recipients for (String recipient : _commandProxy.getAllRecipients()) { // If the subscription has expired, continue if (_commandProxy.getProxySubscriptionManager().getSubscriber(recipient).hasExpired()) continue; // Filter do filter handling, if any Notify toSend = _commandProxy.getRecipientFilteredNotify(recipient, notifywrapper.notify, namespaceContextResolver); // If any message was left to send, send it if (toSend != null) { InternalMessage outMessage = new InternalMessage(InternalMessage.STATUS_OK | InternalMessage.STATUS_HAS_MESSAGE | InternalMessage.STATUS_ENDPOINTREF_IS_SET, toSend); // Update the requestinformation outMessage.getRequestInformation() .setEndpointReference(_commandProxy.getEndpointReferenceOfRecipient(recipient)); // Check if the subscriber has requested raw message format // If the recipient has requested UseRaw, remove Notify payload wrapping if (_commandProxy.getProxySubscriptionManager().getSubscriber(recipient) .getAttribute(WSNSubscriptionManager.WSN_USERAW_TOKEN) != null) { Object content = WSNTools.extractMessageContentFromNotify(toSend); // Update the InternalMessage with the content of the NotificationMessage outMessage.setMessage(content); } // Pass it along to the request parser wrapped as a thread pool executed job clientPool.execute(() -> _requestParser.acceptLocalMessage(outMessage)); } } } else { log.debug("Message originated from WSN protocol, already processed"); } }
From source file:nz.co.testamation.common.util.PrefixMapNamespaceContext.java
public String getNamespaceURI(String prefix) { switch (prefix) { case XMLConstants.XML_NS_PREFIX: return XMLConstants.XML_NS_URI; case XMLConstants.XMLNS_ATTRIBUTE: return XMLConstants.XMLNS_ATTRIBUTE_NS_URI; default:/*from w w w. j a va 2s. c o m*/ return StringUtils.defaultString(prefixNamespaceMap.get(prefix), XMLConstants.NULL_NS_URI); } }
From source file:org.alfresco.repo.rendition.StandardRenditionLocationResolverImpl.java
public static String buildNamespaceDeclaration(final Document xml) { final Element docEl = xml.getDocumentElement(); final NamedNodeMap attributes = docEl.getAttributes(); final StringBuilder result = new StringBuilder(); for (int i = 0; i < attributes.getLength(); i++) { final Node a = attributes.item(i); if (a.getNodeName().startsWith(XMLConstants.XMLNS_ATTRIBUTE)) { final String prefix = a.getNodeName().substring((XMLConstants.XMLNS_ATTRIBUTE + ":").length()); final String uri = a.getNodeValue(); if (result.length() != 0) { result.append(",\n"); }//w w w. j av a 2s. co m result.append("\"").append(prefix).append("\":\"").append(uri).append("\""); } } return "<#ftl ns_prefixes={\n" + result.toString() + "}>\n"; }
From source file:org.apache.sling.its.servlets.ItsImportServlet.java
/** * Creates the jcr node and appends the necessary properties. * * @param absPath/*from w ww .j av a2 s .com*/ * absolute path of the node. * @param attr * attribute of the element * @param textContent * text content of the element. */ private void output(final String absPath, final Attr attr, final String textContent) { javax.jcr.Node node = null; try { if (this.session.itemExists(absPath) && attr == null && textContent == null) { node = (javax.jcr.Node) this.session.getItem(absPath); node.remove(); } node = JcrResourceUtil.createPath(absPath, "nt:unstructured", "nt:unstructured", this.session, false); if (textContent != null) { node.setProperty(SlingItsConstants.TEXT_CONTENT, textContent); } if (attr != null) { if (attr.getNodeName().startsWith(XMLConstants.XMLNS_ATTRIBUTE)) { node.setProperty(attr.getLocalName(), attr.getNodeValue()); if (node.hasProperty(SlingItsConstants.NAMESPACE_DECLARATION)) { final ArrayList<String> prefixes = new ArrayList<String>(ValueUtils.convertToArrayList( node.getProperty(SlingItsConstants.NAMESPACE_DECLARATION).getValues())); if (!prefixes.contains(attr.getLocalName())) { prefixes.add(attr.getLocalName()); node.setProperty(SlingItsConstants.NAMESPACE_DECLARATION, prefixes.toArray(new String[prefixes.size()])); } } else { node.setProperty(SlingItsConstants.NAMESPACE_DECLARATION, new String[] { attr.getLocalName() }); } } else if (StringUtils.equals(attr.getNodeName(), SlingItsConstants.XML_PRIMARY_TYPE_PROP) || StringUtils.equals(attr.getNodeName(), SlingItsConstants.HTML_PRIMARY_TYPE_PROP)) { node.setPrimaryType(attr.getNodeValue()); } else if (StringUtils.equals(attr.getNodeName(), SlingItsConstants.HTML_RESOURCE_TYPE_PROP)) { node.setProperty(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY, attr.getNodeValue()); } else { node.setProperty(attr.getNodeName(), attr.getNodeValue()); } } this.session.save(); } catch (final RepositoryException e) { LOG.error("Unable to access repository to access or create node. Stack Trace: ", e); } }
From source file:org.ballerinalang.model.values.BXMLItem.java
/** * {@inheritDoc}/*from w ww. j a va 2 s .c om*/ */ @Override public void setAttribute(String localName, String namespaceUri, String prefix, String value) { if (nodeType != XMLNodeType.ELEMENT) { return; } if (localName == null || localName.isEmpty()) { throw new BallerinaException("localname of the attribute cannot be empty"); } // Validate whether the attribute name is an XML supported qualified name, according to the XML recommendation. XMLValidationUtils.validateXMLName(localName); XMLValidationUtils.validateXMLName(prefix); // If the attribute already exists, update the value. OMElement node = (OMElement) omNode; QName qname = getQName(localName, namespaceUri, prefix); OMAttribute attr = node.getAttribute(qname); if (attr != null) { attr.setAttributeValue(value); return; } // If the prefix is 'xmlns' then this is a namespace addition if (prefix != null && prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) { node.declareNamespace(value, localName); return; } createAttribute(localName, namespaceUri, prefix, value, node); }
From source file:org.ballerinalang.model.values.BXMLItem.java
private void createAttribute(String localName, String namespaceUri, String prefix, String value, OMElement node) {//from w w w. j a v a2s.com // If the namespace is null/empty, only the local part exists. Therefore add a simple attribute. if (namespaceUri == null || namespaceUri.isEmpty()) { node.addAttribute(localName, value, null); return; } if (!(prefix == null || prefix.isEmpty())) { OMNamespace existingNs = node.findNamespaceURI(prefix); // If a namespace exists with the same prefix but a different uri, then do not add the new attribute. if (existingNs != null && !namespaceUri.equals(existingNs.getNamespaceURI())) { throw new BallerinaException("failed to add attribute '" + prefix + ":" + localName + "'. prefix '" + prefix + "' is already bound to namespace '" + existingNs.getNamespaceURI() + "'"); } node.addAttribute(localName, value, new OMNamespaceImpl(namespaceUri, prefix)); return; } // We reach here if the namespace prefix is null/empty, and a namespace uri exists. // Find a prefix that has the same namespaceUri, out of the defined namespaces Iterator<String> prefixes = node.getNamespaceContext(false).getPrefixes(namespaceUri); if (prefixes.hasNext()) { prefix = prefixes.next(); if (prefix.isEmpty()) { node.addAttribute(localName, value, null); return; } if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) { // If found, and if its the default namespace, add a namespace decl node.declareNamespace(value, localName); return; } } // Else use the prefix. If the prefix is null, a random prefix will be generated. node.addAttribute(localName, value, new OMNamespaceImpl(namespaceUri, prefix)); }
From source file:org.betaconceptframework.astroboa.engine.jcr.io.SerializationBean.java
private void createXSISchemaLocationValueForAllDefinitions(AttributesImpl attributes, StringBuilder xsiSchemaLocations, Map<String, String> prefixesPerType) { Map<QName, String> locationMap = definitionServiceDao.getLocationURLForDefinitions(); if (MapUtils.isNotEmpty(locationMap)) { List<String> processedURIs = new ArrayList<String>(); for (Entry<QName, String> location : locationMap.entrySet()) { final String namespaceURI = location.getKey().getNamespaceURI(); if (!processedURIs.contains(namespaceURI)) { xsiSchemaLocations.append(namespaceURI); xsiSchemaLocations.append(" "); xsiSchemaLocations.append(location.getValue()); xsiSchemaLocations.append(" "); IOUtils.addAttribute(attributes, XMLConstants.XMLNS_ATTRIBUTE + ":" + location.getKey().getPrefix(), location.getKey().getNamespaceURI()); processedURIs.add(namespaceURI); }//from w w w . j a va2s. c o m prefixesPerType.put(location.getKey().getLocalPart(), location.getKey().getPrefix()); } } }