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.urbantower.j4s.spring.ServerParser.java
@Override public BeanDefinition parse(Element element, ParserContext parserContext) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(SpringServer.class); //set port//from w ww . j a v a 2s . co m String port = element.getAttribute("http-port"); builder.addPropertyValue("httpPort", Integer.parseInt(port)); //parse & set handlers ManagedList<BeanDefinition> handlers = new ManagedList<>(); if (element.hasAttribute("handler")) { String handlerRef = element.getAttribute("handler"); builder.addPropertyValue("handler", new RuntimeBeanReference(handlerRef)); } else { List<Element> childs = DomUtils.getChildElements(element); if (childs != null && childs.size() > 0) { BeanDefinition handlerDef = parserContext.getDelegate().parseCustomElement(childs.get(0), builder.getBeanDefinition()); builder.addPropertyValue("handler", handlerDef); } } //get id String id = parserContext.getReaderContext().generateBeanName(builder.getBeanDefinition()); if (element.hasAttribute("id")) { id = element.getAttribute("id"); } //get the thread-pool if (element.hasAttribute("thread-pool")) { builder.addConstructorArgValue(new RuntimeBeanReference(element.getAttribute("thread-pool"))); } //register server def. parserContext.getRegistry().registerBeanDefinition(id, builder.getBeanDefinition()); return builder.getBeanDefinition(); }
From source file:net.sourceforge.dita4publishers.impl.dita.InMemoryDitaKeySpace.java
/** * @param keyDef/*from ww w . ja v a 2 s .co m*/ * @throws AddressingException * @throws BosException */ private Object resolveKeyrefResource(DitaKeyDefinition keyDef) throws AddressingException { Element keydefElem = keyDef.getKeyDefElem(); if (keydefElem.hasAttribute("href")) { String format = keydefElem.getAttribute("format"); if (format == null || "".equals(format)) { format = "dita"; } String href = keydefElem.getAttribute("href"); if (format.equals("dita") || format.equals("ditamap")) { // target should be a DITA map or topic document Document doc = AddressingUtil.resolveHrefToDoc(keydefElem, href, this.bosOptions, false); if (doc == null) { log.warn("Failed to resolve keyref \"" + keyDef.getKey() + "\" to a DITA resource with URL \"" + href + "\""); keyDef.setResource(new UnresolvedResource()); } else { keyDef.setResource(doc); } } else { URI uri = AddressingUtil.resolveHrefToUri(keydefElem, href, false); if (uri == null) { log.warn("Failed to resolve keyref \"" + keyDef.getKey() + "\" to a non-DITA resource with URL \"" + href + "\""); keyDef.setResource(new UnresolvedResource()); } else { keyDef.setResource(uri); } } } else { // If no HREF, then the keydef is the resource. keyDef.setResource(keydefElem); } return keyDef.getResource(); }
From source file:keel.Algorithms.UnsupervisedLearning.AssociationRules.Visualization.keelassotiationrulesbarchart.ResultsProccessor.java
private Double processMeasure(Element rule, String measureName, String beautifulName) { Double measureValue = 0.0;/*from w ww. j av a2 s .c om*/ if (rule.hasAttribute(measureName)) { measureValue = Double.parseDouble(rule.getAttribute(measureName)); } if (algorithmMeasures.containsKey(actualAlgorithm)) { if (!algorithmMeasures.get(actualAlgorithm).containsKey(beautifulName)) { // Initialize if not exists algorithmMeasures.get(actualAlgorithm).put(beautifulName, measureValue); } else { // update if exists Double newValue = algorithmMeasures.get(actualAlgorithm).get(beautifulName) + measureValue; algorithmMeasures.get(actualAlgorithm).put(beautifulName, newValue); } } else { HashMap tmp = new HashMap<String, Double>(); tmp.put(beautifulName, measureValue); algorithmMeasures.put(actualAlgorithm, tmp); } return measureValue; }
From source file:com.concursive.connect.web.modules.wiki.utils.HTMLToWikiUtils.java
public static void processVideo(StringBuffer sb, Node n, Element element, String appendToCRLF, String contextPath) {//from w w w. j a va 2 s . c o m // Determine if a thumbnail boolean thumbnail = false; if ("120".equals(element.getAttribute("width"))) { thumbnail = true; } // Object (w/out embed) if (element.hasAttribute("value")) { LOG.trace(" value"); //<object width="400" height="300" value="http://vimeo.com/moogaloop.swf?clip_id=11513988&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1"> String video = element.getAttribute("value"); if (video.contains("http://www.vimeo.com/") || video.contains("http://vimeo.com/")) { video = video.substring(video.indexOf("/", video.indexOf("http://") + 7) + 1); if (video.contains("#")) { video = video.substring(0, video.indexOf("#")); } if (video.contains("&")) { video = video.substring(0, video.indexOf("&")); } video = "http://www.vimeo.com/" + video.substring(video.indexOf("clip_id") + 8); } // Write out the markup try { URL url = new URL(video); sb.append("[[Video:" + video + (thumbnail ? "|thumb" : "") + "]]"); } catch (Exception e) { LOG.error("Could not create URL", e); } } else if (element.hasAttribute("data")) { LOG.trace(" data"); //<object width="425" height="344" type="application/x-shockwave-flash" data="http://www.youtube.com/v/CreiaYbjda4"></object> String video = element.getAttribute("data"); // Justin.tv //<object type="application/x-shockwave-flash" height="300" width="400" id="live_embed_player_flash" data="http://www.justin.tv/widgets/live_embed_player.swf?channel=redspades" bgcolor="#000000"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="allowNetworking" value="all" /><param name="movie" value="http://www.justin.tv/widgets/live_embed_player.swf" /><param name="flashvars" value="channel=redspades&auto_play=false&start_volume=25" /></object><a href="http://www.justin.tv/redspades#r=TRp3S20~&s=em" class="trk" style="padding:2px 0px 4px; display:block; width:345px; font-weight:normal; font-size:10px; text-decoration:underline; text-align:center;">Watch live video from RedSpades Live! Show on Justin.tv</a> if (video.contains("http://www.justin.tv/")) { video = "http://www.justin.tv/" + video.substring(video.indexOf("channel=") + 8); if (video.contains("#")) { video = video.substring(0, video.indexOf("#")); } } // otherwise Youtube/Google // Write out the markup try { URL url = new URL(video); sb.append("[[Video:" + video + (thumbnail ? "|thumb" : "") + "]]"); } catch (Exception e) { LOG.error("Could not create URL", e); } } else { LOG.trace(" checking nodes"); // Parse the object parameters // <object width=\"425\" height=\"344\">\n // <param name=\"movie\" value=\"" + video + "\"></param>\n" + // <param name=\"wmode\" value=\"transparent\"></param>\n" + // <embed src=\"" + video + "\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"425\" height=\"350\"></embed>\n" + // </object> NodeList objectNodes = element.getChildNodes(); boolean foundQikVideo = false; boolean handleException = false; for (int i = 0; i < objectNodes.getLength(); i++) { // For each object, parse the params Node node = objectNodes.item(i); LOG.trace(" " + ((Element) node).getTagName()); if (node.getNodeType() == Node.ELEMENT_NODE && "param".equals(((Element) node).getTagName())) { if ("movie".equals(((Element) node).getAttribute("name"))) { String video = ((Element) node).getAttribute("value"); // Ustream if (video.contains("ustream.tv/")) { handleException = true; String ustreamLink = XMLUtils.toString(n); ustreamLink = StringUtils.replace(ustreamLink, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>", ""); ustreamLink = StringUtils.replace(ustreamLink, "\r", ""); ustreamLink = StringUtils.replace(ustreamLink, "\n", ""); ustreamLink = StringUtils.replace(ustreamLink, " ", ""); sb.append("[[Video:" + ustreamLink + "]]"); } // Qik.com if (video.contains("qik.com")) { foundQikVideo = true; handleException = true; } // Livestream.com if (video.indexOf("livestream.com") > -1) { //"<param name=\"movie\" value=\"http://cdn.livestream.com/grid/LSPlayer.swf?channel=" + channel + "&autoPlay=true\"></param>" + String channel = video.substring(video.indexOf("channel=") + 8, video.indexOf("&")); video = "http://www.livestream.com/" + channel; } // otherwise assume Youtube/Google if (!handleException) { // Write out the markup try { URL url = new URL(video); sb.append("[[Video:" + video + (thumbnail ? "|thumb" : "") + "]]"); } catch (Exception e) { LOG.error("Could not create URL", e); } } } else if ("FlashVars".equals(((Element) node).getAttribute("name"))) { String value = ((Element) node).getAttribute("value"); // Qik.com if (foundQikVideo && value.contains("username=")) { String username = value.substring(value.indexOf("username=") + 9); sb.append( "[[Video:" + "http://qik.com/" + username + (thumbnail ? "|thumb" : "") + "]]"); } } } } } }
From source file:org.mule.transport.zmq.config.InboundEndpointDefinitionParser.java
public BeanDefinition parseChild(Element element, ParserContext parserContent) { BeanDefinitionBuilder builder = BeanDefinitionBuilder .rootBeanDefinition(InboundEndpointMessageSource.class.getName()); String configRef = element.getAttribute("config-ref"); if ((configRef != null) && (!StringUtils.isBlank(configRef))) { builder.addPropertyValue("moduleObject", configRef); }//from www . ja v a 2 s. c o m 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")); } if ((element.getAttribute("retryMax") != null) && (!StringUtils.isBlank(element.getAttribute("retryMax")))) { builder.addPropertyValue("retryMax", element.getAttribute("retryMax")); } BeanDefinition definition = builder.getBeanDefinition(); definition.setAttribute(MuleHierarchicalBeanDefinitionParserDelegate.MULE_NO_RECURSE, Boolean.TRUE); MutablePropertyValues propertyValues = parserContent.getContainingBeanDefinition().getPropertyValues(); propertyValues.addPropertyValue("messageSource", definition); return definition; }
From source file:com.google.appengine.tools.mapreduce.ConfigurationTemplatePreprocessor.java
/** * Substitutes in the values in params for templated values. After this method * is called, any subsequent calls to this method for the same object result in * an {@link IllegalStateException}. To preprocess the template again, * create another {@code ConfigurationTemplatePreprocessor} from the source XML. * * @param params a map from key to value of all the template parameters * @return the document as an XML string with the template parameters filled * in// www . j a v a 2 s .c o m * @throws MissingTemplateParameterException if any required parameter is * omitted * @throws IllegalStateException if this method has previously been called * on this object */ public String preprocess(Map<String, String> params) { HashMap<String, String> paramsCopy = new HashMap<String, String>(params); if (preprocessCalled) { throw new IllegalStateException("Preprocess can't be called twice for the same object"); } preprocessCalled = true; for (Entry<String, Element> entry : nameToValueElement.entrySet()) { Element valueElem = entry.getValue(); boolean isTemplateValue = valueElem.hasAttribute("template"); if (paramsCopy.containsKey(entry.getKey()) && isTemplateValue) { // Modifies the map in place, but that's fine for our use. Text valueData = (Text) valueElem.getFirstChild(); String newValue = paramsCopy.get(entry.getKey()); if (valueData != null) { valueData.setData(newValue); } else { valueElem.appendChild(doc.createTextNode(newValue)); } // Remove parameter, so we can tell if they gave us extras. paramsCopy.remove(entry.getKey()); } else if (isTemplateValue) { String templateAttribute = valueElem.getAttribute("template"); if ("required".equals(templateAttribute)) { throw new MissingTemplateParameterException( "Couldn't find expected parameter " + entry.getKey()); } else if ("optional".equals(templateAttribute)) { // The default value is the one already in the value text, so // leave it be. The one exception is if they self-closed the value tag, // so go ahead and add a Text child so Configuration doesn't barf. if (valueElem.getFirstChild() == null) { valueElem.appendChild(doc.createTextNode("")); } } else { throw new IllegalArgumentException("Value " + templateAttribute + " is not a valid template " + "attribute. Valid possibilities are: \"required\" or \"optional\"."); } // Remove parameter, so we can tell if they gave us extras. paramsCopy.remove(entry.getKey()); } else { throw new IllegalArgumentException( "Configuration property " + entry.getKey() + " is not a template property"); } // removeAttribute has no effect if the attributes don't exist valueElem.removeAttribute("template"); } if (paramsCopy.size() > 0) { // TODO(user): Is there a good way to bubble up all bad parameters? throw new UnexpectedTemplateParameterException("Parameter " + paramsCopy.keySet().iterator().next() + " wasn't found in the configuration template."); } return getDocAsXmlString(); }
From source file:net.sf.cb2xml.convert.MainframeToXml.java
private Element convertNode(Element element, Context context) throws JCopybookUnmarshallException { String text = null;/*from ww w . ja va2s .com*/ String resultElementName = element.getAttribute("name").replaceAll("[^0-9^A-Z\\-]+", "||"); Element resultElement = resultDocument.createElement(resultElementName); try { int length = Integer.parseInt(element.getAttribute("display-length")); int childElementCount = 0; NodeList nodeList = element.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) { Element childElement = (Element) node; if (!childElement.getAttribute("level").equals("88") && "item".equals(childElement.getNodeName())) { childElementCount++; if (childElement.hasAttribute("occurs")) { boolean dependOn = StringUtils.isNotEmpty(childElement.getAttribute("depending-on")); BigInteger count = numerics.get(childElement.getAttribute("depending-on")); int childOccurs = Integer.parseInt(childElement.getAttribute("occurs")); if (dependOn && count != null) { childOccurs = count.intValue(); } for (int j = 0; j < childOccurs; j++) { resultElement.appendChild(convertNode(childElement, context)); } } else { if (!"item".equals(childElement.getAttribute("name"))) resultElement.appendChild(convertNode(childElement, context)); } } } } if (childElementCount == 0 && !"true".equals(element.getAttribute("redefined"))) { text = mainframeBuffer.substring(context.offset, context.offset + length); if ("true".equals(element.getAttribute("numeric"))) { String textForNumeric = text.trim(); if (textForNumeric.isEmpty()) { textForNumeric = "true".equals(element.getAttribute("signed")) ? "{" : "0"; } textForNumeric = removeLeftZeros(textForNumeric); if ("true".equals(element.getAttribute("signed"))) { String originalDigit = textForNumeric.substring(textForNumeric.length() - 1, textForNumeric.length()); String digit = SignedNumericMappingTable.decodeMap.get(originalDigit); if (digit == null) throw new Exception("bad signed numeric last digit: " + originalDigit); textForNumeric = (digit.startsWith("-") ? "-" : "") + textForNumeric.substring(0, textForNumeric.length() - 1) + (digit.length() == 2 ? digit.substring(1) : digit); } if (textForNumeric.length() == 0) text = "0"; else if (StringUtils.isNotEmpty(element.getAttribute("scale"))) { int scale = Integer.parseInt(element.getAttribute("scale")); textForNumeric = getDecimalValue(textForNumeric, scale); } else numerics.put(resultElementName, new BigInteger(textForNumeric)); text = textForNumeric; } context.offset += length; Text textNode = resultDocument.createTextNode(text.trim()); resultElement.appendChild(textNode); } return resultElement; } catch (Exception e) { if (e instanceof JCopybookUnmarshallException) throw (JCopybookUnmarshallException) e; throw new JCopybookUnmarshallException( String.format("can't parse copybook string on element '%s' and text '%s'", resultElementName, text), e, mainframeBuffer, XmlUtils.domToString(resultElement.getOwnerDocument()).toString(), resultElementName, text, element.getOwnerDocument()); } }
From source file:com.intuit.karate.cucumber.KarateJunitFormatter.java
private void increaseAttributeValue(Element element, String attribute) { int value = 0; if (element.hasAttribute(attribute)) { value = Integer.parseInt(element.getAttribute(attribute)); }/* ww w . j a v a2 s. c o m*/ element.setAttribute(attribute, String.valueOf(++value)); }
From source file:com.google.appengine.tools.mapreduce.ConfigurationTemplatePreprocessor.java
/** * For a single {@code Configuration} property, process it, looking * for parameter-related attributes, and updating the relevant object maps * if found.// w ww .j ava2 s . co m */ private void populateParameterFromProperty(Element prop) { String name = null; String humanName = null; Element templateValue = null; String defaultValue = null; NodeList fields = prop.getChildNodes(); for (int j = 0; j < fields.getLength(); j++) { Node fieldNode = fields.item(j); if (!(fieldNode instanceof Element)) { continue; } Element field = (Element) fieldNode; if ("name".equals(field.getTagName())) { if (field.hasAttribute("human")) { humanName = field.getAttribute("human"); } name = ((Text) field.getFirstChild()).getData().trim(); } if ("value".equals(field.getTagName()) && field.hasAttribute("template")) { templateValue = field; if (field.getAttribute("template").equals("optional")) { if (field.getFirstChild() != null) { defaultValue = field.getFirstChild().getTextContent(); } else { defaultValue = ""; } } } } if (templateValue != null) { nameToMetadata.put(name, new TemplateEntryMetadata(name, humanName, defaultValue)); nameToValueElement.put(name, templateValue); } }
From source file:de.itsvs.cwtrpc.controller.config.AutowiredRemoteServiceGroupConfigBeanDefinitionParser.java
protected BeanDefinition parseFilter(Element element, ParserContext parserContext) { final BeanDefinitionBuilder bdd; final Object type; final String expression; bdd = BeanDefinitionBuilder.rootBeanDefinition(PatternFactory.class); bdd.getRawBeanDefinition().setSource(parserContext.extractSource(element)); if (parserContext.isDefaultLazyInit()) { bdd.setLazyInit(true);/*w w w . j a v a2 s. com*/ } if (element.hasAttribute(XmlNames.TYPE_ATTR)) { type = element.getAttribute(XmlNames.TYPE_ATTR); } else { type = DEFAULT_PATTERN_TYPE; } expression = element.getAttribute(XmlNames.EXPRESSION_ATTR); if (!StringUtils.hasText(expression)) { parserContext.getReaderContext().error("Filter expression must not be empty", parserContext.extractSource(element)); } bdd.setFactoryMethod("compile"); bdd.addConstructorArgValue(type); bdd.addConstructorArgValue(MatcherType.PACKAGE); bdd.addConstructorArgValue(expression); return bdd.getBeanDefinition(); }