001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.ken.util; 017 018import java.io.IOException; 019import java.io.StringReader; 020 021import org.kuali.rice.ken.bo.NotificationContentTypeBo; 022import org.kuali.rice.ken.service.NotificationContentTypeService; 023import org.xml.sax.EntityResolver; 024import org.xml.sax.InputSource; 025import org.xml.sax.SAXException; 026 027/** 028 * Entity resolver that resolves content type XSD resources to XSDs define in 029 * the respective content type's NotificationContentType record 030 * @author Kuali Rice Team (rice.collab@kuali.org) 031 */ 032public class ContentTypeEntityResolver extends ContentTypeResourceResolver implements EntityResolver { 033 /** 034 * Constructs a ContentTypeEntityResolver.java. 035 * @param notificationContentTypeService 036 */ 037 public ContentTypeEntityResolver(NotificationContentTypeService notificationContentTypeService) { 038 super(notificationContentTypeService); 039 } 040 041 /** 042 * @see org.xml.sax.EntityResolver#resolveEntity(java.lang.String, java.lang.String) 043 */ 044 public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { 045 LOG.debug("Resolving '" + publicId + "' / '" + systemId + "'"); 046 if (!systemId.startsWith(CONTENT_TYPE_PREFIX)) { 047 LOG.warn("Cannot resolve non-ContentType resources"); 048 return null; 049 } 050 NotificationContentTypeBo notificationContentType = resolveContentType(systemId); 051 if (notificationContentType == null) { 052 LOG.error("Unable to resolve system id '" + systemId + "' locally...delegating to default resolution strategy."); 053 return null; 054 } 055 LOG.debug("Resolved '" + systemId + "' to " + notificationContentType.getXsd()); 056 return new InputSource(new StringReader(notificationContentType.getXsd())); 057 } 058 059 /** 060 * @see java.lang.Object#toString() 061 */ 062 public String toString() { 063 return "[ContentTypeEntityResolver]"; 064 } 065}