source: trunk/greenstone3-extensions/gs3build/src/org/greenstone/gsdl3/gs3build/xpointer/IdentifierXPointer.java@ 12188

Last change on this file since 12188 was 12188, checked in by kjdon, 18 years ago

Initial revision

  • Property svn:keywords set to Author Date Id Revision
File size: 1.4 KB
Line 
1package org.greenstone.gsdl3.gs3build.xpointer;
2
3import org.w3c.dom.*;
4import org.apache.xpath.*;
5
6public 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}
Note: See TracBrowser for help on using the repository browser.