List of usage examples for org.w3c.dom Element getTagName
public String getTagName();
From source file:dpfmanager.shell.interfaces.gui.component.dessign.DessignController.java
public String readDescription(File file) { try {//from ww w . j a v a 2 s. co m DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(file); NodeList nList = doc.getDocumentElement().getChildNodes(); for (int i = 0; i < nList.getLength(); i++) { org.w3c.dom.Node node = nList.item(i); if (node.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) { Element elem = (Element) node; if (elem.getTagName().equals("description")) { return elem.getTextContent(); } } } return null; } catch (Exception e) { return null; } }
From source file:dpfmanager.shell.modules.periodic.core.ControllerWindows.java
public PeriodicCheck parseXmlString(String xmlTask, String uuid) { try {/* w w w.ja v a 2 s . com*/ boolean preIssue250 = true; InputStream is = IOUtils.toInputStream(xmlTask, "UTF-16"); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(is); // Parse input & configuration String arguments = doc.getDocumentElement().getElementsByTagName("Arguments").item(0).getTextContent(); if (arguments.startsWith("\"")) { preIssue250 = false; arguments = arguments.substring(arguments.substring(1).indexOf("\"") + 3, arguments.length()); } String input = getInputFromArguments(arguments); String configuration = getConfigurationFromArguments(arguments); // Parse periodicity Periodicity periodicity = new Periodicity(); Periodicity.Mode mode; NodeList schDay = doc.getDocumentElement().getElementsByTagName("ScheduleByDay"); NodeList schWeek = doc.getDocumentElement().getElementsByTagName("ScheduleByWeek"); NodeList schMonth = doc.getDocumentElement().getElementsByTagName("ScheduleByMonth"); if (schDay.getLength() > 0) { periodicity.setMode(Periodicity.Mode.DAILY); } else if (schWeek.getLength() > 0) { periodicity.setMode(Periodicity.Mode.WEEKLY); Element elemWeek = (Element) schWeek.item(0); Node node = elemWeek.getElementsByTagName("DaysOfWeek").item(0); NodeList childs = node.getChildNodes(); for (int i = 0; i < childs.getLength(); i++) { Node child = childs.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { Element elem = (Element) child; periodicity.addDaysOfWeek(parseDayName(elem.getTagName())); } } } else if (schMonth.getLength() > 0) { periodicity.setMode(Periodicity.Mode.MONTHLY); Element elem = (Element) schMonth.item(0); String dayStr = elem.getElementsByTagName("Day").item(0).getTextContent(); periodicity.setDayOfMonth(Integer.parseInt(dayStr)); } // Parse time String timeStr = doc.getDocumentElement().getElementsByTagName("StartBoundary").item(0) .getTextContent(); String time = timeStr.substring(11, 16); periodicity.setTime(LocalTime.parse(time)); is.close(); PeriodicCheck pc = new PeriodicCheck(uuid, input, configuration, periodicity); if (preIssue250) { editPeriodicalCheck(pc); } return pc; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:net.sf.cb2xml.convert.MainframeToXml.java
public Document convert(String mainframeBuffer, Document copyBookXml) throws JCopybookUnmarshallException { this.resultDocument = XmlUtils.getNewXmlDocument(); try {/*from w w w . j a va 2 s . c o m*/ this.mainframeBuffer = stripNullChars(mainframeBuffer); int bufferLength = mainframeBuffer.length(); Element documentElement = copyBookXml.getDocumentElement(); Element recordNode = Utils.getFirstElement(documentElement); Element resultRoot = resultDocument.createElement(documentElement.getTagName()); int recordLength = Integer.parseInt(recordNode.getAttribute("display-length")); for (int offset = 0; offset < bufferLength; offset += recordLength) { if ("true".equals(recordNode.getAttribute("redefined"))) continue; Element resultTree = convertNode(recordNode, new Context()); resultRoot.appendChild(resultTree); } resultDocument.appendChild(resultRoot); return resultDocument; } catch (Exception e) { if (e instanceof JCopybookUnmarshallException) throw (JCopybookUnmarshallException) e; throw new JCopybookUnmarshallException("can't unmarshall copybook", e, mainframeBuffer, XmlUtils.domToString(resultDocument).toString(), null, null, copyBookXml); } }
From source file:de.itsvs.cwtrpc.controller.config.RemoteServiceControllerConfigBeanDefinitionParser.java
public BeanDefinition parse(Element element, ParserContext parserContext) { final CompositeComponentDefinition compositeDef; final BeanDefinitionBuilder bdd; final AbstractBeanDefinition beanDefinition; String id;//from w w w . jav a2 s . c om compositeDef = new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element)); parserContext.pushContainingComponent(compositeDef); bdd = BeanDefinitionBuilder.rootBeanDefinition(RemoteServiceControllerConfig.class); bdd.getRawBeanDefinition().setSource(parserContext.extractSource(element)); if (parserContext.isDefaultLazyInit()) { bdd.setLazyInit(true); } bdd.addConstructorArgReference(getSerializationPolicyProviderBeanRef(element, parserContext).getBeanName()); bdd.addPropertyValue("serviceModuleConfigs", parseModules(element, parserContext)); getBaseServiceConfigParser().update(element, parserContext, bdd, RemoteServiceControllerConfig.DEFAULT_RPC_VALIDATOR_SERVICE_NAME); id = element.getAttribute(XmlNames.ID_ATTR); if (!StringUtils.hasText(id)) { id = RemoteServiceControllerConfig.DEFAULT_BEAN_ID; } beanDefinition = bdd.getBeanDefinition(); parserContext.registerBeanComponent(new BeanComponentDefinition(beanDefinition, id)); parserContext.popAndRegisterContainingComponent(); return beanDefinition; }
From source file:com.enonic.esl.xml.XMLTool.java
/** * Create a map using the element names as keys. * * @param nodeList NodeList/*from w w w .ja va2 s. c o m*/ * @return Map */ public static Map<String, Element> filterElements(NodeList nodeList) { Map<String, Element> nodes = new HashMap<String, Element>(); if (nodeList == null) { return nodes; } for (int i = 0; i < nodeList.getLength(); i++) { Node n = nodeList.item(i); if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; nodes.put(e.getTagName(), e); } } return nodes; }
From source file:com.concursive.connect.web.modules.wiki.utils.HTMLToWikiUtils.java
public static void processChildNodes(ArrayList<Node> nodeList, StringBuffer sb, int indentLevel, boolean doText, boolean withFormatting, boolean trim, String appendToCRLF, String contextPath, int projectId) { Iterator nodeI = nodeList.iterator(); while (nodeI.hasNext()) { Node n = (Node) nodeI.next(); if (n != null) { if (n.getNodeType() == Node.TEXT_NODE || n.getNodeType() == Node.CDATA_SECTION_NODE) { if (doText) { String value = n.getNodeValue(); // Escaped characters value = StringUtils.replace(value, "*", "\\*"); value = StringUtils.replace(value, "#", "\\#"); value = StringUtils.replace(value, "=", "\\="); value = StringUtils.replace(value, "|", "\\|"); value = StringUtils.replace(value, "[", "\\{"); value = StringUtils.replace(value, "]", "\\}"); if (trim && !nodeI.hasNext()) { // If within a cell, make sure returns include the cell value // String value = (appendToCRLF.length() > 0 ? StringUtils.replace(n.getNodeValue(), CRLF, CRLF + appendToCRLF) : n.getNodeValue()); LOG.trace(" <text:trim>"); // Output the value, trim is required sb.append(StringUtils.fromHtmlValue(value.trim())); } else { // If within a cell, make sure returns include the cell value if (appendToCRLF.length() > 0 && (hasParentNodeType(n, "th") || hasParentNodeType(n, "td")) && value.trim().length() == 0) { // This is an empty value... check to see if the previous line has content or not before appending a new line } else { LOG.trace(" <text>"); sb.append(StringUtils.fromHtmlValue((appendToCRLF.length() > 0 ? StringUtils.replace(value, CRLF, CRLF + appendToCRLF) : value))); }/*from w w w . j a va2s. com*/ } } } else if (n.getNodeType() == Node.ELEMENT_NODE) { Element element = ((Element) n); String tag = element.getTagName(); LOG.trace(tag); if ("h1".equals(tag)) { startOnNewLine(sb, appendToCRLF); sb.append("= ").append(StringUtils.fromHtmlValue(element.getTextContent().trim())) .append(" =").append(CRLF + appendToCRLF); } else if ("h2".equals(tag)) { startOnNewLine(sb, appendToCRLF); sb.append("== ").append(StringUtils.fromHtmlValue(element.getTextContent().trim())) .append(" ==").append(CRLF + appendToCRLF); } else if ("h3".equals(tag)) { startOnNewLine(sb, appendToCRLF); sb.append("=== ").append(StringUtils.fromHtmlValue(element.getTextContent().trim())) .append(" ===").append(CRLF + appendToCRLF); } else if ("h4".equals(tag)) { startOnNewLine(sb, appendToCRLF); sb.append("==== ").append(StringUtils.fromHtmlValue(element.getTextContent().trim())) .append(" ====").append(CRLF + appendToCRLF); } else if ("h5".equals(tag)) { startOnNewLine(sb, appendToCRLF); sb.append("===== ").append(StringUtils.fromHtmlValue(element.getTextContent().trim())) .append(" =====").append(CRLF + appendToCRLF); } else if ("h6".equals(tag)) { startOnNewLine(sb, appendToCRLF); sb.append("====== ").append(StringUtils.fromHtmlValue(element.getTextContent().trim())) .append(" ======").append(CRLF + appendToCRLF); } else if ("p".equals(tag) || "div".equals(tag)) { if (n.getChildNodes().getLength() > 0 && (hasTextContent(n) || hasImageNodes(n.getChildNodes()))) { // If this contains a Table, UL, OL, or object skip everything else to get there ArrayList<Node> subNodes = new ArrayList<Node>(); getNodes(n.getChildNodes(), subNodes, new String[] { "table", "ul", "ol", "object" }, false); if (subNodes.size() > 0) { LOG.trace(" nonTextNodes - yes"); processChildNodes(subNodes, sb, indentLevel, true, true, false, appendToCRLF, contextPath, projectId); } else { LOG.trace(" nonTextNodes - no"); startOnNewLine(sb, appendToCRLF); processChildNodes(getNodeList(n), sb, indentLevel, true, true, false, appendToCRLF, contextPath, projectId); } } } else if ("strong".equals(tag) || "b".equals(tag)) { if (n.getChildNodes().getLength() > 0) { if ("".equals(StringUtils.fromHtmlValue(n.getTextContent()).trim())) { processChildNodes(getNodeList(n), sb, indentLevel, true, false, false, appendToCRLF, contextPath, projectId); } else { if (hasNonTextNodes(n.getChildNodes())) { processChildNodes(getNodeList(n), sb, indentLevel, true, withFormatting, false, appendToCRLF, contextPath, projectId); } else { if (withFormatting) { sb.append("'''"); } processChildNodes(getNodeList(n), sb, indentLevel, true, withFormatting, false, appendToCRLF, contextPath, projectId); if (withFormatting) { sb.append("'''"); } } } } } else if ("em".equals(tag) || "i".equals(tag)) { if (n.getChildNodes().getLength() > 0) { if ("".equals(StringUtils.fromHtmlValue(n.getTextContent()).trim())) { processChildNodes(getNodeList(n), sb, indentLevel, true, false, trim, appendToCRLF, contextPath, projectId); } else { if (hasNonTextNodes(n.getChildNodes())) { processChildNodes(getNodeList(n), sb, indentLevel, true, withFormatting, trim, appendToCRLF, contextPath, projectId); } else { if (withFormatting) { sb.append("''"); } processChildNodes(getNodeList(n), sb, indentLevel, true, withFormatting, trim, appendToCRLF, contextPath, projectId); if (withFormatting) { sb.append("''"); } } } } } else if ("span".equals(tag)) { if (n.getChildNodes().getLength() > 0 && !"".equals(StringUtils.fromHtmlValue(n.getTextContent()).trim())) { if (element.hasAttribute("style")) { String value = element.getAttribute("style"); if (withFormatting) { if (value.contains("underline")) { sb.append("__"); } if (value.contains("line-through")) { sb.append("<s>"); } if (value.contains("bold")) { sb.append("'''"); } if (value.contains("italic")) { sb.append("''"); } } processChildNodes(getNodeList(n), sb, indentLevel, true, withFormatting, trim, appendToCRLF, contextPath, projectId); if (withFormatting) { if (value.contains("italic")) { sb.append("''"); } if (value.contains("bold")) { sb.append("'''"); } if (value.contains("line-through")) { sb.append("</s>"); } if (value.contains("underline")) { sb.append("__"); } } } else { processChildNodes(getNodeList(n), sb, indentLevel, true, withFormatting, trim, appendToCRLF, contextPath, projectId); } } } else if ("ul".equals(tag) || "ol".equals(tag) || "dl".equals(tag)) { ++indentLevel; if (indentLevel == 1) { if (appendToCRLF.length() == 0) { startOnNewLine(sb, appendToCRLF); } else { // Something\n // ! // !* Item 1 // !* Item 2 if (!sb.toString().endsWith("|") && !sb.toString().endsWith(CRLF + appendToCRLF)) { LOG.trace("ul newline CRLF"); sb.append(CRLF + appendToCRLF); } } } if (indentLevel > 1 && !sb.toString().endsWith(CRLF + appendToCRLF)) { LOG.trace("ul indent CRLF"); sb.append(CRLF + appendToCRLF); } processChildNodes(getNodeList(n), sb, indentLevel, false, false, trim, appendToCRLF, contextPath, projectId); --indentLevel; } else if ("li".equals(tag)) { String parentTag = ((Element) element.getParentNode()).getTagName(); for (int counter = 0; counter < indentLevel; counter++) { if ("ul".equals(parentTag)) { sb.append("*"); } else if ("ol".equals(parentTag)) { sb.append("#"); } } sb.append(" "); processChildNodes(getNodeList(n), sb, indentLevel, true, false, true, appendToCRLF, contextPath, projectId); if (!sb.toString().endsWith(CRLF + appendToCRLF)) { LOG.trace("li CRLF"); sb.append(CRLF + appendToCRLF); } } else if ("dt".equals(tag) || "dd".equals(tag)) { processChildNodes(getNodeList(n), sb, indentLevel, true, false, trim, appendToCRLF, contextPath, projectId); if (!sb.toString().endsWith(CRLF + appendToCRLF)) { LOG.trace("dt CRLF"); sb.append(CRLF + appendToCRLF); } } else if ("pre".equals(tag)) { startOnNewLine(sb, appendToCRLF); sb.append("<pre>"); processChildNodes(getNodeList(n), sb, indentLevel, true, true, trim, appendToCRLF, contextPath, projectId); sb.append("</pre>"); if (nodeI.hasNext()) { sb.append(CRLF + appendToCRLF); sb.append(CRLF + appendToCRLF); } } else if ("code".equals(tag)) { startOnNewLine(sb, appendToCRLF); sb.append("<code>"); processChildNodes(getNodeList(n), sb, indentLevel, true, true, trim, appendToCRLF, contextPath, projectId); sb.append("</code>"); if (nodeI.hasNext()) { sb.append(CRLF + appendToCRLF); sb.append(CRLF + appendToCRLF); } } else if ("br".equals(tag)) { LOG.trace("br CRLF"); sb.append(CRLF + appendToCRLF); } else if ("table".equals(tag)) { // Always start a table on a new line startOnNewLine(sb, appendToCRLF); processTable(n.getChildNodes(), sb, 0, false, false, contextPath, projectId, 0); //if (nodeI.hasNext()) { // sb.append(CRLF); //} } else if ("form".equals(tag)) { // Always start a form on a new line startOnNewLine(sb, appendToCRLF); CustomForm form = processForm(n); convertFormToWiki(form, sb); } else if ("a".equals(tag)) { // Determine if the link is around text or around an image if (n.getChildNodes().getLength() > 0 && hasImageNodes(n.getChildNodes())) { // The link is around an image LOG.debug("Processing link as an image"); // Get the img tag and pass to processImage... ArrayList<Node> subNodes = new ArrayList<Node>(); getNodes(n.getChildNodes(), subNodes, new String[] { "img" }, false); processImage(sb, subNodes.get(0), (Element) subNodes.get(0), appendToCRLF, contextPath, projectId); } else { // The link is around text processLink(sb, element, appendToCRLF, contextPath, projectId); } } else if ("img".equals(tag)) { processImage(sb, n, element, appendToCRLF, contextPath, projectId); } else if ("object".equals(tag)) { startOnNewLine(sb, appendToCRLF); processVideo(sb, n, element, appendToCRLF, contextPath); } else { processChildNodes(getNodeList(n), sb, indentLevel, false, true, trim, appendToCRLF, contextPath, projectId); } } } } }
From source file:edu.lternet.pasta.client.ReservationsManager.java
/** * Return the number of subscriptions for a given user. * /*from w ww . j a v a2 s . co m*/ * @return the number of subscriptions for this user. */ public int numberOfReservations() throws Exception { int numberOfReservations = 0; 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 principal = ""; 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)) { numberOfReservations++; } } } } } } } catch (Exception e) { logger.error("Exception:\n" + e.getMessage()); e.printStackTrace(); throw new PastaEventException(e.getMessage()); } } return numberOfReservations; }
From source file:com.subgraph.vega.impl.scanner.urls.ResponseAnalyzer.java
private void analyzeHtmlElement(IInjectionModuleContext ctx, HttpUriRequest req, IHttpResponse res, Element elem) { boolean remoteScript = false; NamedNodeMap attributes = elem.getAttributes(); final String tag = elem.getTagName().toLowerCase(); for (int i = 0; i < attributes.getLength(); i++) { Node item = attributes.item(i); if (item instanceof Attr) { String n = ((Attr) item).getName().toLowerCase(); String v = ((Attr) item).getValue().toLowerCase(); if (match(tag, "script") && match(n, "src")) remoteScript = true;/* w w w. j a v a 2 s .c o m*/ if ((v != null) && (match(n, "href", "src", "action", "codebase") || (match(n, "value") && !match(tag, "input")))) { if (v.startsWith("vega://")) alert(ctx, "vinfo-url-inject", "URL injection into <" + tag + "> tag", req, res); if (v.startsWith("http://vega.invalid/") || v.startsWith("//vega.invalid/")) { if (match(tag, "script", "link")) alert(ctx, "vinfo-url-inject", "URL injection into actively fetched field in tag <" + tag + "> (high risk)", req, res); else if (match(tag, "a")) alert(ctx, "vinfo-url-inject", "URL injection into anchor tag (low risk)", req, res); else alert(ctx, "vinfo-url-inject", "URL injection into tag <" + tag + ">", req, res); } } if ((v != null) && (n.startsWith("on") || n.equals("style"))) { checkJavascriptXSS(ctx, req, res, v); } if (n.contains("vvv")) possibleXssAlert(ctx, req, res, n, n.indexOf("vvv"), "xss-inject", "Injected XSS tag into HTML attribute value"); } } if (tag.startsWith("vvv")) possibleXssAlert(ctx, req, res, tag, 0, "vinfo-xss-inject", "Injected XSS tag into HTML tag name"); if (tag.equals("style") || (tag.equals("script") && !remoteScript)) { String content = elem.getTextContent(); if (content != null) checkJavascriptXSS(ctx, req, res, content); } }
From source file:com.apporiented.spring.override.AbstractGenericBeanDefinitionParser.java
public final BeanDefinition parse(Element element, ParserContext parserContext) { if (!enabled) { throw new FatalBeanException("Support for " + element.getTagName() + " has been disabled. Please add the required jar files " + "to your classpath."); }// ww w . j a va2s . com AbstractBeanDefinition definition = parseInternal(element, parserContext); if (!parserContext.isNested()) { try { String id = resolveId(element, definition, parserContext); if (!StringUtils.hasText(id)) { parserContext.getReaderContext().error("Id is required for element '" + element.getLocalName() + "' when used as a top-level tag", element); } String[] aliases = resolveAliases(element, definition, parserContext); BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, id, aliases); if (decorator != null) { holder = decorator.decorate(element, holder, parserContext); } registerBeanDefinition(holder, parserContext.getRegistry()); if (shouldFireEvents()) { BeanComponentDefinition componentDefinition = new BeanComponentDefinition(holder); postProcessComponentDefinition(componentDefinition); parserContext.registerComponent(componentDefinition); } } catch (BeanDefinitionStoreException ex) { parserContext.getReaderContext().error(ex.getMessage(), element); return null; } } else if (decorator != null) { BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, ""); decorator.decorate(element, holder, parserContext); } return definition; }
From source file:org.apache.servicemix.jms.JmsConsumerEndpointTest.java
public void testConsumerDefaultInOut() 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.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);// w ww . j a va 2s. co m }