001/* 002 * Copyright 2010 Anyware Services 003 * 004 * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0 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.ametys.web.content; 017 018import java.io.IOException; 019 020import org.apache.cocoon.environment.Request; 021import org.apache.excalibur.source.Source; 022 023import org.ametys.cms.repository.Content; 024 025/** 026 * This action export the current site and skin name. 027 */ 028public class GetWrapperContextAction extends org.ametys.cms.content.GetWrapperContextAction 029{ 030 @Override 031 protected String getWrapperURI(Request request, String uri) throws IOException 032 { 033 String wrapperURI = null; 034 035 Content content = (Content) request.getAttribute(Content.class.getName()); 036 String cTypeId = _contentTypesHelper.getContentTypeIdForRendering(content); 037 038 // Ex : skin://stylesheets/content/_wrapper/content-[cType].xsl 039 int index = uri.indexOf(".xsl"); 040 wrapperURI = "skin://" + uri.substring(0, index) + "-" + cTypeId + ".xsl"; 041 Source src = _srcResolver.resolveURI(wrapperURI); 042 if (!src.exists()) 043 { 044 if (getLogger().isDebugEnabled()) 045 { 046 getLogger().debug("Failed to find a file in the skin for '" + wrapperURI + "'. Rollink back to skin protocol."); 047 } 048 049 // Ex : skin://stylesheets/content/_wrapper/content.xsl 050 wrapperURI = "skin://" + uri; 051 src = _srcResolver.resolveURI(wrapperURI); 052 if (!src.exists()) 053 { 054 if (getLogger().isDebugEnabled()) 055 { 056 getLogger().debug("Failed to find a file in the skin for '" + wrapperURI + "'. Rollink back to context protocol."); 057 } 058 059 wrapperURI = super.getWrapperURI(request, uri); 060 } 061 } 062 063 return wrapperURI; 064 } 065} 066