View Javadoc

1   package org.apache.archiva.redback.components.modello.jpox;
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 org.xml.sax.EntityResolver;
23  import org.xml.sax.InputSource;
24  import org.xml.sax.SAXException;
25  
26  import java.io.IOException;
27  import java.net.URL;
28  import java.util.HashMap;
29  import java.util.Map;
30  
31  /**
32   * JdoEntityResolver 
33   *
34   * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
35   * @version $Id: JdoEntityResolver.java 1414988 2012-11-28 23:14:35Z olamy $
36   */
37  public class JdoEntityResolver
38      implements EntityResolver
39  {
40      private static final Map PUBLICID_TO_RESOURCE_MAP;
41  
42      static
43      {
44          PUBLICID_TO_RESOURCE_MAP = new HashMap();
45  
46          PUBLICID_TO_RESOURCE_MAP.put( "-//Sun Microsystems, Inc.//DTD Java Data Objects Metadata 1.0//EN",
47                                        "/jdo_1_0.dtd" );
48          PUBLICID_TO_RESOURCE_MAP.put( "-//Sun Microsystems, Inc.//DTD Java Data Objects Metadata 2.0//EN",
49                                        "/jdo_2_0.dtd" );
50      }
51  
52      public InputSource resolveEntity( String publicId, String systemId )
53          throws SAXException, IOException
54      {
55          if ( PUBLICID_TO_RESOURCE_MAP.containsKey( publicId ) )
56          {
57              URL url = this.getClass().getResource( (String) PUBLICID_TO_RESOURCE_MAP.get( publicId ) );
58              return new InputSource( url.openStream() );
59          }
60  
61          return null;
62      }
63  
64  }