List of usage examples for org.w3c.dom NamedNodeMap getNamedItem
public Node getNamedItem(String name);
From source file:edu.eurac.commul.pepperModules.mmax2.Salt2MMAXMapping.java
public static SRelationSourceTypeMatchCondition parseSRelationSourceTypeMatchCondition(Node node) { NamedNodeMap attributes = node.getAttributes(); Node sourceTypeAttributeNode = attributes.getNamedItem(SREL_SOURCE_TYPE_REGEXP); String sourceTypeRegExp = null; if (sourceTypeAttributeNode != null) { sourceTypeRegExp = sourceTypeAttributeNode.getNodeValue(); attributes.removeNamedItem(SREL_SOURCE_TYPE_REGEXP); } else {/* ww w . j a v a 2s . c o m*/ throw new PepperModuleException("'" + SREL_SOURCE_TYPE_REGEXP + " attribute not found on SRelation SourceType Match Condition '" + node + "'"); } if (attributes.getLength() != 0) { throw new PepperModuleException( "Additional unexpected attributes found on SRelation SourceType Match Condition '" + node + "'"); } return new SRelationSourceTypeMatchCondition(Pattern.compile(sourceTypeRegExp)); }
From source file:edu.eurac.commul.pepperModules.mmax2.Salt2MMAXMapping.java
public static SRelationTargetTypeMatchCondition parseSRelationTargetTypeMatchCondition(Node node) { NamedNodeMap attributes = node.getAttributes(); Node targetTypeAttributeNode = attributes.getNamedItem(SREL_TARGET_TYPE_REGEXP); String targetTypeRegExp = null; if (targetTypeAttributeNode != null) { targetTypeRegExp = targetTypeAttributeNode.getNodeValue(); attributes.removeNamedItem(SREL_TARGET_TYPE_REGEXP); } else {/*from w w w. j a v a2s . c o m*/ throw new PepperModuleException("'" + SREL_TARGET_TYPE_REGEXP + " attribute not found on SRelation TargetType Match Condition '" + node + "'"); } if (attributes.getLength() != 0) { throw new PepperModuleException( "Additional unexpected attributes found on SRelation TargetType Match Condition '" + node + "'"); } return new SRelationTargetTypeMatchCondition(Pattern.compile(targetTypeRegExp)); }
From source file:edu.eurac.commul.pepperModules.mmax2.Salt2MMAXMapping.java
public static SAnnotationStringValueMatchCondition parseSAnnotationStringValueMatchCondition(Node node) { NamedNodeMap attributes = node.getAttributes(); Node stringValueAttributeNode = attributes.getNamedItem(SANN_STRING_VALUE_REGEXP); String stringValueRegExp = null; if (stringValueAttributeNode != null) { stringValueRegExp = stringValueAttributeNode.getNodeValue(); attributes.removeNamedItem(SANN_STRING_VALUE_REGEXP); } else {//from w ww.ja va2s . c o m throw new PepperModuleException("'" + SANN_STRING_VALUE_REGEXP + "' attribute not found on SAnnotation String Value Match Condition '" + node + "'"); } if (attributes.getLength() != 0) { throw new PepperModuleException( "Additional unexpected attributes found on SAnnotation String Value Match Condition '" + node + "'"); } return new SAnnotationStringValueMatchCondition(Pattern.compile(stringValueRegExp)); }
From source file:com.microsoft.tfs.core.clients.versioncontrol.workspacecache.WorkspaceInfo.java
/** * Creates an instance from the XML representation used in the cache file. * * @param serverINfo/*from ww w .j a v a 2 s .co m*/ * the workspace's host server * @param workspaceInfoNode * the {@value #XML_WORKSPACE_INFO} node to load from * @return an instance of a {@link WorkspaceInfo} created from the XML */ public static WorkspaceInfo loadFromXML(final InternalServerInfo serverInfo, final Element workspaceInfoNode) { final WorkspaceInfo workspaceInfo = new WorkspaceInfo(); workspaceInfo.serverInfo = serverInfo; final NamedNodeMap attributes = workspaceInfoNode.getAttributes(); Check.notNull(attributes, "attributes"); //$NON-NLS-1$ workspaceInfo.name = getStringValue(attributes.getNamedItem(XML_NAME)); workspaceInfo.ownerName = getStringValue(attributes.getNamedItem(XML_OWNER_NAME)); workspaceInfo.ownerDisplayName = getStringValue(attributes.getNamedItem(XML_OWNER_DISPLAY_NAME)); // The "ownerDisplayName" attribute was absent for some users. // Expecting it to always exist was causing a NullPointerException. // Now, use the "ownerName" if the "ownerDisplayName" is missing. if (StringUtil.isNullOrEmpty(workspaceInfo.ownerDisplayName)) { workspaceInfo.ownerDisplayName = workspaceInfo.getOwnerName(); } workspaceInfo.computer = getStringValue(attributes.getNamedItem(XML_COMPUTER)); workspaceInfo.comment = getStringValue(attributes.getNamedItem(XML_COMMENT)); workspaceInfo.securityToken = getStringValue(attributes.getNamedItem(XML_SECURITY_TOKEN), null); workspaceInfo.isLocalWorkspace = getBooleanValue(attributes.getNamedItem(XML_IS_LOCAL_WORKSPACE)); workspaceInfo.lastSavedCheckinTimeStamp = getTimeStampValue( attributes.getNamedItem(XML_LAST_SAVED_CHECKIN_TIME_STAMP)); workspaceInfo.options = getWorkspaceOptionsValue(attributes.getNamedItem(OPTIONS_NAME)); for (final Element child : DOMUtils.getChildElements(workspaceInfoNode)) { final String name = child.getNodeName(); if (name.equals(XML_MAPPED_PATHS)) { final Element[] mappedPathElements = DOMUtils.getChildElements(child, XML_MAPPED_PATH); workspaceInfo.mappedPaths = new String[mappedPathElements.length]; for (int i = 0; i < mappedPathElements.length; i++) { workspaceInfo.mappedPaths[i] = getStringValue( mappedPathElements[i].getAttributes().getNamedItem(XML_PATH)); } } else if (name.equals(XML_WORKING_FOLDERS)) { // Backwards compatibility with PDC build of Dev11 (and // earlier). final Element[] mapElements = DOMUtils.getChildElements(child, XML_MAP); workspaceInfo.mappedPaths = new String[mapElements.length]; for (int i = 0; i < mapElements.length; i++) { workspaceInfo.mappedPaths[i] = getStringValue( mapElements[i].getAttributes().getNamedItem(XML_LOCAL_PATH)); } workspaceInfo.state = LocalWorkspaceState.MODIFIED; } else if (name.equals(XML_LAST_SAVED_CHECKIN)) { Check.isTrue(DOMUtils.getChildElements(child, SavedCheckin.XML_SAVED_CHECKIN).length == 1, MessageFormat.format("Wrong number of LastSavedCheckin children: {0}", //$NON-NLS-1$ DOMUtils.getChildElements(child, SavedCheckin.XML_SAVED_CHECKIN).length)); workspaceInfo.lastSavedCheckin = SavedCheckin .loadFromXML(DOMUtils.getFirstChildElement(child, SavedCheckin.XML_SAVED_CHECKIN)); } else if (name.equals(XML_OWNER_ALIASES)) { final Element[] aliasNodes = DOMUtils.getChildElements(child, XML_OWNER_ALIAS); final List<String> aliases = new ArrayList<String>(aliasNodes.length); for (int i = 0; i < aliasNodes.length; i++) { final String alias = getStringValue( aliasNodes[i].getAttributes().getNamedItem(XML_OWNER_ALIAS)); if (!StringUtil.isNullOrEmpty(alias)) { aliases.add(alias); } else { log.error(MessageFormat.format("Owner alias loaded from cache was null or empty: {0}", //$NON-NLS-1$ workspaceInfo)); } } workspaceInfo.ownerAliases = aliases.toArray(new String[aliases.size()]); } else { log.warn(MessageFormat.format("Unknown workspace child node: {0}", name)); //$NON-NLS-1$ } } if (workspaceInfo.ownerAliases == null) { workspaceInfo.ownerAliases = new String[0]; } // Since we've just loaded the workspace, make sure it is marked as // clean. workspaceInfo.markClean(); return workspaceInfo; }
From source file:net.hasor.rsf.spring.parser.RsfDefinitionParser.java
/** ? */ protected String revertProperty(NamedNodeMap attributes, String attName) { Node attNode = attributes.getNamedItem(attName); return (attNode != null) ? attNode.getNodeValue() : null; }
From source file:com.aionemu.packetsamurai.parser.valuereader.ClientStringReader.java
public boolean loadReaderFromXML(Node n) { NamedNodeMap enumAttrs = n.getAttributes(); Node nameAttr = enumAttrs.getNamedItem("real"); if (nameAttr != null) { this._real = Boolean.parseBoolean(nameAttr.getNodeValue()); }/*from w w w . j a v a 2 s. com*/ return true; }
From source file:edu.eurac.commul.pepperModules.mmax2.Salt2MMAXMapping.java
public static ArrayList<SAnnotationMapping> getSAnnotationMappingsFromFile(MMAX2ExporterProperties props) { ArrayList<SAnnotationMapping> mappings = new ArrayList<SAnnotationMapping>(); if (props.getSAnnotationMappingsFilePath() != null) { DocumentBuilder documentBuilder; try {/*from ww w . j a v a 2s .c o m*/ documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new PepperModuleException(e.getMessage(), e); } File configurationFile = new File(props.getSAnnotationMappingsFilePath()); NodeList nodes = null; try { nodes = documentBuilder.parse(configurationFile).getDocumentElement().getChildNodes(); } catch (SAXException e) { throw new PepperModuleException(e.getMessage(), e); } catch (IOException e) { throw new PepperModuleException(e.getMessage(), e); } for (int i = 0; i < nodes.getLength(); i++) { Node xmlNode = nodes.item(i); if (xmlNode.getNodeType() != Node.ELEMENT_NODE) { continue; } String nodeName = xmlNode.getNodeName(); if (nodeName.equals(MAPPING_NODE_NAME)) { Node mapping_infos = null; Node condition_infos = null; NodeList sub_nodes = xmlNode.getChildNodes(); for (int j = 0; j < sub_nodes.getLength(); j++) { Node sub_xmlNode = sub_nodes.item(j); if (sub_xmlNode.getNodeType() != Node.ELEMENT_NODE) { continue; } String sub_nodeName = sub_xmlNode.getNodeName(); if (sub_nodeName.equals(MAPPING_INFOS_NODE_NAME)) { if (mapping_infos == null) { mapping_infos = sub_xmlNode; } else { throw new PepperModuleException( "More than one mapping infos defined on SAnnotation Mapping '" + xmlNode + "'"); } } else if (sub_nodeName.equals(CONDITION_NODE_NAME)) { if (condition_infos == null) { condition_infos = sub_xmlNode; } else { throw new PepperModuleException( "More than one match condition defined on SAnnotation Mapping '" + xmlNode + "'"); } } else { throw new PepperModuleException("Unknown type of Node '" + sub_xmlNode + "' with name '" + sub_nodeName + "' on SAnnotation Mapping '" + xmlNode + "'"); } } NamedNodeMap mapping_attributes = mapping_infos.getAttributes(); Node associatedSchemeNameAttribute = mapping_attributes.getNamedItem(SANN_MAPPING_ASS_SCHEME); if (associatedSchemeNameAttribute == null) { throw new PepperModuleException("associated scheme name '" + SANN_MAPPING_ASS_SCHEME + "' on SAnnotation Mapping infos Node '" + mapping_infos + "' is not defined..."); } String associatedSchemeName = associatedSchemeNameAttribute.getNodeValue(); mapping_attributes.removeNamedItem(SANN_MAPPING_ASS_SCHEME); Node associatedAttributeNameAttribute = mapping_attributes.getNamedItem(SANN_MAPPING_ASS_ATTR); if (associatedAttributeNameAttribute == null) { throw new PepperModuleException("associated attribute name '" + SANN_MAPPING_ASS_ATTR + "' on SAnnotation Mapping infos Node '" + mapping_infos + "' is not defined..."); } String associatedAttributeName = associatedAttributeNameAttribute.getNodeValue(); mapping_attributes.removeNamedItem(SANN_MAPPING_ASS_ATTR); SAnnotationMatchCondition condition = parseSAnnotationMatchCondition(condition_infos); if (mapping_attributes.getLength() != 0) { ArrayList<String> unknownAttributes = new ArrayList<String>(); for (int j = 0; j < mapping_attributes.getLength(); j++) { unknownAttributes.add(mapping_attributes.item(j).getNodeName()); } throw new PepperModuleException( "Unknown attributes '" + StringUtils.join(unknownAttributes, ",") + "' on SAnnotation Mapping infos Node '" + mapping_infos + "'"); } mappings.add(new SAnnotationMapping(condition, associatedSchemeName, associatedAttributeName)); } else if (xmlNode.getNodeType() == Node.ELEMENT_NODE) { throw new PepperModuleException("Unknown type of Node among Mapping nodes '" + xmlNode + "' with name '" + nodeName + "'"); } } } return mappings; }
From source file:edu.eurac.commul.pepperModules.mmax2.Salt2MMAXMapping.java
public static ArrayList<SRelationMapping> getSRelationMappingsFromFile(MMAX2ExporterProperties props) { ArrayList<SRelationMapping> mappings = new ArrayList<SRelationMapping>(); if (props.getSRelationMappingsFilePath() != null) { DocumentBuilder documentBuilder; try {/*w w w. j av a 2 s .co m*/ documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new PepperModuleException(e.getMessage(), e); } File configurationFile = new File(props.getSRelationMappingsFilePath()); NodeList nodes = null; try { nodes = documentBuilder.parse(configurationFile).getDocumentElement().getChildNodes(); } catch (SAXException e) { throw new PepperModuleException(e.getMessage(), e); } catch (IOException e) { throw new PepperModuleException(e.getMessage(), e); } for (int i = 0; i < nodes.getLength(); i++) { Node xmlNode = nodes.item(i); if (xmlNode.getNodeType() != Node.ELEMENT_NODE) { continue; } String nodeName = xmlNode.getNodeName(); if (nodeName.equals(MAPPING_NODE_NAME)) { Node mapping_infos = null; Node condition_infos = null; NodeList sub_nodes = xmlNode.getChildNodes(); for (int j = 0; j < sub_nodes.getLength(); j++) { Node sub_xmlNode = sub_nodes.item(j); if (sub_xmlNode.getNodeType() != Node.ELEMENT_NODE) { continue; } String sub_nodeName = sub_xmlNode.getNodeName(); if (sub_nodeName.equals(MAPPING_INFOS_NODE_NAME)) { if (mapping_infos == null) { mapping_infos = sub_xmlNode; } else { throw new PepperModuleException( "More than one mapping infos defined on SRelation Mapping '" + xmlNode + "'"); } } else if (sub_nodeName.equals(CONDITION_NODE_NAME)) { if (condition_infos == null) { condition_infos = sub_xmlNode; } else { throw new PepperModuleException( "More than one match condition defined on SRelation Mapping '" + xmlNode + "'"); } } else if (!sub_nodeName.equals("")) { throw new PepperModuleException("Unknown type of Node '" + sub_xmlNode + "' with name '" + sub_nodeName + "' on SRelation Mapping '" + xmlNode + "'"); } } NamedNodeMap mapping_attributes = mapping_infos.getAttributes(); Node sourceDestSchemeNode = mapping_attributes.getNamedItem(SREL_MAPP_SOURCE_SCHEME_NAME); if (sourceDestSchemeNode == null) { throw new PepperModuleException("Source destination scheme '" + SREL_MAPP_SOURCE_SCHEME_NAME + "' on SRelation Mapping infos Node '" + mapping_infos + "' is not defined..."); } mapping_attributes.removeNamedItem(SREL_MAPP_SOURCE_SCHEME_NAME); String sourceSchemeName = sourceDestSchemeNode.getNodeValue(); Node targetDestSchemeNode = mapping_attributes.getNamedItem(SREL_MAPP_TARGET_SCHEME_NAME); if (targetDestSchemeNode == null) { throw new PepperModuleException("Target destination scheme '" + SREL_MAPP_TARGET_SCHEME_NAME + "' on SRelation Mapping infos Node '" + mapping_infos + "' is not defined..."); } mapping_attributes.removeNamedItem(SREL_MAPP_TARGET_SCHEME_NAME); String targetSchemeName = targetDestSchemeNode.getNodeValue(); Node destAttrNode = mapping_attributes.getNamedItem(SREL_MAPP_POINTER_ATTR_NAME); if (destAttrNode == null) { throw new PepperModuleException("Source attribute '" + SREL_MAPP_POINTER_ATTR_NAME + "' on SRelation Mapping infos Node '" + mapping_infos + "' is not defined..."); } mapping_attributes.removeNamedItem(SREL_MAPP_POINTER_ATTR_NAME); String attrName = destAttrNode.getNodeValue(); SRelationMatchCondition condition = parseSRelationMatchCondition(condition_infos); if (mapping_attributes.getLength() != 0) { ArrayList<String> unknownAttributes = new ArrayList<String>(); for (int j = 0; j < mapping_attributes.getLength(); j++) { unknownAttributes.add(mapping_attributes.item(j).getNodeName()); } throw new PepperModuleException( "Unknown attributes '" + StringUtils.join(unknownAttributes, ",") + "' on SRelation Mapping infos Node '" + mapping_infos + "'"); } mappings.add(new SRelationMapping(condition, sourceSchemeName, targetSchemeName, attrName)); } else { throw new PepperModuleException("Unknown type of Node among Mapping nodes '" + xmlNode + "' with name '" + nodeName + "'"); } } } return mappings; }
From source file:net.sourceforge.ajaxtags.tags.AjaxAnchorsTag.java
/** * Rewrite link. Change (or create) "onclick" attribute, set "href" attribute to * "javascript://nop/"./* ww w. j ava2s . c om*/ * * @param link * node of document with link * @param target * target of request */ protected final void rewriteLink(final Node link, final String target) { final NamedNodeMap map = link.getAttributes(); final Attr href = (Attr) map.getNamedItem("href"); if (href != null) { Attr onclick = (Attr) map.getNamedItem("onclick"); if (onclick == null) { onclick = link.getOwnerDocument().createAttribute("onclick"); map.setNamedItem(onclick); } onclick.setValue(getOnclickAjax(target, href.getValue(), getOptionsBuilder())); href.setValue("javascript://nop/"); } }
From source file:com.fluidops.iwb.deepzoom.CXMLServlet.java
static void readImageCollectionFile(String collection) { InputStream stream = null;//w ww . java 2 s . c om try { stream = new FileInputStream(collection); Document doc = null; doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(stream); XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); XPathExpression expr = xpath.compile("//I"); NodeList result = (NodeList) expr.evaluate(doc, XPathConstants.NODESET); for (int i = 0; i < result.getLength(); i++) { Node node = result.item(i); NamedNodeMap map = node.getAttributes(); String source = map.getNamedItem("Source").getNodeValue(); String id = map.getNamedItem("Id").getNodeValue(); source = source.substring("dzimages/".length(), source.lastIndexOf(".xml")); ids.put(source, id); } } catch (RuntimeException e) { logger.error(e.getMessage(), e); } catch (Exception e) { logger.error(e.getMessage(), e); } finally { IOUtils.closeQuietly(stream); } }