本文整理汇总了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");
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}