Here you can find the source of writeDescription(PrintWriter out, Node node, String offSet)
Parameter | Description |
---|---|
out | The output stream to write in |
node | The affected Node |
offSet | The offset that should be used before each line (commonly empty spaces) |
public static void writeDescription(PrintWriter out, Node node, String offSet)
//package com.java2s; //License from project: Apache License import java.io.PrintWriter; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /**/* www.j a va2 s. c o m*/ * Parses and writes the description of a given Node into the output stream * @param out The output stream to write in * @param node The affected Node * @param offSet The offset that should be used before each line (commonly empty spaces) */ public static void writeDescription(PrintWriter out, Node node, String offSet) { Node childNodeDescriptive = null; Node childNodeBrief = null; Node childNodeDescription = null; if (node == null) return; childNodeDescriptive = getNodeByName("descriptive", node.getChildNodes()); if (childNodeDescriptive == null) return; childNodeBrief = getNodeByName("brief", childNodeDescriptive.getChildNodes()); childNodeDescription = getNodeByName("description", childNodeDescriptive.getChildNodes()); String desc = ""; String outline = "\n" + offSet + "/**"; if (childNodeBrief != null) { desc = childNodeBrief.getTextContent().trim().replace("\n", "\n" + offSet + " * "); outline += "\n" + offSet + " * " + desc; } if (!outline.endsWith(" * ")) outline += "\n" + offSet + " *"; if (childNodeDescription != null) { NodeList l = childNodeDescription.getChildNodes(); for (int i = 0; i < l.getLength(); i++) { desc = childNodeDescription.getChildNodes().item(i).getTextContent().trim().replace("\n", "\n" + offSet + " * "); outline += "\n" + offSet + " * " + desc; } } //TODO add code examples //TODO add param descriptions and return value descriptions //TODO add throws description outline += "\n" + offSet + " */"; out.println(outline); } /** * Gets the first node with a specific name * @param name * @param nodeList * @return */ static Node getNodeByName(String name, NodeList nodeList) { for (int i = 0; i < nodeList.getLength(); i++) { if (nodeList.item(i).getNodeName().equals(name)) { return nodeList.item(i); } } return null; } }