当前位置: 首页>>代码示例>>Java>>正文


Java Attr.getOwnerElement方法代码示例

本文整理汇总了Java中org.w3c.dom.Attr.getOwnerElement方法的典型用法代码示例。如果您正苦于以下问题:Java Attr.getOwnerElement方法的具体用法?Java Attr.getOwnerElement怎么用?Java Attr.getOwnerElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.w3c.dom.Attr的用法示例。


在下文中一共展示了Attr.getOwnerElement方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: visitAttribute

import org.w3c.dom.Attr; //导入方法依赖的package包/类
@Override
public void visitAttribute(XmlContext context, Attr attribute) {
    super.visitAttribute(context, attribute);

    String value = attribute.getValue();
    if (Utils.stringIsEmpty(value)) return;

    //onClick 属性被赋值
    Element element = attribute.getOwnerElement();
    boolean has = element.hasAttributeNS(SdkConstants.ANDROID_URI, SdkConstants.ATTR_ID);
    if (!has) {

        Location location = context.getLocation(attribute);
        context.report(ISSUE_MISSING_ID, location, "the view with onClick attribute set should has id attribute");
    }
}
 
开发者ID:jessie345,项目名称:CustomLintRules,代码行数:17,代码来源:AutoPointLayoutOnclickDetector.java

示例2: setAttributeNode

import org.w3c.dom.Attr; //导入方法依赖的package包/类
public Attr setAttributeNode(Attr newAttr) throws DOMException {
    Element owner = newAttr.getOwnerElement();
    if (owner != null) {
        if (owner == this) {
            return null;
        } else {
            throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR,
                                   "Attribute is already in use");
        }
    }

    IIOAttr attr;
    if (newAttr instanceof IIOAttr) {
        attr = (IIOAttr)newAttr;
        attr.setOwnerElement(this);
    } else {
        attr = new IIOAttr(this,
                           newAttr.getName(),
                           newAttr.getValue());
    }

    Attr oldAttr = getAttributeNode(attr.getName());
    if (oldAttr != null) {
        removeAttributeNode(oldAttr);
    }

    attributes.add(attr);

    return oldAttr;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:31,代码来源:IIOMetadataNode.java

示例3: calcXpath

import org.w3c.dom.Attr; //导入方法依赖的package包/类
/**
 * Compute the xpath of a node relative to an anchor.
 * 
 * @param node
 *            node to find the xpath from.
 * @param anchor
 *            the relative point to fid from.
 * @return the computed xpath.
 */
public static String calcXpath(Node node, Node anchor) {
	String xpath = "";
	Node current = null;

	if (node == null || node.equals(anchor))
		return "";

	// add attribute to xpath
	if (node instanceof Attr) {
		Attr attr = (Attr) node;
		node = attr.getOwnerElement();
		xpath = '@' + attr.getName() + '/';
	}

	while ((current = node.getParentNode()) != anchor) {
		Engine.logEngine.trace("Calc Xpath : current node : " + current.getNodeName());
		NodeList childs = current.getChildNodes();
		int index = 0;
		for (int i = 0; i < childs.getLength(); i++) {
			if (childs.item(i).getNodeType() != Node.ELEMENT_NODE
					&& !childs.item(i).getNodeName().equalsIgnoreCase("#text"))
				continue;

			Engine.logEngine.trace("Calc Xpath : ==== > Child node : " + childs.item(i).getNodeName());

			// Bump the index if we have the same tag names..
			if (childs.item(i).getNodeName().equalsIgnoreCase(node.getNodeName())) {
				// tag names are equal ==> bump the index.
				index++;
				// is our node the one that is listed ?
				if (childs.item(i).equals(node))
					// We found our node in the parent node list
					break;
			}
		}
		// count the number of elements having the same tag
		int nbElements = 0;
		for (int i = 0; i < childs.getLength(); i++) {
			if (childs.item(i).getNodeName().equalsIgnoreCase(node.getNodeName())) {
				nbElements++;
			}
		}

		String name = node.getNodeName();
		if (name.equalsIgnoreCase("#text"))
			name = "text()";
		name = xpathEscapeColon(name);

		if (nbElements > 1) {
			xpath = name + "[" + index + "]/" + xpath;
		} else {
			// only one element had the same tag ==> do not compute the [xx]
			// syntax..
			xpath = name + "/" + xpath;
		}
		node = current;
	}
	if (xpath.length() > 0)
		// remove the trailing '/'
		xpath = xpath.substring(0, xpath.length() - 1);

	return xpath;
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:73,代码来源:XMLUtils.java

示例4: protectAgainstWrappingAttack

import org.w3c.dom.Attr; //导入方法依赖的package包/类
/**
 * This method is a tree-search to help prevent against wrapping attacks. It checks that no
 * two Elements have ID Attributes that match the "value" argument, if this is the case then
 * "false" is returned. Note that a return value of "true" does not necessarily mean that
 * a matching Element has been found, just that no wrapping attack has been detected.
 */
public static boolean protectAgainstWrappingAttack(Node startNode, String value) {
    Node startParent = startNode.getParentNode();
    Node processedNode = null;
    Element foundElement = null;

    String id = value.trim();
    if (id.charAt(0) == '#') {
        id = id.substring(1);
    }

    while (startNode != null) {
        if (startNode.getNodeType() == Node.ELEMENT_NODE) {
            Element se = (Element) startNode;

            NamedNodeMap attributes = se.getAttributes();
            if (attributes != null) {
                for (int i = 0; i < attributes.getLength(); i++) {
                    Attr attr = (Attr)attributes.item(i);
                    if (attr.isId() && id.equals(attr.getValue())) {
                        if (foundElement == null) {
                            // Continue searching to find duplicates
                            foundElement = attr.getOwnerElement();
                        } else {
                            log.log(java.util.logging.Level.FINE, "Multiple elements with the same 'Id' attribute value!");
                            return false;
                        }
                    }
                }
            }
        }

        processedNode = startNode;
        startNode = startNode.getFirstChild();

        // no child, this node is done.
        if (startNode == null) {
            // close node processing, get sibling
            startNode = processedNode.getNextSibling();
        }

        // no more siblings, get parent, all children
        // of parent are processed.
        while (startNode == null) {
            processedNode = processedNode.getParentNode();
            if (processedNode == startParent) {
                return true;
            }
            // close parent node processing (processed node now)
            startNode = processedNode.getNextSibling();
        }
    }
    return true;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:60,代码来源:XMLUtils.java

示例5: protectAgainstWrappingAttack

import org.w3c.dom.Attr; //导入方法依赖的package包/类
/**
 * This method is a tree-search to help prevent against wrapping attacks. It checks that no
 * two Elements have ID Attributes that match the "value" argument, if this is the case then
 * "false" is returned. Note that a return value of "true" does not necessarily mean that
 * a matching Element has been found, just that no wrapping attack has been detected.
 */
public static boolean protectAgainstWrappingAttack(Node startNode, String value) {
    Node startParent = startNode.getParentNode();
    Node processedNode = null;
    Element foundElement = null;

    String id = value.trim();
    if (!id.isEmpty() && id.charAt(0) == '#') {
        id = id.substring(1);
    }

    while (startNode != null) {
        if (startNode.getNodeType() == Node.ELEMENT_NODE) {
            Element se = (Element) startNode;

            NamedNodeMap attributes = se.getAttributes();
            if (attributes != null) {
                for (int i = 0; i < attributes.getLength(); i++) {
                    Attr attr = (Attr)attributes.item(i);
                    if (attr.isId() && id.equals(attr.getValue())) {
                        if (foundElement == null) {
                            // Continue searching to find duplicates
                            foundElement = attr.getOwnerElement();
                        } else {
                            log.log(java.util.logging.Level.FINE, "Multiple elements with the same 'Id' attribute value!");
                            return false;
                        }
                    }
                }
            }
        }

        processedNode = startNode;
        startNode = startNode.getFirstChild();

        // no child, this node is done.
        if (startNode == null) {
            // close node processing, get sibling
            startNode = processedNode.getNextSibling();
        }

        // no more siblings, get parent, all children
        // of parent are processed.
        while (startNode == null) {
            processedNode = processedNode.getParentNode();
            if (processedNode == startParent) {
                return true;
            }
            // close parent node processing (processed node now)
            startNode = processedNode.getNextSibling();
        }
    }
    return true;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:60,代码来源:XMLUtils.java


注:本文中的org.w3c.dom.Attr.getOwnerElement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。