Home » apache-openwebbeans-1.0.0-incubating-M3-sources » org.apache.webbeans.xml » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements. See the NOTICE file distributed with this
    4    * work for additional information regarding copyright ownership. The ASF
    5    * licenses this file to You under the Apache License, Version 2.0 (the
    6    * "License"); you may not use this file except in compliance with the License.
    7    * You may obtain a copy of the License at
    8    * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
    9    * or agreed to in writing, software distributed under the License is
   10    * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   11    * KIND, either express or implied. See the License for the specific language
   12    * governing permissions and limitations under the License.
   13    */
   14   package org.apache.webbeans.xml;
   15   
   16   import java.io.IOException;
   17   import java.io.InputStream;
   18   
   19   import org.apache.webbeans.WebBeansConstants;
   20   import org.apache.webbeans.logger.WebBeansLogger;
   21   import org.apache.webbeans.util.WebBeansUtil;
   22   import org.xml.sax.EntityResolver;
   23   import org.xml.sax.InputSource;
   24   import org.xml.sax.SAXException;
   25   
   26   /**
   27    * Resolver for the web beans systemId's.
   28    */
   29   public class WebBeansResolver implements EntityResolver
   30   {
   31       /** Logger instance */
   32       private static WebBeansLogger logger = WebBeansLogger.getLogger(WebBeansResolver.class);
   33   
   34       /**
   35        * Resolve entity.
   36        */
   37       public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException
   38       {
   39           logger.debug("Resolving systemId with : " + systemId);
   40   
   41           if (systemId.equals(WebBeansConstants.WEB_BEANS_XML_SYSID))
   42           {
   43               InputStream stream = getClass().getClassLoader().getResourceAsStream("org/apache/webbeans/web-beans-1.0.xsd");
   44   
   45               if (stream != null)
   46               {
   47                   logger.debug("Resolving is success with systemId : " + systemId);
   48                   return createInputSource(stream, publicId, systemId);
   49               }
   50           }
   51   
   52           else if (systemId.startsWith(WebBeansConstants.CLASSPATH_URI_SCHEMA))
   53           {
   54               String path = systemId.replaceFirst("classpath:", "");
   55               InputStream stream = WebBeansUtil.getCurrentClassLoader().getResourceAsStream(path);
   56   
   57               if (stream != null)
   58               {
   59                   logger.debug("Resolving is success with systemId : " + systemId);
   60                   return createInputSource(stream, publicId, systemId);
   61               }
   62           }
   63   
   64           logger.debug("Resolving is failed with systemId : " + systemId + ", using default SAXResolver");
   65           return null;
   66       }
   67   
   68       /**
   69        * Creates the new input source.
   70        */
   71       private InputSource createInputSource(InputStream stream, String publicId, String systemId)
   72       {
   73           InputSource source = new InputSource();
   74           source.setPublicId(publicId);
   75           source.setSystemId(systemId);
   76           source.setByteStream(stream);
   77   
   78           return source;
   79   
   80       }
   81   
   82   }

Home » apache-openwebbeans-1.0.0-incubating-M3-sources » org.apache.webbeans.xml » [javadoc | source]