List of usage examples for org.w3c.dom Element hasAttribute
public boolean hasAttribute(String name);
true
when an attribute with a given name is specified on this element or has a default value, false
otherwise. From source file:org.kalypsodeegree_impl.graphics.sld.SLDFactory.java
private static UOM readUOM(final Element symbolizerElement) { final UOM uom; if (symbolizerElement.hasAttribute("uom"))//$NON-NLS-1$ uom = UOM.valueOf(symbolizerElement.getAttribute("uom"));//$NON-NLS-1$ else// ww w .ja v a2 s .c o m uom = UOM.pixel; return uom; }
From source file:org.megadix.jfcm.utils.FcmIOTest.java
private void checkXmlAttribute(Element elem, String name, String value) { if (value == null) { assertFalse("Unexpected attribute: " + name, elem.hasAttribute(name)); } else {/* w ww . ja v a2s . c o m*/ assertEquals(value, elem.getAttribute(name)); } }
From source file:org.metaeffekt.dcc.commons.spring.xml.DCCConfigurationBeanDefinitionParser.java
private String parseString(Element element, String name, String defaultValue, BeanDefinitionRegistry registry) { String result = defaultValue; if (element.hasAttribute(name)) { result = element.getAttribute(name); // if the value does not exist of blanks (intentionally) if (!StringUtils.isBlank(result)) { // we trim... result = result.trim();/* w ww . j av a2 s. co m*/ // FIXME: what if this is international // in any case we remove multiple spaces result = result.replaceAll(" *", " "); } } return replaceVariables(registry, result); }
From source file:org.nuxeo.launcher.info.PackageInfo.java
/** * @since 8.3//from w ww .j a va 2s . c o m */ private Set<String> templates(Package pkg) { if (!(pkg instanceof LocalPackage)) { return Collections.emptySet(); } Set<String> templatesFound = new HashSet<>(); try { File installFile = ((LocalPackage) pkg).getInstallFile(); if (!installFile.exists()) { return Collections.emptySet(); } DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document dom = db.parse(installFile); NodeList nodes = dom.getDocumentElement().getElementsByTagName("config"); for (int i = 0; i < nodes.getLength(); i++) { Element node = (Element) nodes.item(i); if (!node.hasAttribute("addtemplate")) { continue; } StringTokenizer tokenizer = new StringTokenizer(node.getAttribute("addtemplate"), ","); while (tokenizer.hasMoreTokens()) { templatesFound.add(tokenizer.nextToken()); } } } catch (PackageException | ParserConfigurationException | SAXException | IOException e) { LogFactory.getLog(PackageInfo.class).warn("Could not parse install file for " + pkg.getName(), e); } return templatesFound; }
From source file:org.nuxeo.launcher.NuxeoLauncher.java
/** * @throws PackageException/*from ww w . j av a 2 s .com*/ * @throws IOException * @since 5.6 */ protected boolean showConfig() throws IOException, PackageException { InstanceInfo nxInstance = new InstanceInfo(); log.info("***** Nuxeo instance configuration *****"); nxInstance.NUXEO_CONF = configurationGenerator.getNuxeoConf().getPath(); log.info("NUXEO_CONF: " + nxInstance.NUXEO_CONF); nxInstance.NUXEO_HOME = configurationGenerator.getNuxeoHome().getPath(); log.info("NUXEO_HOME: " + nxInstance.NUXEO_HOME); // CLID try { nxInstance.clid = getConnectBroker().getCLID(); log.info("Instance CLID: " + nxInstance.clid); } catch (NoCLID e) { // leave nxInstance.clid unset } catch (Exception e) { // something went wrong in the NuxeoConnectClient initialization errorValue = EXIT_CODE_UNAUTHORIZED; log.error("Could not initialize NuxeoConnectClient", e); return false; } // distribution.properties DistributionInfo nxDistrib; File distFile = new File(configurationGenerator.getConfigDir(), "distribution.properties"); if (!distFile.exists()) { // fallback in the file in templates distFile = new File(configurationGenerator.getNuxeoHome(), "templates"); distFile = new File(distFile, "common"); distFile = new File(distFile, "config"); distFile = new File(distFile, "distribution.properties"); } try { nxDistrib = new DistributionInfo(distFile); } catch (IOException e) { nxDistrib = new DistributionInfo(); } nxInstance.distribution = nxDistrib; log.info("** Distribution"); log.info("- name: " + nxDistrib.name); log.info("- server: " + nxDistrib.server); log.info("- version: " + nxDistrib.version); log.info("- date: " + nxDistrib.date); log.info("- packaging: " + nxDistrib.packaging); // packages List<LocalPackage> pkgs = getConnectBroker().getPkgList(); log.info("** Packages:"); List<String> pkgTemplates = new ArrayList<String>(); for (LocalPackage pkg : pkgs) { nxInstance.packages.add(new PackageInfo(pkg)); log.info(String.format("- %s (version: %s - id: %s - state: %s)", pkg.getName(), pkg.getVersion(), pkg.getId(), PackageState.getByValue(pkg.getState()).getLabel())); // store template(s) added by this package try { File installFile = pkg.getInstallFile(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document dom = db.parse(installFile); NodeList nodes = dom.getDocumentElement().getElementsByTagName("config"); for (int i = 0; i < nodes.getLength(); i++) { Element node = (Element) nodes.item(i); if (node.hasAttribute("addtemplate")) { pkgTemplates.add(node.getAttribute("addtemplate")); } } } catch (Exception e) { log.warn("Could not parse install file for " + pkg.getName(), e); } } // nuxeo.conf ConfigurationInfo nxConfig = new ConfigurationInfo(); nxConfig.dbtemplate = configurationGenerator.extractDatabaseTemplateName(); log.info("** Templates:"); log.info("Database template: " + nxConfig.dbtemplate); String userTemplates = configurationGenerator.getUserTemplates(); StringTokenizer st = new StringTokenizer(userTemplates, ","); while (st.hasMoreTokens()) { String template = st.nextToken(); if (template.equals(nxConfig.dbtemplate)) { continue; } if (pkgTemplates.contains(template)) { nxConfig.pkgtemplates.add(template); log.info("Package template: " + template); } else { File testBase = new File(configurationGenerator.getNuxeoHome(), ConfigurationGenerator.TEMPLATES + File.separator + template); if (testBase.exists()) { nxConfig.basetemplates.add(template); log.info("Base template: " + template); } else { nxConfig.usertemplates.add(template); log.info("User template: " + template); } } } log.info("** Settings from nuxeo.conf:"); Properties userConfig = configurationGenerator.getUserConfig(); @SuppressWarnings("rawtypes") Enumeration nxConfEnum = userConfig.keys(); while (nxConfEnum.hasMoreElements()) { String key = (String) nxConfEnum.nextElement(); String value = userConfig.getProperty(key); if (key.equals("JAVA_OPTS")) { value = getJavaOptsProperty(); } KeyValueInfo kv = new KeyValueInfo(key, value); nxConfig.keyvals.add(kv); if (!key.contains("password") && !key.equals(ConfigurationGenerator.PARAM_STATUS_KEY)) { log.info(key + "=" + value); } else { log.info(key + "=********"); } } nxInstance.config = nxConfig; log.info("****************************************"); printInstanceXMLOutput(nxInstance); return true; }
From source file:org.openestate.io.openimmo.converters.OpenImmo_1_2_3.java
/** * Downgrade <ausricht_balkon_terrasse> elements to OpenImmo 1.2.2. * <p>//from w ww. j av a 2s . c om * The attributes "NORDOST", "NORDWEST", "SUEDOST", "SUEDWEST" for * <ausricht_balkon_terrasse> elements are not available in version * 1.2.2. * <p> * Any occurences of these values are replaced by the single components - * e.g. "NORDOST" is removed and "NORD" + "OST" is set. * * @param doc OpenImmo document in version 1.2.3 * @throws JaxenException */ protected void downgradeAusrichtBalkonTerrasseElements(Document doc) throws JaxenException { List nodes = XmlUtils.newXPath( "/io:openimmo/io:anbieter/io:immobilie/io:ausstattung/io:ausricht_balkon_terrasse[@NORDOST or @NORDWEST or @SUEDOST or @SUEDWEST]", doc).selectNodes(doc); for (Object item : nodes) { Element node = (Element) item; if (node.hasAttribute("NORDOST")) { String value = StringUtils.trimToEmpty(node.getAttribute("NORDOST")).toLowerCase(); if (value.equals("1") || value.equals("true")) { node.setAttribute("NORD", "true"); node.setAttribute("OST", "true"); } node.removeAttribute("NORDOST"); } if (node.hasAttribute("NORDWEST")) { String value = StringUtils.trimToEmpty(node.getAttribute("NORDWEST")).toLowerCase(); if (value.equals("1") || value.equals("true")) { node.setAttribute("NORD", "true"); node.setAttribute("WEST", "true"); } node.removeAttribute("NORDWEST"); } if (node.hasAttribute("SUEDOST")) { String value = StringUtils.trimToEmpty(node.getAttribute("SUEDOST")).toLowerCase(); if (value.equals("1") || value.equals("true")) { node.setAttribute("SUED", "true"); node.setAttribute("OST", "true"); } node.removeAttribute("SUEDOST"); } if (node.hasAttribute("SUEDWEST")) { String value = StringUtils.trimToEmpty(node.getAttribute("SUEDWEST")).toLowerCase(); if (value.equals("1") || value.equals("true")) { node.setAttribute("SUED", "true"); node.setAttribute("WEST", "true"); } node.removeAttribute("SUEDWEST"); } } }
From source file:org.openmrs.module.kenyaemr.regimen.RegimenManager.java
/** * Loads definitions from an input stream containing XML * @param stream the path to XML resource * @throws ParserConfigurationException/* www . ja v a 2s . co m*/ * @throws IOException * @throws SAXException */ public void loadDefinitionsFromXML(InputStream stream) throws ParserConfigurationException, IOException, SAXException { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = dbFactory.newDocumentBuilder(); Document document = builder.parse(stream); Element root = document.getDocumentElement(); // Parse each category NodeList categoryNodes = root.getElementsByTagName("category"); for (int c = 0; c < categoryNodes.getLength(); c++) { Element categoryElement = (Element) categoryNodes.item(c); String categoryCode = categoryElement.getAttribute("code"); String masterSetUuid = categoryElement.getAttribute("masterSetUuid"); Concept masterSetConcept = MetadataUtils.existing(Concept.class, masterSetUuid); masterSetConcepts.put(categoryCode, masterSetConcept.getConceptId()); Map<String, DrugReference> categoryDrugs = new HashMap<String, DrugReference>(); List<RegimenDefinitionGroup> categoryGroups = new ArrayList<RegimenDefinitionGroup>(); // Parse all drug concepts for this category NodeList drugNodes = categoryElement.getElementsByTagName("drug"); for (int d = 0; d < drugNodes.getLength(); d++) { Element drugElement = (Element) drugNodes.item(d); String drugCode = drugElement.getAttribute("code"); String drugConceptUuid = drugElement.hasAttribute("conceptUuid") ? drugElement.getAttribute("conceptUuid") : null; String drugDrugUuid = drugElement.hasAttribute("drugUuid") ? drugElement.getAttribute("drugUuid") : null; DrugReference drug = (drugDrugUuid != null) ? DrugReference.fromDrugUuid(drugDrugUuid) : DrugReference.fromConceptUuid(drugConceptUuid); if (drug != null) { categoryDrugs.put(drugCode, drug); } } // Parse all groups for this category NodeList groupNodes = categoryElement.getElementsByTagName("group"); for (int g = 0; g < groupNodes.getLength(); g++) { Element groupElement = (Element) groupNodes.item(g); String groupCode = groupElement.getAttribute("code"); String groupName = groupElement.getAttribute("name"); RegimenDefinitionGroup group = new RegimenDefinitionGroup(groupCode, groupName); categoryGroups.add(group); // Parse all regimen definitions for this group NodeList regimenNodes = groupElement.getElementsByTagName("regimen"); for (int r = 0; r < regimenNodes.getLength(); r++) { Element regimenElement = (Element) regimenNodes.item(r); String name = regimenElement.getAttribute("name"); RegimenDefinition regimenDefinition = new RegimenDefinition(name, group); // Parse all components for this regimen NodeList componentNodes = regimenElement.getElementsByTagName("component"); for (int p = 0; p < componentNodes.getLength(); p++) { Element componentElement = (Element) componentNodes.item(p); String drugCode = componentElement.getAttribute("drugCode"); Double dose = componentElement.hasAttribute("dose") ? Double.parseDouble(componentElement.getAttribute("dose")) : null; String units = componentElement.hasAttribute("units") ? componentElement.getAttribute("units") : null; String frequency = componentElement.hasAttribute("frequency") ? componentElement.getAttribute("frequency") : null; DrugReference drug = categoryDrugs.get(drugCode); if (drug == null) throw new RuntimeException("Regimen component references invalid drug: " + drugCode); regimenDefinition.addComponent(drug, dose, units, frequency); } group.addRegimen(regimenDefinition); } } drugs.put(categoryCode, categoryDrugs); regimenGroups.put(categoryCode, categoryGroups); } }
From source file:org.red5.io.FileKeyFrameMetaCache.java
/** {@inheritDoc} */ public KeyFrameMeta loadKeyFrameMeta(File file) { String filename = file.getAbsolutePath() + ".meta"; File metadataFile = new File(filename); if (!metadataFile.exists()) // No such metadata return null; Document dom;// w w w . j a v a 2 s.c o m DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try { // Using factory get an instance of document builder DocumentBuilder db = dbf.newDocumentBuilder(); // parse using builder to get DOM representation of the XML file dom = db.parse(filename); } catch (ParserConfigurationException pce) { log.error("Could not parse XML file.", pce); return null; } catch (SAXException se) { log.error("Could not parse XML file.", se); return null; } catch (IOException ioe) { log.error("Could not parse XML file.", ioe); return null; } Element root = dom.getDocumentElement(); // Check if .xml file is valid and for this .flv file if (!"FrameMetadata".equals(root.getNodeName())) // Invalid XML return null; String modified = root.getAttribute("modified"); if (modified == null || !modified.equals(String.valueOf(file.lastModified()))) // File has changed in the meantime return null; if (!root.hasAttribute("duration")) // Old file without duration informations return null; if (!root.hasAttribute("audioOnly")) // Old file without audio/video informations return null; XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); NodeList keyFrames; try { XPathExpression xexpr = xpath.compile("/FrameMetadata/KeyFrame"); keyFrames = (NodeList) xexpr.evaluate(dom, XPathConstants.NODESET); } catch (XPathExpressionException err) { log.error("could not compile xpath expression", err); return null; } int length = keyFrames.getLength(); if (keyFrames == null || length == 0) // File doesn't contain informations about keyframes return null; KeyFrameMeta result = new KeyFrameMeta(); result.duration = Long.parseLong(root.getAttribute("duration")); result.positions = new long[length]; result.timestamps = new int[length]; for (int i = 0; i < length; i++) { Node node = keyFrames.item(i); NamedNodeMap attrs = node.getAttributes(); result.positions[i] = Long.parseLong(attrs.getNamedItem("position").getNodeValue()); result.timestamps[i] = Integer.parseInt(attrs.getNamedItem("timestamp").getNodeValue()); } result.audioOnly = "true".equals(root.getAttribute("audioOnly")); return result; }
From source file:org.reficio.p2.FeatureBuilder.java
void buildXml() throws ParserConfigurationException, FileNotFoundException { xmlDoc = this.fetchOrCreateXml(); Element featureElement = XmlUtils.fetchOrCreateElement(xmlDoc, xmlDoc, "feature"); if (null != this.p2FeatureDefintion.getId()) { featureElement.setAttribute("id", this.p2FeatureDefintion.getId()); } else if (featureElement.hasAttribute("id")) { this.p2FeatureDefintion.setId(featureElement.getAttribute("id")); } else {/*www .j a v a 2 s.c o m*/ throw new RuntimeException("No id defined for feature in pom or featureFile"); } if (null != this.p2FeatureDefintion.getVersion()) { featureElement.setAttribute("version", this.p2FeatureDefintion.getVersion()); } else if (featureElement.hasAttribute("version")) { this.p2FeatureDefintion.setVersion(featureElement.getAttribute("version")); } else { throw new RuntimeException("No version defined for feature in pom or featureFile"); } if (null != this.p2FeatureDefintion.getLabel()) { featureElement.setAttribute("label", this.p2FeatureDefintion.getLabel()); } if (null != this.p2FeatureDefintion.getProviderName()) { featureElement.setAttribute("provider-name", this.p2FeatureDefintion.getProviderName()); } if (null != this.p2FeatureDefintion.getDescription()) { Element descriptionElement = XmlUtils.fetchOrCreateElement(xmlDoc, featureElement, "description"); descriptionElement.setTextContent(this.p2FeatureDefintion.getDescription()); } if (null != this.p2FeatureDefintion.getCopyright()) { Element copyrightElement = XmlUtils.fetchOrCreateElement(xmlDoc, featureElement, "copyright"); copyrightElement.setTextContent(this.p2FeatureDefintion.getCopyright()); } if (null != this.p2FeatureDefintion.getLicense()) { Element licenceElement = XmlUtils.fetchOrCreateElement(xmlDoc, featureElement, "license"); licenceElement.setTextContent(this.p2FeatureDefintion.getLicense()); } for (P2Artifact artifact : this.p2FeatureDefintion.artifacts) { Element pluginElement = XmlUtils.createElement(xmlDoc, featureElement, "plugin"); String id = this.bundlerInstructions.get(artifact).getSymbolicName(); String version = this.bundlerInstructions.get(artifact).getProposedVersion(); pluginElement.setAttribute("id", id); pluginElement.setAttribute("download-size", "0"); //TODO pluginElement.setAttribute("install-size", "0"); //TODO pluginElement.setAttribute("version", version); pluginElement.setAttribute("unpack", "false"); } //update qualified version if need be String xmlVersion = featureElement.getAttribute("version"); if (xmlVersion.contains("qualifier")) { featureElement.setAttribute("version", xmlVersion.replace("qualifier", this.getFeatureTimeStamp())); } }
From source file:org.sakaiproject.assignment.impl.BaseAssignmentService.java
/** * Replace the WT user id with the new qualified id * // ww w .ja v a 2s . c om * @param el * The XML element holding the perproties * @param useIdTrans * The HashMap to track old WT id to new CTools id */ protected void WTUserIdTrans(Element el, Map userIdTrans) { NodeList children4 = el.getChildNodes(); int length4 = children4.getLength(); for (int i4 = 0; i4 < length4; i4++) { Node child4 = children4.item(i4); if (child4.getNodeType() == Node.ELEMENT_NODE) { Element element4 = (Element) child4; if (element4.getTagName().equals("property")) { String creatorId = ""; String modifierId = ""; if (element4.hasAttribute("CHEF:creator")) { if ("BASE64".equalsIgnoreCase(element4.getAttribute("enc"))) { creatorId = Xml.decodeAttribute(element4, "CHEF:creator"); } else { creatorId = element4.getAttribute("CHEF:creator"); } String newCreatorId = (String) userIdTrans.get(creatorId); if (newCreatorId != null) { Xml.encodeAttribute(element4, "CHEF:creator", newCreatorId); element4.setAttribute("enc", "BASE64"); } } else if (element4.hasAttribute("CHEF:modifiedby")) { if ("BASE64".equalsIgnoreCase(element4.getAttribute("enc"))) { modifierId = Xml.decodeAttribute(element4, "CHEF:modifiedby"); } else { modifierId = element4.getAttribute("CHEF:modifiedby"); } String newModifierId = (String) userIdTrans.get(modifierId); if (newModifierId != null) { Xml.encodeAttribute(element4, "CHEF:modifiedby", newModifierId); element4.setAttribute("enc", "BASE64"); } } } } } }