01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.components.validation.impl;
18:
19: import org.apache.cocoon.components.validation.ValidationHandler;
20: import org.apache.excalibur.source.SourceValidity;
21: import org.apache.excalibur.xml.sax.NOPContentHandler;
22: import org.apache.excalibur.xml.sax.NOPLexicalHandler;
23: import org.apache.excalibur.xml.sax.XMLConsumerProxy;
24: import org.xml.sax.ContentHandler;
25: import org.xml.sax.ext.LexicalHandler;
26:
27: /**
28: * <p>The default implementation of the {@link ValidationHandler} interface.</p>
29: *
30: */
31: public class DefaultValidationHandler extends XMLConsumerProxy
32: implements ValidationHandler {
33:
34: /** <p>The {@link SourceValidity} associated with the schema.</p> */
35: private final SourceValidity validity;
36:
37: /**
38: * <p>Create a new {@link DefaultValidationHandler} instance.</p>
39: */
40: public DefaultValidationHandler(SourceValidity validity,
41: ContentHandler handler) {
42: this (validity, handler, null);
43: }
44:
45: /**
46: * <p>Create a new {@link DefaultValidationHandler} instance.</p>
47: */
48: public DefaultValidationHandler(SourceValidity validity,
49: ContentHandler contentHandler, LexicalHandler lexicalHandler) {
50: super (contentHandler == null ? new NOPContentHandler()
51: : contentHandler,
52: lexicalHandler == null ? new NOPLexicalHandler()
53: : lexicalHandler);
54: this .validity = validity;
55: }
56:
57: /**
58: * <p>Return a {@link SourceValidity} instance associated with the original
59: * resources of the schema describing the validation instructions.</p>
60: *
61: * <p>As the handler might be tied to one (or more) resources from where the
62: * original schema was read from, the {@link #getValidity()} method provides a
63: * way to verify whether the validation instruction are still valid or not.</p>
64: */
65: public SourceValidity getValidity() {
66: return this.validity;
67: }
68: }
|