1 package net.sf.saxon.jdom; 2 3 import net.sf.saxon.Configuration; 4 import net.sf.saxon.event.PipelineConfiguration; 5 import net.sf.saxon.event.Receiver; 6 import net.sf.saxon.expr.XPathContext; 7 import net.sf.saxon.om.DocumentInfo; 8 import net.sf.saxon.om.ExternalObjectModel; 9 import net.sf.saxon.om.NodeInfo; 10 import net.sf.saxon.trans.XPathException; 11 import net.sf.saxon.value.Value; 12 import net.sf.saxon.value.SequenceExtent; 13 import org.jdom.*; 14 15 import javax.xml.transform.Result ; 16 import javax.xml.transform.Source ; 17 import java.io.Serializable ; 18 19 20 25 26 public class JDOMObjectModel implements ExternalObjectModel, Serializable { 27 28 public JDOMObjectModel() {} 29 30 33 34 public boolean isRecognizedNode(Object object) { 35 return object instanceof Document || 36 object instanceof Element || 37 object instanceof Attribute || 38 object instanceof Text || 39 object instanceof CDATA || 40 object instanceof Comment || 41 object instanceof ProcessingInstruction || 42 object instanceof Namespace; 43 } 44 45 52 53 public boolean isRecognizedNodeClass(Class nodeClass) { 54 return Document.class.isAssignableFrom(nodeClass) || 55 Element.class.isAssignableFrom(nodeClass) || 56 Attribute.class.isAssignableFrom(nodeClass) || 57 Text.class.isAssignableFrom(nodeClass) || 58 CDATA.class.isAssignableFrom(nodeClass) || 59 Comment.class.isAssignableFrom(nodeClass) || 60 ProcessingInstruction.class.isAssignableFrom(nodeClass) || 61 Namespace.class.isAssignableFrom(nodeClass); 62 } 63 64 71 72 public boolean isRecognizedNodeListClass(Class nodeClass) { 73 return false; 74 } 75 76 81 82 public Receiver getDocumentBuilder(Result result) { 83 return null; } 85 86 91 92 public boolean sendSource(Source source, Receiver receiver, PipelineConfiguration pipe) throws XPathException { 93 return false; } 95 96 100 101 public NodeInfo unravel(Source source, Configuration config) { 102 return null; } 104 105 111 112 public Value convertObjectToXPathValue(Object object, Configuration config) throws XPathException { 113 return null; } 115 116 123 124 public Object convertXPathValueToObject(Value value, Class targetClass, XPathContext context) { 125 return null; } 127 128 136 137 public DocumentInfo wrapDocument(Object node, String baseURI, Configuration config) { 138 Document documentNode = getDocumentRoot(node); 139 return new DocumentWrapper(documentNode, baseURI, config); 140 } 141 142 150 151 public NodeInfo wrapNode(DocumentInfo document, Object node) { 152 return ((DocumentWrapper)document).wrap(node); 153 } 154 155 158 159 private Document getDocumentRoot(Object node) { 160 while (!(node instanceof Document)) { 161 if (node instanceof Element) { 162 if (((Element)node).isRootElement()) { 163 return ((Element)node).getDocument(); 164 } else { 165 node = ((Element)node).getParent(); 166 } 167 } else if (node instanceof Text) { 168 node = ((Text)node).getParent(); 169 } else if (node instanceof Comment) { 170 node = ((Comment)node).getParent(); 171 } else if (node instanceof ProcessingInstruction) { 172 node = ((ProcessingInstruction)node).getParent(); 173 } else if (node instanceof Attribute) { 174 node = ((Attribute)node).getParent(); 175 } else if (node instanceof Document) { 176 return (Document)node; 177 } else if (node instanceof Namespace) { 178 throw new UnsupportedOperationException ("Cannot find parent of JDOM namespace node"); 179 } else { 180 throw new IllegalStateException ("Unknown JDOM node type " + node.getClass()); 181 } 182 } 183 return (Document)node; 184 } 185 186 193 194 public Object convertToNodeList(SequenceExtent extent) { 195 return null; 196 } 197 } 198 199 200 | Popular Tags |