下面列出了org.w3c.dom.Attr#getPrefix ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
protected void visitAttr(Attr node)
throws XMLStreamException {
String name = node.getLocalName();
if (name.equals("xmlns")) {
out.writeDefaultNamespace(node.getNamespaceURI());
} else {
String prefix = node.getPrefix();
if (prefix != null && prefix.equals("xmlns")) {
out.writeNamespace(prefix, node.getNamespaceURI());
} else if (prefix != null) {
out.writeAttribute(prefix
, node.getNamespaceURI()
, name
, node.getNodeValue()
);
} else {
out.writeAttribute(node.getNamespaceURI()
, name
, node.getNodeValue());
}
}
}
protected void visitAttr(Attr node)
throws XMLStreamException {
String name = node.getLocalName();
if (name.equals("xmlns")) {
out.writeDefaultNamespace(node.getNamespaceURI());
} else {
String prefix = node.getPrefix();
if (prefix != null && prefix.equals("xmlns")) {
out.writeNamespace(prefix, node.getNamespaceURI());
} else if (prefix != null) {
out.writeAttribute(prefix
, node.getNamespaceURI()
, name
, node.getNodeValue()
);
} else {
out.writeAttribute(node.getNamespaceURI()
, name
, node.getNodeValue());
}
}
}
protected void visitAttr(Attr node)
throws XMLStreamException {
String name = node.getLocalName();
if (name.equals("xmlns")) {
out.writeDefaultNamespace(node.getNamespaceURI());
} else {
String prefix = node.getPrefix();
if (prefix != null && prefix.equals("xmlns")) {
out.writeNamespace(prefix, node.getNamespaceURI());
} else if (prefix != null) {
out.writeAttribute(prefix
, node.getNamespaceURI()
, name
, node.getNodeValue()
);
} else {
out.writeAttribute(node.getNamespaceURI()
, name
, node.getNodeValue());
}
}
}
protected void visitAttr(Attr node)
throws XMLStreamException {
String name = node.getLocalName();
if (name.equals("xmlns")) {
out.writeDefaultNamespace(node.getNamespaceURI());
} else {
String prefix = node.getPrefix();
if (prefix != null && prefix.equals("xmlns")) {
out.writeNamespace(prefix, node.getNamespaceURI());
} else if (prefix != null) {
out.writeAttribute(prefix
, node.getNamespaceURI()
, name
, node.getNodeValue()
);
} else {
out.writeAttribute(node.getNamespaceURI()
, name
, node.getNodeValue());
}
}
}
protected void visitAttr(Attr node)
throws XMLStreamException {
String name = node.getLocalName();
if (name.equals("xmlns")) {
out.writeDefaultNamespace(node.getNamespaceURI());
} else {
String prefix = node.getPrefix();
if (prefix != null && prefix.equals("xmlns")) {
out.writeNamespace(prefix, node.getNamespaceURI());
} else if (prefix != null) {
out.writeAttribute(prefix
, node.getNamespaceURI()
, name
, node.getNodeValue()
);
} else {
out.writeAttribute(node.getNamespaceURI()
, name
, node.getNodeValue());
}
}
}
protected boolean printAttributeWithoutPrefix(Attr attribute, boolean hasAttribute) {
String prefix = attribute.getPrefix();
if (prefix == null || prefix.length() == 0) {
if (!hasAttribute) {
hasAttribute = true;
} else {
print(", ");
}
String localName = getLocalName(attribute);
boolean needsEscaping = checkEscaping(localName);
if (needsEscaping) print(qt);
print(localName);
if (needsEscaping) print(qt);
print(":");
printQuoted(getAttributeValue(attribute));
}
return hasAttribute;
}
private void unmarshalParams(Element paramsElem) {
String xPath = paramsElem.getFirstChild().getNodeValue();
// create a Map of namespace prefixes
NamedNodeMap attributes = paramsElem.getAttributes();
if (attributes != null) {
int length = attributes.getLength();
Map<String, String> namespaceMap =
new HashMap<String, String>(length);
for (int i = 0; i < length; i++) {
Attr attr = (Attr)attributes.item(i);
String prefix = attr.getPrefix();
if (prefix != null && prefix.equals("xmlns")) {
namespaceMap.put(attr.getLocalName(), attr.getValue());
}
}
this.params = new XPathFilterParameterSpec(xPath, namespaceMap);
} else {
this.params = new XPathFilterParameterSpec(xPath);
}
}
protected void visitAttr(Attr node)
throws XMLStreamException {
String name = node.getLocalName();
if (name.equals("xmlns")) {
out.writeDefaultNamespace(node.getNamespaceURI());
} else {
String prefix = node.getPrefix();
if (prefix != null && prefix.equals("xmlns")) {
out.writeNamespace(prefix, node.getNamespaceURI());
} else if (prefix != null) {
out.writeAttribute(prefix
, node.getNamespaceURI()
, name
, node.getNodeValue()
);
} else {
out.writeAttribute(node.getNamespaceURI()
, name
, node.getNodeValue());
}
}
}
private void unmarshalParams(Element paramsElem) {
String xPath = paramsElem.getFirstChild().getNodeValue();
// create a Map of namespace prefixes
NamedNodeMap attributes = paramsElem.getAttributes();
if (attributes != null) {
int length = attributes.getLength();
Map<String, String> namespaceMap =
new HashMap<String, String>(length);
for (int i = 0; i < length; i++) {
Attr attr = (Attr)attributes.item(i);
String prefix = attr.getPrefix();
if (prefix != null && prefix.equals("xmlns")) {
namespaceMap.put(attr.getLocalName(), attr.getValue());
}
}
this.params = new XPathFilterParameterSpec(xPath, namespaceMap);
} else {
this.params = new XPathFilterParameterSpec(xPath);
}
}
public void serializeAttributes(NamedNodeMap attributes) throws XMLStreamException {
for (int i=0; i < attributes.getLength(); i++) {
Attr attribute = (Attr) attributes.item(i);
String namespaceURI = attribute.getNamespaceURI();
String prefix = (namespaceURI != null) ? attribute.getPrefix() : null;
String localName = (namespaceURI != null) ? attribute.getLocalName() : attribute.getName();
String value = attribute.getValue();
if ("http://www.w3.org/2000/xmlns/".equals(namespaceURI)) {
//TODO: Seems there should be a better way to prevent redundant namespaces.
} else if (prefix != null) {
serializer.writeAttribute(prefix, namespaceURI, localName, value);
} else if (namespaceURI != null) {
serializer.writeAttribute(namespaceURI, localName, value);
} else {
serializer.writeAttribute(localName, value);
}
}
}
static public Map<QName, String> getAttributes(Node node) {
Map<QName, String> atts = new HashMap<QName, String>();
NamedNodeMap nnm = node.getAttributes();
if (nnm != null) {
for (int i = 0; i < nnm.getLength(); i++) {
Attr att = (Attr) nnm.item(i);
String uri = att.getBaseURI();
String localname = att.getLocalName();
String prefix = att.getPrefix();
QName name;
if (uri == null) {
name = new QName(localname);
} else if (prefix == null) {
name = new QName(uri, localname);
} else {
name = new QName(uri, localname, prefix);
}
if (prefix == null
|| !(prefix.equals("xmlns") || prefix.equals("xml"))) {
atts.put(name, att.getValue());
}
}
}
return atts;
}
private void unmarshalParams(Element paramsElem) {
String xPath = paramsElem.getFirstChild().getNodeValue();
// create a Map of namespace prefixes
NamedNodeMap attributes = paramsElem.getAttributes();
if (attributes != null) {
int length = attributes.getLength();
Map<String, String> namespaceMap =
new HashMap<String, String>(length);
for (int i = 0; i < length; i++) {
Attr attr = (Attr)attributes.item(i);
String prefix = attr.getPrefix();
if (prefix != null && prefix.equals("xmlns")) {
namespaceMap.put(attr.getLocalName(), attr.getValue());
}
}
this.params = new XPathFilterParameterSpec(xPath, namespaceMap);
} else {
this.params = new XPathFilterParameterSpec(xPath);
}
}
private void unmarshalParams(Element paramsElem) {
String xPath = paramsElem.getFirstChild().getNodeValue();
// create a Map of namespace prefixes
NamedNodeMap attributes = paramsElem.getAttributes();
if (attributes != null) {
int length = attributes.getLength();
Map<String, String> namespaceMap =
new HashMap<String, String>(length);
for (int i = 0; i < length; i++) {
Attr attr = (Attr)attributes.item(i);
String prefix = attr.getPrefix();
if (prefix != null && prefix.equals("xmlns")) {
namespaceMap.put(attr.getLocalName(), attr.getValue());
}
}
this.params = new XPathFilterParameterSpec(xPath, namespaceMap);
} else {
this.params = new XPathFilterParameterSpec(xPath);
}
}
protected boolean parseAttributes(Element element, ParserContext ctx, MutableBeanMetadata 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;
}
if ("createdFromAPI".equals(name) || "abstract".equals(name)) {
bean.setScope(BeanMetadata.SCOPE_PROTOTYPE);
} else {
if ("depends-on".equals(name)) {
bean.addDependsOn(val);
} else if ("name".equals(name)) {
processNameAttribute(element, ctx, bean, val);
} else if ("bus".equals(name)) {
processBusAttribute(element, ctx, bean, val);
} else if (!"id".equals(name) && isAttribute(pre, name)) {
mapAttribute(bean, element, name, val, ctx);
}
}
}
return setBus; // 'setBus' is always false
}
public QName getAttributeName(int i) {
Attr at = getAttribute(i);
String prefix = at.getPrefix();
String ln = getLocalName(at);
// at.getNodeName();
String ns = at.getNamespaceURI();
if (prefix == null) {
return new QName(ns, ln);
}
return new QName(ns, ln, prefix);
}
private void unmarshalParams(Element curXPathElem) throws MarshalException
{
List<XPathType> list = new ArrayList<XPathType>();
while (curXPathElem != null) {
String xPath = curXPathElem.getFirstChild().getNodeValue();
String filterVal = DOMUtils.getAttributeValue(curXPathElem,
"Filter");
if (filterVal == null) {
throw new MarshalException("filter cannot be null");
}
XPathType.Filter filter = null;
if (filterVal.equals("intersect")) {
filter = XPathType.Filter.INTERSECT;
} else if (filterVal.equals("subtract")) {
filter = XPathType.Filter.SUBTRACT;
} else if (filterVal.equals("union")) {
filter = XPathType.Filter.UNION;
} else {
throw new MarshalException("Unknown XPathType filter type" +
filterVal);
}
NamedNodeMap attributes = curXPathElem.getAttributes();
if (attributes != null) {
int length = attributes.getLength();
Map<String, String> namespaceMap =
new HashMap<String, String>(length);
for (int i = 0; i < length; i++) {
Attr attr = (Attr)attributes.item(i);
String prefix = attr.getPrefix();
if (prefix != null && prefix.equals("xmlns")) {
namespaceMap.put(attr.getLocalName(), attr.getValue());
}
}
list.add(new XPathType(xPath, filter, namespaceMap));
} else {
list.add(new XPathType(xPath, filter));
}
curXPathElem = DOMUtils.getNextSiblingElement(curXPathElem);
}
this.params = new XPathFilter2ParameterSpec(list);
}
private void unmarshalParams(Element curXPathElem) throws MarshalException
{
List<XPathType> list = new ArrayList<XPathType>();
while (curXPathElem != null) {
String xPath = curXPathElem.getFirstChild().getNodeValue();
String filterVal = DOMUtils.getAttributeValue(curXPathElem,
"Filter");
if (filterVal == null) {
throw new MarshalException("filter cannot be null");
}
XPathType.Filter filter = null;
if (filterVal.equals("intersect")) {
filter = XPathType.Filter.INTERSECT;
} else if (filterVal.equals("subtract")) {
filter = XPathType.Filter.SUBTRACT;
} else if (filterVal.equals("union")) {
filter = XPathType.Filter.UNION;
} else {
throw new MarshalException("Unknown XPathType filter type" +
filterVal);
}
NamedNodeMap attributes = curXPathElem.getAttributes();
if (attributes != null) {
int length = attributes.getLength();
Map<String, String> namespaceMap =
new HashMap<String, String>(length);
for (int i = 0; i < length; i++) {
Attr attr = (Attr)attributes.item(i);
String prefix = attr.getPrefix();
if (prefix != null && prefix.equals("xmlns")) {
namespaceMap.put(attr.getLocalName(), attr.getValue());
}
}
list.add(new XPathType(xPath, filter, namespaceMap));
} else {
list.add(new XPathType(xPath, filter));
}
curXPathElem = DOMUtils.getNextSiblingElement(curXPathElem);
}
this.params = new XPathFilter2ParameterSpec(list);
}
private void unmarshalParams(Element curXPathElem) throws MarshalException
{
List<XPathType> list = new ArrayList<XPathType>();
while (curXPathElem != null) {
String xPath = curXPathElem.getFirstChild().getNodeValue();
String filterVal = DOMUtils.getAttributeValue(curXPathElem,
"Filter");
if (filterVal == null) {
throw new MarshalException("filter cannot be null");
}
XPathType.Filter filter = null;
if (filterVal.equals("intersect")) {
filter = XPathType.Filter.INTERSECT;
} else if (filterVal.equals("subtract")) {
filter = XPathType.Filter.SUBTRACT;
} else if (filterVal.equals("union")) {
filter = XPathType.Filter.UNION;
} else {
throw new MarshalException("Unknown XPathType filter type" +
filterVal);
}
NamedNodeMap attributes = curXPathElem.getAttributes();
if (attributes != null) {
int length = attributes.getLength();
Map<String, String> namespaceMap =
new HashMap<String, String>(length);
for (int i = 0; i < length; i++) {
Attr attr = (Attr)attributes.item(i);
String prefix = attr.getPrefix();
if (prefix != null && prefix.equals("xmlns")) {
namespaceMap.put(attr.getLocalName(), attr.getValue());
}
}
list.add(new XPathType(xPath, filter, namespaceMap));
} else {
list.add(new XPathType(xPath, filter));
}
curXPathElem = DOMUtils.getNextSiblingElement(curXPathElem);
}
this.params = new XPathFilter2ParameterSpec(list);
}
private void unmarshalParams(Element curXPathElem) throws MarshalException
{
List<XPathType> list = new ArrayList<XPathType>();
while (curXPathElem != null) {
String xPath = curXPathElem.getFirstChild().getNodeValue();
String filterVal = DOMUtils.getAttributeValue(curXPathElem,
"Filter");
if (filterVal == null) {
throw new MarshalException("filter cannot be null");
}
XPathType.Filter filter = null;
if (filterVal.equals("intersect")) {
filter = XPathType.Filter.INTERSECT;
} else if (filterVal.equals("subtract")) {
filter = XPathType.Filter.SUBTRACT;
} else if (filterVal.equals("union")) {
filter = XPathType.Filter.UNION;
} else {
throw new MarshalException("Unknown XPathType filter type" +
filterVal);
}
NamedNodeMap attributes = curXPathElem.getAttributes();
if (attributes != null) {
int length = attributes.getLength();
Map<String, String> namespaceMap =
new HashMap<String, String>(length);
for (int i = 0; i < length; i++) {
Attr attr = (Attr)attributes.item(i);
String prefix = attr.getPrefix();
if (prefix != null && prefix.equals("xmlns")) {
namespaceMap.put(attr.getLocalName(), attr.getValue());
}
}
list.add(new XPathType(xPath, filter, namespaceMap));
} else {
list.add(new XPathType(xPath, filter));
}
curXPathElem = DOMUtils.getNextSiblingElement(curXPathElem);
}
this.params = new XPathFilter2ParameterSpec(list);
}
/**
* Check if the attribute node is a namespace definition.
*
* @param attr
* @return
*/
public static boolean isNamespaceDef(Attr attr) {
String prefix = attr.getPrefix();
return (prefix != null && prefix.equals(XMLConstants.XMLNS_ATTRIBUTE))
|| attr.getNodeName().equals(XMLConstants.XMLNS_ATTRIBUTE);
}