本文整理匯總了Java中org.w3c.dom.Node.getLocalName方法的典型用法代碼示例。如果您正苦於以下問題:Java Node.getLocalName方法的具體用法?Java Node.getLocalName怎麽用?Java Node.getLocalName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.w3c.dom.Node
的用法示例。
在下文中一共展示了Node.getLocalName方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: findDuplicateElements
import org.w3c.dom.Node; //導入方法依賴的package包/類
static void findDuplicateElements(@NonNull Element parent, @NonNull ProblemProvider pp, FileObject config) {
NodeList l = parent.getChildNodes();
int nodeCount = l.getLength();
Set<String> known = new HashSet<String>();
for (int i = 0; i < nodeCount; i++) {
if (l.item(i).getNodeType() == Node.ELEMENT_NODE) {
Node node = l.item(i);
String localName = node.getLocalName();
localName = localName == null ? node.getNodeName() : localName;
String id = localName + "|" + node.getNamespaceURI();
if (!known.add(id)) {
//we have a duplicate;
pp.setProblem(ProjectProblem.createWarning(
TXT_Problem_Broken_Config2(),
DESC_Problem_Broken_Config2(),
new ProblemReporterImpl.MavenProblemResolver(ProblemReporterImpl.createOpenFileAction(config), BROKEN_NBCONFIG)));
}
}
}
}
示例2: getPrefixes
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* @return mapping from prefix to namespace.
*/
public Map<String, String> getPrefixes() {
Map<String,String> prefixes = new HashMap<String,String>();
NamedNodeMap nodes = getPeer().getAttributes();
for (int i = 0; i < nodes.getLength(); i++) {
Node n = nodes.item(i);
String name = n.getLocalName();
String prefix = n.getPrefix();
final String xmlns = XMLConstants.XMLNS_ATTRIBUTE; //NOI18N
if (xmlns.equals(name) || // default namespace
xmlns.equals(prefix)) { // namespace prefix
String ns = n.getNodeValue();
prefixes.put(name, ns);
}
}
String defaultNamespace = prefixes.remove(XMLConstants.XMLNS_ATTRIBUTE);
if (defaultNamespace != null) {
prefixes.put(XMLConstants.DEFAULT_NS_PREFIX, defaultNamespace);
}
return prefixes;
}
示例3: fillQName
import org.w3c.dom.Node; //導入方法依賴的package包/類
private void fillQName(QName toFill, Node node) {
final String prefix = node.getPrefix();
final String localName = node.getLocalName();
final String rawName = node.getNodeName();
final String namespace = node.getNamespaceURI();
toFill.uri = (namespace != null && namespace.length() > 0) ? fSymbolTable.addSymbol(namespace) : null;
toFill.rawname = (rawName != null) ? fSymbolTable.addSymbol(rawName) : XMLSymbols.EMPTY_STRING;
// Is this a DOM level1 document?
if (localName == null) {
int k = rawName.indexOf(':');
if (k > 0) {
toFill.prefix = fSymbolTable.addSymbol(rawName.substring(0, k));
toFill.localpart = fSymbolTable.addSymbol(rawName.substring(k + 1));
}
else {
toFill.prefix = XMLSymbols.EMPTY_STRING;
toFill.localpart = toFill.rawname;
}
}
else {
toFill.prefix = (prefix != null) ? fSymbolTable.addSymbol(prefix) : XMLSymbols.EMPTY_STRING;
toFill.localpart = (localName != null) ? fSymbolTable.addSymbol(localName) : XMLSymbols.EMPTY_STRING;
}
}
示例4: isDomainElement
import org.w3c.dom.Node; //導入方法依賴的package包/類
protected boolean isDomainElement(Node e) {
if (! (e instanceof Element)) {
return false;
}
QName q = new QName(e.getNamespaceURI(), e.getLocalName());
return getQNames().contains(q) || getElementNames().contains(q.getLocalPart());
}
示例5: getQName
import org.w3c.dom.Node; //導入方法依賴的package包/類
public static QName getQName(Node n) {
String namespace = n.getNamespaceURI();
String localName = n.getLocalName();
String prefix = n.getPrefix();
assert(localName != null);
if (namespace == null && prefix == null) {
return new QName(localName);
} else if (namespace != null && prefix == null) {
return new QName(namespace, localName);
} else {
return new QName(namespace, localName, prefix);
}
}
示例6: XmlPlatformConfig
import org.w3c.dom.Node; //導入方法依賴的package包/類
public XmlPlatformConfig(FileSystem fileSystem, Path configDir, Path cacheDir, String configName)
throws IOException, SAXException, ParserConfigurationException {
super(fileSystem, configDir, cacheDir);
Path file = configDir.resolve(configName + ".xml");
if (Files.exists(file)) {
LOGGER.info("Platform configuration defined by XML file {}", file);
try (InputStream is = Files.newInputStream(file)) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(is);
Element root = doc.getDocumentElement();
root.normalize();
NodeList moduleNodes = root.getChildNodes();
for (int i = 0; i < moduleNodes.getLength(); i++) {
Node moduleNode = moduleNodes.item(i);
if (moduleNode.getNodeType() == Node.ELEMENT_NODE) {
String moduleName = moduleNode.getLocalName();
Map<Object, Object> properties = new HashMap<>();
NodeList propertyNodes = moduleNode.getChildNodes();
for (int j = 0; j < propertyNodes.getLength(); j++) {
Node propertyNode = propertyNodes.item(j);
if (propertyNode.getNodeType() == Node.ELEMENT_NODE) {
String propertyName = propertyNode.getLocalName();
Node child = propertyNode.getFirstChild();
String propertyValue = child != null ? child.getTextContent() : "";
properties.put(propertyName, propertyValue);
}
}
((InMemoryModuleConfigContainer) container).getConfigs().put(moduleName, new MapModuleConfig(properties, fileSystem));
}
}
}
} else {
LOGGER.info("Platform configuration XML file {} not found", file);
}
}
示例7: getLocalName
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* If the DOM was created using a DOM 1.0 API, the local name may be
* null. If so, get the local name from the qualified name before
* generating the SAX event.
*/
private static String getLocalName(Node node) {
final String localName = node.getLocalName();
if (localName == null) {
final String qname = node.getNodeName();
final int col = qname.lastIndexOf(':');
return (col > 0) ? qname.substring(col + 1) : qname;
}
return localName;
}
示例8: updateQName
import org.w3c.dom.Node; //導入方法依賴的package包/類
protected final void updateQName (Node node, QName qname){
String prefix = node.getPrefix();
String namespace = node.getNamespaceURI();
String localName = node.getLocalName();
// REVISIT: the symbols are added too often: start/endElement
// and in the namespaceFixup. Should reduce number of calls to symbol table.
qname.prefix = (prefix!=null && prefix.length()!=0)?fSymbolTable.addSymbol(prefix):null;
qname.localpart = (localName != null)?fSymbolTable.addSymbol(localName):null;
qname.rawname = fSymbolTable.addSymbol(node.getNodeName());
qname.uri = (namespace != null)?fSymbolTable.addSymbol(namespace):null;
}
示例9: getNodeName
import org.w3c.dom.Node; //導入方法依賴的package包/類
public String getNodeName(Node node){
String nodeName = node.getLocalName();
if (nodeName == null) {
nodeName = node.getNodeName();
}
return nodeName;
}
示例10: getType
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* Returns the type of the ResourceItem based on a node's attributes.
* @param node the node
* @return the ResourceType or null if it could not be inferred.
*/
static ResourceType getType(@NonNull Node node, @Nullable File from) {
String nodeName = node.getLocalName();
String typeString = null;
if (TAG_ITEM.equals(nodeName)) {
Attr attribute = (Attr) node.getAttributes().getNamedItemNS(null, ATTR_TYPE);
if (attribute != null) {
typeString = attribute.getValue();
}
} else if (TAG_EAT_COMMENT.equals(nodeName) || TAG_SKIP.equals(nodeName)) {
return null;
} else {
// the type is the name of the node.
typeString = nodeName;
}
if (typeString != null) {
ResourceType type = ResourceType.getEnum(typeString);
if (type != null) {
return type;
}
if (from != null) {
throw new RuntimeException(String.format("Unsupported type '%s' in file %s", typeString, from));
}
throw new RuntimeException(String.format("Unsupported type '%s'", typeString));
}
if (from != null) {
throw new RuntimeException(String.format("Unsupported node '%s' in file %s", nodeName, from));
}
throw new RuntimeException(String.format("Unsupported node '%s'", nodeName));
}
示例11: printlnCommon
import org.w3c.dom.Node; //導入方法依賴的package包/類
private static void printlnCommon(Node n) {
logger.log(Level.FINE, " nodeName=\"" + n.getNodeName() + "\"");
String val = n.getNamespaceURI();
if (val != null) {
logger.log(Level.FINE, " uri=\"" + val + "\"");
}
val = n.getPrefix();
if (val != null) {
logger.log(Level.FINE, " pre=\"" + val + "\"");
}
val = n.getLocalName();
if (val != null) {
logger.log(Level.FINE, " local=\"" + val + "\"");
}
val = n.getNodeValue();
if (val != null) {
logger.log(Level.FINE, " nodeValue=");
if (val.trim().equals("")) {
// Whitespace
logger.log(Level.FINE, "[WS]");
} else {
logger.log(Level.FINE, "\"" + n.getNodeValue() + "\"");
}
}
}
示例12: getFirstDetailEntryName
import org.w3c.dom.Node; //導入方法依賴的package包/類
public @XmlTransient @Nullable QName getFirstDetailEntryName() {
DetailType dt = getDetail();
if (dt != null) {
Node entry = dt.getDetail(0);
if (entry != null) {
return new QName(entry.getNamespaceURI(), entry.getLocalName());
}
}
return null;
}
示例13: verifyDOMIntegrity
import org.w3c.dom.Node; //導入方法依賴的package包/類
private static void verifyDOMIntegrity(Node node) {
switch (node.getNodeType()) {
case ELEMENT_NODE:
case ATTRIBUTE_NODE:
// DOM level 1?
if (node.getLocalName() == null) {
System.out.println("WARNING: DOM level 1 node found");
System.out.println(" -> node.getNodeName() = " + node.getNodeName());
System.out.println(" -> node.getNamespaceURI() = " + node.getNamespaceURI());
System.out.println(" -> node.getLocalName() = " + node.getLocalName());
System.out.println(" -> node.getPrefix() = " + node.getPrefix());
}
if (node.getNodeType() == ATTRIBUTE_NODE) return;
NamedNodeMap attrs = node.getAttributes();
for (int i = 0; i < attrs.getLength(); i++) {
verifyDOMIntegrity(attrs.item(i));
}
case DOCUMENT_NODE:
NodeList children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
verifyDOMIntegrity(children.item(i));
}
}
}
示例14: checkXMLs
import org.w3c.dom.Node; //導入方法依賴的package包/類
public boolean checkXMLs(Node template, Node source) {
if (source == null || template == null) {
return template == source;
}
String tname = template.getLocalName();
String tvalue = template.getNodeValue();
NamedNodeMap tattr = template.getAttributes();
NodeList tchildren = template.getChildNodes();
String sname = source.getLocalName();
String svalue = source.getNodeValue();
NamedNodeMap sattr = source.getAttributes();
NodeList schildren = source.getChildNodes();
if (tname != null && !tname.equals(sname)) {
return false;
}
if (tvalue != null && !tvalue.equals(svalue)) {
return false;
}
if (tattr != null && sattr != null) {
if (sattr.getLength() != tattr.getLength()) {
return false;
}
for (int i = 0; i < tattr.getLength(); i++) {
Attr t = (Attr) tattr.item(i);
Attr s = (Attr) sattr.getNamedItem(t.getName());
if (!checkXMLAttrs(t, s)) {
// ref.println(sname+": [expected attr: " + t +
// "; actual attr: " +s+"]");
return false;
}
}
} else if (tattr != null || sattr != null) {
return false;
}
for (int i = 0; i < tchildren.getLength(); i++) {
if (!checkXMLs(tchildren.item(i), schildren.item(i))) {
// ref.println(sname+": [expected node: "+tchildren.item(i)
// +"; actual node: "+schildren.item(i)+"]");
return false;
}
}
return true;
}
示例15: remove
import org.w3c.dom.Node; //導入方法依賴的package包/類
private final Node remove(AttrImpl attr, int index,
boolean addDefault) {
CoreDocumentImpl ownerDocument = ownerNode.ownerDocument();
String name = attr.getNodeName();
if (attr.isIdAttribute()) {
ownerDocument.removeIdentifier(attr.getValue());
}
if (hasDefaults() && addDefault) {
// If there's a default, add it instead
NamedNodeMapImpl defaults =
((ElementImpl) ownerNode).getDefaultAttributes();
Node d;
if (defaults != null &&
(d = defaults.getNamedItem(name)) != null &&
findNamePoint(name, index+1) < 0) {
NodeImpl clone = (NodeImpl)d.cloneNode(true);
if (d.getLocalName() !=null){
// we must rely on the name to find a default attribute
// ("test:attr"), but while copying it from the DOCTYPE
// we should not loose namespace URI that was assigned
// to the attribute in the instance document.
((AttrNSImpl)clone).namespaceURI = attr.getNamespaceURI();
}
clone.ownerNode = ownerNode;
clone.isOwned(true);
clone.isSpecified(false);
nodes.set(index, clone);
if (attr.isIdAttribute()) {
ownerDocument.putIdentifier(clone.getNodeValue(),
(ElementImpl)ownerNode);
}
} else {
nodes.remove(index);
}
} else {
nodes.remove(index);
}
// changed(true);
// remove reference to owner
attr.ownerNode = ownerDocument;
attr.isOwned(false);
// make sure it won't be mistaken with defaults in case it's
// reused
attr.isSpecified(true);
attr.isIdAttribute(false);
// notify document
ownerDocument.removedAttrNode(attr, ownerNode, name);
return attr;
}