List of usage examples for org.w3c.dom Element getAttributes
public NamedNodeMap getAttributes();
NamedNodeMap
containing the attributes of this node (if it is an Element
) or null
otherwise. From source file:com.amalto.workbench.actions.XSDNewParticleFromParticleAction.java
public Map<String, List<String>> cloneXSDAnnotation(XSDAnnotation oldAnn) { Map<String, List<String>> infor = new HashMap<String, List<String>>(); try {//from w w w .ja v a 2 s. c o m if (oldAnn != null) { for (int i = 0; i < oldAnn.getApplicationInformation().size(); i++) { Element oldElem = oldAnn.getApplicationInformation().get(i); String type = oldElem.getAttributes().getNamedItem("source").getNodeValue();//$NON-NLS-1$ // X_Write,X_Hide,X_Workflow if (type.equals("X_Write") || type.equals("X_Hide") || type.equals("X_Workflow")) {//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ if (!infor.containsKey(type)) { List<String> typeList = new ArrayList<String>(); typeList.add(oldElem.getFirstChild().getNodeValue()); infor.put(type, typeList); } else { (infor.get(type)).add(oldElem.getFirstChild().getNodeValue()); } } } } } catch (Exception e) { log.error(e.getMessage(), e); MessageDialog.openError(this.page.getSite().getShell(), Messages._Error, Messages.bind(Messages._ErrorPasteEntity, e.getLocalizedMessage())); } return infor; }
From source file:org.solmix.runtime.support.spring.AbstractBeanDefinitionParser.java
/**?Element,?Container*/ protected boolean parseAttributes(Element element, ParserContext ctx, BeanDefinitionBuilder bean) { NamedNodeMap atts = element.getAttributes(); boolean setBus = false; for (int i = 0; i < atts.getLength(); i++) { Attr node = (Attr) atts.item(i); String val = node.getValue(); String pre = node.getPrefix(); String name = node.getLocalName(); String prefix = node.getPrefix(); // Don't process namespaces if (isNamespace(name, prefix)) { continue; }/*from w ww . j av a 2s .c om*/ if ("createdFromAPI".equals(name)) { bean.setAbstract(true); } else if ("abstract".equals(name)) { bean.setAbstract(true); } else if ("depends-on".equals(name)) { bean.addDependsOn(val); } else if ("name".equals(name)) { parseNameAttribute(element, ctx, bean, val); } else if ("container".equals(name)) { setBus = parseContainerAttribute(element, ctx, bean, val); } else if ("id".equals(name)) { parseIdAttribute(bean, element, name, val, ctx); } else if (isAttribute(pre, name)) { parseAttribute(bean, element, name, val, ctx); } } return setBus; }
From source file:com.streamsets.pipeline.stage.processor.xmlflattener.XMLFlatteningProcessor.java
private void addAttrs(Record record, Element element, String elementPrefix) { if (!ignoreAttrs) { NamedNodeMap attrs = element.getAttributes(); for (int j = 0; j < attrs.getLength(); j++) { Node attr = attrs.item(j); String attrName = attr.getNodeName(); if (attrName.equals("xmlns")) { //handled separately. continue; }/*from www . j a v a2 s .c om*/ record.set(getPathPrefix() + elementPrefix + attrDelimiter + attr.getNodeName(), Field.create(attr.getNodeValue())); } } if (!ignoreNamespace) { String namespaceURI = element.getNamespaceURI(); if (namespaceURI != null) { record.set(getPathPrefix() + elementPrefix + attrDelimiter + "xmlns", Field.create(namespaceURI)); } } }
From source file:com.evolveum.midpoint.util.DOMUtil.java
public static boolean hasApplicationAttributes(Element element) { NamedNodeMap attributes = element.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Attr attr = (Attr) attributes.item(i); if (isApplicationAttribute(attr)) { return true; }/*w ww. j av a2 s . co m*/ } return false; }
From source file:com.subgraph.vega.impl.scanner.urls.ResponseAnalyzer.java
private void analyzeHtmlElement(IInjectionModuleContext ctx, HttpUriRequest req, IHttpResponse res, Element elem) { boolean remoteScript = false; NamedNodeMap attributes = elem.getAttributes(); final String tag = elem.getTagName().toLowerCase(); for (int i = 0; i < attributes.getLength(); i++) { Node item = attributes.item(i); if (item instanceof Attr) { String n = ((Attr) item).getName().toLowerCase(); String v = ((Attr) item).getValue().toLowerCase(); if (match(tag, "script") && match(n, "src")) remoteScript = true;/*www . ja v a 2s .c om*/ if ((v != null) && (match(n, "href", "src", "action", "codebase") || (match(n, "value") && !match(tag, "input")))) { if (v.startsWith("vega://")) alert(ctx, "vinfo-url-inject", "URL injection into <" + tag + "> tag", req, res); if (v.startsWith("http://vega.invalid/") || v.startsWith("//vega.invalid/")) { if (match(tag, "script", "link")) alert(ctx, "vinfo-url-inject", "URL injection into actively fetched field in tag <" + tag + "> (high risk)", req, res); else if (match(tag, "a")) alert(ctx, "vinfo-url-inject", "URL injection into anchor tag (low risk)", req, res); else alert(ctx, "vinfo-url-inject", "URL injection into tag <" + tag + ">", req, res); } } if ((v != null) && (n.startsWith("on") || n.equals("style"))) { checkJavascriptXSS(ctx, req, res, v); } if (n.contains("vvv")) possibleXssAlert(ctx, req, res, n, n.indexOf("vvv"), "xss-inject", "Injected XSS tag into HTML attribute value"); } } if (tag.startsWith("vvv")) possibleXssAlert(ctx, req, res, tag, 0, "vinfo-xss-inject", "Injected XSS tag into HTML tag name"); if (tag.equals("style") || (tag.equals("script") && !remoteScript)) { String content = elem.getTextContent(); if (content != null) checkJavascriptXSS(ctx, req, res, content); } }
From source file:com.evolveum.midpoint.util.DOMUtil.java
private static void fixNamespaceDeclarations(Element targetElement, Element currentElement) { NamedNodeMap attributes = currentElement.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Attr attr = (Attr) attributes.item(i); if (isNamespaceDefinition(attr)) { String prefix = getNamespaceDeclarationPrefix(attr); String namespace = getNamespaceDeclarationNamespace(attr); if (hasNamespaceDeclarationForPrefix(targetElement, prefix)) { if (targetElement != currentElement) { // We are processing parent element, while the original element already // has prefix declaration. That means it must have been processed before // we can skip the usage check continue; }//from w ww . j ava2s . c o m } else { setNamespaceDeclaration(targetElement, prefix, getNamespaceDeclarationNamespace(attr)); } } } Node parentNode = currentElement.getParentNode(); if (parentNode instanceof Element) { fixNamespaceDeclarations(targetElement, (Element) parentNode); } }
From source file:com.evolveum.midpoint.util.DOMUtil.java
public static void copyContent(Element source, Element destination) { NamedNodeMap attributes = source.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Attr attr = (Attr) attributes.item(i); Attr clone = (Attr) attr.cloneNode(true); destination.setAttributeNode(clone); }/*w w w.j a va 2 s. c o m*/ NodeList childNodes = source.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node item = childNodes.item(i); destination.appendChild(item); } }
From source file:com.evolveum.midpoint.util.DOMUtil.java
public static String getNamespaceDeclarationForPrefix(Element targetElement, String prefix) { NamedNodeMap attributes = targetElement.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Attr attr = (Attr) attributes.item(i); if (isNamespaceDefinition(attr)) { String thisPrefix = getNamespaceDeclarationPrefix(attr); if (comparePrefix(prefix, thisPrefix)) { return getNamespaceDeclarationNamespace(attr); }/* w w w .j av a 2s. co m*/ } } return null; }
From source file:jp.igapyon.selecrawler.SeleCrawlerWebContentAnalyzer.java
public void processFile(final File file, final String urlString) throws IOException { final List<String> anchorList = new ArrayList<String>(); final List<String> headList = new ArrayList<String>(); final List<String> scriptSrcList = new ArrayList<String>(); final String contents = FileUtils.readFileToString( new File(file.getParentFile(), file.getName() + SeleCrawlerConstants.EXT_SC_NORMAL), "UTF-8"); final Document document = SimpleMyXmlUtil.string2Document(contents); {/*from www. j av a 2 s . com*/ final String title = SimpleMyXmlUtil.getXPathString(document, "/html/head/title/text()"); if (title != null && title.trim().length() > 0) { headList.add("title: " + title); } } { final NodeList nodes = SimpleMyXmlUtil.getXPathNodeList(document, "/html/head/meta"); for (int index = 0; index < nodes.getLength(); index++) { if (nodes.item(index) instanceof Element) { final Element eleMeta = (Element) nodes.item(index); headList.add("meta:"); final NamedNodeMap nnm = eleMeta.getAttributes(); for (int indexNnm = 0; indexNnm < nnm.getLength(); indexNnm++) { final Attr attr = (Attr) nnm.item(indexNnm); headList.add(" " + attr.getName() + " [" + attr.getValue() + "]"); } } } } { final NodeList nodes = SimpleMyXmlUtil.getXPathNodeList(document, "/html/head/link"); for (int index = 0; index < nodes.getLength(); index++) { if (nodes.item(index) instanceof Element) { final Element eleMeta = (Element) nodes.item(index); headList.add("link:"); final NamedNodeMap nnm = eleMeta.getAttributes(); for (int indexNnm = 0; indexNnm < nnm.getLength(); indexNnm++) { final Attr attr = (Attr) nnm.item(indexNnm); headList.add(" " + attr.getName() + " [" + attr.getValue() + "]"); } } } } { // search anchor with href final NodeList nodes = SimpleMyXmlUtil.getXPathNodeList(document, "//a"); for (int index = 0; index < nodes.getLength(); index++) { if (nodes.item(index) instanceof Element) { final Element eleAnchor = (Element) nodes.item(index); String href = eleAnchor.getAttribute("href"); href = adjustAnchorUrl(href, urlString); if (href == null) { continue; } anchorList.add(href); } } } { // search script final NodeList nodes = SimpleMyXmlUtil.getXPathNodeList(document, "//script"); for (int index = 0; index < nodes.getLength(); index++) { if (nodes.item(index) instanceof Element) { final Element eleScript = (Element) nodes.item(index); String srcString = eleScript.getAttribute("src"); srcString = adjustAnchorUrl(srcString, urlString); if (srcString == null) { continue; } scriptSrcList.add(srcString); } } } { final File fileMetaAnchor = new File(file.getParentFile(), file.getName() + SeleCrawlerConstants.EXT_SC_ANCHOR); FileUtils.writeLines(fileMetaAnchor, "UTF-8", anchorList); } { final File fileMetaHead = new File(file.getParentFile(), file.getName() + SeleCrawlerConstants.EXT_SC_HEAD); FileUtils.writeLines(fileMetaHead, "UTF-8", headList); } { final File fileScriptSrc = new File(file.getParentFile(), file.getName() + SeleCrawlerConstants.EXT_SC_SCRIPTSRC); FileUtils.writeLines(fileScriptSrc, "UTF-8", scriptSrcList); } }
From source file:au.gov.ga.earthsci.bookmark.properties.layer.LayersPropertyPersister.java
@Override public IBookmarkProperty createFromXML(String type, Element propertyElement) { Validate.isTrue(LayersProperty.TYPE.equals(type), INVALID_TYPE_MSG); Validate.notNull(propertyElement, "A property element is required"); //$NON-NLS-1$ LayersProperty result = new LayersProperty(); for (Element state : XmlUtil.getElements(propertyElement, LAYER_XPATH, null)) { // state.getAttributes() String id = XMLUtil.getText(state, ID_ATTRIBUTE_XPATH); Double opacity = XMLUtil.getDouble(state, OPACITY_ATTRIBUTE_XPATH, 1.0d); NamedNodeMap attrs = state.getAttributes(); if (id != null) { List<Pair<String, String>> pairs = new ArrayList<Pair<String, String>>(); for (int i = 0; i < attrs.getLength(); i++) { String key = attrs.item(i).getNodeName(); String value = attrs.item(i).getNodeValue(); if (!key.equals(ID_ATTRIBUTE_NAME)) { pairs.add(new ImmutablePair<String, String>(key, value)); }//from w w w . j a va2 s.c o m } result.addLayer(id, pairs.toArray(new Pair[0])); } } return result; }