Java Code Examples for org.dom4j.Element#attributeCount()
The following examples show how to use
org.dom4j.Element#attributeCount() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LowercaseTableNames.java From unitime with Apache License 2.0 | 6 votes |
protected void writeAttributes(Element element) throws IOException { for (int i = 0, size = element.attributeCount(); i < size; i++) { Attribute attribute = element.attribute(i); char quote = format.getAttributeQuoteCharacter(); if (element.attributeCount() > 2) { writePrintln(); indent(); writer.write(format.getIndent()); } else { writer.write(" "); } writer.write(attribute.getQualifiedName()); writer.write("="); writer.write(quote); writeEscapeAttributeEntities(attribute.getValue()); writer.write(quote); } }
Example 2
Source File: XmlReadUtil.java From PatatiumWebUi with Apache License 2.0 | 5 votes |
public static String getTestngParametersValue(String path,String ParametersName) throws DocumentException, IOException { File file = new File(path); if (!file.exists()) { throw new IOException("Can't find " + path); } String value=null; SAXReader reader = new SAXReader(); Document document = reader.read(file); Element root = document.getRootElement(); for (Iterator<?> i = root.elementIterator(); i.hasNext();) { Element page = (Element) i.next(); if(page.attributeCount()>0) { if (page.attribute(0).getValue().equalsIgnoreCase(ParametersName)) { value=page.attribute(1).getValue(); //System.out.println(page.attribute(1).getValue()); } continue; } //continue; } return value; }
Example 3
Source File: TestReport.java From PatatiumWebUi with Apache License 2.0 | 5 votes |
private String getTestngParametersValue(String path,String ParametersName) throws DocumentException, IOException { File file = new File(path); if (!file.exists()) { throw new IOException("Can't find " + path); } String value=null; SAXReader reader = new SAXReader(); Document document = reader.read(file); Element root = document.getRootElement(); for (Iterator<?> i = root.elementIterator(); i.hasNext();) { Element page = (Element) i.next(); if(page.attributeCount()>0) { if (page.attribute(0).getValue().equalsIgnoreCase(ParametersName)) { value=page.attribute(1).getValue(); //System.out.println(page.attribute(1).getValue()); } continue; } //continue; } return value; }
Example 4
Source File: XmlReadUtil.java From PatatiumAppUi with GNU General Public License v2.0 | 5 votes |
public static String getTestngParametersValue(String path,String ParametersName) throws DocumentException, IOException { File file = new File(path); if (!file.exists()) { throw new IOException("Can't find " + path); } String value=null; SAXReader reader = new SAXReader(); Document document = reader.read(file); Element root = document.getRootElement(); for (Iterator<?> i = root.elementIterator(); i.hasNext();) { Element page = (Element) i.next(); if(page.attributeCount()>0) { if (page.attribute(0).getValue().equalsIgnoreCase(ParametersName)) { value=page.attribute(1).getValue(); //System.out.println(page.attribute(1).getValue()); } continue; } //continue; } return value; }
Example 5
Source File: TestReport.java From PatatiumAppUi with GNU General Public License v2.0 | 5 votes |
private String getTestngParametersValue(String path,String ParametersName) throws DocumentException, IOException { File file = new File(path); if (!file.exists()) { throw new IOException("Can't find " + path); } String value=null; SAXReader reader = new SAXReader(); Document document = reader.read(file); Element root = document.getRootElement(); for (Iterator<?> i = root.elementIterator(); i.hasNext();) { Element page = (Element) i.next(); if(page.attributeCount()>0) { if (page.attribute(0).getValue().equalsIgnoreCase(ParametersName)) { value=page.attribute(1).getValue(); //System.out.println(page.attribute(1).getValue()); } continue; } //continue; } return value; }
Example 6
Source File: XMLToObject.java From FoxBPM with Apache License 2.0 | 5 votes |
/** * 处理属性 * * @param element * @param paramObj * @param temp * @throws InvocationTargetException * @throws IllegalAccessException * @throws IllegalArgumentException */ private void doAttributes(Element element, Object paramObj, Map<String, Method> methods) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { // 处理element属性 Method method = null; Attribute attribute = null; for (int i = 0, length = element.attributeCount(); i < length; i++) { attribute = element.attribute(i); method = methods.get(generateMethodName(GENERAL_M_PREFIX, attribute.getName())); if (null != method && method.getParameterTypes().length == 1) { doAttributeValue(paramObj, method, attribute.getValue(), method.getParameterTypes()[0]); } } }
Example 7
Source File: FoxBPMCfgParseUtil.java From FoxBPM with Apache License 2.0 | 5 votes |
private void doAttributes(Element element, Object paramObj){ // 处理element属性 Method method = null; Attribute attribute = null; Map<String, Method> methodMap = getSetMethods(GENERAL_M_PREFIX, paramObj); for (int i = 0, length = element.attributeCount(); i < length; i++) { attribute = element.attribute(i); method = methodMap.get(generateMethodName(GENERAL_M_PREFIX, attribute.getName())); if (null != method) { doAttributeValue(paramObj, method, attribute.getValue(), method.getParameterTypes()[0]); } } }
Example 8
Source File: RESTUtil.java From rest-client with Apache License 2.0 | 4 votes |
/** * * @Title: xmlTree * @Description: To generate a XML tree * @param @param e * @param @param layer * @param @param sb * @return void * @throws */ public static void xmlTree(Element e, int layer, StringBuilder sb) { if (e.nodeCount() <= 0) { return; } String spaces = " "; String vertLine = "│ "; String line = RESTConst.LINE; String type = RESTConst.UNKNOWN; String indent = dup(layer, spaces); layer++; if (layer <= 0) { line = " "; } @SuppressWarnings("unchecked") List<Element> es = e.elements(); for (Element ce : es) { indent = dup(layer, spaces); if (layer >= 2) { indent = dup(1, spaces) + dup(layer - 1, vertLine); } if (!ce.elements().isEmpty() || ce.attributeCount() > 0) { type = Object.class.getSimpleName(); } else if (StringUtils.isNotEmpty(ce.getText()) && StringUtils.isNumeric(ce.getStringValue())) { type = Number.class.getSimpleName(); } else { type = String.class.getSimpleName(); } /* Element */ sb.append(indent).append(line) .append(ce.getName()).append(" [") .append(type.toLowerCase()) .append("]").append(lines(1)); /* Attributes */ if (ce.attributeCount() > 0) { indent = dup(layer + 1, spaces); if (layer + 1 >= 2) { indent = dup(1, spaces) + dup(layer, vertLine); } @SuppressWarnings("unchecked") List<Attribute> as = ce.attributes(); for (Attribute a : as) { if (StringUtils.isNotEmpty(ce.getText()) && StringUtils.isNumeric(a.getValue())) { type = Number.class.getSimpleName(); } else { type = String.class.getSimpleName(); } sb.append(indent).append(RESTConst.LINE) .append(a.getName()).append(" [") .append(type.toLowerCase()) .append("]").append(lines(1)); } } xmlTree(ce, layer, sb); } }
Example 9
Source File: VdTree.java From SVG-Android with Apache License 2.0 | 4 votes |
private void parseRootNode(Element rootNode) { if (rootNode.attributeCount() != 0) { parseSize(rootNode.attributes()); } }
Example 10
Source File: PageObjectAutoCode.java From PatatiumWebUi with Apache License 2.0 | 4 votes |
public static void autoCode() throws Exception { File file = new File(path); if (!file.exists()) { throw new IOException("Can't find " + path); } SAXReader reader = new SAXReader(); Document document = reader.read(file); //对象库xml文件根节点 Element root = document.getRootElement(); //遍历根节点下的第一个节点(page节点) for(Iterator<?> i=root.elementIterator();i.hasNext();) { Element page=(Element)i.next(); //获取page节点的name属性值 String pageName=page.attribute(0).getValue(); System.out.println(pageName); //将pageName存储为数组 String[] pageNameArray=pageName.split("\\."); System.out.println(pageNameArray); System.out.println(pageNameArray[0]); //获取要写入的page所属的类名 String pageClassName=pageNameArray[4].toString(); //获取对象库包名 String packageName=pageNameArray[0].toString()+"."+pageNameArray[1].toString()+"."+pageNameArray[2].toString()+"."+pageNameArray[3].toString(); //--自动编写对象库代码(XXPage.java)开始-- StringBuffer sb=new StringBuffer("package "+packageName+";\n"); sb.append("import java.io.IOException;\n"); sb.append("import java.io.InputStream;\n"); sb.append("import org.webdriver.patatiumwebui.utils.BaseAction;\n"); sb.append("import org.webdriver.patatiumwebui.utils.Locator;\n"); sb.append("import org.webdriver.patatiumwebui.pageObjectConfig.PageObjectAutoCode;"); sb.append("//"+page.attribute(2).getValue()+"_对象库类\n"); sb.append("public class "+ pageClassName+" extends BaseAction {\n"); sb.append("//用于eclipse工程内运行查找对象库文件路径\n"); sb.append("private String path=\"src/main/java/org/webdriver/patatiumwebui/pageObjectConfig/UILibrary.xml\";\n"); //sb.append("//用户打包成jar后查找对象库文件路径\n"); //sb.append("private InputStream pathInputStream=PageObjectAutoCode.class.getClassLoader().getResourceAsStream(\"net/hk515/pageObjectConfig/UILibrary.xml\"); \n"); sb.append(" public " + pageClassName + "() {\n"); sb.append("//工程内读取对象库文件\n "); sb.append("setXmlObjectPath(path);\n"); sb.append("getLocatorMap();"); sb.append("\n}"); //sb.append("\n private String path=PageObjectAutoCode.class.getClassLoader().getResource(\"net/hk515/pageObjectConfig/UILibrary.xml\").getPath();"); //遍历Page节点下的Locator节点 for(Iterator<?> j=page.elementIterator();j.hasNext();) { //获取locaror节点 Element locator =(Element)j.next(); String locatorName=locator.getTextTrim(); if(locator.attributeCount()>3) {sb.append("\n/***\n" + "* "+locator.attribute(3).getValue()+"\n" + "* @return\n" + "* @throws IOException\n" + "*/\n"); } else { sb.append("\n"); } sb.append("public Locator "+locatorName+"() throws IOException\n {\n"); //sb.append(" setXmlObjectPath(path);\n"); sb.append(" Locator locator=getLocator(\""+locatorName+"\");\n"); sb.append(" return locator;\n }\n"); } sb.append("}"); //将自动生成的PageObject代码写入文件 File pageObjectFile=new File("src/main/java/org/webdriver/patatiumwebui/pageObject/"+pageClassName+".java"); if(pageObjectFile.exists()) { pageObjectFile.delete();; } try { FileWriter fileWriter=new FileWriter(pageObjectFile, false); BufferedWriter output = new BufferedWriter(fileWriter); output.write(sb.toString()); output.flush(); output.close(); } catch (IOException e1) { // TODO 自动生成的 catch 块 e1.printStackTrace(); } System.out.println(sb); Log log=new Log(PageObjectAutoCode.class); log.info("自动生成对象库java代码成功"); } }
Example 11
Source File: Config.java From PatatiumWebUi with Apache License 2.0 | 4 votes |
public static void SetXML(String Base_Url,String UserName,String PassWord,String driver,String nodeURL,String Recipients,String ReportUrl,String LogUrl) throws IOException, DocumentException { File file = new File(path); if (!file.exists()) { throw new IOException("Can't find " + path); } SAXReader reader = new SAXReader(); Document document = reader.read(file); Element root = document.getRootElement(); for (Iterator<?> i = root.elementIterator(); i.hasNext();) { Element page = (Element) i.next(); if(page.attributeCount()>0) { if (page.attribute(0).getValue().equalsIgnoreCase("Base_Url")) { page.attribute(1).setValue(Base_Url); //System.out.println(page.attribute(1).getValue()); } if (page.attribute(0).getValue().equalsIgnoreCase("UserName")) { page.attribute(1).setValue(UserName); } if (page.attribute(0).getValue().equalsIgnoreCase("PassWord")) { page.attribute(1).setValue(PassWord); } if (page.attribute(0).getValue().equalsIgnoreCase("driver")) { page.attribute(1).setValue(driver); } if (page.attribute(0).getValue().equalsIgnoreCase("nodeURL")) { page.attribute(1).setValue("http://"+nodeURL+"/wd/hub"); } if (page.attribute(0).getValue().equalsIgnoreCase("Recipients")) { page.attribute(1).setValue(Recipients); } if (page.attribute(0).getValue().equalsIgnoreCase("ReportUrl")) { page.attribute(1).setValue(ReportUrl); } if (page.attribute(0).getValue().equalsIgnoreCase("LogUrl")) { page.attribute(1).setValue(LogUrl); } continue; } //continue; } if (driver.equalsIgnoreCase("FirefoxDriver")) { driver="火狐浏览器"; } else if (driver.equalsIgnoreCase("ChormeDriver")) { driver="谷歌浏览器"; } else if(driver.equalsIgnoreCase("InternetExplorerDriver-8")) { driver="IE8浏览器"; } else if(driver.equalsIgnoreCase("InternetExplorerDriver-9")) { driver="IE9浏览器"; } else { driver="火狐浏览器"; } try{ /** 格式化输出,类型IE浏览一样 */ OutputFormat format = OutputFormat.createPrettyPrint(); /** 指定XML编码 */ format.setEncoding("gb2312"); /** 将document中的内容写入文件中 */ XMLWriter writer = new XMLWriter(new FileWriter(new File(path)),format); writer.write(document); writer.close(); /** 执行成功,需返回1 */ int returnValue = 1; System.out.println("设置配置环境:"+Base_Url + ";用户名:"+UserName + "密码:" + PassWord +"浏览器:" +driver +"成功!"); System.out.println("设置报表url:"+ReportUrl); System.out.println("设置报表日志:"+LogUrl); System.out.println("设置收件人地址:"+Recipients); }catch(Exception ex){ ex.printStackTrace(); System.out.println("设置配置环境:"+Base_Url + ";用户名:"+UserName + "密码:" + PassWord +"浏览器:" +driver +"失败!"); } }
Example 12
Source File: PageObjectAutoCodeForXml.java From PatatiumAppUi with GNU General Public License v2.0 | 4 votes |
public static void autoCode() throws Exception { File file = new File(path); if (!file.exists()) { throw new IOException("Can't find " + path); } SAXReader reader = new SAXReader(); Document document = reader.read(file); //对象库xml文件根节点 Element root = document.getRootElement(); //遍历根节点下的第一个节点(page节点) for(Iterator<?> i=root.elementIterator();i.hasNext();) { Element page=(Element)i.next(); //获取page节点的name属性值 String pageName=page.attribute(0).getValue(); System.out.println(pageName); //将pageName存储为数组 String[] pageNameArray=pageName.split("\\."); System.out.println(pageNameArray); System.out.println(pageNameArray[0]); //获取要写入的page所属的类名 String pageClassName=pageNameArray[4].toString(); //获取对象库包名 String packageName=pageNameArray[0].toString()+"."+pageNameArray[1].toString()+"."+pageNameArray[2].toString()+"."+pageNameArray[3].toString(); //--自动编写对象库代码(XXPage.java)开始-- StringBuffer sb=new StringBuffer("package "+packageName+";\n"); sb.append("import java.io.IOException;\n"); sb.append("import java.io.InputStream;\n"); sb.append("import org.webdriver.patatiumappui.utils.BaseAction;\n"); sb.append("import org.webdriver.patatiumappui.utils.Locator;\n"); sb.append("import org.webdriver.patatiumappui.pageObjectConfig.PageObjectAutoCodeForXml;"); sb.append("//"+page.attribute(2).getValue()+"_对象库类\n"); sb.append("public class "+ pageClassName+" extends BaseAction {\n"); sb.append("//用于eclipse工程内运行查找对象库文件路径\n"); sb.append("private String path=\"src/main/java/org/webdriver/patatiumappui/pageObjectConfig/UILibrary.xml\";\n"); //sb.append("//用户打包成jar后查找对象库文件路径\n"); //sb.append("private InputStream pathInputStream=PageObjectAutoCode.class.getClassLoader().getResourceAsStream(\"net/hk515/pageObjectConfig/UILibrary.xml\"); \n"); sb.append(" public " + pageClassName + "() {\n"); sb.append("//工程内读取对象库文件\n "); sb.append("setXmlObjectPath(path);\n"); sb.append("getLocatorMap();"); sb.append("\n}"); //sb.append("\n private String path=PageObjectAutoCode.class.getClassLoader().getResource(\"net/hk515/pageObjectConfig/UILibrary.xml\").getPath();"); //遍历Page节点下的Locator节点 for(Iterator<?> j=page.elementIterator();j.hasNext();) { //获取locaror节点 Element locator =(Element)j.next(); String locatorName=locator.getTextTrim(); if(locator.attributeCount()>3) {sb.append("\n/***\n" + "* "+locator.attribute(3).getValue()+"\n" + "* @return\n" + "* @throws IOException\n" + "*/\n"); } else { sb.append("\n"); } sb.append("public Locator "+locatorName+"() throws IOException\n {\n"); //sb.append(" setXmlObjectPath(path);\n"); sb.append(" Locator locator=getLocator(\""+locatorName+"\");\n"); sb.append(" return locator;\n }\n"); } sb.append("}"); //将自动生成的PageObject代码写入文件 File pageObjectFile=new File("src/main/java/org/webdriver/patatiumappui/pageObject/"+pageClassName+".java"); if(pageObjectFile.exists()) { pageObjectFile.delete();; } try { FileWriter fileWriter=new FileWriter(pageObjectFile, false); BufferedWriter output = new BufferedWriter(fileWriter); output.write(sb.toString()); output.flush(); output.close(); } catch (IOException e1) { // TODO 自动生成的 catch 块 e1.printStackTrace(); } System.out.println(sb); Log log=new Log(PageObjectAutoCodeForXml.class); log.info("自动生成对象库java代码成功"); } }
Example 13
Source File: PageObjectAutoCodeForYaml.java From PatatiumAppUi with GNU General Public License v2.0 | 4 votes |
public static void autoCode2() throws Exception { File file = new File(path); if (!file.exists()) { throw new IOException("Can't find " + path); } SAXReader reader = new SAXReader(); Document document = reader.read(file); //对象库xml文件根节点 Element root = document.getRootElement(); //遍历根节点下的第一个节点(page节点) for(Iterator<?> i=root.elementIterator();i.hasNext();) { Element page=(Element)i.next(); //获取page节点的name属性值 String pageName=page.attribute(0).getValue(); System.out.println(pageName); //将pageName存储为数组 String[] pageNameArray=pageName.split("\\."); System.out.println(pageNameArray); System.out.println(pageNameArray[0]); //获取要写入的page所属的类名 String pageClassName=pageNameArray[4].toString(); //获取对象库包名 String packageName=pageNameArray[0].toString()+"."+pageNameArray[1].toString()+"."+pageNameArray[2].toString()+"."+pageNameArray[3].toString(); //--自动编写对象库代码(XXPage.java)开始-- StringBuffer sb=new StringBuffer("package "+packageName+";\n"); sb.append("import java.io.IOException;\n"); sb.append("import java.io.InputStream;\n"); sb.append("import org.webdriver.patatiumappui.utils.BaseAction;\n"); sb.append("import org.webdriver.patatiumappui.utils.Locator;\n"); sb.append("import org.webdriver.patatiumappui.pageObjectConfig.PageObjectAutoCode;"); sb.append("//"+page.attribute(2).getValue()+"_对象库类\n"); sb.append("public class "+ pageClassName+" extends BaseAction {\n"); sb.append("//用于eclipse工程内运行查找对象库文件路径\n"); sb.append("private String path=\"src/main/java/org/webdriver/patatiumappui/pageObjectConfig/UILibrary.xml\";\n"); //sb.append("//用户打包成jar后查找对象库文件路径\n"); //sb.append("private InputStream pathInputStream=PageObjectAutoCode.class.getClassLoader().getResourceAsStream(\"net/hk515/pageObjectConfig/UILibrary.xml\"); \n"); sb.append(" public " + pageClassName + "() {\n"); sb.append("//工程内读取对象库文件\n "); sb.append("setXmlObjectPath(path);\n"); sb.append("getLocatorMap();"); sb.append("\n}"); //sb.append("\n private String path=PageObjectAutoCode.class.getClassLoader().getResource(\"net/hk515/pageObjectConfig/UILibrary.xml\").getPath();"); //遍历Page节点下的Locator节点 for(Iterator<?> j=page.elementIterator();j.hasNext();) { //获取locaror节点 Element locator =(Element)j.next(); String locatorName=locator.getTextTrim(); if(locator.attributeCount()>3) {sb.append("\n/***\n" + "* "+locator.attribute(3).getValue()+"\n" + "* @return\n" + "* @throws IOException\n" + "*/\n"); } else { sb.append("\n"); } sb.append("public Locator "+locatorName+"() throws IOException\n {\n"); //sb.append(" setXmlObjectPath(path);\n"); sb.append(" Locator locator=getLocator(\""+locatorName+"\");\n"); sb.append(" return locator;\n }\n"); } sb.append("}"); //将自动生成的PageObject代码写入文件 File pageObjectFile=new File("src/main/java/org/webdriver/patatiumappui/pageObject/"+pageClassName+".java"); if(pageObjectFile.exists()) { pageObjectFile.delete();; } try { FileWriter fileWriter=new FileWriter(pageObjectFile, false); BufferedWriter output = new BufferedWriter(fileWriter); output.write(sb.toString()); output.flush(); output.close(); } catch (IOException e1) { // TODO 自动生成的 catch 块 e1.printStackTrace(); } System.out.println(sb); Log log=new Log(PageObjectAutoCodeForYaml.class); log.info("自动生成对象库java代码成功"); } }
Example 14
Source File: Config.java From PatatiumAppUi with GNU General Public License v2.0 | 4 votes |
public static void SetXML(String Base_Url,String UserName,String PassWord,String driver,String nodeURL,String Recipients,String ReportUrl,String LogUrl) throws IOException, DocumentException { File file = new File(path); if (!file.exists()) { throw new IOException("Can't find " + path); } SAXReader reader = new SAXReader(); Document document = reader.read(file); Element root = document.getRootElement(); for (Iterator<?> i = root.elementIterator(); i.hasNext();) { Element page = (Element) i.next(); if(page.attributeCount()>0) { if (page.attribute(0).getValue().equalsIgnoreCase("Base_Url")) { page.attribute(1).setValue(Base_Url); //System.out.println(page.attribute(1).getValue()); } if (page.attribute(0).getValue().equalsIgnoreCase("UserName")) { page.attribute(1).setValue(UserName); } if (page.attribute(0).getValue().equalsIgnoreCase("PassWord")) { page.attribute(1).setValue(PassWord); } if (page.attribute(0).getValue().equalsIgnoreCase("driver")) { page.attribute(1).setValue(driver); } if (page.attribute(0).getValue().equalsIgnoreCase("nodeURL")) { page.attribute(1).setValue("http://"+nodeURL+"/wd/hub"); } if (page.attribute(0).getValue().equalsIgnoreCase("Recipients")) { page.attribute(1).setValue(Recipients); } if (page.attribute(0).getValue().equalsIgnoreCase("ReportUrl")) { page.attribute(1).setValue(ReportUrl); } if (page.attribute(0).getValue().equalsIgnoreCase("LogUrl")) { page.attribute(1).setValue(LogUrl); } continue; } //continue; } if (driver.equalsIgnoreCase("FirefoxDriver")) { driver="火狐浏览器"; } else if (driver.equalsIgnoreCase("ChormeDriver")) { driver="谷歌浏览器"; } else if(driver.equalsIgnoreCase("InternetExplorerDriver-8")) { driver="IE8浏览器"; } else if(driver.equalsIgnoreCase("InternetExplorerDriver-9")) { driver="IE9浏览器"; } else { driver="火狐浏览器"; } try{ /** 格式化输出,类型IE浏览一样 */ OutputFormat format = OutputFormat.createPrettyPrint(); /** 指定XML编码 */ format.setEncoding("gb2312"); /** 将document中的内容写入文件中 */ XMLWriter writer = new XMLWriter(new FileWriter(new File(path)),format); writer.write(document); writer.close(); /** 执行成功,需返回1 */ int returnValue = 1; System.out.println("设置配置环境:"+Base_Url + ";用户名:"+UserName + "密码:" + PassWord +"浏览器:" +driver +"成功!"); System.out.println("设置报表url:"+ReportUrl); System.out.println("设置报表日志:"+LogUrl); System.out.println("设置收件人地址:"+Recipients); }catch(Exception ex){ ex.printStackTrace(); System.out.println("设置配置环境:"+Base_Url + ";用户名:"+UserName + "密码:" + PassWord +"浏览器:" +driver +"失败!"); } }
Example 15
Source File: LowercaseTableNames.java From unitime with Apache License 2.0 | 4 votes |
protected void writeElement(Element element) throws IOException { int size = element.nodeCount(); String qualifiedName = element.getQualifiedName(); writePrintln(); indent(); writer.write("<"); writer.write(qualifiedName); boolean textOnly = true; for (int i = 0; i < size; i++) { Node node = element.node(i); if (node instanceof Element) { textOnly = false; } else if (node instanceof Comment) { textOnly = false; } } writeAttributes(element); lastOutputNodeType = Node.ELEMENT_NODE; if (size <= 0) { writeEmptyElementClose(qualifiedName); } else { writer.write(">"); if (textOnly) { // we have at least one text node so lets assume // that its non-empty writeElementContent(element); } else { if (element.attributeCount() > 3) writePrintln(); // we know it's not null or empty from above ++indentLevel; writeElementContent(element); --indentLevel; writePrintln(); indent(); } writer.write("</"); writer.write(qualifiedName); writer.write(">"); } if (element.attributeCount() > 2 && indentLevel > 0) writePrintln(); lastOutputNodeType = Node.ELEMENT_NODE; }