1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
package tex4ht;
/**********************************************************/
/* DbUtilities.java 2008-11-14-02:41 */
/* Copyright (C) 2008 Eitan M. Gurari */
/* */
/* This work may be distributed and/or modified under the */
/* conditions of the LaTeX Project Public License, either */
/* version 1.3 of this license or (at your option) any */
/* later version. The latest version of this license is */
/* in */
/* http://www.latex-project.org/lppl.txt */
/* and version 1.3 or later is part of all distributions */
/* of LaTeX version 2003/12/01 or later. */
/* */
/* This work has the LPPL maintenance status "maintained".*/
/* */
/* This Current Maintainer of this work */
/* is Eitan M. Gurari. */
/* */
/* gurari@cse.ohio-state.edu */
/* http://www.cse.ohio-state.edu/~gurari */
/**********************************************************/
import org.w3c.dom.*;
public class DbUtilities {
public static void cline(Node dom) {
Node row, entry, para, nextrow;
Node node = dom.getFirstChild();
if( node != null ){
row = node.getLastChild();
while( (row != null)
&& ( (entry = row.getLastChild()) != null)
&& ( (para = entry.getFirstChild()) != null)
&& ( para.getNextSibling() == null)
&& ( para.getFirstChild() == null)
){
node.removeChild(row);
row = node.getLastChild();
}
row = node.getFirstChild();
while( row != null ){
if( (row.getNodeType() == Node.ELEMENT_NODE)
&& ((Element) row).getAttribute("rowsep").equals("")
&& !((Element) row).getAttribute("role" ).equals("cline")
&& ((nextrow = row.getNextSibling()) != null)
&& (nextrow.getNodeType() == Node.ELEMENT_NODE)
&& ((Element) nextrow).getAttribute("role" ).equals("cline")
){
boolean compatible = true;
Node entry1 = row.getFirstChild();
Node entry2 = nextrow.getFirstChild();
while( true ){
if( (entry1 == null) || (entry2 == null) ){ break; }
int range;
try{
range =
Integer.parseInt( ((Element) entry1).getAttribute("nameend") )
-
Integer.parseInt( ((Element) entry1).getAttribute("namest") )
+
1;
} catch( Exception e){ range = 1;}
if( range > 1 ){
String rowsep = ((Element) entry2).getAttribute("rowsep");
while( --range > 0 ){
entry2 = entry2.getNextSibling();
if( entry2 == null ){
compatible = false;
break;
}
String value = ((Element) entry2).getAttribute("rowsep");
if( !value.equals( rowsep ) ){
compatible = false;
break;
}
}
}
if( !compatible ){ break; }
entry1 = entry1.getNextSibling();
entry2 = entry2.getNextSibling();
}
if( compatible ){
entry1 = row.getFirstChild();
entry2 = nextrow.getFirstChild();
while( true ){
if( (entry1 == null) || (entry2 == null) ){ break; }
int range;
try{
range =
Integer.parseInt( ((Element) entry1).getAttribute("nameend") )
-
Integer.parseInt( ((Element) entry1).getAttribute("namest") )
+
1;
} catch( Exception e){ range = 1;}
((Element) entry1).setAttribute(
"rowsep",
((Element) entry2).getAttribute("rowsep") );
while( --range > 0 ){
entry2 = entry2.getNextSibling();
}
entry1 = entry1.getNextSibling();
entry2 = entry2.getNextSibling();
}
node.removeChild(nextrow);
}
}
row = row.getNextSibling();
}
}
}
public static void para(Node dom) {
Node pNode = dom.getFirstChild();
if( pNode.hasChildNodes() ){
Node child = pNode.getFirstChild();
if( child != null ){
if( (child.getNodeType() == Node.TEXT_NODE)
&&
((Text) child).getWholeText().trim().equals("")
){
pNode.removeChild( child );
} } }
if( pNode.hasChildNodes() ){
Node child = pNode.getLastChild();
if( child != null ){
if( (child.getNodeType() == Node.TEXT_NODE)
&&
((Text) child).getWholeText().trim().equals("")
){
pNode.removeChild( child );
} } }
if( pNode.hasChildNodes() ){
Node child = pNode.getFirstChild();
if( (child != null)
&& (child.getNextSibling() == null)
&& (child.getNodeType() == Node.TEXT_NODE)
){
String txt = ((Text) child).getWholeText();
String trm = txt.trim();
if( !trm.equals(txt) ){
((Text)child).replaceWholeText(trm);
} } }
}
}
|