001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.ukit.jaxp;
028:
029: import javax.xml.parsers.SAXParser;
030: import javax.xml.parsers.SAXParserFactory;
031: import javax.xml.parsers.ParserConfigurationException;
032:
033: import org.xml.sax.SAXException;
034: import org.xml.sax.SAXNotRecognizedException;
035: import org.xml.sax.SAXNotSupportedException;
036:
037: /**
038: * Implementation of JAXP SAXParserFactory.
039: */
040: public class ParserFactory extends SAXParserFactory {
041: public final static String FEATURE_NS = "http://xml.org/sax/features/namespaces";
042: public final static String FEATURE_PREF = "http://xml.org/sax/features/namespace-prefixes";
043:
044: private boolean namespaces = false;
045: private boolean prefixes = true;
046:
047: /**
048: * Creates a new instance of a SAXParser using the currently
049: * configured factory parameters.
050: *
051: * @return A new instance of a SAXParser.
052: *
053: * @exception ParserConfigurationException if a parser cannot
054: * be created which satisfies the requested configuration.
055: */
056: public SAXParser newSAXParser()
057: throws ParserConfigurationException, SAXException {
058: if ((namespaces == true) && (prefixes == false)) {
059: return new Parser(true);
060: } else if ((namespaces == false) && (prefixes == true)) {
061: return new Parser(false);
062: } else {
063: throw new ParserConfigurationException("");
064: }
065: }
066:
067: /**
068: * Specifies that the parser produced by this code will
069: * provide support for XML namespaces. By default the value of this is set
070: * to <code>false</code>.
071: *
072: * @param awareness true if the parser produced by this code will
073: * provide support for XML namespaces; false otherwise.
074: */
075: public void setNamespaceAware(boolean awareness) {
076: super .setNamespaceAware(awareness);
077: if (awareness == true) {
078: namespaces = true;
079: prefixes = false;
080: } else {
081: namespaces = false;
082: prefixes = true;
083: }
084: }
085:
086: /**
087: * Sets the particular feature in the underlying implementation of
088: * DefaultHandler.
089: * A list of the core features and properties can be found at
090: * <a href="http://www.saxproject.org/?selected=get-set">
091: * http://www.saxproject.org/?selected=get-set </a>
092: *
093: * @param name The name of the feature to be set.
094: * @param value The value of the feature to be set.
095: * @exception SAXNotRecognizedException When the underlying DefaultHandler does
096: * not recognize the property name.
097: *
098: * @exception SAXNotSupportedException When the underlying DefaultHandler
099: * recognizes the property name but doesn't support the
100: * property.
101: */
102: public void setFeature(String name, boolean value)
103: throws ParserConfigurationException,
104: SAXNotRecognizedException, SAXNotSupportedException {
105: if (FEATURE_NS.equals(name) == true) {
106: namespaces = value;
107: } else if (FEATURE_PREF.equals(name) == true) {
108: prefixes = value;
109: } else {
110: throw new SAXNotRecognizedException(name);
111: }
112: }
113:
114: /**
115: * Returns the particular property requested for in the underlying
116: * implementation of DefaultHandler.
117: *
118: * @param name The name of the property to be retrieved.
119: * @return Value of the requested property.
120: *
121: * @exception SAXNotRecognizedException When the underlying DefaultHandler does
122: * not recognize the property name.
123: *
124: * @exception SAXNotSupportedException When the underlying DefaultHandler
125: * recognizes the property name but doesn't support the
126: * property.
127: */
128: public boolean getFeature(String name)
129: throws ParserConfigurationException,
130: SAXNotRecognizedException, SAXNotSupportedException {
131: if (FEATURE_NS.equals(name) == true) {
132: return namespaces;
133: } else if (FEATURE_PREF.equals(name) == true) {
134: return prefixes;
135: } else {
136: throw new SAXNotRecognizedException(name);
137: }
138: }
139: }
|