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:com.github.spring.mvc.util.handler.config.UriMatchingAnnotationDrivenBeanDefinitionParser.java
/** * Create {@link PointcutAdvisor} that puts the {@link Pointcut} and {@link MethodInterceptor} together. * @return Reference to the {@link PointcutAdvisor}. Should never be null. *//*from ww w.java2 s. c o m*/ protected RuntimeBeanReference setupPointcutAdvisor(Element element, ParserContext parserContext, Object elementSource, RuntimeBeanReference pointcutReference, RuntimeBeanReference interceptorReference) { final RootBeanDefinition pointcutAdvisor = new RootBeanDefinition(DefaultBeanFactoryPointcutAdvisor.class); pointcutAdvisor.setSource(elementSource); pointcutAdvisor.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); final MutablePropertyValues propertyValues = pointcutAdvisor.getPropertyValues(); propertyValues.addPropertyValue("adviceBeanName", interceptorReference.getBeanName()); propertyValues.addPropertyValue("pointcut", pointcutReference); if (element.hasAttribute("order")) { propertyValues.addPropertyValue("order", element.getAttribute("order")); } final BeanDefinitionRegistry registry = parserContext.getRegistry(); registry.registerBeanDefinition(CACHING_ADVISOR_BEAN_NAME, pointcutAdvisor); return new RuntimeBeanReference(CACHING_ADVISOR_BEAN_NAME); }
From source file:marytts.language.de.JPhonemiser.java
@Override public MaryData process(MaryData d) throws Exception { Document doc = d.getDocument(); inflection.determineEndings(doc);//from w w w .ja va 2s .c o m NodeIterator it = MaryDomUtils.createNodeIterator(doc, doc, MaryXML.TOKEN); Element t = null; while ((t = (Element) it.nextNode()) != null) { String text; // Do not touch tokens for which a transcription is already // given (exception: transcription contains a '*' character: if (t.hasAttribute("ph") && t.getAttribute("ph").indexOf('*') == -1) { continue; } if (t.hasAttribute("sounds_like")) text = t.getAttribute("sounds_like"); else text = MaryDomUtils.tokenText(t); String pos = null; // use part-of-speech if available if (t.hasAttribute("pos")) { pos = t.getAttribute("pos"); } boolean isEnglish = false; if (t.hasAttribute("xml:lang") && MaryUtils.subsumes(Locale.ENGLISH, MaryUtils.string2locale(t.getAttribute("xml:lang")))) { isEnglish = true; } if (text != null && !text.equals("")) { // If text consists of several parts (e.g., because that was // inserted into the sounds_like attribute), each part // is transcribed separately. StringBuilder ph = new StringBuilder(); String g2pMethod = null; StringTokenizer st = new StringTokenizer(text, " -"); while (st.hasMoreTokens()) { String graph = st.nextToken(); StringBuilder helper = new StringBuilder(); String phon = null; if (isEnglish && usEnglishLexicon != null) { phon = phonemiseEn(graph); if (phon != null) helper.append("foreign:en"); } if (phon == null) { phon = phonemise(graph, pos, helper); } if (ph.length() == 0) { // first part // The g2pMethod of the combined beast is // the g2pMethod of the first constituant. g2pMethod = helper.toString(); ph.append(phon); } else { // following parts ph.append(" - "); // Reduce primary to secondary stress: ph.append(phon.replace('\'', ',')); } } if (ph != null && ph.length() > 0) { setPh(t, ph.toString()); t.setAttribute("g2p_method", g2pMethod); } } } MaryData result = new MaryData(outputType(), d.getLocale()); result.setDocument(doc); return result; }
From source file:com.icesoft.faces.context.DOMResponseWriter.java
private void enhanceHead(Element head) { Element meta = (Element) head.appendChild(document.createElement("meta")); meta.setAttribute("name", "icefaces"); meta.setAttribute("content", "Rendered by ICEFaces D2D"); //avoid reloading the head when only document's title is changed Element title = (Element) head.getElementsByTagName("title").item(0); if (title != null && !title.hasAttribute("id")) { title.setAttribute("id", "document:title"); }/*ww w .jav a 2 s . c o m*/ if (!context.isContentIncluded()) { appendContentReferences(head); } }
From source file:de.huberlin.wbi.hiway.am.galaxy.GalaxyApplicationMaster.java
/** * A helper function for processing the Galaxy config file that specifies the extensions and python script locations for Galaxy's data types * //from w ww . j a va 2s . co m * @param file * the Galaxy data type config file */ private void processDataTypes(File file) { try { System.out.println("Processing Galaxy data type config file " + file.getCanonicalPath()); DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = builder.parse(file); NodeList datatypeNds = doc.getElementsByTagName("datatype"); for (int i = 0; i < datatypeNds.getLength(); i++) { Element datatypeEl = (Element) datatypeNds.item(i); if (!datatypeEl.hasAttribute("extension") || !datatypeEl.hasAttribute("type") || datatypeEl.hasAttribute("subclass")) continue; String extension = datatypeEl.getAttribute("extension"); String[] splitType = datatypeEl.getAttribute("type").split(":"); galaxyDataTypes.put(extension, new GalaxyDataType(splitType[0], splitType[1], extension)); } } catch (SAXException | IOException | ParserConfigurationException e) { e.printStackTrace(); System.exit(-1); } }
From source file:de.huberlin.wbi.hiway.am.galaxy.GalaxyApplicationMaster.java
/** * A helper function for processing a Galaxy config file that lists the tools within a single library * //from w ww. j a v a2 s. com * @param file * the Galaxy tool library config file * @param defaultPath * the directory in which pre-installed Galaxy tools are located * @param dependencyDir * the directory in which the tool's dependencies are located */ private void processToolLibraries(File file, String defaultPath, String dependencyDir) { try { System.out.println("Processing Galaxy tool library config file " + file.getCanonicalPath()); File galaxyPathFile = new File(galaxyPath); File dir = new File(galaxyPathFile, defaultPath); DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = builder.parse(file); Element toolboxEl = doc.getDocumentElement(); if (toolboxEl.hasAttribute("tool_path")) { dir = new File(galaxyPathFile, toolboxEl.getAttribute("tool_path")); } NodeList tools = toolboxEl.getElementsByTagName("tool"); for (int i = 0; i < tools.getLength(); i++) { // (1) parse a single XML tool file Element toolEl = (Element) tools.item(i); String toolFile = toolEl.getAttribute("file"); GalaxyTool tool = parseToolFile(new File(dir, toolFile)); // (2) go over the tool's dependencies and determine the environment-setting pre-script accordingly NodeList repositoryNameNds = toolEl.getElementsByTagName("repository_name"); String repositoryName = repositoryNameNds.getLength() > 0 ? repositoryNameNds.item(0).getChildNodes().item(0).getNodeValue().trim() : ""; NodeList ownerNds = toolEl.getElementsByTagName("repository_owner"); String owner = ownerNds.getLength() > 0 ? ownerNds.item(0).getChildNodes().item(0).getNodeValue().trim() : ""; NodeList revisionNds = toolEl.getElementsByTagName("installed_changeset_revision"); String revision = revisionNds.getLength() > 0 ? revisionNds.item(0).getChildNodes().item(0).getNodeValue().trim() : ""; if (repositoryName.length() > 0 && owner.length() > 0 && revision.length() > 0) { for (String requirementName : tool.getRequirements()) { File envFile = new File(galaxyPath + "/" + dependencyDir, requirementName + "/" + tool.getRequirementVersion(requirementName) + "/" + owner + "/" + repositoryName + "/" + revision + "/env.sh"); if (envFile.exists()) { try (BufferedReader br = new BufferedReader(new FileReader(envFile))) { String line; while ((line = br.readLine()) != null) { tool.addEnv(line); } } } } } } } catch (SAXException | IOException | ParserConfigurationException e) { e.printStackTrace(); System.exit(-1); } }
From source file:com.concursive.connect.cms.portal.dao.DashboardPortletList.java
/** * Take page design and build portlet list in memory only, preferences cannot * be saved on these portlets/* w w w. j av a2 s. c om*/ * * @param page * @throws Exception */ public void buildTemporaryList(DashboardPage page) throws Exception { XMLUtils xml = new XMLUtils(page.getXmlDesign()); // Counter for number of instances on this page int falseIdCount = 0; // Pages have rows ArrayList rows = new ArrayList(); XMLUtils.getAllChildren(xml.getDocumentElement(), "row", rows); // ERROR if no rows found if (rows.isEmpty()) { LOG.error("buildTemporaryList-> rows is empty"); } Iterator i = rows.iterator(); while (i.hasNext()) { Element rowEl = (Element) i.next(); // Rows have columns ArrayList columns = new ArrayList(); XMLUtils.getAllChildren(rowEl, "column", columns); // ERROR if no columns found if (columns.isEmpty()) { LOG.error("buildTemporaryList-> columns is empty"); } Iterator j = columns.iterator(); while (j.hasNext()) { Element columnEl = (Element) j.next(); // Columns have portlets ArrayList portlets = new ArrayList(); XMLUtils.getAllChildren(columnEl, "portlet", portlets); Iterator k = portlets.iterator(); while (k.hasNext()) { Element portletEl = (Element) k.next(); // Give the portlet an instance reference ++falseIdCount; // Set the portlet information DashboardPortlet portlet = new DashboardPortlet(); portlet.setPageId(page.getId()); portlet.setName(portletEl.getAttribute("name")); if (portletEl.hasAttribute("viewer")) { portlet.setViewer(portletEl.getAttribute("viewer")); } if (portletEl.hasAttribute("class")) { portlet.setHtmlClass(portletEl.getAttribute("class")); } if (portletEl.hasAttribute("cache")) { portlet.setCacheTime(Integer.parseInt(portletEl.getAttribute("cache"))); } if (portletEl.hasAttribute("timeout")) { portlet.setTimeout(Integer.parseInt(portletEl.getAttribute("timeout"))); } if (portletEl.hasAttribute("isSensitive")) { portlet.setSensitive(portletEl.getAttribute("isSensitive")); } // This portlet can temporarily be used DashboardPortletItem portletItem = new DashboardPortletItem(); portletItem.setName(portlet.getName()); portletItem.setEnabled(true); // Portlets could have default preferences specified in the layout ArrayList<Element> preferences = new ArrayList<Element>(); XMLUtils.getAllChildren(portletEl, preferences); Iterator l = preferences.iterator(); while (l.hasNext()) { Element preferenceEl = (Element) l.next(); if ("portlet-events".equals(preferenceEl.getNodeName())) { // This is the registration of a generateDataEvent ArrayList<Element> generateDataEvents = new ArrayList<Element>(); XMLUtils.getAllChildren(preferenceEl, "generates-data", generateDataEvents); for (Element gde : generateDataEvents) { portlet.addGenerateDataEvent(XMLUtils.getNodeText(gde)); } // This is the registration of a consumeDataEvent ArrayList<Element> consumeDataEvents = new ArrayList<Element>(); XMLUtils.getAllChildren(preferenceEl, "consumes-data", consumeDataEvents); for (Element cde : consumeDataEvents) { portlet.addConsumeDataEvent(XMLUtils.getNodeText(cde)); } // This is the registration of generateSessionData ArrayList<Element> generateSessionData = new ArrayList<Element>(); XMLUtils.getAllChildren(preferenceEl, "generates-session-data", generateSessionData); for (Element cde : generateSessionData) { portlet.addGenerateSessionData(XMLUtils.getNodeText(cde)); } // This is the registration of consumeSessionData ArrayList<Element> consumeSessionData = new ArrayList<Element>(); XMLUtils.getAllChildren(preferenceEl, "consumes-session-data", consumeSessionData); for (Element cde : consumeSessionData) { portlet.addConsumeSessionDataEvent(XMLUtils.getNodeText(cde)); } // This is the registration of generateRequestData ArrayList<Element> generateRequestData = new ArrayList<Element>(); XMLUtils.getAllChildren(preferenceEl, "generates-request-data", generateRequestData); for (Element cde : generateRequestData) { portlet.addGenerateRequestData(XMLUtils.getNodeText(cde)); } // This is the registration of consumeRequestData ArrayList<Element> consumeRequestData = new ArrayList<Element>(); XMLUtils.getAllChildren(preferenceEl, "consumes-request-data", consumeRequestData); for (Element cde : consumeRequestData) { portlet.addConsumeRequestDataEvent(XMLUtils.getNodeText(cde)); } } else { // Provide the default preference DashboardPortletPrefs prefs = new DashboardPortletPrefs(); prefs.setName(preferenceEl.getNodeName()); // Check to see if the prefs are provided as an array ArrayList<String> valueList = new ArrayList<String>(); ArrayList valueElements = new ArrayList(); XMLUtils.getAllChildren(preferenceEl, "value", valueElements); if (valueElements.size() > 0) { // There are <value> nodes Iterator vi = valueElements.iterator(); while (vi.hasNext()) { valueList.add(XMLUtils.getNodeText((Element) vi.next())); } prefs.setValues(valueList.toArray(new String[valueList.size()])); } else { // There is a single value prefs.setValues(new String[] { XMLUtils.getNodeText(preferenceEl) }); } portlet.addDefaultPreference(prefs.getName(), prefs); } } portlet.setId(falseIdCount); this.add(portlet); } } } }
From source file:eu.europa.ec.markt.dss.validation.xades.XAdESSignature.java
private void recursiveIdBrowse(DOMValidateContext context, Element element) { for (int i = 0; i < element.getChildNodes().getLength(); i++) { Node node = element.getChildNodes().item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element childEl = (Element) node; if (childEl.hasAttribute("Id")) { context.setIdAttributeNS(childEl, null, "Id"); }//from ww w . ja v a 2 s . com recursiveIdBrowse(context, childEl); } } }
From source file:net.sourceforge.dita4publishers.impl.ditabos.DitaTreeWalkerBase.java
private void findConrefDependencies(BoundedObjectSet bos, XmlBosMember member, Set<BosMember> newMembers) throws Exception { NodeList conrefs;// w w w .j a va2 s . co m try { conrefs = (NodeList) DitaUtil.allConrefs.evaluate(member.getElement(), XPathConstants.NODESET); } catch (XPathExpressionException e) { throw new BosException("Unexpected exception evaluating xpath " + DitaUtil.allTopicrefs); } for (int i = 0; i < conrefs.getLength(); i++) { Element conref = (Element) conrefs.item(i); Document targetDoc = null; // If there is a key reference, attempt to resolve it, // then fall back to href, if any. String href = null; try { if (conref.hasAttribute("conkeyref")) { targetDoc = resolveKeyrefToDoc(conref.getAttribute("conkeyref")); } if (targetDoc == null && conref.hasAttribute("conref")) { href = conref.getAttribute("conref"); if (!href.startsWith("#")) targetDoc = AddressingUtil.resolveHrefToDoc(conref, href, bosConstructionOptions, this.failOnAddressResolutionFailure); } } catch (AddressingException e) { if (this.failOnAddressResolutionFailure) { throw new BosException( "Failed to resolve href \"" + conref.getAttribute("conref") + "\" to a managed object", e); } } if (targetDoc != null && targetDoc != member.getDocument()) { BosMember childMember = bos.constructBosMember(member, targetDoc); // bos.addMember(member, childMember); newMembers.add(childMember); if (href != null) { bos.addMemberAsDependency(href, Constants.CONREF_DEPENDENCY, member, childMember); } else { bos.addMember(childMember); } } } }
From source file:net.sourceforge.dita4publishers.impl.ditabos.DitaTreeWalkerBase.java
/** * @param bos// ww w. j ava2 s. c o m * @param member * @param newMembers */ private void findObjectDependencies(BoundedObjectSet bos, XmlBosMember member, Set<BosMember> newMembers) throws BosException { NodeList objects; try { objects = (NodeList) DitaUtil.allObjects.evaluate(member.getElement(), XPathConstants.NODESET); } catch (XPathExpressionException e) { throw new BosException("Unexcepted exception evaluating xpath " + DitaUtil.allObjects); } log.debug("findObjectDependencies(): Found " + objects.getLength() + " topic/object elements"); for (int i = 0; i < objects.getLength(); i++) { Element objectElem = (Element) objects.item(i); URI targetUri = null; // If there is a key reference, attempt to resolve it, // then fall back to href, if any. String href = null; try { if (objectElem.hasAttribute("data")) { log.debug("findObjectDependencies(): resolving reference to data \"" + objectElem.getAttribute("data") + "\"..."); href = objectElem.getAttribute("data"); // FIXME: This assumes that the @data value will be a relative URL. In fact, it could be relative // to the value of the @codebase attribute if specified. targetUri = AddressingUtil.resolveObjectDataToUri(objectElem, this.failOnAddressResolutionFailure); } } catch (AddressingException e) { if (this.failOnAddressResolutionFailure) { throw new BosException( "Failed to resolve @data \"" + objectElem.getAttribute("data") + "\" to a resource", e); } } if (targetUri == null) continue; BosMember childMember = null; if (targetUri != null) { log.debug("findObjectDependencies(): Got URI \"" + targetUri.toString() + "\""); childMember = bos.constructBosMember((BosMember) member, targetUri); } bos.addMember(member, childMember); newMembers.add(childMember); if (href != null) member.registerDependency(href, childMember, Constants.OBJECT_DEPENDENCY); } }
From source file:de.itsvs.cwtrpc.controller.config.RemoteServiceGroupConfigBeanDefinitionParser.java
protected AbstractBeanDefinition createServiceConfigBeanDefinition(Element element, ParserContext parserContext) {//from w w w.jav a2 s .c o m final String serviceName; final BeanDefinitionBuilder bdd; final String relativePath; serviceName = element.getAttribute(XmlNames.SERVICE_REF_ATTR); if (!StringUtils.hasText(serviceName)) { parserContext.getReaderContext().error("Service reference must not be empty", parserContext.extractSource(element)); } bdd = BeanDefinitionBuilder.rootBeanDefinition(RemoteServiceConfig.class); if (parserContext.isDefaultLazyInit()) { bdd.setLazyInit(true); } bdd.getRawBeanDefinition().setSource(parserContext.extractSource(element)); bdd.addConstructorArgValue(serviceName); if (element.hasAttribute(XmlNames.SERVICE_INTERFACE_ATTR)) { bdd.addPropertyValue("serviceInterface", element.getAttribute(XmlNames.SERVICE_INTERFACE_ATTR)); } if (element.hasAttribute(XmlNames.RELATIVE_PATH_ATTR)) { relativePath = element.getAttribute(XmlNames.RELATIVE_PATH_ATTR); if (!StringUtils.hasText(relativePath)) { parserContext.getReaderContext().error("Relative path must not be empty", parserContext.extractSource(element)); } bdd.addPropertyValue("relativePath", relativePath); } getBaseServiceConfigParser().update(element, parserContext, bdd); return bdd.getBeanDefinition(); }