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          private static final String DTD = "/dtd/xhtml1-transitional.dtd";
39  
40          private static final String LAT1_PUBLIC_ID = "-//W3C//ENTITIES Latin 1 for XHTML//EN";
41          private static final String LAT1 = "/dtd/xhtml-lat1.ent";
42  
43          private static final String SYMBOL_PUBLIC_ID = "-//W3C//ENTITIES Symbols for XHTML//EN";
44          private static final String SYMBOL = "/dtd/xhtml-symbol.ent";
45  
46          private static final String SPECIAL_PUBLIC_ID = "-//W3C//ENTITIES Special for XHTML//EN";
47          private static final String SPECIAL = "/dtd/xhtml-special.ent";
48  
49  
50          /** {@inheritDoc} */
51          public InputSource resolveEntity( String publicId, String systemId )
52              throws SAXException, IOException
53          {
54              if ( publicId == null )
55              {
56                  return null;
57              }
58  
59              if ( publicId.equals( XHTML_PUBLIC_ID ) )
60              {
61                  return new InputSource( XhtmlEntityResolver.class.getResourceAsStream( DTD ) );
62              }
63              else if ( publicId.equals( LAT1_PUBLIC_ID ) )
64              {
65                  return new InputSource( XhtmlEntityResolver.class.getResourceAsStream( LAT1 ) );
66              }
67              else if ( publicId.equals( SYMBOL_PUBLIC_ID ) )
68              {
69                  return new InputSource( XhtmlEntityResolver.class.getResourceAsStream( SYMBOL ) );
70              }
71              else if ( publicId.equals( SPECIAL_PUBLIC_ID ) )
72              {
73                  return new InputSource( XhtmlEntityResolver.class.getResourceAsStream( SPECIAL ) );
74              }
75              else
76              {
77                  return null;
78              }
79          }
80      }