View Javadoc

1   /*
2    * Copyright (c) 2009 Kathryn Huxtable
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   * $Id$
17   */
18  package org.kathrynhuxtable.maven.plugins.htmlfiltersite;
19  
20  import java.io.IOException;
21  
22  import org.xml.sax.EntityResolver;
23  import org.xml.sax.InputSource;
24  import org.xml.sax.SAXException;
25  
26  /**
27   * Custom DTDHandler since for some reason w3c throws exceptions.
28   */
29  public class DTDHandler implements EntityResolver {
30  
31      /**
32       * @see org.xml.sax.EntityResolver#resolveEntity(java.lang.String, java.lang.String)
33       */
34      public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
35          if (publicId.equals("-//W3C//DTD XHTML 1.0 Strict//EN")) {
36              return inputSource("/xhtml/dtd/xhtml1-strict.dtd");
37          } else if (publicId.equals("-//W3C//DTD XHTML 1.0 Transitional//EN")) {
38              return inputSource("/xhtml/dtd/xhtml1-transitional.dtd");
39          } else if (publicId.equals("-//W3C//DTD XHTML 1.0 Frameset//EN")) {
40              return inputSource("/xhtml/dtd/xhtml1-frameset.dtd");
41          } else if (publicId.equals("-//W3C//ENTITIES Latin 1 for XHTML//EN")) {
42              return inputSource("/xhtml/dtd/xhtml-lat1.ent");
43          } else if (publicId.equals("-//W3C//ENTITIES Symbols for XHTML//EN")) {
44              return inputSource("/xhtml/dtd/xhtml-symbol.ent");
45          } else if (publicId.equals("-//W3C//ENTITIES Special for XHTML//EN")) {
46              return inputSource("/xhtml/dtd/xhtml-special.ent");
47          } else {
48              return null;
49          }
50      }
51  
52      /**
53       * DOCUMENT ME!
54       *
55       * @param  resource DOCUMENT ME!
56       *
57       * @return DOCUMENT ME!
58       */
59      private InputSource inputSource(String resource) {
60          return new InputSource(DTDHandler.class.getResourceAsStream(resource));
61      }
62  }