1 | package org.greenstone.gsdl3.gs3build.xpointer;
|
---|
2 |
|
---|
3 | import org.w3c.dom.*;
|
---|
4 | import org.apache.xpath.*;
|
---|
5 |
|
---|
6 | public class IdentifierXPointer extends XPointer
|
---|
7 | { NodeList nodes;
|
---|
8 |
|
---|
9 | public IdentifierXPointer(Document document, String xpointer)
|
---|
10 | { super(document, xpointer);
|
---|
11 |
|
---|
12 | this.xpointer = XPointer.expandXPath(this.xpointer);
|
---|
13 |
|
---|
14 | this.nodes = this.getNodes();
|
---|
15 | }
|
---|
16 |
|
---|
17 | private NodeList getNodes()
|
---|
18 | {
|
---|
19 | try {
|
---|
20 | NodeList nodes = XPathAPI.selectNodeList(this.document, this.xpointer,
|
---|
21 | this.document.getDocumentElement());
|
---|
22 | return nodes;
|
---|
23 | }
|
---|
24 | catch (Exception ex)
|
---|
25 | { System.out.println(ex.toString());
|
---|
26 | }
|
---|
27 | return null;
|
---|
28 | }
|
---|
29 |
|
---|
30 | public Node getStartNode()
|
---|
31 | { return this.nodes.item(0);
|
---|
32 | }
|
---|
33 |
|
---|
34 | private void recurseStringify(NodeList nodes, StringBuffer buffer)
|
---|
35 | {
|
---|
36 | for (int n = 0; n < nodes.getLength(); n ++) {
|
---|
37 | Node node = nodes.item(n);
|
---|
38 |
|
---|
39 | // append the actual node itself
|
---|
40 | this.printNode(node, buffer, false);
|
---|
41 |
|
---|
42 | // then process its children...
|
---|
43 | if (node.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {
|
---|
44 | NodeList children = node.getChildNodes();
|
---|
45 | this.recurseStringify(children, buffer);
|
---|
46 | }
|
---|
47 |
|
---|
48 | // do the close node
|
---|
49 | this.printNode(node, buffer, true);
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | public String toString()
|
---|
54 | {
|
---|
55 | StringBuffer reply = new StringBuffer();
|
---|
56 | this.recurseStringify(this.nodes, reply);
|
---|
57 | return reply.toString();
|
---|
58 | }
|
---|
59 | }
|
---|