1:
37:
38: package ;
39:
40: import ;
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51:
52:
58: public class DomDocumentBuilderFactory
59: extends DocumentBuilderFactory
60: {
61:
62: final DOMImplementation impl;
63: final DOMImplementationLS ls;
64: private boolean secureProcessing;
65:
66: public DomDocumentBuilderFactory()
67: {
68: try
69: {
70: DOMImplementationRegistry reg =
71: DOMImplementationRegistry.newInstance();
72: impl = reg.getDOMImplementation("LS 3.0");
73: if (impl == null)
74: {
75: throw new FactoryConfigurationError("no LS implementations found");
76: }
77: ls = (DOMImplementationLS) impl;
78: }
79: catch (Exception e)
80: {
81: throw new FactoryConfigurationError(e);
82: }
83: }
84:
85: public DocumentBuilder newDocumentBuilder()
86: throws ParserConfigurationException
87: {
88: LSParser parser = null;
89: try
90: {
91: parser = ls.createLSParser(DOMImplementationLS.MODE_ASYNCHRONOUS,
92: "http://www.w3.org/TR/REC-xml");
93: }
94: catch (DOMException e)
95: {
96: if (e.code == DOMException.NOT_SUPPORTED_ERR)
97: {
98:
99: try
100: {
101: parser = ls.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS,
102: "http://www.w3.org/TR/REC-xml");
103: }
104: catch (DOMException e2)
105: {
106: ParserConfigurationException pce =
107: new ParserConfigurationException();
108: pce.initCause(e2);
109: throw pce;
110: }
111: }
112: else
113: {
114: ParserConfigurationException pce =
115: new ParserConfigurationException();
116: pce.initCause(e);
117: throw pce;
118: }
119: }
120: DOMConfiguration config = parser.getDomConfig();
121: setParameter(config, "namespaces",
122: isNamespaceAware() ? Boolean.TRUE : Boolean.FALSE);
123: setParameter(config, "element-content-whitespace",
124: isIgnoringElementContentWhitespace() ? Boolean.FALSE :
125: Boolean.TRUE);
126: setParameter(config, "comments",
127: isIgnoringComments() ? Boolean.FALSE : Boolean.TRUE);
128: setParameter(config, "expand-entity-references",
129: isExpandEntityReferences() ? Boolean.TRUE : Boolean.FALSE);
130: setParameter(config, "coalescing",
131: isCoalescing() ? Boolean.TRUE : Boolean.FALSE);
132: setParameter(config, "validating",
133: isValidating() ? Boolean.TRUE : Boolean.FALSE);
134: setParameter(config, "xinclude-aware",
135: isXIncludeAware() ? Boolean.TRUE : Boolean.FALSE);
136: return new DomDocumentBuilder(impl, ls, parser);
137: }
138:
139: void setParameter(DOMConfiguration config, String name, Object value)
140: throws ParserConfigurationException
141: {
142: if (!config.canSetParameter(name, value))
143: {
144: throw new ParserConfigurationException(name);
145: }
146: config.setParameter(name, value);
147: }
148:
149: public Object getAttribute(String name)
150: {
151:
152: return null;
153: }
154:
155: public void setAttribute(String name, Object value)
156: {
157:
158: }
159:
160: public void setFeature(String name, boolean value)
161: throws ParserConfigurationException
162: {
163: if (name == null)
164: throw new NullPointerException();
165: if (XMLConstants.FEATURE_SECURE_PROCESSING.equals(name))
166: {
167: secureProcessing = true;
168: return;
169: }
170: throw new ParserConfigurationException(name);
171: }
172:
173: public boolean getFeature(String name)
174: throws ParserConfigurationException
175: {
176: if (XMLConstants.FEATURE_SECURE_PROCESSING.equals(name))
177: return secureProcessing;
178: throw new ParserConfigurationException(name);
179: }
180:
181: }