Coverage Report - org.apache.myfaces.config.impl.FacesConfigEntityResolver
 
Classes in this File Line Coverage Branch Coverage Complexity
FacesConfigEntityResolver
0%
0/34
0%
0/14
3.667
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *   http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 18  
  */
 19  
 package org.apache.myfaces.config.impl;
 20  
 
 21  
 import org.apache.myfaces.shared_impl.util.ClassUtils;
 22  
 import org.xml.sax.EntityResolver;
 23  
 import org.xml.sax.InputSource;
 24  
 
 25  
 import org.apache.commons.logging.Log;
 26  
 import org.apache.commons.logging.LogFactory;
 27  
 
 28  
 import javax.faces.context.ExternalContext;
 29  
 import java.io.IOException;
 30  
 import java.io.InputStream;
 31  
 import java.net.JarURLConnection;
 32  
 import java.net.URL;
 33  
 import java.util.jar.JarEntry;
 34  
 
 35  
 /**
 36  
  * DOCUMENT ME!
 37  
  * @author Manfred Geiler (latest modification by $Author: lu4242 $)
 38  
  * @author Thomas Spiegl
 39  
  * @version $Revision: 775310 $ $Date: 2009-05-15 15:20:30 -0500 (Fri, 15 May 2009) $
 40  
  */
 41  
 public class FacesConfigEntityResolver
 42  
     implements EntityResolver
 43  
 {
 44  0
     private static final Log log = LogFactory.getLog(FacesConfigEntityResolver.class);
 45  
 
 46  
     private static final String FACES_CONFIG_1_0_DTD_SYSTEM_ID = "http://java.sun.com/dtd/web-facesconfig_1_0.dtd";
 47  0
     private static final String FACES_CONFIG_1_0_DTD_RESOURCE
 48  
             = "org.apache.myfaces.resource".replace('.', '/') + "/web-facesconfig_1_0.dtd";
 49  
     private static final String FACES_CONFIG_1_1_DTD_SYSTEM_ID = "http://java.sun.com/dtd/web-facesconfig_1_1.dtd";
 50  0
     private static final String FACES_CONFIG_1_1_DTD_RESOURCE
 51  
             = "org.apache.myfaces.resource".replace('.', '/') + "/web-facesconfig_1_1.dtd";
 52  
 
 53  0
     private ExternalContext _externalContext = null;
 54  
 
 55  
     public FacesConfigEntityResolver(ExternalContext context)
 56  0
     {
 57  0
         _externalContext = context;
 58  0
     }
 59  
 
 60  
     public FacesConfigEntityResolver()
 61  0
     {
 62  0
     }
 63  
 
 64  
     public InputSource resolveEntity(String publicId,
 65  
                                      String systemId)
 66  
         throws IOException
 67  
     {
 68  
         InputStream stream;
 69  0
         if (systemId.equals(FACES_CONFIG_1_0_DTD_SYSTEM_ID))
 70  
         {
 71  0
             stream = ClassUtils.getResourceAsStream(FACES_CONFIG_1_0_DTD_RESOURCE);
 72  
         }
 73  0
         else if (systemId.equals(FACES_CONFIG_1_1_DTD_SYSTEM_ID))
 74  
         {
 75  0
             stream = ClassUtils.getResourceAsStream(FACES_CONFIG_1_1_DTD_RESOURCE);
 76  
         }
 77  
 
 78  0
         else if (systemId.startsWith("jar:"))
 79  
         {
 80  0
             URL url = new URL(systemId);
 81  0
             JarURLConnection conn = (JarURLConnection) url.openConnection();
 82  0
             conn.setUseCaches(false);
 83  0
             JarEntry jarEntry = conn.getJarEntry();
 84  0
             if (jarEntry == null)
 85  
             {
 86  0
                 log.fatal("JAR entry '" + systemId + "' not found.");
 87  
             }
 88  
             //_jarFile.getInputStream(jarEntry);
 89  0
             stream = conn.getJarFile().getInputStream(jarEntry);
 90  0
         }
 91  
         else
 92  
         {
 93  0
             if (_externalContext == null)
 94  
             {
 95  0
                 stream = ClassUtils.getResourceAsStream(systemId);
 96  
             }
 97  
             else
 98  
             {
 99  0
                 if (systemId.startsWith("file:")) {
 100  0
                     systemId = systemId.substring(7); // remove file://
 101  
                 }
 102  0
                 stream = _externalContext.getResourceAsStream(systemId);
 103  
             }
 104  
         }
 105  
 
 106  0
         if (stream == null) {
 107  0
             return null;
 108  
         }
 109  0
         InputSource is = new InputSource(stream);
 110  0
         is.setPublicId(publicId);
 111  0
         is.setSystemId(systemId);
 112  0
         is.setEncoding("ISO-8859-1");
 113  0
         return is;
 114  
     }
 115  
 
 116  
 }