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 org.apache.log4j.Logger;
019import org.kuali.rice.ken.bo.NotificationContentTypeBo;
020import org.kuali.rice.ken.service.NotificationContentTypeService;
021
022/**
023 * Utility base class for Entity and LSResource Resolvers that should resolve
024 * arguments to XSDs defined for NotificationContentTypes
025 * @author Kuali Rice Team (rice.collab@kuali.org)
026 */
027public class ContentTypeResourceResolver {
028    protected static final String CONTENT_TYPE_PREFIX = "resource:notification/ContentType";
029
030    protected final Logger LOG = Logger.getLogger(getClass());
031    
032    private NotificationContentTypeService notificationContentTypeService;
033
034    /**
035     * Constructs a ContentTypeResourceResolver.java.
036     * @param notificationContentTypeService
037     */
038    public ContentTypeResourceResolver(NotificationContentTypeService notificationContentTypeService) {
039        this.notificationContentTypeService = notificationContentTypeService;
040    }
041
042    /**
043     * This method resolves the NotificationContentType by id.
044     * @param id
045     * @return
046     */
047    public NotificationContentTypeBo resolveContentType(String id) {
048        if (!id.startsWith(CONTENT_TYPE_PREFIX)) return null;
049        String contentType = id.substring(CONTENT_TYPE_PREFIX.length());
050        NotificationContentTypeBo notificationContentType = notificationContentTypeService.getNotificationContentType(contentType);
051        if (contentType == null) {
052            LOG.warn("Content type '" + contentType + "' not found in notification database");
053            return null;
054        }
055
056        LOG.info("Resolved '" + id + "' to notification content type: " + notificationContentType);
057        return notificationContentType;
058    }
059}