Coverage Report - org.kuali.rice.ken.util.ContentTypeLSResourceResolver
 
Classes in this File Line Coverage Branch Coverage Complexity
ContentTypeLSResourceResolver
0%
0/21
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.Reader;
 19  
 import java.io.StringReader;
 20  
 
 21  
 import javax.xml.XMLConstants;
 22  
 import javax.xml.parsers.DocumentBuilder;
 23  
 import javax.xml.parsers.DocumentBuilderFactory;
 24  
 
 25  
 import org.kuali.rice.ken.bo.NotificationContentType;
 26  
 import org.kuali.rice.ken.service.NotificationContentTypeService;
 27  
 import org.w3c.dom.DOMImplementation;
 28  
 import org.w3c.dom.ls.DOMImplementationLS;
 29  
 import org.w3c.dom.ls.LSInput;
 30  
 import org.w3c.dom.ls.LSResourceResolver;
 31  
 
 32  
 /**
 33  
  * Resource resolver for SchemaFactory.  For now used during validation of NotificationRequest content element.
 34  
  * Looks up XSD in NotificationContentType record.
 35  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 36  
  */
 37  
 public class ContentTypeLSResourceResolver extends ContentTypeResourceResolver implements LSResourceResolver {
 38  
     /**
 39  
      * Constructs a ContentTypeLSResourceResolver.java.
 40  
      * @param notificationContentTypeService
 41  
      */
 42  
     public ContentTypeLSResourceResolver(NotificationContentTypeService notificationContentTypeService) {
 43  0
         super(notificationContentTypeService);
 44  0
     }
 45  
 
 46  
     /**
 47  
      * @see org.w3c.dom.ls.LSResourceResolver#resolveResource(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 48  
      */
 49  
     public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
 50  0
         if (!type.equals(XMLConstants.W3C_XML_SCHEMA_NS_URI)) {
 51  0
             return null;
 52  
         }
 53  
 
 54  0
         if (!systemId.startsWith(CONTENT_TYPE_PREFIX)) {
 55  0
             LOG.warn("Cannot resolve non-ContentType resources");
 56  0
             return null;
 57  
         }
 58  
 
 59  0
         NotificationContentType notificationContentType = resolveContentType(systemId);
 60  0
         if (notificationContentType == null) {
 61  0
             LOG.error("Unable to resolve system id '" + systemId + "' locally...delegating to default resolution strategy.");
 62  0
             return null;
 63  
         }
 64  
 
 65  0
         Reader reader = new StringReader(notificationContentType.getXsd());
 66  
         try {
 67  0
             DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
 68  0
             DocumentBuilder builder = factory.newDocumentBuilder();
 69  0
             DOMImplementation domImpl = builder.getDOMImplementation();
 70  0
             DOMImplementationLS dils = (DOMImplementationLS) domImpl;
 71  0
             LSInput input = dils.createLSInput();
 72  0
             input.setCharacterStream(reader);
 73  0
             return input;
 74  0
         } catch (Exception e) {
 75  0
             throw new RuntimeException(e);
 76  
         }
 77  
     }
 78  
 }