List of usage examples for org.w3c.dom Text getData
public String getData() throws DOMException;
From source file:edu.lternet.pasta.client.ReservationsManager.java
/** * Composes HTML table rows to render the list of active reservations for * this user./*from ww w . j a v a 2s . co m*/ * * @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.duroty.lucene.bookmark.BookmarkToLuceneBookmark.java
/** * DOCUMENT ME!/* w ww . j a va 2 s . co m*/ * * @param mime DOCUMENT ME! * * @return DOCUMENT ME! * @throws URISyntaxException * @throws IOException */ public LuceneBookmark parse(String idint, BookmarkObj bookmarkObj) throws URISyntaxException, IOException { if ((idint == null) || (bookmarkObj == null)) { return null; } LuceneBookmark luceneBookmark = new LuceneBookmark(idint); luceneBookmark.setCacheDate(new Date()); String comments = null; try { comments = factory.parse(bookmarkObj.getComments(), "text/html", Charset.defaultCharset().displayName()); } catch (Exception ex) { if (ex != null) { comments = ex.getMessage(); } } luceneBookmark.setComments(comments); if (!StringUtils.isBlank(comments)) { luceneBookmark.setNotebook(true); } String url = bookmarkObj.getUrl(); HttpContent httpContent = new HttpContent(new URL(url)); MimeType mimeType = httpContent.getContentType(); String contentType = "text/html"; if (mimeType != null) { contentType = mimeType.getBaseType(); } InputStream inputStream = httpContent.newInputStream(); if (!StringUtils.isBlank(bookmarkObj.getTitle())) { luceneBookmark.setTitle(bookmarkObj.getTitle()); } else { Vector elements = Extractor.getElements(httpContent.newInputStream(), null, "title"); Text text = null; if ((elements != null) && (elements.size() == 1)) { Element element = (Element) elements.get(0); text = (Text) element.getFirstChild(); } if (text != null) { luceneBookmark.setTitle(text.getData()); } else { luceneBookmark.setTitle(url); } } String charset = httpContent.getCharset(); if (charset == null) { charset = Charset.defaultCharset().displayName(); } String contents = null; try { contents = factory.parse(inputStream, contentType, charset); } catch (Exception ex) { if (ex != null) { contents = ex.getMessage(); } } luceneBookmark.setContents(contents); luceneBookmark.setDepth(bookmarkObj.getDepth()); luceneBookmark.setFlagged(bookmarkObj.isFlagged()); luceneBookmark.setInsertDate(new Date()); luceneBookmark.setKeywords(bookmarkObj.getKeywords()); //luceneBookmark.setNotebook(bookmarkObj.isNotebook()); luceneBookmark.setParent(String.valueOf(bookmarkObj.getParent())); luceneBookmark.setUrl(url); luceneBookmark.setUrlStr(url); return luceneBookmark; }
From source file:edu.lternet.pasta.portal.search.BrowseGroup.java
private void addFetchDownElements() { String fetchDownXML = ControlledVocabularyClient.webServiceFetchDown(this.termId); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); try {/* w w w . j ava2s. c o m*/ DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); InputStream inputStream = IOUtils.toInputStream(fetchDownXML, "UTF-8"); Document document = documentBuilder.parse(inputStream); Element documentElement = document.getDocumentElement(); NodeList documentNodeList = documentElement.getElementsByTagName("term"); for (int i = 0; i < documentNodeList.getLength(); i++) { Node documentNode = documentNodeList.item(i); NodeList childNodes = documentNode.getChildNodes(); String termId = null; String value = null; String hasMoreDown = null; for (int j = 0; j < childNodes.getLength(); j++) { Node childNode = childNodes.item(j); if (childNode instanceof Element) { Element childElement = (Element) childNode; if (childElement.getTagName().equals("term_id")) { Text text = (Text) childElement.getFirstChild(); termId = text.getData().trim(); } else if (childElement.getTagName().equals("string")) { Text text = (Text) childElement.getFirstChild(); value = text.getData().trim(); } else if (childElement.getTagName().equals("hasMoreDown")) { Text text = (Text) childElement.getFirstChild(); hasMoreDown = text.getData().trim(); } } } if (hasMoreDown != null && hasMoreDown.equals("1")) { BrowseGroup downTerm = new BrowseGroup(value); this.addBrowseGroup(downTerm); downTerm.setTermId(termId); downTerm.setHasMoreDown(hasMoreDown); downTerm.addFetchDownElements(); } else { BrowseTerm downTerm = new BrowseTerm(value); downTerm.setTermId(termId); this.addBrowseTerm(downTerm); } } } catch (Exception e) { logger.error("Exception:\n" + e.getMessage()); e.printStackTrace(); } if (!isBlacklistedTerm(this.value)) { BrowseTerm browseTerm = new BrowseTerm(this.value); browseTerm.setLevel(level + 1); this.addBrowseTerm(browseTerm); } }
From source file:fr.gouv.finances.dgfip.xemelios.utils.TextWriter.java
private String getChildText(Node node) { StringBuffer sb = new StringBuffer(); NodeList l = node.getChildNodes(); int size = l.getLength(); for (int i = 0; i < size; i++) { Node n = l.item(i);/*from ww w . j av a2s .c o m*/ if (n.getNodeType() == Node.TEXT_NODE) { Text t = (Text) n; sb.append(t.getData()); } else return null; } return sb.toString(); }
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 {// www. j a v a 2 s .com 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:fr.gouv.finances.dgfip.xemelios.utils.TextWriter.java
private void text(Writer writer, Text text) throws IOException { if (prettyPrint) textBuffer.append(text.getData()); else/*from w ww. ja v a 2 s .c om*/ writeEscapedText(writer, text.getData(), false); }
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 {/*w ww . ja v a 2 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 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: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 w w. j a va 2s . c o m 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; }
From source file:edu.lternet.pasta.client.EventSubscriptionClient.java
public String subscriptionTableHTML() throws PastaEventException { String html = ""; if (this.uid != null && !this.uid.equals("public")) { StringBuilder sb = new StringBuilder(""); String xmlString = readByFilter(""); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); try {//from w w w . j a va2 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 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 = ""; String packageId = ""; String url = ""; 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(); } } else if (subscriptionElement.getTagName().equals("packageId")) { Text text = (Text) subscriptionElement.getFirstChild(); if (text != null) { packageId = text.getData().trim(); } } else if (subscriptionElement.getTagName().equals("url")) { Text text = (Text) subscriptionElement.getFirstChild(); if (text != null) { url = text.getData().trim(); } } } } sb.append("<tr>\n"); sb.append("<td class='nis' align='center'>"); sb.append(subscriptionId); 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(url); 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:com.enonic.vertical.engine.handlers.ContentObjectHandler.java
public void copyContentObjectsPostOp(int oldMenuKey, CopyContext copyContext) throws VerticalCopyException { boolean includeContents = copyContext.isIncludeContents(); int newMenuKey = copyContext.getMenuKey(oldMenuKey); try {// ww w.j av a 2s.c om Document doc = getContentObjectsByMenu(newMenuKey); Element[] contentobjectElems = XMLTool.getElements(doc.getDocumentElement()); for (Element contentobjectElem : contentobjectElems) { Element codElem = XMLTool.getElement(contentobjectElem, "contentobjectdata"); // datasource NodeList parameterList = XMLTool.selectNodes(codElem, "datasources/datasource/parameters/parameter"); for (int k = 0; k < parameterList.getLength(); k++) { Element parameterElem = (Element) parameterList.item(k); String name = parameterElem.getAttribute("name"); if ("cat".equalsIgnoreCase(name)) { Text text = (Text) parameterElem.getFirstChild(); if (text != null) { String oldCategoryKeys = text.getData(); Matcher m = CATEGORY_KEYLIST_PATTERN.matcher(oldCategoryKeys); if (m.matches()) { StringBuffer data = translateCategoryKeys(copyContext, oldCategoryKeys); text.setData(data.toString()); } } } else if ("menu".equalsIgnoreCase(name)) { Text text = (Text) parameterElem.getFirstChild(); if (text != null) { int oldKey = Integer.parseInt(text.getData()); int newKey = copyContext.getMenuKey(oldKey); if (newKey >= 0) { text.setData(String.valueOf(newKey)); } else { text.setData(String.valueOf(oldKey)); } } } } // stylesheet parameters NodeList stylesheetparamList = XMLTool.selectNodes(codElem, "stylesheetparams/stylesheetparam"); for (int k = 0; k < stylesheetparamList.getLength(); k++) { Element stylesheetparamElem = (Element) stylesheetparamList.item(k); String type = stylesheetparamElem.getAttribute("type"); if ("page".equals(type)) { Text text = (Text) stylesheetparamElem.getFirstChild(); if (text != null) { String oldMenuItemKey = text.getData(); if (oldMenuItemKey != null && oldMenuItemKey.length() > 0) { int newMenuItemKey = copyContext.getMenuItemKey(Integer.parseInt(oldMenuItemKey)); if (newMenuItemKey >= 0) { text.setData(String.valueOf(newMenuItemKey)); } else { XMLTool.removeChildNodes(stylesheetparamElem, true); } } else { XMLTool.removeChildNodes(stylesheetparamElem, true); } } } } // border parameters NodeList borderparamList = XMLTool.selectNodes(codElem, "borderparams/borderparam"); for (int k = 0; k < borderparamList.getLength(); k++) { Element borderparamElem = (Element) borderparamList.item(k); String type = borderparamElem.getAttribute("type"); if ("page".equals(type)) { Text text = (Text) borderparamElem.getFirstChild(); if (text != null) { String oldMenuItemKey = text.getData(); if (oldMenuItemKey != null && oldMenuItemKey.length() > 0) { int newMenuItemKey = copyContext.getMenuItemKey(Integer.parseInt(oldMenuItemKey)); if (newMenuItemKey >= 0) { text.setData(String.valueOf(newMenuItemKey)); } else { XMLTool.removeChildNodes(borderparamElem, true); } } else { XMLTool.removeChildNodes(borderparamElem, true); } } } } } updateContentObject(doc); } catch (VerticalUpdateException vue) { String message = "Failed to copy content objects (post operation): %t"; VerticalEngineLogger.errorCopy(this.getClass(), 0, message, vue); } }