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:net.exclaimindustries.geohashdroid.wiki.WikiUtils.java
/** * Returns the raw content of a wiki page in a single string. Optionally, * also attaches the fields for future resubmission to a HashMap (namely, an * edittoken and a timestamp)./*from w w w . ja v a2s . co m*/ * * @param httpclient an active HTTP session * @param pagename the name of the wiki page * @param formfields if not null, this hashmap will be filled with the correct HTML form fields to resubmit the page. * @return the raw code of the wiki page, or null if the page doesn't exist * @throws WikiException problem with the wiki, translate the ID * @throws Exception anything else happened, use getMessage */ public static String getWikiPage(HttpClient httpclient, String pagename, HashMap<String, String> formfields) throws Exception { // We can use a GET statement here. HttpGet httpget = new HttpGet( WIKI_API_URL + "?action=query&format=xml&prop=" + URLEncoder.encode("info|revisions", "UTF-8") + "&rvprop=content&format=xml&intoken=edit&titles=" + URLEncoder.encode(pagename, "UTF-8")); String page; Document response = getHttpDocument(httpclient, httpget); // Good, good. First, figure out if the page even exists. Element root = response.getDocumentElement(); // Error check! if (doesResponseHaveError(root)) { throw new WikiException(getErrorTextId(findErrorCode(root))); } Element pageElem; Element text; try { pageElem = DOMUtil.getFirstElement(root, "page"); } catch (Exception e) { throw new WikiException(R.string.wiki_error_xml); } // If we got an "invalid" attribute, the page not only doesn't exist, but it // CAN'T exist, and is therefore an error. if (pageElem.hasAttribute("invalid")) throw new WikiException(R.string.wiki_error_invalid_page); if (formfields != null) { // If we have a formfields hash ready, populate it with a couple values. formfields.put("summary", "An expedition message sent via Geohash Droid for Android."); if (pageElem.hasAttribute("edittoken")) formfields.put("token", DOMUtil.getSimpleAttributeText(pageElem, "edittoken")); if (pageElem.hasAttribute("touched")) formfields.put("basetimestamp", DOMUtil.getSimpleAttributeText(pageElem, "touched")); } // If we got a "missing" attribute, the page hasn't been made yet, so we // return null. if (pageElem.hasAttribute("missing")) return null; // Otherwise, get the text and fill out the form fields. try { text = DOMUtil.getFirstElement(pageElem, "rev"); } catch (Exception e) { throw new WikiException(R.string.wiki_error_xml); } page = DOMUtil.getSimpleElementText(text); return page; }
From source file:org.brekka.stillingar.spring.config.ConfigurationServiceBeanDefinitionParser.java
/** * @param naming/*from ww w. j a v a 2s. com*/ * @param string * @param prefix * @return */ protected static String attribute(Element elem, String attributeName, String defaultValue) { String value; if (elem.hasAttribute(attributeName)) { value = elem.getAttribute(attributeName); } else { value = defaultValue; } return value; }
From source file:org.xmatthew.spy2servers.config.ComponentParser.java
protected void doParse(Element element, BeanDefinitionBuilder builder) { if (element.hasAttribute(NAME_ELEMENT)) { builder.addPropertyValue(NAME_ELEMENT, element.getAttribute(NAME_ELEMENT)); }// w ww .j a v a2s .c om }
From source file:org.jdal.aop.config.SerializableProxyBeanDefinitionDecorator.java
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) { boolean proxyTargetClass = true; if (node instanceof Element) { Element ele = (Element) node; if (ele.hasAttribute(PROXY_TARGET_CLASS)) { proxyTargetClass = Boolean.valueOf(ele.getAttribute(PROXY_TARGET_CLASS)); }//from ww w .j av a2 s.c o m } // Register the original bean definition BeanDefinitionHolder holder = SerializableProxyUtils.createSerializableProxy(definition, parserContext.getRegistry(), proxyTargetClass); String targetBeanName = SerializableProxyUtils.getTargetBeanName(definition.getBeanName()); parserContext.getReaderContext().fireComponentRegistered( new BeanComponentDefinition(definition.getBeanDefinition(), targetBeanName)); return holder; }
From source file:org.springmodules.validation.bean.conf.loader.xml.handler.ExpressionPropertyValidationElementHandler.java
public boolean isConditionGloballyScoped(Element element) { if (!element.hasAttribute(SCOPE_ATTR)) { return true; }/*from www . j a v a 2 s. c o m*/ String value = element.getAttribute(SCOPE_ATTR); if (GLOBAL_SCOPE_VALUE.equals(value)) { return true; } if (PROPERTY_SCOPE_VALUE.equals(value)) { return false; } throw new ValidationConfigurationException( "Unknown value '" + value + "' for attribute '" + SCOPE_ATTR + "'"); }
From source file:org.xmatthew.spy2servers.config.ChannelParser.java
protected void doParse(Element element, BeanDefinitionBuilder builder) { if (element.hasAttribute("from")) { String from = element.getAttribute("from"); builder.addPropertyReference("from", from); }//from w w w .ja va 2s. c o m if (element.hasAttribute("to")) { String to = element.getAttribute("to"); builder.addPropertyReference("to", to); } }
From source file:org.jdal.beans.ColumnBeanDefinitionParser.java
/** * {@inheritDoc}//from ww w. jav a 2s . com */ @Override protected void postProcess(BeanDefinitionBuilder beanDefinition, Element element) { beanDefinition.setScope("prototype"); if (element.hasAttribute(RENDERER_ATTRIBUTE)) beanDefinition.addPropertyReference(RENDERER_ATTRIBUTE, element.getAttribute(RENDERER_ATTRIBUTE)); }
From source file:com.mtgi.analytics.aop.config.v11.BtAdviceBeanDefinitionParser.java
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { if (element.hasAttribute(BtNamespaceConstants.ATT_TRACKING_MANAGER)) { builder.addPropertyReference(BtNamespaceConstants.PROP_TRACKING_MANAGER, element.getAttribute(BtNamespaceConstants.ATT_TRACKING_MANAGER)); //if there is an explicit tracking manager reference, there's no need to register our post-processor. return;//from w w w.j av a 2 s .com } else { //add reference to default tracking manager alias. this will result in a runtime //error if the configuration is inconsistent builder.addPropertyReference(BtNamespaceConstants.PROP_TRACKING_MANAGER, "defaultTrackingManager"); } }
From source file:org.jdal.beans.SimpleBeanDefinitionParser.java
protected void parseDefaultAttributes(Element element, BeanDefinitionBuilder builder) { if (element.hasAttribute(SCOPE_ATTRIBUTE)) builder.setScope(element.getAttribute(SCOPE_ATTRIBUTE)); }
From source file:org.xmatthew.spy2servers.config.JmxServiceComponentParser.java
protected void doParse(Element element, BeanDefinitionBuilder builder) { super.doParse(element, builder); if (element.hasAttribute("port")) { int port = Integer.valueOf(element.getAttribute("port")); builder.addPropertyValue("port", port); }/*www . ja v a2 s . c o m*/ }