View Javadoc
1   package org.apache.maven.doxia.siterenderer;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.IOException;
23  
24  import org.xml.sax.EntityResolver;
25  import org.xml.sax.InputSource;
26  import org.xml.sax.SAXException;
27  
28  /**
29   *
30   * @author ltheussl
31   *
32   * @since 1.2
33   */
34  public class XhtmlEntityResolver
35      implements EntityResolver
36  {
37      private static final String XHTML_PUBLIC_ID = "-//W3C//DTD XHTML 1.0 Transitional//EN";
38  
39      private static final String DTD = "/dtd/xhtml1-transitional.dtd";
40  
41      private static final String LAT1_PUBLIC_ID = "-//W3C//ENTITIES Latin 1 for XHTML//EN";
42  
43      private static final String LAT1 = "/dtd/xhtml-lat1.ent";
44  
45      private static final String SYMBOL_PUBLIC_ID = "-//W3C//ENTITIES Symbols for XHTML//EN";
46  
47      private static final String SYMBOL = "/dtd/xhtml-symbol.ent";
48  
49      private static final String SPECIAL_PUBLIC_ID = "-//W3C//ENTITIES Special for XHTML//EN";
50  
51      private static final String SPECIAL = "/dtd/xhtml-special.ent";
52  
53      /** {@inheritDoc} */
54      public InputSource resolveEntity( String publicId, String systemId )
55          throws SAXException, IOException
56      {
57          if ( publicId == null )
58          {
59              return null;
60          }
61  
62          if ( publicId.equals( XHTML_PUBLIC_ID ) )
63          {
64              return new InputSource( XhtmlEntityResolver.class.getResourceAsStream( DTD ) );
65          }
66          else if ( publicId.equals( LAT1_PUBLIC_ID ) )
67          {
68              return new InputSource( XhtmlEntityResolver.class.getResourceAsStream( LAT1 ) );
69          }
70          else if ( publicId.equals( SYMBOL_PUBLIC_ID ) )
71          {
72              return new InputSource( XhtmlEntityResolver.class.getResourceAsStream( SYMBOL ) );
73          }
74          else if ( publicId.equals( SPECIAL_PUBLIC_ID ) )
75          {
76              return new InputSource( XhtmlEntityResolver.class.getResourceAsStream( SPECIAL ) );
77          }
78          else
79          {
80              return null;
81          }
82      }
83  }