001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.xerces.impl.validation;
019:
020: /**
021: * <p>An extension of ValidationState which can be configured to turn
022: * off checking for ID/IDREF errors and unparsed entity errors.</p>
023: *
024: * @xerces.internal
025: *
026: * @author Peter McCracken, IBM
027: * @version $Id: ConfigurableValidationState.java 449320 2006-09-23 22:37:56Z mrglavas $
028: */
029: public final class ConfigurableValidationState extends ValidationState {
030:
031: /**
032: * Whether to check for ID/IDREF errors
033: */
034: private boolean fIdIdrefChecking;
035:
036: /**
037: * Whether to check for unparsed entity errors
038: */
039: private boolean fUnparsedEntityChecking;
040:
041: /**
042: * Creates a new ConfigurableValidationState.
043: * By default, error checking for both ID/IDREFs
044: * and unparsed entities are turned on.
045: */
046: public ConfigurableValidationState() {
047: super ();
048: fIdIdrefChecking = true;
049: fUnparsedEntityChecking = true;
050: }
051:
052: /**
053: * Turns checking for ID/IDREF errors on and off.
054: * @param setting true to turn on error checking,
055: * false to turn off error checking
056: */
057: public void setIdIdrefChecking(boolean setting) {
058: fIdIdrefChecking = setting;
059: }
060:
061: /**
062: * Turns checking for unparsed entity errors on and off.
063: * @param setting true to turn on error checking,
064: * false to turn off error checking
065: */
066: public void setUnparsedEntityChecking(boolean setting) {
067: fUnparsedEntityChecking = setting;
068: }
069:
070: /**
071: * Checks if all IDREFs have a corresponding ID.
072: * @return null, if ID/IDREF checking is turned off
073: * otherwise, returns the value of the super implementation
074: */
075: public String checkIDRefID() {
076: return (fIdIdrefChecking) ? super .checkIDRefID() : null;
077: }
078:
079: /**
080: * Checks if an ID has already been declared.
081: * @return false, if ID/IDREF checking is turned off
082: * otherwise, returns the value of the super implementation
083: */
084: public boolean isIdDeclared(String name) {
085: return (fIdIdrefChecking) ? super .isIdDeclared(name) : false;
086: }
087:
088: /**
089: * Checks if an entity is declared.
090: * @return true, if unparsed entity checking is turned off
091: * otherwise, returns the value of the super implementation
092: */
093: public boolean isEntityDeclared(String name) {
094: return (fUnparsedEntityChecking) ? super .isEntityDeclared(name)
095: : true;
096: }
097:
098: /**
099: * Checks if an entity is unparsed.
100: * @return true, if unparsed entity checking is turned off
101: * otherwise, returns the value of the super implementation
102: */
103: public boolean isEntityUnparsed(String name) {
104: return (fUnparsedEntityChecking) ? super .isEntityUnparsed(name)
105: : true;
106: }
107:
108: /**
109: * Adds the ID, if ID/IDREF checking is enabled.
110: * @param name the ID to add
111: */
112: public void addId(String name) {
113: if (fIdIdrefChecking) {
114: super .addId(name);
115: }
116: }
117:
118: /**
119: * Adds the IDREF, if ID/IDREF checking is enabled.
120: * @param name the IDREF to add
121: */
122: public void addIdRef(String name) {
123: if (fIdIdrefChecking) {
124: super.addIdRef(name);
125: }
126: }
127: }
|