List of usage examples for org.w3c.dom Element getTagName
public String getTagName();
From source file:edu.lternet.pasta.client.ReservationsManager.java
/** * Builds an options list for the number of reservations the end user is * requesting with a single button click. * // ww w. j av a2 s.c om * @return the options HTML to be inserted into the <select> element * @throws PastaEventException */ public String reservationsDeleteOptionsHTML() throws Exception { String html; StringBuilder sb = new StringBuilder(""); if (this.uid != null && !this.uid.equals("public")) { String xmlString = listActiveReservations(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); try { DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); InputStream inputStream = IOUtils.toInputStream(xmlString, "UTF-8"); Document document = documentBuilder.parse(inputStream); Element documentElement = document.getDocumentElement(); NodeList reservations = documentElement.getElementsByTagName("reservation"); int nReservations = reservations.getLength(); for (int i = 0; i < nReservations; i++) { Node reservationNode = reservations.item(i); NodeList reservationChildren = reservationNode.getChildNodes(); String docid = ""; String principal = ""; boolean include = false; for (int j = 0; j < reservationChildren.getLength(); j++) { Node childNode = reservationChildren.item(j); if (childNode instanceof Element) { Element reservationElement = (Element) childNode; if (reservationElement.getTagName().equals("principal")) { Text text = (Text) reservationElement.getFirstChild(); if (text != null) { principal = text.getData().trim(); if (principal.startsWith(this.uid)) { include = true; } } } else if (reservationElement.getTagName().equals("docid")) { Text text = (Text) reservationElement.getFirstChild(); if (text != null) { docid = text.getData().trim(); } } } } if (include) { sb.append(String.format(" <option value=\"%s\">%s</option>\n", docid, docid)); } } } catch (Exception e) { logger.error("Exception:\n" + e.getMessage()); e.printStackTrace(); throw new PastaEventException(e.getMessage()); } } html = sb.toString(); return html; }
From source file:org.apache.servicemix.jms.JmsConsumerEndpointTest.java
public void testConsumerDefaultInOutJmsTx() throws Exception { JmsComponent component = new JmsComponent(); JmsConsumerEndpoint endpoint = new JmsConsumerEndpoint(); endpoint.setService(new QName("jms")); endpoint.setEndpoint("endpoint"); endpoint.setTargetService(new QName("echo")); endpoint.setListenerType("default"); endpoint.setConnectionFactory(connectionFactory); endpoint.setDestinationName("destination"); endpoint.setReplyDestinationName("replyDestination"); endpoint.setTransacted("jms"); endpoint.setMarshaler(new DefaultConsumerMarshaler(JbiConstants.IN_OUT)); component.setEndpoints(new JmsConsumerEndpoint[] { endpoint }); container.activateComponent(component, "servicemix-jms"); jmsTemplate.convertAndSend("destination", "<hello>world</hello>"); TextMessage msg = (TextMessage) jmsTemplate.receive("replyDestination"); Element e = sourceTransformer.toDOMElement(new StringSource(msg.getText())); assertEquals("hello", e.getTagName()); assertEquals("world", e.getTextContent()); Thread.sleep(500);/*from ww w.j ava2 s.c om*/ }
From source file:edu.cornell.mannlib.vitro.webapp.web.templatemodels.customlistview.CustomListViewConfigFile.java
private void elementMustNotBeEmpty(Element element) throws InvalidConfigurationException { String contents = element.getTextContent(); if (contents.trim().isEmpty()) { throw new InvalidConfigurationException( "In a config file, the <" + element.getTagName() + "> element must not be empty."); }//from ww w . ja v a 2 s . c o m }
From source file:org.springmodules.validation.bean.conf.namespace.ValangConditionParserDefinitionParser.java
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { BeanDefinitionBuilder builder = BeanDefinitionBuilder .rootBeanDefinition(ValangConditionExpressionParser.class); Map functionByName = new HashMap(); Map dateParsers = new HashMap(); for (Iterator elements = DomUtils.childElements(element); elements.hasNext();) { Element child = (Element) elements.next(); if (isFunctionDefinition(child)) { registerFunction(child, functionByName); } else if (isDateParserDefinition(child)) { registerDateParser(child, dateParsers); } else {//www .j ava 2s . c om throw new ValidationConfigurationException("unknown element '" + child.getTagName() + "'"); } } builder.addPropertyValue("customFunctions", functionByName); builder.addPropertyValue("dateParsers", dateParsers); return builder.getBeanDefinition(); }
From source file:it.grid.storm.namespace.config.xml.XMLNamespaceLoader.java
private String getNamespaceSchemaFileName() { String schemaName = it.grid.storm.config.Configuration.getInstance().getNamespaceSchemaFilename(); if (schemaName.equals("Schema UNKNOWN!")) { schemaName = "namespace.xsd"; String namespaceFN = getNamespaceFileName(); File namespaceFile = new File(namespaceFN); if (namespaceFile.exists()) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); try { DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(namespaceFN); Element rootElement = doc.getDocumentElement(); String tagName = rootElement.getTagName(); if (tagName.equals("namespace")) { if (rootElement.hasAttributes()) { String value = rootElement.getAttribute("xsi:noNamespaceSchemaLocation"); if ((value != null) && (value.length() > 0)) { schemaName = value; // log.debug("namespace schema is : " + schemaName); }/*from w w w . j a v a 2 s . com*/ } else { log.error(namespaceFN + " don't have a valid root element attributes"); } } else { log.error(namespaceFN + " don't have a valid root element."); } } catch (ParserConfigurationException e) { log.error("Error while parsing " + namespaceFN + e.getMessage()); } catch (SAXException e) { log.error("Error while parsing " + namespaceFN + e.getMessage()); } catch (IOException e) { log.error("Error while parsing " + namespaceFN + e.getMessage()); } } } return schemaName; }
From source file:edu.lternet.pasta.client.ReservationsManager.java
/** * Composes HTML table rows to render the list of active reservations for * this user.//w ww . j av a 2s . c om * * @return an HTML snippet of table row (<tr>) elements, one per * active data package identifier reservation for this user. * @throws Exception */ public String reservationsTableHTML() throws Exception { String html; StringBuilder sb = new StringBuilder(""); if (this.uid != null && !this.uid.equals("public")) { String xmlString = listActiveReservations(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); try { DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); InputStream inputStream = IOUtils.toInputStream(xmlString, "UTF-8"); Document document = documentBuilder.parse(inputStream); Element documentElement = document.getDocumentElement(); NodeList reservations = documentElement.getElementsByTagName("reservation"); int nReservations = reservations.getLength(); for (int i = 0; i < nReservations; i++) { Node reservationNode = reservations.item(i); NodeList reservationChildren = reservationNode.getChildNodes(); String docid = ""; String principal = ""; String dateReserved = ""; boolean include = false; for (int j = 0; j < reservationChildren.getLength(); j++) { Node childNode = reservationChildren.item(j); if (childNode instanceof Element) { Element reservationElement = (Element) childNode; if (reservationElement.getTagName().equals("principal")) { Text text = (Text) reservationElement.getFirstChild(); if (text != null) { principal = text.getData().trim(); if (principal.startsWith(this.uid)) { include = true; } } } else if (reservationElement.getTagName().equals("docid")) { Text text = (Text) reservationElement.getFirstChild(); if (text != null) { docid = text.getData().trim(); } } else if (reservationElement.getTagName().equals("dateReserved")) { Text text = (Text) reservationElement.getFirstChild(); if (text != null) { dateReserved = text.getData().trim(); } } } } if (include) { sb.append("<tr>\n"); sb.append(" <td class='nis' align='center'>"); sb.append(docid); sb.append("</td>\n"); sb.append(" <td class='nis' align='center'>"); sb.append(principal); sb.append("</td>\n"); sb.append(" <td class='nis'>"); sb.append(dateReserved); sb.append("</td>\n"); sb.append("</tr>\n"); } } } catch (Exception e) { logger.error("Exception:\n" + e.getMessage()); e.printStackTrace(); throw new PastaEventException(e.getMessage()); } } html = sb.toString(); return html; }
From source file:com.krawler.esp.utils.ConfigReader.java
private void loadResource(Properties properties, Object name, boolean quietFail) { try {//from ww w .j av a 2 s . co m DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = null; if (name instanceof String) { // a CLASSPATH resource String path = getResourceAsString((String) name); LOG.debug("Path is " + path); if (path != null) { doc = builder.parse(path); } } else if (name instanceof File) { // a file resource File file = (File) name; if (file.exists()) { doc = builder.parse(file); } } if (doc == null) { if (quietFail) return; throw new RuntimeException(name + " not found"); } Element root = doc.getDocumentElement(); if (!"krawler-conf".equals(root.getTagName())) System.err.print("bad conf file: top-level element not <krawler-conf>"); NodeList props = root.getChildNodes(); for (int i = 0; i < props.getLength(); i++) { Node propNode = props.item(i); if (!(propNode instanceof Element)) continue; Element prop = (Element) propNode; if (!"property".equals(prop.getTagName())) System.err.print("bad conf file: element not <property>"); NodeList fields = prop.getChildNodes(); String attr = null; String value = null; 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())) attr = ((Text) field.getFirstChild()).getData(); if ("value".equals(field.getTagName()) && field.hasChildNodes()) value = ((Text) field.getFirstChild()).getData(); } if (attr != null && value != null) properties.setProperty(attr, value); } } catch (Exception e) { System.err.print("error parsing conf file: " + e); throw new RuntimeException(e); } }
From source file:com.interface21.beans.factory.xml.XmlBeanFactory.java
private Object parsePropertySubelement(Element ele) { if (ele.getTagName().equals(REF_ELEMENT)) { // a reference to another bean in this factory? String beanName = ele.getAttribute(BEAN_REF_ATTRIBUTE); if ("".equals(beanName)) { // a reference to an external bean (in a parent factory)? beanName = ele.getAttribute(EXTERNAL_REF_ATTRIBUTE); if ("".equals(beanName)) { throw new FatalBeanException("Either 'bean' or 'external' is required for a reference"); }/* w ww . j av a 2 s .co m*/ } return new RuntimeBeanReference(beanName); } else if (ele.getTagName().equals(VALUE_ELEMENT)) { // It's a literal value return getTextValue(ele); } else if (ele.getTagName().equals(LIST_ELEMENT)) { return getList(ele); } else if (ele.getTagName().equals(MAP_ELEMENT)) { return getMap(ele); } else if (ele.getTagName().equals(PROPS_ELEMENT)) { return getProps(ele); } throw new BeanDefinitionStoreException("Unknown subelement of <property>: <" + ele.getTagName() + ">", null); }
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.//from w ww. j av a 2 s . com */ 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:com.google.appengine.tools.mapreduce.ConfigurationTemplatePreprocessor.java
/** * Initializes a ConfigurationTemplatePreprocessor with the template XML * * @param xmlString the template XML configuration *///from w w w. j a v a 2 s . c o m public ConfigurationTemplatePreprocessor(String xmlString) { DocumentBuilderFactory docBuilderFactory = createConfigurationDocBuilderFactory(); try { DocumentBuilder builder = docBuilderFactory.newDocumentBuilder(); doc = builder.parse(new ByteArrayInputStream(xmlString.getBytes("UTF8"))); Element root = doc.getDocumentElement(); if (!"configuration".equals(root.getTagName())) { throw new RuntimeException("Bad configuration file: top-level element not <configuration>"); } NodeList props = root.getChildNodes(); for (int i = 0; i < props.getLength(); i++) { Node propNode = props.item(i); if (!(propNode instanceof Element)) { continue; } Element prop = (Element) propNode; // TODO(user): Currently not implementing nested configuration elements. // If there's demand, this can be revisited. populateParameterFromProperty(prop); } } catch (ParserConfigurationException e) { throw new RuntimeException("Couldn't create XML parser", e); } catch (UnsupportedEncodingException e) { throw new RuntimeException("JDK doesn't support UTF8", e); } catch (SAXException e) { // Would throw a better exception, but Configuration doesn't. throw new RuntimeException("Encountered error parsing configuration XML", e); } catch (IOException e) { throw new RuntimeException("Encountered IOException on a ByteArrayInputStream", e); } }