List of usage examples for org.w3c.dom Element removeAttributeNode
public Attr removeAttributeNode(Attr oldAttr) throws DOMException;
From source file:nl.strohalm.cyclos.utils.conversion.HtmlConverter.java
private static void removeBadNodes(final Document document) { final NodeList elements = document.getElementsByTagName("*"); for (int i = 0; i < elements.getLength(); i++) { final Element element = (Element) elements.item(i); if (ArrayUtils.contains(BAD_TAGS, element.getTagName())) { element.getParentNode().removeChild(element); }//from w w w . j a v a 2 s. c o m final NamedNodeMap attributes = element.getAttributes(); for (int j = 0; j < attributes.getLength(); j++) { final Attr attr = (Attr) attributes.item(j); if (attr.getNodeName().startsWith("on")) { // This is an event handler: remove it element.removeAttributeNode(attr); } } } }
From source file:org.apache.camel.component.xmlsecurity.api.XAdESSignatureProperties.java
protected void replacePrefix(Element el, Input input) { replacePrefixForNode(el, input);/* ww w.j a v a 2 s. co m*/ NamedNodeMap nnm = el.getAttributes(); List<Attr> xmlnsToBeRemoved = new ArrayList<Attr>(2); int length = nnm.getLength(); for (int i = 0; i < length; i++) { Node attr = nnm.item(i); replacePrefixForNode(attr, input); if (attr.getNodeType() == Node.ATTRIBUTE_NODE) { if ("xmlns".equals(attr.getLocalName()) || "xmlns".equals(attr.getPrefix())) { if (XMLSignature.XMLNS.equals(attr.getTextContent()) || findNamespace(input.getMessage()).equals(attr.getTextContent())) { xmlnsToBeRemoved.add((Attr) attr); } } } } // remove xml namespace declaration for XML signature and XAdES namespace for (Attr toBeRemoved : xmlnsToBeRemoved) { el.removeAttributeNode(toBeRemoved); } }
From source file:org.apache.hadoop.gateway.filter.rewrite.impl.xml.XmlFilterReader.java
private void streamAttribute(Element element, Attribute attribute) throws XPathExpressionException { Attr node;//w w w . java 2 s. c o m QName name = attribute.getName(); String prefix = name.getPrefix(); String uri = name.getNamespaceURI(); if (uri == null || uri.isEmpty()) { node = document.createAttribute(name.getLocalPart()); element.setAttributeNode(node); } else { node = document.createAttributeNS(uri, name.getLocalPart()); if (prefix != null && !prefix.isEmpty()) { node.setPrefix(prefix); } element.setAttributeNodeNS(node); } String value = attribute.getValue(); Level level = stack.peek(); if ((level.scopeConfig) == null || (level.scopeConfig.getSelectors().isEmpty())) { value = filterAttribute(null, attribute.getName(), value, null); node.setValue(value); } else { UrlRewriteFilterPathDescriptor path = pickFirstMatchingPath(level); if (path instanceof UrlRewriteFilterApplyDescriptor) { String rule = ((UrlRewriteFilterApplyDescriptor) path).rule(); value = filterAttribute(null, attribute.getName(), value, rule); node.setValue(value); } } //dump( document ); if (prefix == null || prefix.isEmpty()) { writer.write(" "); writer.write(name.getLocalPart()); } else { writer.write(" "); writer.write(prefix); writer.write(":"); writer.write(name.getLocalPart()); } writer.write("=\""); writer.write(value); writer.write("\""); element.removeAttributeNode(node); }
From source file:org.apache.ode.utils.DOMUtils.java
/** * Drop the attributes from an element, except possibly an <code>xmlns</code> * attribute that declares its namespace. * @param target the element whose attributes will be removed. * @param flag preserve namespace declaration *///w w w. ja v a 2 s . c o m public static void removeAttributes(Element target, boolean flag) { if (!target.hasAttributes()) { return; } String prefix = target.getPrefix(); NamedNodeMap nnm = target.getAttributes(); Attr toPutBack = null; if (flag) { if (prefix == null) { toPutBack = target.getAttributeNodeNS(NS_URI_XMLNS, "xmlns"); } else { toPutBack = target.getAttributeNodeNS(NS_URI_XMLNS, "xmlns:" + prefix); } } while (nnm.getLength() != 0) { target.removeAttributeNode((Attr) nnm.item(0)); } if (toPutBack != null) { target.setAttributeNodeNS(toPutBack); } }
From source file:org.dita.dost.module.BranchFilterModule.java
/** Modify and filter topics for branches. These files use an existing file name. */ private void filterTopics(final Element topicref, final List<FilterUtils> filters) { final List<FilterUtils> fs = combineFilterUtils(topicref, filters); final String href = topicref.getAttribute(ATTRIBUTE_NAME_HREF); final Attr skipFilter = topicref.getAttributeNode(SKIP_FILTER); final URI srcAbsUri = job.tempDirURI.resolve(map.resolve(href)); if (!fs.isEmpty() && skipFilter == null && !filtered.contains(srcAbsUri) && !href.isEmpty() && !ATTR_SCOPE_VALUE_EXTERNAL.equals(topicref.getAttribute(ATTRIBUTE_NAME_SCOPE)) && !ATTR_PROCESSING_ROLE_VALUE_RESOURCE_ONLY .equals(topicref.getAttribute(ATTRIBUTE_NAME_PROCESSING_ROLE)) && isDitaFormat(topicref.getAttributeNode(ATTRIBUTE_NAME_FORMAT))) { final ProfilingFilter writer = new ProfilingFilter(); writer.setLogger(logger);// w w w.j av a 2s . co m writer.setJob(job); writer.setFilterUtils(fs); writer.setCurrentFile(srcAbsUri); final List<XMLFilter> pipe = singletonList(writer); logger.info("Filtering " + srcAbsUri); try { xmlUtils.transform(srcAbsUri, pipe); } catch (final DITAOTException e) { logger.error("Failed to filter " + srcAbsUri + ": " + e.getMessage(), e); } filtered.add(srcAbsUri); } if (skipFilter != null) { topicref.removeAttributeNode(skipFilter); } for (final Element child : getChildElements(topicref, MAP_TOPICREF)) { if (DITAVAREF_D_DITAVALREF.matches(child)) { continue; } filterTopics(child, fs); } }
From source file:org.wso2.carbon.event.output.adapter.core.internal.util.EventAdapterConfigHelper.java
private static void secureLoadElement(Element element) throws CryptoException { Attr secureAttr = element.getAttributeNodeNS(EventAdapterConstants.SECURE_VAULT_NS, EventAdapterConstants.SECRET_ALIAS_ATTR_NAME); if (secureAttr != null) { element.setTextContent(loadFromSecureVault(secureAttr.getValue())); element.removeAttributeNode(secureAttr); }//from w w w. j av a 2 s. co m NodeList childNodes = element.getChildNodes(); int count = childNodes.getLength(); Node tmpNode; for (int i = 0; i < count; i++) { tmpNode = childNodes.item(i); if (tmpNode instanceof Element) { secureLoadElement((Element) tmpNode); } } }
From source file:org.wso2.carbon.ndatasource.core.utils.DataSourceUtils.java
private static void secureLoadElement(Element element, boolean checkSecureVault) throws CryptoException { if (checkSecureVault) { Attr secureAttr = element.getAttributeNodeNS(DataSourceConstants.SECURE_VAULT_NS, DataSourceConstants.SECRET_ALIAS_ATTR_NAME); if (secureAttr != null) { element.setTextContent(loadFromSecureVault(secureAttr.getValue())); element.removeAttributeNode(secureAttr); }//from w w w .j a v a 2s . c o m } else { String encryptedStr = element.getAttribute(DataSourceConstants.ENCRYPTED_ATTR_NAME); if (encryptedStr != null) { boolean encrypted = Boolean.parseBoolean(encryptedStr); if (encrypted) { element.setTextContent(new String(CryptoUtil .getDefaultCryptoUtil(DataSourceServiceComponent.getServerConfigurationService(), DataSourceServiceComponent.getRegistryService()) .base64DecodeAndDecrypt(element.getTextContent()))); } } } NodeList childNodes = element.getChildNodes(); int count = childNodes.getLength(); Node tmpNode; for (int i = 0; i < count; i++) { tmpNode = childNodes.item(i); if (tmpNode instanceof Element) { secureLoadElement((Element) tmpNode, checkSecureVault); } } }
From source file:org.wso2.carbon.rssmanager.core.util.RSSManagerUtil.java
private static void secureLoadElement(Element element) throws RSSManagerException { Attr secureAttr = element.getAttributeNodeNS(RSSManagerConstants.SecureValueProperties.SECURE_VAULT_NS, RSSManagerConstants.SecureValueProperties.SECRET_ALIAS_ATTRIBUTE_NAME_WITH_NAMESPACE); if (secureAttr != null) { element.setTextContent(RSSManagerUtil.loadFromSecureVault(secureAttr.getValue())); element.removeAttributeNode(secureAttr); }//from w w w .j a v a 2 s . com NodeList childNodes = element.getChildNodes(); int count = childNodes.getLength(); Node tmpNode; for (int i = 0; i < count; i++) { tmpNode = childNodes.item(i); if (tmpNode instanceof Element) { secureLoadElement((Element) tmpNode); } } }