List of usage examples for org.w3c.dom Element getTagName
public String getTagName();
From source file:com.twinsoft.convertigo.engine.util.XMLUtils.java
public static void handleElement(Element elt, JSONObject obj, boolean ignoreStepIds, boolean useType) throws JSONException { String key = elt.getTagName(); JSONObject value = new JSONObject(); NodeList nl = elt.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i);/* w ww .ja v a2 s . c o m*/ if (node instanceof Element) { Element child = (Element) node; Object childValue = useType ? getValue(child, ignoreStepIds, useType) : null; if (childValue != null) { value.accumulate(child.getTagName(), childValue); } else { handleElement(child, value, ignoreStepIds, useType); } } } JSONObject attr = new JSONObject(); NamedNodeMap nnm = elt.getAttributes(); for (int i = 0; i < nnm.getLength(); i++) { Node node = nnm.item(i); if (ignoreStepIds && (node.getNodeName() != "step_id")) { attr.accumulate(node.getNodeName(), node.getNodeValue()); } } if (value.length() == 0) { String content = elt.getTextContent(); if (attr.length() == 0) { obj.accumulate(key, content); } else { value.accumulate("text", content); } } if (attr.length() != 0) { value.accumulate("attr", attr); } if (value.length() != 0) { obj.accumulate(key, value); } }
From source file:org.springmodules.validation.bean.conf.loader.xml.DefaultXmlBeanValidationConfigurationLoader.java
/** * Handles the <global> element and updates the given configuration with the global validation rules. * * @param globalDefinition The <global> element. * @param clazz The validated class./* ww w.j a v a 2 s .c o m*/ * @param configuration The bean validation configuration to update. */ protected void handleGlobalDefinition(Element globalDefinition, Class clazz, MutableBeanValidationConfiguration configuration) { NodeList nodes = globalDefinition.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node.getNodeType() != Node.ELEMENT_NODE) { continue; } Element ruleDefinition = (Element) node; ClassValidationElementHandler handler = handlerRegistry.findClassHandler(ruleDefinition, clazz); if (handler == null) { logger.error("Could not handle element '" + ruleDefinition.getTagName() + "'. Please make sure the proper validation rule definition handler is registered"); throw new ValidationConfigurationException( "Could not handler element '" + ruleDefinition.getTagName() + "'"); } handler.handle(ruleDefinition, configuration); } }
From source file:com.enonic.esl.xml.XMLTool.java
private static Document domparse(InputSource inputSource, String[] rootNames) { Document doc;//from ww w . j a va 2 s .c o m try { doc = getDocumentBuilder().parse(inputSource); } catch (IOException e) { throw new XMLToolException("Failed to retrieve XML source document on the given URL", e); } catch (SAXException e) { throw new XMLToolException("Failed to parse xml document", e); } if (rootNames != null) { Element root = doc.getDocumentElement(); if (root == null) { throw new XMLToolException("No root element in XML document"); } Arrays.sort(rootNames); if (Arrays.binarySearch(rootNames, root.getTagName()) < 0) { throw new XMLToolException("Wrong root element name: " + root.getTagName()); } } return doc; }
From source file:edu.lternet.pasta.client.JournalCitationsClient.java
public String citationsOptionsHTML() throws Exception { String html = ""; if (this.uid != null && !this.uid.equals("public")) { StringBuilder sb = new StringBuilder(""); String xmlString = listPrincipalOwnerCitations(this.uid); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); try {// w w w. j av a2 s. c o m DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); InputStream inputStream = IOUtils.toInputStream(xmlString, "UTF-8"); Document document = documentBuilder.parse(inputStream); Element documentElement = document.getDocumentElement(); NodeList citationsList = documentElement.getElementsByTagName("journalCitation"); int nCitations = citationsList.getLength(); for (int i = 0; i < nCitations; i++) { Node journalCitationNode = citationsList.item(i); NodeList journalCitationChildren = journalCitationNode.getChildNodes(); String journalCitationId = ""; for (int j = 0; j < journalCitationChildren.getLength(); j++) { Node childNode = journalCitationChildren.item(j); if (childNode instanceof Element) { Element journalCitationElement = (Element) childNode; if (journalCitationElement.getTagName().equals("journalCitationId")) { Text text = (Text) journalCitationElement.getFirstChild(); if (text != null) { journalCitationId = text.getData().trim(); } } } } sb.append(String.format("<option value='%s'>%s</option>\n", journalCitationId, journalCitationId)); } html = sb.toString(); } catch (Exception e) { logger.error("Exception:\n" + e.getMessage()); e.printStackTrace(); throw new PastaEventException(e.getMessage()); } } return html; }
From source file:com.waitwha.nessus.server.Server.java
/** * Executes the given HttpPost using a HttpClient. If 200 OK is returned, * we will parse the contents and return a ServerReply implementation. * //from ww w .j a va 2s .com * @param post HttpPost to execute. * @return ServerReply */ public ServerReply getReply(HttpPost post) { ServerReply reply = null; HttpClient client = this.getClient(); try { log.finest(String.format("[%s] Executing POST.", post.getURI())); HttpResponse resp = client.execute(post); try { HttpEntity entity = resp.getEntity(); if (resp.getStatusLine().getStatusCode() == 200) { InputStream in = entity.getContent(); log.finest(String.format("[%s] Received HTTP code %d: %dbytes (%s)", post.getURI(), resp.getStatusLine().getStatusCode(), entity.getContentLength(), entity.getContentType().getValue())); Document document = this.builder.parse(in); Element replyElement = (Element) document.getFirstChild(); Element contents = ElementUtils.getFirstElementByName(replyElement, "contents"); /* * Test the first element found within the element 'contents'. If the * element's name is 'token', then this is a LoginReply. However, if the * name of the element is 'reports', this will mean this is a ReportListReply. * */ Element firstElement = (Element) contents.getFirstChild(); if (firstElement == null) reply = new ErrorReply(replyElement); else if (firstElement.getTagName().equals("reports")) reply = new ReportListReply(replyElement); else reply = new LoginReply(replyElement); log.finest(String.format("[%s] Parsed XML succcessfully: %s", post.getURI(), reply.getClass().getName())); } else { log.warning(String.format("[%s] Received HTTP code %d. Skipping parsing of content.", post.getURI(), resp.getStatusLine().getStatusCode())); EntityUtils.consume(entity); } } catch (IOException | SAXException | ElementNotFoundException e) { log.warning(String.format("Could read/parse reply from server %s: %s %s", this.url, e.getClass().getName(), e.getMessage())); } } catch (IOException e) { log.warning(String.format("Could not connect to server %s: %s", this.url, e.getMessage())); } return reply; }
From source file:greenfoot.export.mygame.MyGameClient.java
private List<String> parseTagListXmlElement(Element element) { List<String> tags = new ArrayList<String>(); Node child = element.getFirstChild(); while (child != null) { if (child.getNodeType() == Node.ELEMENT_NODE) { element = (Element) child; if (element.getTagName().equals("tag")) { tags.add(element.getTextContent()); }/*from w w w . ja va 2s.com*/ } child = child.getNextSibling(); } return tags; }
From source file:edu.lternet.pasta.client.JournalCitationsClient.java
public String citationsTableHTML() throws Exception { String html = ""; if (this.uid != null && !this.uid.equals("public")) { StringBuilder sb = new StringBuilder(""); String xmlString = listPrincipalOwnerCitations(this.uid); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); try {//from w ww .j a v a 2 s . co m DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); InputStream inputStream = IOUtils.toInputStream(xmlString, "UTF-8"); Document document = documentBuilder.parse(inputStream); Element documentElement = document.getDocumentElement(); NodeList citationsNodeList = documentElement.getElementsByTagName("journalCitation"); int nJournalCitations = citationsNodeList.getLength(); for (int i = 0; i < nJournalCitations; i++) { Node journalCitationNode = citationsNodeList.item(i); NodeList journalCitationChildren = journalCitationNode.getChildNodes(); String journalCitationId = ""; String packageId = ""; String articleDoi = ""; String articleUrl = ""; String articleTitle = ""; String journalTitle = ""; for (int j = 0; j < journalCitationChildren.getLength(); j++) { Node childNode = journalCitationChildren.item(j); if (childNode instanceof Element) { Element subscriptionElement = (Element) childNode; if (subscriptionElement.getTagName().equals("journalCitationId")) { Text text = (Text) subscriptionElement.getFirstChild(); if (text != null) { journalCitationId = text.getData().trim(); } } else if (subscriptionElement.getTagName().equals("packageId")) { Text text = (Text) subscriptionElement.getFirstChild(); if (text != null) { packageId = text.getData().trim(); } } else if (subscriptionElement.getTagName().equals("articleDoi")) { Text text = (Text) subscriptionElement.getFirstChild(); if (text != null) { articleDoi = text.getData().trim(); } } else if (subscriptionElement.getTagName().equals("articleUrl")) { Text text = (Text) subscriptionElement.getFirstChild(); if (text != null) { articleUrl = text.getData().trim(); } } else if (subscriptionElement.getTagName().equals("articleTitle")) { Text text = (Text) subscriptionElement.getFirstChild(); if (text != null) { articleTitle = text.getData().trim(); } } else if (subscriptionElement.getTagName().equals("journalTitle")) { Text text = (Text) subscriptionElement.getFirstChild(); if (text != null) { journalTitle = text.getData().trim(); } } } } sb.append("<tr>\n"); sb.append("<td class='nis' align='center'>"); sb.append(journalCitationId); sb.append("</td>\n"); sb.append("<td class='nis' align='center'>"); sb.append(packageId); sb.append("</td>\n"); sb.append("<td class='nis'>"); sb.append(articleDoi); sb.append("</td>\n"); sb.append("<td class='nis'>"); sb.append(articleUrl); sb.append("</td>\n"); sb.append("<td class='nis'>"); sb.append(articleTitle); sb.append("</td>\n"); sb.append("<td class='nis'>"); sb.append(journalTitle); sb.append("</td>\n"); sb.append("</tr>\n"); } html = sb.toString(); } catch (Exception e) { logger.error("Exception:\n" + e.getMessage()); e.printStackTrace(); throw new PastaEventException(e.getMessage()); } } return html; }
From source file:org.smf4j.spring.RegistryNodeTemplateDefinitionParser.java
protected String getName(ParserContext context, Element element) { String name = element.getAttribute(NAME_ATTR); if (!StringUtils.hasLength(name)) { context.getReaderContext().error("'" + element.getTagName() + "' tag requires a 'name'.", element); }//from w ww . j a v a2s . co m return name; }
From source file:name.vysoky.epub.Part.java
private void removeStyleClass(Element element, String styleClass) { String classAttributeValue = element.getAttribute("class"); if (classAttributeValue != null && classAttributeValue.contains(styleClass)) { classAttributeValue = removeStyleClass(classAttributeValue, styleClass); if (classAttributeValue.isEmpty()) element.removeAttribute("class"); else/* w ww . j a v a 2 s . co m*/ element.setAttribute("class", classAttributeValue); if (element.getTagName().equals("span") && hasNoStyleInformation(element)) DomUtils.removeElement(element, true); } // recursive call for (Element child : listChildElements(element)) removeStyleClass(child, styleClass); }
From source file:edu.lternet.pasta.client.EventSubscriptionClient.java
public String subscriptionOptionsHTML() throws PastaEventException { String html = ""; if (this.uid != null && !this.uid.equals("public")) { StringBuilder sb = new StringBuilder(""); String xmlString = readByFilter(""); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); try {/* w ww . j a v a 2 s. c om*/ DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); InputStream inputStream = IOUtils.toInputStream(xmlString, "UTF-8"); Document document = documentBuilder.parse(inputStream); Element documentElement = document.getDocumentElement(); NodeList subscriptionList = documentElement.getElementsByTagName("subscription"); int nSubscriptions = subscriptionList.getLength(); for (int i = 0; i < nSubscriptions; i++) { Node subscriptionNode = subscriptionList.item(i); NodeList subscriptionChildren = subscriptionNode.getChildNodes(); String subscriptionId = ""; for (int j = 0; j < subscriptionChildren.getLength(); j++) { Node childNode = subscriptionChildren.item(j); if (childNode instanceof Element) { Element subscriptionElement = (Element) childNode; if (subscriptionElement.getTagName().equals("id")) { Text text = (Text) subscriptionElement.getFirstChild(); if (text != null) { subscriptionId = text.getData().trim(); } } } } sb.append(String.format("<option value='%s'>%s</option>\n", subscriptionId, subscriptionId)); } html = sb.toString(); } catch (Exception e) { logger.error("Exception:\n" + e.getMessage()); e.printStackTrace(); throw new PastaEventException(e.getMessage()); } } return html; }