Coverage Report - org.kuali.rice.ken.util.ClassLoaderLSResourceResolver
 
Classes in this File Line Coverage Branch Coverage Complexity
ClassLoaderLSResourceResolver
0%
0/27
0%
0/6
5.5
 
 1  
 /*
 2  
  * Copyright 2007-2008 The Kuali Foundation
 3  
  * 
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  * 
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  * 
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.ken.util;
 17  
 
 18  
 import java.io.InputStream;
 19  
 
 20  
 import javax.xml.XMLConstants;
 21  
 import javax.xml.parsers.DocumentBuilder;
 22  
 import javax.xml.parsers.DocumentBuilderFactory;
 23  
 
 24  
 import org.w3c.dom.DOMImplementation;
 25  
 import org.w3c.dom.ls.DOMImplementationLS;
 26  
 import org.w3c.dom.ls.LSInput;
 27  
 import org.w3c.dom.ls.LSResourceResolver;
 28  
 
 29  
 /**
 30  
  * Resource resolver for SchemaFactory.  For now used during validation of NotificationRequest content element.
 31  
  * Looks up XSD from classloader.
 32  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 33  
  */
 34  
 public class ClassLoaderLSResourceResolver extends ClassLoaderResourceResolver implements LSResourceResolver {
 35  
     /**
 36  
      * Constructs a ClassLoaderLSResourceResolver.java.
 37  
      * @param base
 38  
      * @param prefix
 39  
      */
 40  
     public ClassLoaderLSResourceResolver(String base, String prefix) {
 41  0
         super(base, prefix);
 42  0
     }
 43  
 
 44  
     /**
 45  
      * @see org.w3c.dom.ls.LSResourceResolver#resolveResource(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 46  
      */
 47  
     public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
 48  0
         if (!type.equals(XMLConstants.W3C_XML_SCHEMA_NS_URI)) {
 49  0
             return null;
 50  
         }
 51  0
         LOG.error(type);
 52  0
         LOG.error(namespaceURI);
 53  0
         LOG.error(publicId);
 54  0
         LOG.error(systemId);
 55  0
         LOG.error(baseURI);
 56  0
         String path = resolveSystemId(systemId);
 57  0
         if (path == null) {
 58  0
             return null;
 59  
         }
 60  0
         LOG.debug("Looking up resource '" + path + "' for system id '" + systemId + "'");
 61  0
         InputStream is = getClass().getClassLoader().getResourceAsStream(path);
 62  0
         if (is == null) {
 63  0
             String message = "Unable to find schema (" + path + ") for: " + systemId;
 64  0
             LOG.error(message);
 65  0
             throw new RuntimeException/*SAXException*/(message);
 66  
         }
 67  
         try {
 68  0
             DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
 69  0
             DocumentBuilder builder = factory.newDocumentBuilder();
 70  0
             DOMImplementation domImpl = builder.getDOMImplementation();
 71  0
             DOMImplementationLS dils = (DOMImplementationLS) domImpl;
 72  0
             LSInput input = dils.createLSInput();
 73  0
             input.setByteStream(is);
 74  0
             return input;
 75  0
         } catch (Exception e) {
 76  0
             throw new RuntimeException(e);
 77  
         }
 78  
     }
 79  
 }