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.consol.citrus.selenium.xml.WebClientConfigurationParser.java
@Override protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(WebClient.class); BeanDefinitionBuilder configurationBuilder = BeanDefinitionBuilder .genericBeanDefinition(WebClientConfiguration.class); BeanDefinitionParserUtils.setPropertyValue(configurationBuilder, element.getAttribute("browser-type"), "browserType"); BeanDefinitionParserUtils.setPropertyValue(configurationBuilder, element.getAttribute("start-url"), "startUrl"); BeanDefinitionParserUtils.setPropertyValue(configurationBuilder, element.getAttribute("model-namespace"), "modelNamespace"); BeanDefinitionParserUtils.setPropertyValue(configurationBuilder, element.getAttribute("selenium-server"), "seleniumServer"); BeanDefinitionParserUtils.setPropertyValue(configurationBuilder, element.getAttribute("enable-javascript"), "enableJavascript"); if (element.hasAttribute("error-strategy")) { configurationBuilder.addPropertyValue("errorHandlingStrategy", ErrorHandlingStrategy.fromName(element.getAttribute("error-strategy"))); }// w w w .j ava 2 s. co m String clientConfigurationId = element.getAttribute(ID_ATTRIBUTE) + "Configuration"; BeanDefinitionParserUtils.registerBean(clientConfigurationId, configurationBuilder.getBeanDefinition(), parserContext, shouldFireEvents()); builder.addConstructorArgReference(clientConfigurationId); return builder.getBeanDefinition(); }
From source file:eap.config.ConfigBeanDefinitionParser.java
/** * Creates the RootBeanDefinition for a POJO advice bean. Also causes pointcut * parsing to occur so that the pointcut may be associate with the advice bean. * This same pointcut is also configured as the pointcut for the enclosing * Advisor definition using the supplied MutablePropertyValues. */// www.j a va2s .com private AbstractBeanDefinition createAdviceDefinition(Element adviceElement, ParserContext parserContext, String aspectName, int order, RootBeanDefinition methodDef, RootBeanDefinition aspectFactoryDef, List<BeanDefinition> beanDefinitions, List<BeanReference> beanReferences) { RootBeanDefinition adviceDefinition = new RootBeanDefinition(getAdviceClass(adviceElement, parserContext)); adviceDefinition.setSource(parserContext.extractSource(adviceElement)); adviceDefinition.getPropertyValues().add(ASPECT_NAME_PROPERTY, aspectName); adviceDefinition.getPropertyValues().add(DECLARATION_ORDER_PROPERTY, order); if (adviceElement.hasAttribute(RETURNING)) { adviceDefinition.getPropertyValues().add(RETURNING_PROPERTY, adviceElement.getAttribute(RETURNING)); } if (adviceElement.hasAttribute(THROWING)) { adviceDefinition.getPropertyValues().add(THROWING_PROPERTY, adviceElement.getAttribute(THROWING)); } if (adviceElement.hasAttribute(ARG_NAMES)) { adviceDefinition.getPropertyValues().add(ARG_NAMES_PROPERTY, adviceElement.getAttribute(ARG_NAMES)); } ConstructorArgumentValues cav = adviceDefinition.getConstructorArgumentValues(); cav.addIndexedArgumentValue(METHOD_INDEX, methodDef); Object pointcut = parsePointcutProperty(adviceElement, parserContext); if (pointcut instanceof BeanDefinition) { cav.addIndexedArgumentValue(POINTCUT_INDEX, pointcut); beanDefinitions.add((BeanDefinition) pointcut); } else if (pointcut instanceof String) { RuntimeBeanReference pointcutRef = new RuntimeBeanReference((String) pointcut); cav.addIndexedArgumentValue(POINTCUT_INDEX, pointcutRef); beanReferences.add(pointcutRef); } cav.addIndexedArgumentValue(ASPECT_INSTANCE_FACTORY_INDEX, aspectFactoryDef); return adviceDefinition; }
From source file:marytts.tools.install.ComponentDescription.java
protected ComponentDescription(Element xmlDescription) throws NullPointerException { this.name = xmlDescription.getAttribute("name"); this.locale = MaryUtils.string2locale(xmlDescription.getAttribute("locale")); this.version = xmlDescription.getAttribute("version"); Element descriptionElement = (Element) xmlDescription.getElementsByTagName("description").item(0); this.description = descriptionElement.getTextContent().trim(); Element licenseElement = (Element) xmlDescription.getElementsByTagName("license").item(0); try {//w ww . j av a2 s . co m this.license = new URL(licenseElement.getAttribute("href").trim().replaceAll(" ", "%20")); } catch (MalformedURLException mue) { new Exception("Invalid license URL -- ignoring", mue).printStackTrace(); this.license = null; } Element packageElement = (Element) xmlDescription.getElementsByTagName("package").item(0); packageFilename = packageElement.getAttribute("filename").trim(); packageSize = Integer.parseInt(packageElement.getAttribute("size")); packageMD5 = packageElement.getAttribute("md5sum"); NodeList locationElements = packageElement.getElementsByTagName("location"); locations = new ArrayList<URL>(locationElements.getLength()); for (int i = 0, max = locationElements.getLength(); i < max; i++) { Element aLocationElement = (Element) locationElements.item(i); try { String urlString = aLocationElement.getAttribute("href").trim().replaceAll(" ", "%20"); boolean isFolder = true; if (aLocationElement.hasAttribute("folder")) { isFolder = Boolean.valueOf(aLocationElement.getAttribute("folder")); } if (isFolder && !urlString.endsWith(packageFilename)) { if (!urlString.endsWith("/")) { urlString += "/"; } urlString += packageFilename; } locations.add(new URL(urlString)); } catch (MalformedURLException mue) { new Exception("Invalid location -- ignoring", mue).printStackTrace(); } } archiveFile = new File(System.getProperty("mary.downloadDir"), packageFilename); String infoFilename = packageFilename.substring(0, packageFilename.lastIndexOf('.')) + "-component.xml"; infoFile = new File(System.getProperty("mary.installedDir"), infoFilename); determineStatus(); NodeList filesElements = xmlDescription.getElementsByTagName("files"); if (filesElements.getLength() > 0) { Element filesElement = (Element) filesElements.item(0); installedFilesNames = filesElement.getTextContent(); } }
From source file:eap.config.ConfigBeanDefinitionParser.java
/** * Create a {@link RootBeanDefinition} for the advisor described in the supplied. Does <strong>not</strong> * parse any associated '{@code pointcut}' or '{@code pointcut-ref}' attributes. *//*from www . j a v a2 s . co m*/ private AbstractBeanDefinition createAdvisorBeanDefinition(Element advisorElement, ParserContext parserContext) { RootBeanDefinition advisorDefinition = new RootBeanDefinition(DefaultBeanFactoryPointcutAdvisor.class); advisorDefinition.setSource(parserContext.extractSource(advisorElement)); String adviceRef = advisorElement.getAttribute(ADVICE_REF); if (!StringUtils.hasText(adviceRef)) { parserContext.getReaderContext().error("'advice-ref' attribute contains empty value.", advisorElement, this.parseState.snapshot()); } else { advisorDefinition.getPropertyValues().add(ADVICE_BEAN_NAME, new RuntimeBeanNameReference(adviceRef)); } if (advisorElement.hasAttribute(ORDER_PROPERTY)) { advisorDefinition.getPropertyValues().add(ORDER_PROPERTY, advisorElement.getAttribute(ORDER_PROPERTY)); } return advisorDefinition; }
From source file:org.jsr107.ri.annotations.spring.config.AnnotationDrivenJCacheBeanDefinitionParser.java
/** * Create {@link org.springframework.aop.PointcutAdvisor} that puts the * {@link org.springframework.aop.Pointcut} and {@link AbstractCacheInterceptor} together. */// w ww.jav a 2 s. c om protected void setupPointcutAdvisor(Class<? extends AbstractCacheInterceptor<?>> interceptorClass, Element element, ParserContext parserContext, Object elementSource, RuntimeBeanReference cacheOperationSourceReference) { final RuntimeBeanReference interceptorReference = this.setupInterceptor(interceptorClass, parserContext, elementSource, cacheOperationSourceReference); final RuntimeBeanReference pointcutReference = this.setupPointcut(parserContext, elementSource, cacheOperationSourceReference, 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 XmlReaderContext readerContext = parserContext.getReaderContext(); readerContext.registerWithGeneratedName(pointcutAdvisor); }
From source file:net.sourceforge.dita4publishers.impl.ditabos.DitaTreeWalkerBase.java
/** * @param bos/* w ww . ja v a2s. c o m*/ * @param member * @throws Exception */ protected void walkMapGetDependencies(BoundedObjectSet bos, DitaMapBosMember member) throws Exception { NodeList topicrefs; try { topicrefs = (NodeList) DitaUtil.allTopicrefs.evaluate(member.getElement(), XPathConstants.NODESET); } catch (XPathExpressionException e) { throw new BosException("Unexcepted exception evaluating xpath " + DitaUtil.allTopicrefs); } Set<BosMember> newMembers = new HashSet<BosMember>(); for (int i = 0; i < topicrefs.getLength(); i++) { Element topicref = (Element) topicrefs.item(i); Document targetDoc = null; URI targetUri = null; // For now, only consider local resources. if (!DitaUtil.isLocalScope(topicref)) continue; // If there is a key reference, attempt to resolve it, // then fall back to href, if any. String href = null; try { if (bosConstructionOptions.isMapTreeOnly()) { if (DitaUtil.targetIsADitaMap(topicref) && topicref.hasAttribute("href")) { href = topicref.getAttribute("href"); // Don't bother resolving pointers to the same doc. // We don't record dependencies on ourself. if (!href.startsWith("#")) targetDoc = AddressingUtil.resolveHrefToDoc(topicref, href, bosConstructionOptions, this.failOnAddressResolutionFailure); } } else if (DitaUtil.targetIsADitaFormat(topicref)) { if (topicref.hasAttribute("keyref")) { targetDoc = resolveKeyrefToDoc(topicref.getAttribute("keyref")); } if (targetDoc == null && topicref.hasAttribute("href")) { href = topicref.getAttribute("href"); // Don't bother resolving pointers to the same doc. // We don't record dependencies on ourself. if (!href.startsWith("#")) targetDoc = AddressingUtil.resolveHrefToDoc(topicref, href, bosConstructionOptions, this.failOnAddressResolutionFailure); } } else { if (topicref.hasAttribute("keyref")) { targetUri = resolveKeyrefToUri(topicref.getAttribute("keyref")); } if (targetUri == null && topicref.hasAttribute("href")) { href = topicref.getAttribute("href"); // Don't bother resolving pointers to the same doc. // We don't record dependencies on ourself. if (!href.startsWith("#")) targetUri = AddressingUtil.resolveHrefToUri(topicref, href, this.failOnAddressResolutionFailure); } } } catch (AddressingException e) { if (this.failOnAddressResolutionFailure) { throw new BosException( "Failed to resolve href \"" + topicref.getAttribute("href") + "\" to a managed object", e); } } BosMember childMember = null; if (targetDoc != null) { childMember = bos.constructBosMember(member, targetDoc); } if (targetUri != null) { childMember = bos.constructBosMember(member, targetUri); } if (childMember != null) { bos.addMember(member, childMember); newMembers.add((BosMember) childMember); if (href != null) member.registerDependency(href, childMember, Constants.TOPICREF_DEPENDENCY); } } // Now walk the new members: for (BosMember newMember : newMembers) { if (!walkedMembers.contains(newMember)) walkMemberGetDependencies(bos, newMember); } }
From source file:org.alfresco.web.config.forms.FormConfigRuntime.java
/** * @return/* ww w . java 2s . c o m*/ */ public HashMap<String, HashMap<String, FormConfigElement>> getAspectConfigForms() { HashMap<String, HashMap<String, FormConfigElement>> aspectConfigForms = new HashMap<String, HashMap<String, FormConfigElement>>(); for (Element modelTypeElem : XmlUtils.findElements("config[@evaluator='aspect']", (Element) configDocument.getFirstChild())) { if (modelTypeElem.hasAttribute("condition")) { String condition = modelTypeElem.getAttribute("condition"); HashMap<String, FormConfigElement> conditionForms = new HashMap<String, FormConfigElement>(); for (Element conditionFormElem : XmlUtils.findElements( "config[@evaluator='aspect' and @condition='" + condition + "']/forms/form", (Element) configDocument.getFirstChild())) { if (conditionFormElem.hasAttribute("id")) { String formId = conditionFormElem.getAttribute("id"); conditionForms.put(formId, this.getModelTypeConfigForm(condition, formId)); } else { conditionForms.put("default", this.getModelTypeConfigForm(condition, null)); } } aspectConfigForms.put(condition, conditionForms); } } return aspectConfigForms; }
From source file:org.mule.transport.zmq.config.OutboundEndpointDefinitionParser.java
public BeanDefinition parse(Element element, ParserContext parserContent) { BeanDefinitionBuilder builder = BeanDefinitionBuilder .rootBeanDefinition(OutboundEndpointMessageProcessor.class.getName()); String configRef = element.getAttribute("config-ref"); if ((configRef != null) && (!StringUtils.isBlank(configRef))) { builder.addPropertyValue("moduleObject", configRef); }//ww w . j av a 2 s .c o m if ((element.getAttribute("payload-ref") != null) && (!StringUtils.isBlank(element.getAttribute("payload-ref")))) { if (element.getAttribute("payload-ref").startsWith("#")) { builder.addPropertyValue("payload", element.getAttribute("payload-ref")); } else { builder.addPropertyValue("payload", (("#[registry:" + element.getAttribute("payload-ref")) + "]")); } } if ((element.getAttribute("retryMax") != null) && (!StringUtils.isBlank(element.getAttribute("retryMax")))) { builder.addPropertyValue("retryMax", element.getAttribute("retryMax")); } if (element.hasAttribute("exchange-pattern")) { builder.addPropertyValue("exchangePattern", element.getAttribute("exchange-pattern")); } if (element.hasAttribute("socket-operation")) { builder.addPropertyValue("socketOperation", element.getAttribute("socket-operation")); } if ((element.getAttribute("address") != null) && (!StringUtils.isBlank(element.getAttribute("address")))) { builder.addPropertyValue("address", element.getAttribute("address")); } if ((element.getAttribute("filter") != null) && (!StringUtils.isBlank(element.getAttribute("filter")))) { builder.addPropertyValue("filter", element.getAttribute("filter")); } if ((element.getAttribute("identity") != null) && (!StringUtils.isBlank(element.getAttribute("identity")))) { builder.addPropertyValue("identity", element.getAttribute("identity")); } if ((element.getAttribute("multipart") != null) && (!StringUtils.isBlank(element.getAttribute("multipart")))) { builder.addPropertyValue("multipart", element.getAttribute("multipart")); } BeanDefinition definition = builder.getBeanDefinition(); definition.setAttribute(MuleHierarchicalBeanDefinitionParserDelegate.MULE_NO_RECURSE, Boolean.TRUE); MutablePropertyValues propertyValues = parserContent.getContainingBeanDefinition().getPropertyValues(); if (parserContent.getContainingBeanDefinition().getBeanClassName() .equals("org.mule.config.spring.factories.PollingMessageSourceFactoryBean")) { propertyValues.addPropertyValue("messageProcessor", definition); } else { if (parserContent.getContainingBeanDefinition().getBeanClassName() .equals("org.mule.enricher.MessageEnricher")) { propertyValues.addPropertyValue("enrichmentMessageProcessor", definition); } else { PropertyValue messageProcessors = propertyValues.getPropertyValue("messageProcessors"); if ((messageProcessors == null) || (messageProcessors.getValue() == null)) { propertyValues.addPropertyValue("messageProcessors", new ManagedList()); } List listMessageProcessors = ((List) propertyValues.getPropertyValue("messageProcessors") .getValue()); listMessageProcessors.add(definition); } } return definition; }
From source file:com.mtgi.analytics.aop.config.v11.BtHttpRequestsBeanDefinitionParser.java
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { //compile required constructor arguments from attributes and nested elements. first up, event type. builder.addConstructorArg(element.getAttribute(ATT_EVENT_TYPE)); //manager ID from enclosing tag, or ref attribute. String managerId = parserContext.isNested() ? (String) parserContext.getContainingBeanDefinition().getAttribute("id") : element.getAttribute(BtNamespaceConstants.ATT_TRACKING_MANAGER); builder.addConstructorArgReference(managerId); //parameter list to include in event data, if any. String paramList = element.getAttribute(ATT_PARAMETERS); builder.addConstructorArg(parseList(paramList)); //parameter list to include in event name, if any String nameList = element.getAttribute(ATT_NAME_PARAMETERS); builder.addConstructorArg(parseList(nameList)); //URI patterns, if any. can be specified as attribute or nested elements. ArrayList<Pattern> accum = new ArrayList<Pattern>(); if (element.hasAttribute(ATT_URI_PATTERN)) accum.add(Pattern.compile(element.getAttribute(ATT_URI_PATTERN))); NodeList nl = element.getElementsByTagNameNS("*", ATT_URI_PATTERN); for (int i = 0; i < nl.getLength(); ++i) { Element e = (Element) nl.item(i); String pattern = e.getTextContent(); if (StringUtils.hasText(pattern)) accum.add(Pattern.compile(pattern)); }/*from w ww. j ava 2 s . c o m*/ if (accum.isEmpty()) builder.addConstructorArg(null); else builder.addConstructorArg(accum.toArray(new Pattern[accum.size()])); if (parserContext.isNested()) parserContext.getReaderContext().registerWithGeneratedName(builder.getBeanDefinition()); }
From source file:org.alfresco.web.config.forms.FormConfigRuntime.java
/** * @return/*ww w.ja v a 2 s .co m*/ */ public HashMap<String, HashMap<String, FormConfigElement>> getNodeTypeConfigForms() { HashMap<String, HashMap<String, FormConfigElement>> nodeTypeConfigForms = new HashMap<String, HashMap<String, FormConfigElement>>(); for (Element modelTypeElem : XmlUtils.findElements("config[@evaluator='node-type']", (Element) configDocument.getFirstChild())) { if (modelTypeElem.hasAttribute("condition")) { String condition = modelTypeElem.getAttribute("condition"); HashMap<String, FormConfigElement> conditionForms = new HashMap<String, FormConfigElement>(); for (Element conditionFormElem : XmlUtils.findElements( "config[@evaluator='node-type' and @condition='" + condition + "']/forms/form", (Element) configDocument.getFirstChild())) { if (conditionFormElem.hasAttribute("id")) { String formId = conditionFormElem.getAttribute("id"); conditionForms.put(formId, this.getModelTypeConfigForm(condition, formId)); } else { conditionForms.put("default", this.getModelTypeConfigForm(condition, null)); } } nodeTypeConfigForms.put(condition, conditionForms); } } return nodeTypeConfigForms; }