List of usage examples for org.w3c.dom Element getTagName
public String getTagName();
From source file:com.bluexml.xforms.actions.GetAction.java
/** * Returns the instance for FormWorkflow forms, which includes the instance for the data form. <br/> * NOTE: the form name is expected in the returned instance (incl. process & task names), and * the data form is nested under the [form name] tag. * <p>//w w w . j a v a 2 s. c o m * Format: * * <pre> * <workflow> <!-- this is the node returned by getDocumentElement() on XForms instances --> * <FORM NAME> * PROPERTIES OF THE WORFKLOW * <DATA FORM > * THE DATA FORM'S PROPERTIES * </DATA FORM > * </FORM NAME> * </workflow> * </pre> */ private Document getInstanceWorkflow(Page currentPage, String wkFormName) throws ServletException { // // get the instance for the task Document docWkflw = controller.getInstanceWorkflow(transaction, wkFormName); controller.workflowPatchInstance(transaction, wkFormName, docWkflw, currentPage.getWkflwInstanceId()); // // get the instance of the attached data form String dataId = currentPage.getDataId(); String dataFormName = controller.getUnderlyingDataFormForWorkflow(wkFormName); if (dataFormName == null) { return docWkflw; } GetInstanceFormBean bean = new GetInstanceFormBean(dataFormName, dataId, false, false, null); Document docForm = controller.getInstanceForm(transaction, bean); // // we need to nest the data form instance under workflow Element wkDocElt = docWkflw.getDocumentElement(); List<Element> childrenWk = DOMUtil.getAllChildren(wkDocElt); Element wkElt = DOMUtil.getOneElementByTagName(childrenWk, wkFormName); Element clone; List<Element> children = DOMUtil.getAllChildren(docForm.getDocumentElement()); Element dataElt = DOMUtil.getOneElementByTagName(children, dataFormName); clone = (Element) dataElt.cloneNode(true); docWkflw.adoptNode(clone); wkElt.appendChild(clone); // // also copy supplementary tags that are added for internal usage (SIDEDataType, etc.) for (Element child : children) { if (child.getTagName().equals(dataFormName) == false) { clone = (Element) child.cloneNode(true); docWkflw.adoptNode(clone); wkDocElt.appendChild(clone); } } if (logger.isDebugEnabled()) { DOMUtil.logXML(docWkflw, true, ">> Returning instance document for workflow form: " + wkFormName); } return docWkflw; }
From source file:com.threadswarm.imagefeedarchiver.parser.RssDOMFeedParser.java
private RssMediaContent parseMediaContent(Element mediaContentElement) { if (!mediaContentElement.getTagName().equals("media:content")) return null; RssMediaContent mediaContent = new RssMediaContent(); //String based attributes mediaContent.setUrlString(mediaContentElement.getAttribute("url")); mediaContent.setType(mediaContentElement.getAttribute("type")); mediaContent.setMedium(mediaContentElement.getAttribute("medium")); //Numeric attributes String heightString = mediaContentElement.getAttribute("height"); if (heightString != null && !heightString.isEmpty()) { try {//from w w w . j a v a2 s . co m Integer height = Integer.valueOf(heightString); mediaContent.setHeight(height); } catch (NumberFormatException e) { LOGGER.error("Unable to convert 'height' attribute to integer", e); } } String widthString = mediaContentElement.getAttribute("width"); if (widthString != null && !widthString.isEmpty()) { try { Integer width = Integer.valueOf(widthString); mediaContent.setWidth(width); } catch (NumberFormatException e) { LOGGER.error("Unable to convert 'width' attribute to integer", e); } } String fileSizeString = mediaContentElement.getAttribute("fileSize"); if (fileSizeString != null && !fileSizeString.isEmpty()) { try { Long fileSize = Long.valueOf(fileSizeString); mediaContent.setFileSize(fileSize); } catch (NumberFormatException e) { LOGGER.error("Unable to convert 'fileSize' attribute to Long", e); } } return mediaContent; }
From source file:TreeDumper2.java
private void dumpElement(Element node, String indent) { System.out.println(indent + "ELEMENT: " + node.getTagName()); NamedNodeMap nm = node.getAttributes(); for (int i = 0; i < nm.getLength(); i++) dumpLoop(nm.item(i), indent + " "); }
From source file:XMLDocumentWriter.java
/** * Output the specified DOM Node object, printing it using the specified * indentation string//from w w w . ja va 2s . co m */ public void write(Node node, String indent) { // The output depends on the type of the node switch (node.getNodeType()) { case Node.DOCUMENT_NODE: { // If its a Document node Document doc = (Document) node; out.println(indent + "<?xml version='1.0'?>"); // Output header Node child = doc.getFirstChild(); // Get the first node while (child != null) { // Loop 'till no more nodes write(child, indent); // Output node child = child.getNextSibling(); // Get next node } break; } case Node.DOCUMENT_TYPE_NODE: { // It is a <!DOCTYPE> tag DocumentType doctype = (DocumentType) node; // Note that the DOM Level 1 does not give us information about // the the public or system ids of the doctype, so we can't output // a complete <!DOCTYPE> tag here. We can do better with Level 2. out.println("<!DOCTYPE " + doctype.getName() + ">"); break; } case Node.ELEMENT_NODE: { // Most nodes are Elements Element elt = (Element) node; out.print(indent + "<" + elt.getTagName()); // Begin start tag NamedNodeMap attrs = elt.getAttributes(); // Get attributes for (int i = 0; i < attrs.getLength(); i++) { // Loop through them Node a = attrs.item(i); out.print(" " + a.getNodeName() + "='" + // Print attr. name fixup(a.getNodeValue()) + "'"); // Print attr. value } out.println(">"); // Finish start tag String newindent = indent + " "; // Increase indent Node child = elt.getFirstChild(); // Get child while (child != null) { // Loop write(child, newindent); // Output child child = child.getNextSibling(); // Get next child } out.println(indent + "</" + // Output end tag elt.getTagName() + ">"); break; } case Node.TEXT_NODE: { // Plain text node Text textNode = (Text) node; String text = textNode.getData().trim(); // Strip off space if ((text != null) && text.length() > 0) // If non-empty out.println(indent + fixup(text)); // print text break; } case Node.PROCESSING_INSTRUCTION_NODE: { // Handle PI nodes ProcessingInstruction pi = (ProcessingInstruction) node; out.println(indent + "<?" + pi.getTarget() + " " + pi.getData() + "?>"); break; } case Node.ENTITY_REFERENCE_NODE: { // Handle entities out.println(indent + "&" + node.getNodeName() + ";"); break; } case Node.CDATA_SECTION_NODE: { // Output CDATA sections CDATASection cdata = (CDATASection) node; // Careful! Don't put a CDATA section in the program itself! out.println(indent + "<" + "![CDATA[" + cdata.getData() + "]]" + ">"); break; } case Node.COMMENT_NODE: { // Comments Comment c = (Comment) node; out.println(indent + "<!--" + c.getData() + "-->"); break; } default: // Hopefully, this won't happen too much! System.err.println("Ignoring node: " + node.getClass().getName()); break; } }
From source file:com.concursive.connect.web.modules.wiki.utils.HTMLToWikiUtils.java
public static void processTable(NodeList nodeList, StringBuffer sb, int rowCount, boolean doText, boolean anyNodeType, String contextPath, int projectId, int pass) { LOG.trace("line reset"); for (int i = 0; i < nodeList.getLength(); i++) { Node n = nodeList.item(i); if (n != null) { if (n.getNodeType() == Node.TEXT_NODE || n.getNodeType() == Node.CDATA_SECTION_NODE) { if (doText && anyNodeType) { if (StringUtils.hasText(n.getNodeValue())) { String thisLine = StringUtils.fromHtmlValue(n.getNodeValue()); LOG.trace("table - text: " + thisLine); sb.append(thisLine); }//from w ww . ja v a 2 s . c om } } else if (n.getNodeType() == Node.ELEMENT_NODE) { Element element = ((Element) n); String tag = element.getTagName(); if ("tr".equals(tag)) { LOG.trace("table - tr"); ++rowCount; if (rowCount == 1) { LOG.debug("Looking for style"); processTable(n.getChildNodes(), sb, rowCount, false, false, contextPath, projectId, 1); } processTable(n.getChildNodes(), sb, rowCount, false, false, contextPath, projectId, 2); sb.append(CRLF); } else if ("td".equals(tag) || "th".equals(tag)) { if (LOG.isTraceEnabled()) { LOG.trace("table - " + tag + " - " + i + " " + hasNonTextNodes(n.getChildNodes()) + " - pass " + pass); } String separator = "|"; if (tag.equals("th")) { separator = "||"; } // Determin how many columns are spanned by this column int colspan = 1; if (element.hasAttribute("colspan")) { colspan = Integer.parseInt(element.getAttribute("colspan")); } // if (sb.toString().endsWith(separator)) { // sb.append(" "); // } // Style pass boolean hasStyle = false; if (pass == 1) { if (element.hasAttribute("style")) { String style = element.getAttribute("style"); if (style.endsWith(";")) { style = style.substring(0, style.length() - 1); } // Start the wiki markup for (int sI = 0; sI < colspan; sI++) { sb.append(separator); } // Append the style data sb.append("{").append(style).append("}"); hasStyle = true; } // Close the wiki markup if the last cell if (hasStyle) { if (i + 1 == nodeList.getLength()) { sb.append(separator); // The style pass needs to add it's own CRLF sb.append(CRLF); } } } // Data pass if (pass == 2) { // Start the wiki markup for (int sI = 0; sI < colspan; sI++) { sb.append(separator); } if (n.getChildNodes().getLength() > 0) { // Cell data uses a "!" for each return if (hasNonTextNodes(n.getChildNodes())) { processChildNodes(getNodeList(n), sb, 0, true, true, false, "!", contextPath, projectId); } else { processChildNodes(getNodeList(n), sb, 0, true, true, false, "!", contextPath, projectId); } // If the cell didn't have any data, then add a space if (sb.toString().endsWith(separator)) { sb.append(" "); } } else { sb.append(" "); } // Close the wiki markup if (i + 1 == nodeList.getLength()) { sb.append(separator); } } } else { LOG.trace("table - text - ** " + tag); processTable(n.getChildNodes(), sb, rowCount, true, true, contextPath, projectId, 0); } } } } }
From source file:com.bluexml.xforms.actions.ListAction.java
/** * Used when performing searches on lists. Invoked via ModelElementListUpdater. */// w w w . j a v a 2 s . co m @SuppressWarnings("deprecation") @Override public void submit() throws ServletException { // update list using search Document doc = (Document) node; String query = ""; String maxResults = ""; Element queryElement = doc.getDocumentElement(); NodeList childNodes = queryElement.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node child = childNodes.item(i); if (child instanceof Element) { Element element = (Element) child; if (StringUtils.equals(element.getTagName(), "query")) { query = element.getTextContent(); } if (StringUtils.equals(element.getTagName(), "maxResults")) { maxResults = element.getTextContent(); } } } requestParameters.put(MsgId.INT_ACT_PARAM_LIST_QUERY.getText(), query); requestParameters.put(MsgId.INT_ACT_PARAM_LIST_SIZE.getText(), maxResults); // retrieves elements Node list = list(); // convert to string Source xmlSource = new DOMSource(list); ByteArrayOutputStream pos = new ByteArrayOutputStream(); Result outputTarget = new StreamResult(pos); try { documentTransformer.transform(xmlSource, outputTarget); } catch (TransformerException e) { if (logger.isErrorEnabled()) { logger.error("Failed to convert the list document into a string", e); } throw new ServletException(MsgId.MSG_ERROR_DEFAULT_MSG.getText()); } ByteArrayInputStream pis = new ByteArrayInputStream(pos.toByteArray()); result.put(XFormsProcessor.SUBMISSION_RESPONSE_STREAM, pis); }
From source file:com.concursive.connect.web.modules.members.portlets.JoinPortlet.java
public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { // Determine the project container to use Project project = PortalUtils.findProject(request); // Check the user's permissions User user = PortalUtils.getUser(request); try {/*from ww w . j av a 2 s . c om*/ // Get the urls to display ArrayList<HashMap> urlList = new ArrayList<HashMap>(); String[] urls = request.getPreferences().getValues(PREF_URLS, new String[0]); for (String urlPreference : urls) { XMLUtils xml = new XMLUtils("<values>" + urlPreference + "</values>", true); ArrayList<Element> items = new ArrayList<Element>(); XMLUtils.getAllChildren(xml.getDocumentElement(), items); HashMap<String, String> url = new HashMap<String, String>(); for (Element thisItem : items) { String name = thisItem.getTagName(); String value = thisItem.getTextContent(); if (value.contains("${")) { Template template = new Template(value); for (String templateVariable : template.getVariables()) { String[] variable = templateVariable.split("\\."); template.addParseElement("${" + templateVariable + "}", ObjectUtils .getParam(PortalUtils.getGeneratedData(request, variable[0]), variable[1])); } value = template.getParsedText(); } url.put(name, value); } // Determine if the url can be shown boolean valid = true; // See if there are any special rules if (url.containsKey("rule")) { String rule = url.get("rule"); if ("userCanRequestToJoin".equals(rule)) { boolean canRequestToJoin = TeamMemberUtils.userCanRequestToJoin(user, project); if (!canRequestToJoin) { valid = false; } } else if ("userCanJoin".equals(rule)) { // TODO: Update the code that adds the user, and set the team member status to pending, then remove the membership required part boolean canJoin = TeamMemberUtils.userCanJoin(user, project); if (!canJoin) { valid = false; } } else { LOG.error("Rule not found: " + rule); valid = false; } } if (valid) { // Add to the list urlList.add(url); } } request.setAttribute(URL_LIST, urlList); // Only output the portlet if there are any urls to show if (urlList.size() > 0) { // Don't show the portlet on the user's own page if (user.getProfileProjectId() != project.getId()) { // Let the view know if this is a user profile if (project.getProfile()) { request.setAttribute(IS_USER_PROFILE, "true"); } // Show the view PortletContext context = getPortletContext(); PortletRequestDispatcher requestDispatcher = context .getRequestDispatcher(MEMBER_JOIN_PROFILE_FORM); requestDispatcher.include(request, response); } } } catch (Exception e) { LOG.error("doView", e); throw new PortletException(e.getMessage()); } }
From source file:com.threadswarm.imagefeedarchiver.parser.RssDOMFeedParser.java
private RssChannel parseChannel(Document document) { RssChannel channel = new RssChannel(); List<RssItem> rssItemList = new LinkedList<RssItem>(); NodeList channelNodes = document.getElementsByTagName("channel"); Element channelElement = (Element) channelNodes.item(0); NodeList channelChildren = channelElement.getChildNodes(); for (int x = 0; x < channelChildren.getLength(); x++) { Node node = channelChildren.item(x); if (node.getNodeType() == Node.ELEMENT_NODE) { Element childElement = (Element) node; if (childElement.getTagName().equals("title")) { channel.setTitle(childElement.getTextContent()); } else if (childElement.getTagName().equals("pubDate")) { /*// ww w.j a va 2 s . c o m String pubDateString = childElement.getTextContent().trim(); if(pubDateString != null && !pubDateString.isEmpty()){ DateFormat dateFormat = DateFormat.getInstance(); try{ Date pubDate = dateFormat.parse(pubDateString); channel.setPubDate(pubDate); }catch(ParseException e){ // TODO Auto-generated catch block e.printStackTrace(); } } */ } else if (childElement.getTagName().equals("description")) { channel.setDescription(childElement.getTextContent()); } else if (childElement.getTagName().equals("item")) { RssItem rssItem = parseItem(childElement); if (rssItem != null) rssItemList.add(rssItem); } } } channel.setItems(rssItemList); return channel; }
From source file:org.sarons.spring4me.web.page.config.xml.XmlPageConfigFactory.java
private WidgetConfig parseWidget(Element widgetEle, GroupConfig groupConfig) { String id = widgetEle.getAttribute("id"); String name = widgetEle.getAttribute("name"); String path = widgetEle.getAttribute("path"); String cacheStr = widgetEle.getAttribute("cache"); String disabled = widgetEle.getAttribute("disabled"); ////from w ww . ja v a2s . c o m int cache = -1; if (StringUtils.hasText(cacheStr)) { cache = Integer.valueOf(cacheStr); } // WidgetConfig widgetConfig = new WidgetConfig(groupConfig); widgetConfig.setId(id); widgetConfig.setName(name); widgetConfig.setPath(path); widgetConfig.setCache(cache); widgetConfig.setDisabled("true".equals(disabled)); // Element titleEle = DomUtils.getChildElementByTagName(widgetEle, "title"); if (titleEle != null) { String title = titleEle.getTextContent(); widgetConfig.setTitle(title); } // Element descEle = DomUtils.getChildElementByTagName(widgetEle, "description"); if (descEle != null) { String description = descEle.getTextContent(); widgetConfig.setDescription(description); } // Map<String, String> events = new HashMap<String, String>(); Element eventsEle = DomUtils.getChildElementByTagName(widgetEle, "events"); if (eventsEle != null) { List<Element> eventEles = DomUtils.getChildElements(eventsEle); for (Element eventEle : eventEles) { String on = eventEle.getAttribute("on"); String to = eventEle.getAttribute("to"); events.put(on, to); } widgetConfig.getGroupConfig().getPageConfig().setEvents(events); } // Map<String, String> preferences = new HashMap<String, String>(); Element prefEle = DomUtils.getChildElementByTagName(widgetEle, "preference"); if (prefEle != null) { List<Element> keyValueEles = DomUtils.getChildElements(prefEle); for (Element keyValueEle : keyValueEles) { String key = keyValueEle.getTagName(); String value = keyValueEle.getTextContent(); preferences.put(key, value); } widgetConfig.setPreferences(preferences); } // return widgetConfig; }
From source file:de.egore911.reader.servlets.OpmlImportServlet.java
private int countFeeds(NodeList nodes) throws ServletException { int result = 0; for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; if (!"outline".equals(element.getTagName())) { throw new ServletException("Invalid XML"); }//w ww.j a v a2s.c o m String xmlUrl = element.getAttribute("xmlUrl"); if (Strings.isNullOrEmpty(xmlUrl)) { // It does not have a xmlUrl -> this is a category result += countFeeds(element.getChildNodes()); } else { result++; } } } return result; }