List of usage examples for org.w3c.dom Node getNextSibling
public Node getNextSibling();
From source file:com.rubika.aotalk.util.ItemRef.java
private final String getElementValue(Node elem) { Node child; if (elem != null) { if (elem.hasChildNodes()) { for (child = elem.getFirstChild(); child != null; child = child.getNextSibling()) { if (child.getNodeType() == Node.TEXT_NODE) { return child.getNodeValue(); }/*w w w .j a v a 2s. c o m*/ } } } return ""; }
From source file:com.aipo.container.gadgets.parse.AipoNekoSimplifiedHtmlParser.java
private void fixNekoWeirdness(Document document) { // Neko as of versions > 1.9.13 stuffs all leading <script> nodes into // <head>. // This breaks all sorts of assumptions in gadgets, notably the existence of // document.body. // We can't tell Neko to avoid putting <script> into <head> however, since // gadgets/*from w ww.j av a2 s . c o m*/ // like <Content><script>...</script><style>...</style> will break due to // both // <script> and <style> ending up in <body> -- at which point Neko // unceremoniously // drops the <style> (and <link>) elements. // Therefore we just search for <script> elements in <head> and stuff them // all into // the top of <body>. // This method assumes a normalized document as input. Node html = DomUtil.getFirstNamedChildNode(document, "html"); if (html.getNextSibling() != null && html.getNextSibling().getNodeName().equalsIgnoreCase("html")) { // if a doctype is specified, then the desired root <html> node is wrapped // by an <HTML> node // Pull out the <html> root. html = html.getNextSibling(); } Node head = DomUtil.getFirstNamedChildNode(html, "head"); if (head == null) { head = document.createElement("head"); html.insertBefore(head, html.getFirstChild()); } NodeList headNodes = head.getChildNodes(); Stack<Node> headScripts = new Stack<Node>(); for (int i = 0; i < headNodes.getLength(); ++i) { Node headChild = headNodes.item(i); if (headChild.getNodeName().equalsIgnoreCase("script")) { headScripts.add(headChild); } } // Remove from head, add to top of <body> in <head> order. Node body = DomUtil.getFirstNamedChildNode(html, "body"); if (body == null) { body = document.createElement("body"); html.insertBefore(body, head.getNextSibling()); } Node bodyFirst = body.getFirstChild(); while (!headScripts.isEmpty()) { Node headScript = headScripts.pop(); head.removeChild(headScript); body.insertBefore(headScript, bodyFirst); bodyFirst = headScript; } }
From source file:Counter.java
/** Traverses the specified node, recursively. */ public void count(Node node) { // is there anything to do? if (node == null) { return;/*w w w .j a v a 2 s . co m*/ } int type = node.getNodeType(); switch (type) { case Node.DOCUMENT_NODE: { fElements = 0; fAttributes = 0; fCharacters = 0; fIgnorableWhitespace = 0; Document document = (Document) node; count(document.getDocumentElement()); break; } case Node.ELEMENT_NODE: { fElements++; NamedNodeMap attrs = node.getAttributes(); if (attrs != null) { fAttributes += attrs.getLength(); } // drop through to entity reference } case Node.ENTITY_REFERENCE_NODE: { Node child = node.getFirstChild(); while (child != null) { count(child); child = child.getNextSibling(); } break; } case Node.CDATA_SECTION_NODE: { fCharacters += ((Text) node).getLength(); break; } case Node.TEXT_NODE: { if (fDocumentInfo != null) { Text text = (Text) node; int length = text.getLength(); if (fDocumentInfo.isIgnorableWhitespace(text)) { fIgnorableWhitespace += length; } else { fCharacters += length; } } break; } } }
From source file:com.bstek.dorado.view.config.XmlDocumentPreprocessor.java
@SuppressWarnings("unchecked") private void postProcessNodeReplacement(Element element) { Document ownerDocument = element.getOwnerDocument(); Node child = element.getFirstChild(); while (child != null) { Node nextChild = child.getNextSibling(); if (child instanceof Element) { if (child.getUserData("dorado.delete") != null) { List<Element> replaceContent = (List<Element>) child.getUserData("dorado.replace"); if (replaceContent != null) { for (Element el : replaceContent) { Element clonedElement = (Element) ownerDocument.importNode(el, true); element.insertBefore(clonedElement, child); }/*from w w w . ja va 2s . c o m*/ child.setUserData("dorado.replace", null, null); } element.removeChild(child); child.setUserData("dorado.delete", null, null); } } child = nextChild; } }
From source file:com.buzzdavidson.spork.client.OWAClient.java
/** * Retrieve list of messages via OWA/WebDAV * * @param filter type of list to retrieve (new or all messages) * @return list of mime messages (never null) *//*ww w .j a v a 2 s .co m*/ public List<MimeMessage> fetchMail(OWAMessageFilter filter) { List<MimeMessage> retval = new ArrayList<MimeMessage>(); try { WebDavMethod search = new WebDavMethod(inboxAddress, OWA_METHOD_SEARCH, OWA_HEADERS_BRIEF); String msg = ""; if (OWAMessageFilter.ALL_MESSAGES.equals(filter)) { msg = OWA_QUERY_GET_LIST_MAIL_MSG_ALL; } else { msg = OWA_QUERY_GET_LIST_MAIL_MSG; } logger.info(String.format("Requesting %s mail messages", OWAMessageFilter.ALL_MESSAGES.equals(filter) ? "all" : "new")); search.setRequestEntity(new StringRequestEntity(msg, null, null)); int status = client.executeMethod(search); if (logger.isDebugEnabled()) { logger.info("Message request returned status code [" + status + "]"); } if (status == HttpStatus.SC_MULTI_STATUS) { Document doc = XmlUtils.readResponseDocument(search); Node email = XmlUtils.getChild(doc, OWA_FILTER_FIRST_MESSAGE_PATH); int msgCount; for (msgCount = 0; email != null; email = email.getNextSibling()) { msgCount++; if (msgCount > itemFetchLimit) { break; } else { String nodeName = email.getNodeName(); if (nodeName.endsWith(OWA_MSG_RESPONSE_SUFFIX)) { MimeMessage newMessage = OWAUtils.toMimeMessage(email); if (newMessage != null) { String messageUrl = OWAUtils.getMessageURL(email); populateMessage(newMessage, messageUrl); if (markReadAfterFetch) { markMessageRead(messageUrl); } retval.add(newMessage); } } } } } return retval; } catch (HttpException ex) { logger.error("Received HttpException fetching mail", ex); } catch (UnsupportedEncodingException ex) { logger.error("Received UnsupportedEncodingException fetching mail", ex); } catch (IOException ex) { logger.error("Received IOException fetching mail", ex); } return retval; }
From source file:importer.handler.post.stages.Discriminator.java
/** * Get the last child element that is not corrected or deleted * @param elem the element to test/*from w ww. j a v a 2 s. com*/ * @return its last uncancelled/uncorrected child or null */ Element lastOpenChild(Element elem) { Node child = elem.getFirstChild(); Element last = null; while (child != null) { if (child.getNodeType() == Node.ELEMENT_NODE) { Element cElem = (Element) child; if (!isDeleted(cElem) && !isCorrected(cElem)) last = cElem; } child = child.getNextSibling(); } return last; }
From source file:com.l2jfree.gameserver.datatables.MerchantPriceConfigTable.java
public void loadXML() throws SAXException, IOException, ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true);//from www. ja v a 2s . com factory.setIgnoringComments(true); File file = new File(Config.DATAPACK_ROOT, "data/" + MPCS_FILE); if (file.exists()) { int defaultPriceConfigId; Document doc = factory.newDocumentBuilder().parse(file); Node n = doc.getDocumentElement(); Node dpcNode = n.getAttributes().getNamedItem("defaultPriceConfig"); if (dpcNode == null) { throw new IllegalStateException("merchantPriceConfig must define an 'defaultPriceConfig'"); } defaultPriceConfigId = Integer.parseInt(dpcNode.getNodeValue()); MerchantPriceConfig mpc; for (n = n.getFirstChild(); n != null; n = n.getNextSibling()) { mpc = parseMerchantPriceConfig(n); if (mpc != null) { _mpcs.put(mpc.getId(), mpc); } } MerchantPriceConfig defaultMpc = this.getMerchantPriceConfig(defaultPriceConfigId); if (defaultMpc == null) { throw new IllegalStateException("'defaultPriceConfig' points to an non-loaded priceConfig"); } _defaultMpc = defaultMpc; } }
From source file:com.bstek.dorado.view.config.XmlDocumentPreprocessor.java
private List<Element> getPlaceHolderContent(Element placeHolderElement, TemplateContext tempalteContext) throws Exception { String contentId = placeHolderElement.getAttribute(XmlConstants.ATTRIBUTE_ID); List<Element> concreteContent = null; Document document = tempalteContext.getSourceDocument(); Element groupStartElement = getGroupStartElement(document, contentId, tempalteContext); if (groupStartElement != null) { concreteContent = new ArrayList<Element>(); String nodeName = groupStartElement.getNodeName(); if (nodeName.equals(XmlConstants.GROUP_START)) { boolean groupEndFound = false; Node node = groupStartElement.getNextSibling(); while (true) { node = node.getNextSibling(); if (node == null) { break; }/*from www.j a v a2 s . c o m*/ if (node instanceof Element) { Element element = (Element) node; nodeName = element.getNodeName(); if (nodeName.equals(XmlConstants.GROUP_END)) { groupEndFound = true; break; } else if (nodeName.equals(XmlConstants.GROUP_START)) { throw new IllegalArgumentException("Nesting <GroupStart> not supported."); } else { concreteContent.add(element); } } } if (!groupEndFound) { throw new IllegalArgumentException("<GroupEnd> not found for [" + contentId + "]."); } } else if (nodeName.equals(XmlConstants.GROUP_END)) { // do nothing } else { concreteContent.add(groupStartElement); } } return concreteContent; }
From source file:com.alfaariss.oa.util.configuration.ConfigurationManager.java
/** * Resolve the next section.//w w w. j a v a 2 s . com * @see IConfigurationManager#getNextSection(org.w3c.dom.Element) */ public synchronized Element getNextSection(Element eSection) { if (eSection == null) throw new IllegalArgumentException("Suplied section is empty"); String sRequested = eSection.getNodeName(); //Get first Node nNext = eSection.getNextSibling(); while (nNext != null) //No more sections { if (nNext.getNodeType() == Node.ELEMENT_NODE && nNext.getNodeName().equals(sRequested)) break; nNext = nNext.getNextSibling(); //Get next } return (Element) nNext; }