View Javadoc

1   /*
2    * Copyright 2001-2005 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package net.sf.nxqd.xmldb;
17  
18  import java.util.List;
19  import java.util.ArrayList;
20  import java.util.logging.Level;
21  import java.util.logging.Logger;
22  import org.w3c.dom.Node;
23  import org.xml.sax.SAXNotRecognizedException;
24  
25  import net.sf.nxqd.NxqdException;
26  import net.sf.nxqd.common.NxqdUtils;
27  
28  import org.xmldb.api.base.Collection;
29  import org.xmldb.api.base.Database;
30  import org.xmldb.api.base.XMLDBException;
31  import org.xmldb.api.base.ErrorCodes;
32  import org.xmldb.api.base.Resource;
33  import org.xmldb.api.modules.XMLResource;
34  
35  import org.xml.sax.ContentHandler;
36  
37  /**
38   * @see org.xmldb.api.modules.XMLResource
39   *
40   * @author <a href="mailto:"></a>
41   * @version 1.0
42   */
43  public class NxqdXMLResource extends NxqdResource implements XMLResource {
44  
45      /**
46       * The a new <code>NxqdXMLResource</code> constructor creates a new instance
47       * of NxqdXMLResource.
48       *
49       */
50      public NxqdXMLResource(Collection parent, String id, String type)
51  	throws NxqdException, XMLDBException {
52  	super(parent, id, type);
53      }
54  
55      /**
56       * @see org.xmldb.api.modules.XMLResource#getDocumentId()
57       */
58      public String getDocumentId() throws XMLDBException {
59   	return getId();
60      }
61  
62      /**
63       * @see org.xmldb.api.modules.XMLResource#getSAXFeature(java.lang.String)
64       */
65      public boolean getSAXFeature(java.lang.String feature)
66  	throws org.xml.sax.SAXNotRecognizedException,
67  	       org.xml.sax.SAXNotSupportedException {
68  	return false;
69      }
70      
71      /**
72       * @see org.xmldb.api.modules.XMLResource#setSAXFeature(java.lang.String, boolean)
73       */
74      public void setSAXFeature(java.lang.String feature,
75  			      boolean value)
76  	throws org.xml.sax.SAXNotRecognizedException,
77  	       org.xml.sax.SAXNotSupportedException{
78  	throw new SAXNotRecognizedException("SAX is not yet supported");
79      }
80  
81      /**
82       * @see org.xmldb.api.modules.XMLResource#setContentAsSAX()
83       */
84      public ContentHandler setContentAsSAX() throws XMLDBException {
85  	throw new XMLDBException(ErrorCodes.VENDOR_ERROR,
86  				 "SAX is not yet supported");
87      }
88  
89      /**
90       * @see org.xmldb.api.modules.XMLResource#getContentAsSAX(org.xml.sax.ContentHandler)
91       */
92      public void getContentAsSAX(ContentHandler handler) throws XMLDBException {
93  	throw new XMLDBException(ErrorCodes.VENDOR_ERROR,
94  				 "SAX is not yet supported");
95      }
96  
97      /**
98       * @see org.xmldb.api.modules.XMLResource#setContentAsDOM(org.w3c.dom.Node)
99       */
100     public void setContentAsDOM(Node root) throws XMLDBException {
101 	try {
102 	    setContent(NxqdUtils.docToString(root));
103 	} 
104 	catch (NxqdException ne) {
105 	    throw new XMLDBException(ErrorCodes.VENDOR_ERROR,
106 				     "Error setting DOM content :" + ne.getMessage(),
107 				     ne);
108 	}
109     }
110 
111     /**
112      * @see org.xmldb.api.modules.XMLResource#getContentAsDOM()
113      */
114     public Node getContentAsDOM() throws XMLDBException {
115 	try {
116 	    return NxqdUtils.docFromString(getContent().toString());
117 	} 
118 	catch (NxqdException ne) {
119 	    throw new XMLDBException(ErrorCodes.VENDOR_ERROR,
120 				     "Error getting DOM content :" + ne.getMessage(),
121 				     ne);
122 	}
123     }
124 
125     public String asString() throws XMLDBException {
126 	try {
127 	    return ((net.sf.nxqd.NxqdXMLValue)getContent()).asString();
128 	    
129 	} 
130 	catch (NxqdException ne) {
131 	    throw new XMLDBException(ErrorCodes.VENDOR_ERROR,
132 				     "Error converting resource to string:" + ne.getMessage(),
133 				     ne);
134 	}
135     }
136 }
137