List of usage examples for org.w3c.dom Element getTextContent
public String getTextContent() throws DOMException;
From source file:jp.canetrash.maven.plugin.bijint.BujintMojo.java
/** * ?HTML???/*from ww w.ja v a2 s . co m*/ * @param str * @return * @throws IOException * @throws SAXException * @throws TransformerException */ private String bringOutAsciiArtString(String str) { // ??HTML??AA????? String aa = null; DOMParser parser = new DOMParser(); try { parser.setFeature("http://xml.org/sax/features/namespaces", false); parser.parse(new InputSource(new StringReader(str))); NodeList nodeList = XPathAPI.selectNodeList(parser.getDocument(), "/HTML/BODY/PRE"); for (int i = 0; i < nodeList.getLength(); i++) { Element element = (Element) nodeList.item(i); aa = element.getTextContent(); } } catch (Exception e) { throw new RuntimeException(e); } return aa; }
From source file:com.googlecode.osde.internal.editors.locale.LocaleModel.java
private void loadMessageBundleFile(IProject project) { String fileName = MESSAGE_BUNDLE_FILENAME_PREFIX + lang + "_" + country + ".xml"; IFile file = project.getFile(fileName); if (file.exists()) { try {/*from www. j a v a 2 s .c o m*/ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.parse(file.getContents()); NodeList msgList = document.getElementsByTagName("msg"); for (int i = 0; i < msgList.getLength(); i++) { Element msg = (Element) msgList.item(i); String name = msg.getAttribute("name"); String value = msg.getTextContent(); messages.put(name, value); } } catch (ParserConfigurationException e) { logger.warn("Loading message bundle file failed.", e); } catch (SAXException e) { logger.warn("Loading message bundle file failed.", e); } catch (IOException e) { logger.warn("Loading message bundle file failed.", e); } catch (CoreException e) { logger.warn("Loading message bundle file failed.", e); } } }
From source file:io.mycat.config.loader.xml.XMLRuleLoader.java
private RuleConfig loadRule(Element element) throws SQLSyntaxErrorException { //?columns//from w w w . ja v a2 s. com Element columnsEle = ConfigUtil.loadElement(element, "columns"); String column = columnsEle.getTextContent(); String[] columns = SplitUtil.split(column, ',', true); if (columns.length > 1) { throw new ConfigException("table rule coulmns has multi values:" + columnsEle.getTextContent()); } //?algorithm Element algorithmEle = ConfigUtil.loadElement(element, "algorithm"); String algorithm = algorithmEle.getTextContent(); return new RuleConfig(column.toUpperCase(), algorithm); }
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 www. j a va 2 s. co m }
From source file:com.moviejukebox.reader.MovieNFOReader.java
/** * Parse Directors from the XML NFO file * * @param nlElements//ww w . j a va 2s . co m * @param movie */ private static void parseDirectors(NodeList nlElements, Movie movie) { // check if we have a node if (nlElements == null || nlElements.getLength() == 0) { return; } // check if we should override boolean overrideDirectors = OverrideTools.checkOverwriteDirectors(movie, NFO_PLUGIN_ID); boolean overridePeopleDirectors = OverrideTools.checkOverwritePeopleDirectors(movie, NFO_PLUGIN_ID); if (!overrideDirectors && !overridePeopleDirectors) { // nothing to do if nothing should be overridden return; } List<String> newDirectors = new ArrayList<>(); Node nElements; for (int looper = 0; looper < nlElements.getLength(); looper++) { nElements = nlElements.item(looper); if (nElements.getNodeType() == Node.ELEMENT_NODE) { Element eDirector = (Element) nElements; newDirectors.add(eDirector.getTextContent()); } } if (overrideDirectors) { movie.setDirectors(newDirectors, NFO_PLUGIN_ID); } if (overridePeopleDirectors) { movie.setPeopleDirectors(newDirectors, NFO_PLUGIN_ID); } }
From source file:com.evolveum.midpoint.prism.xml.XmlTypeConverter.java
/** * Parse PolyString from DOM element.//w w w . ja va 2 s . c o m */ private static PolyString polyStringToJava(Element polyStringElement) throws SchemaException { Element origElement = DOMUtil.getChildElement(polyStringElement, PrismConstants.POLYSTRING_ELEMENT_ORIG_QNAME); if (origElement == null) { // Check for a special syntactic short-cut. If the there are no child elements use the text content of the // element as the value of orig if (DOMUtil.hasChildElements(polyStringElement)) { throw new SchemaException("Missing element " + PrismConstants.POLYSTRING_ELEMENT_ORIG_QNAME + " in polystring element " + DOMUtil.getQName(polyStringElement)); } String orig = polyStringElement.getTextContent(); return new PolyString(orig); } String orig = origElement.getTextContent(); String norm = null; Element normElement = DOMUtil.getChildElement(polyStringElement, PrismConstants.POLYSTRING_ELEMENT_NORM_QNAME); if (normElement != null) { norm = normElement.getTextContent(); } return new PolyString(orig, norm); }
From source file:edu.cornell.mannlib.vitro.webapp.web.templatemodels.customlistview.CustomListViewConfigFile.java
private Set<String> parseConstructQueries(Document doc) { Set<String> queries = new HashSet<String>(); for (Element element : getElements(doc, TAG_CONSTRUCT)) { String content = element.getTextContent(); if (!content.trim().isEmpty()) { queries.add(content);//w ww . j a v a2 s. c om } } return queries; }
From source file:org.jolokia.roo.JolokiaCommands.java
private void addRepository(Element configuration) { Pom pom = projectOperations.getFocusedModule(); // Check whether we are a snapshot version, if so, we are adding our snapshot repository List<Element> versions = XmlUtils.findElements("/configuration/jolokia/dependencies/dependency/version", configuration);/*w w w .jav a2 s .co m*/ boolean isSnapshot = false; for (Element version : versions) { if (version.getTextContent().matches(".*SNAPSHOT$")) { isSnapshot = true; break; } } List<Element> repositories = isSnapshot ? XmlUtils.findElements("/configuration/jolokia/snapshots-repositories/repository", configuration) : XmlUtils.findElements("/configuration/jolokia/repositories/repository", configuration); for (Element repositoryElement : repositories) { Repository repository = new Repository(repositoryElement); projectOperations.addRepository(pom.getModuleName(), repository); } }
From source file:com.dianping.zebra.shard.jdbc.base.SingleDBBaseTestCase.java
protected void parseCreateTableScriptFile() throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document configDoc = builder//from ww w. j a va 2 s. c om .parse(SingleDBBaseTestCase.class.getClassLoader().getResourceAsStream(getCreateTableScriptPath())); XPathFactory xpathFactory = XPathFactory.newInstance(); XPath xpath = xpathFactory.newXPath(); NodeList tableScriptList = (NodeList) xpath.compile("/tables/table").evaluate(configDoc, XPathConstants.NODESET); for (int i = 0; i < tableScriptList.getLength(); i++) { SingleCreateTableScriptEntry entry = new SingleCreateTableScriptEntry(); Element ele = (Element) tableScriptList.item(i); entry.setTableName(ele.getAttribute("name")); entry.setCreateTableScript(ele.getTextContent()); createdTableList.add(entry); } }
From source file:edu.internet2.middleware.shibboleth.common.config.security.AbstractX509CredentialBeanDefinitionParser.java
/** * Parses the certificates from the credential configuration. * //from w ww.ja v a 2s.com * @param configChildren children of the credential element * @param builder credential build */ protected void parseCertificates(Map<QName, List<Element>> configChildren, BeanDefinitionBuilder builder) { List<Element> certElems = configChildren.get(new QName(SecurityNamespaceHandler.NAMESPACE, "Certificate")); if (certElems == null || certElems.isEmpty()) { return; } log.debug("Parsing x509 credential certificates"); ArrayList<X509Certificate> certs = new ArrayList<X509Certificate>(); byte[] encodedCert; Collection<X509Certificate> decodedCerts; for (Element certElem : certElems) { encodedCert = getEncodedCertificate(DatatypeHelper.safeTrimOrNullString(certElem.getTextContent())); if (encodedCert == null) { continue; } boolean isEntityCert = false; Attr entityCertAttr = certElem.getAttributeNodeNS(null, "entityCertificate"); if (entityCertAttr != null) { isEntityCert = XMLHelper.getAttributeValueAsBoolean(entityCertAttr); } if (isEntityCert) { log.debug("Element config flag found indicating entity certificate"); } try { decodedCerts = X509Util.decodeCertificate(encodedCert); certs.addAll(decodedCerts); if (isEntityCert) { if (decodedCerts.size() == 1) { builder.addPropertyValue("entityCertificate", decodedCerts.iterator().next()); } else { throw new FatalBeanException( "Config element indicated an entityCertificate, but multiple certs where decoded"); } } } catch (CertificateException e) { throw new FatalBeanException("Unable to create X509 credential, unable to parse certificates", e); } } builder.addPropertyValue("certificates", certs); }