001: /*
002: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: * [See end of file]
004: */
005:
006: package com.hp.hpl.jena.rdf.arp;
007:
008: /**
009: * The interface to set the various options on ARP.
010: * User defined
011: * implementations of this interface are not supported. This is a class rather
012: * than an interface to have better backward compatibilitiy with earlier
013: * versions, however constructing instances of this class is deprecated.
014: * In addition, accessing the fields of {@link ARPErrorNumbers} through this
015: * class is not supported. The inheritance of this interface will be removed.
016: *
017: * @author Jeremy J. Carroll
018: *
019: */
020: public class ARPOptions implements ARPErrorNumbers {
021:
022: /**
023: * Do not use this constructor.
024: * An example of not using this constructor is as follows.
025: * <br/>
026: * Deprecated usage:
027: * <br/>
028: * <pre>
029: ARP arp = new ARP();
030: ARPOptions options = new ARPOptions();
031: </pre>
032: <br/>
033: * Preferred code:
034: * <br/>
035: * <pre>
036: ARP arp = new ARP();
037: ARPOptions options = arp.getOptions();
038: </pre>
039: *@deprecated Use {@link ARPConfig#getOptions()}
040: */
041: public ARPOptions() {
042:
043: }
044:
045: private static int defaultErrorMode[] = new int[400];
046: static {
047: for (int i = 0; i < defaultErrorMode.length; i++)
048: defaultErrorMode[i] = i / 100;
049:
050: }
051: private boolean embedding = false;
052: private int errorMode[] = (int[]) defaultErrorMode.clone();
053:
054: /** Sets or gets the error handling mode for a specific error condition.
055: * Changes that cannot be honoured are silently ignored.
056: * Illegal error numbers may result in an ArrayIndexOutOfBoundsException but
057: * are usually ignored.
058: * Most conditions are associated with one or more specific resources or literals
059: * formed during the parse.
060: * Triples involving resource or literal associated with an error condition
061: * are not produced.
062: * The precise definition of 'associated with' is deliberately
063: * undefined, and may change in future releases.
064: * This method can be used to downgrade an error condition to
065: * a warning, or to upgrade a warning to an error.
066: * Such a change modifies which triples are produced.
067: * <p>
068: *
069: * When the condition is a violation of the RDF/XML Syntax (Revised) Recommendations,
070: * and the error mode is {@link ARPErrorNumbers#EM_IGNORE} or {@link ARPErrorNumbers#EM_WARNING},
071: * the precise rules which ARP uses to generate triples for such ill-formed input are
072: * not defined by any standard and are subject to change with future releases.
073: * For input involving no errors, ARP creates triples in accordance with
074: * the RDF/XML Syntax Revised Recommendation.
075: * <p>
076: *
077: * The mode can have one of the following four values.
078: *
079: * <dl>
080: * <dt>{@link ARPErrorNumbers#EM_IGNORE}</dt>
081: * <dd>Ignore this condition. Produce triples.</dd>
082: * <dt>{@link ARPErrorNumbers#EM_WARNING}</dt>
083: * <dd>Invoke ErrorHandler.warning() for this condition. Produce triples.</dd>
084: * <dt>{@link ARPErrorNumbers#EM_ERROR}</dt>
085: * <dd>Invoke ErrorHandler.error() for this condition. Do not produce triples.</dd>
086: * <dt>{@link ARPErrorNumbers#EM_FATAL}</dt>
087: * <dd>Aborts parse and invokes ErrorHandler.fatalError() for this condition.
088: * Do not produce triples.
089: * In unusual situations, a few further warnings and errors may be reported.
090: * </dd>
091: * </dl>
092: *
093: *
094: * @param errno The specific error condition to change.
095: * @param mode The new mode for this condition.
096: * @return The old error mode for this condition.
097: */
098: public int setErrorMode(int errno, int mode) {
099: int old = errorMode[errno];
100: errorMode[errno] = mode;
101: return old;
102: }
103:
104: /** Resets error mode to the default values:
105: * many errors are reported as warnings, and resulting triples are produced.
106: */
107: public void setDefaultErrorMode() {
108: errorMode = (int[]) defaultErrorMode.clone();
109: }
110:
111: /** As many errors as possible are ignored.
112: * As many triples as possible are produced.
113: */
114: public void setLaxErrorMode() {
115: setDefaultErrorMode();
116: for (int i = 100; i < 200; i++)
117: setErrorMode(i, EM_IGNORE);
118: }
119:
120: /** This sets strict conformance to the W3C Recommendations.
121: */
122: public void setStrictErrorMode() {
123: setStrictErrorMode(EM_IGNORE);
124: }
125:
126: /**
127: * This method detects and prohibits errors according to
128: *the W3C Recommendations.
129: * For other conditions, such as
130: {@link ARPErrorNumbers#WARN_PROCESSING_INSTRUCTION_IN_RDF}, nonErrorMode is used.
131: *@param nonErrorMode The way of treating non-error conditions.
132: */
133: public void setStrictErrorMode(int nonErrorMode) {
134: setDefaultErrorMode();
135: for (int i = 1; i < 100; i++)
136: setErrorMode(i, nonErrorMode);
137: int warning = EM_WARNING;
138: int error = EM_ERROR;
139: switch (nonErrorMode) {
140: case EM_ERROR:
141: warning = EM_ERROR;
142: break;
143: case EM_FATAL:
144: warning = error = EM_FATAL;
145: break;
146: }
147: for (int i = 100; i < 200; i++)
148: setErrorMode(i, error);
149: // setErrorMode(IGN_XMLBASE_USED,warning);
150: // setErrorMode(IGN_XMLBASE_SIGNIFICANT,error);
151: setErrorMode(WARN_DEPRECATED_XMLLANG, warning);
152: setErrorMode(WARN_STRING_NOT_NORMAL_FORM_C, warning);
153: // setErrorMode(WARN_EMPTY_ABOUT_EACH,nonErrorMode);
154: setErrorMode(WARN_UNKNOWN_PARSETYPE, warning);
155: // setErrorMode(WARN_BAD_XML, nonErrorMode);
156: setErrorMode(WARN_PROCESSING_INSTRUCTION_IN_RDF, nonErrorMode);
157: // setErrorMode(WARN_LEGAL_REUSE_OF_ID, nonErrorMode);
158: setErrorMode(WARN_RDF_NN_AS_TYPE, nonErrorMode);
159: setErrorMode(WARN_UNKNOWN_RDF_ELEMENT, warning);
160: setErrorMode(WARN_UNKNOWN_RDF_ATTRIBUTE, warning);
161: setErrorMode(WARN_UNQUALIFIED_RDF_ATTRIBUTE, warning);
162: setErrorMode(WARN_UNKNOWN_XML_ATTRIBUTE, nonErrorMode);
163: setErrorMode(WARN_NOT_RDF_NAMESPACE, nonErrorMode);
164: // setErrorMode(WARN_QNAME_AS_ID, error);
165: // setErrorMode(WARN_BAD_XML, error);
166: setErrorMode(WARN_SAX_WARNING, warning);
167: setErrorMode(IGN_DAML_COLLECTION, error);
168: }
169:
170: /**
171: * Copies this object.
172: * @return A copy.
173: * @deprecated Not intended for public use, will be removed from API
174: */
175: public ARPOptions copy() {
176: ARPOptions rslt = new ARPOptions();
177: rslt.errorMode = (int[]) errorMode.clone();
178: rslt.embedding = embedding;
179: return rslt;
180: }
181:
182: /** Sets whether the XML document is only RDF, or contains RDF embedded in other XML.
183: * The default is non-embedded mode.
184: * Embedded mode also matches RDF documents that use the
185: * rdf:RDF tag at the top-level.
186: * Non-embeded mode matches RDF documents which omit that optional tag, and consist of a single rdf:Description or
187: * typed node.
188: * To find embedded RDF it is necessary to setEmbedding(true).
189: * @param embed true: Look for embedded RDF; or false: match a typed node or rdf:Description against the whole document (the default).
190: * @return Previous setting.
191: */
192:
193: public boolean setEmbedding(boolean embed) {
194: boolean old = embedding;
195: embedding = embed;
196: return old;
197: }
198:
199: /**
200: * Returns the error mode for the given error code.
201: * @param eCode
202: * @return One of {@link ARPErrorNumbers#EM_IGNORE},
203: * {@link ARPErrorNumbers#EM_WARNING},
204: * {@link ARPErrorNumbers#EM_ERROR},
205: * {@link ARPErrorNumbers#EM_FATAL}
206: */
207: public int getErrorMode(int eCode) {
208: return errorMode[eCode];
209: }
210:
211: /**
212: * True if the embedding flag is set.
213: * Indicates that the parser should look for rdf:RDF
214: * element, rather than treat the whole file as an RDF/XML
215: * document (possibly without rdf:RDF element).
216: */
217: public boolean getEmbedding() {
218: return embedding;
219: }
220:
221: }
222:
223: /*
224: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
225: * All rights reserved.
226: *
227: * Redistribution and use in source and binary forms, with or without
228: * modification, are permitted provided that the following conditions
229: * are met:
230: * 1. Redistributions of source code must retain the above copyright
231: * notice, this list of conditions and the following disclaimer.
232: * 2. Redistributions in binary form must reproduce the above copyright
233: * notice, this list of conditions and the following disclaimer in the
234: * documentation and/or other materials provided with the distribution.
235: * 3. The name of the author may not be used to endorse or promote products
236: * derived from this software without specific prior written permission.
237: *
238: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
239: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
240: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
241: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
242: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
243: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
244: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
245: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
246: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
247: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
248: */
|