deleted dependency from net.sourceforge.phpeclipse module
[phpeclipse.git] / net.sourceforge.phpeclipse.wizards / src / net / sourceforge / phpeclipse / wizards / xml / ModelUtil.java
1 package net.sourceforge.phpeclipse.wizards.xml;
2
3 import org.w3c.dom.Element;
4 import org.w3c.dom.NamedNodeMap;
5 import org.w3c.dom.Node;
6 import org.w3c.dom.NodeList;
7 import org.w3c.dom.Text;
8
9 import com.quantum.util.StringMatrix;
10
11 public class ModelUtil {
12
13   public static String getTableName(Element root) {
14     NodeList columns = root.getElementsByTagName("table");
15     for (int i = 0; i < columns.getLength(); i++) {
16       Node column = columns.item(i);
17       String header = column.getNodeName();
18       if (header.equals("table")) {
19         NamedNodeMap map = column.getAttributes();
20         Node name = map.getNamedItem("name");
21         if (name == null) {
22           return "";
23         }
24         return name.getNodeValue();
25       }
26     }
27     return "";
28   }
29
30   
31   public static void xmlToStringMatrix(StringMatrix matrix, Element root, String sub) {
32     NodeList columns = root.getElementsByTagName(sub);
33     for (int i = 0; i < columns.getLength(); i++) {
34       Node column = columns.item(i);
35       NodeList columnList = column.getChildNodes();
36       for (int j = 0; j < columnList.getLength(); j++) {
37         Node node = columnList.item(j);
38         String header = node.getNodeName();
39         if (header.equals("#text")) //$NON-NLS-1$
40           continue;
41         String value = null;
42         if (node != null && node.hasChildNodes()) {
43           Node valueNode = node.getFirstChild();
44           if (valueNode instanceof Text) {
45             value = valueNode.getNodeValue();
46           }
47         }
48         if (!matrix.contains(header))
49           matrix.addHeader(header);
50         matrix.addAt(header, value, i);
51       }
52     }
53   }
54 }