001/* 002 * Copyright 2012 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.core.cocoon; 017 018import java.io.IOException; 019import java.net.MalformedURLException; 020import java.util.Map; 021 022import org.apache.avalon.framework.parameters.Parameters; 023import org.apache.avalon.framework.service.ServiceException; 024import org.apache.cocoon.ProcessingException; 025import org.apache.cocoon.environment.Source; 026import org.apache.cocoon.environment.SourceResolver; 027import org.apache.cocoon.generation.FileGenerator; 028import org.xml.sax.SAXException; 029 030/** 031 * File generator but where the source resolver is the runtime one. 032 */ 033@SuppressWarnings("deprecation") 034public class RuntimeFileGenerator extends FileGenerator 035{ 036 @Override 037 public void setup(SourceResolver initialResolver, Map cocoonObjectModel, String src, Parameters par) throws ProcessingException, SAXException, IOException 038 { 039 org.apache.excalibur.source.SourceResolver runtimeResolver; 040 try 041 { 042 runtimeResolver = (org.apache.excalibur.source.SourceResolver) manager.lookup(org.apache.excalibur.source.SourceResolver.ROLE); 043 } 044 catch (ServiceException e) 045 { 046 String errorMessage = "The runtime resource reader cannot be setup : the runtime source resolver cannot be retrived"; 047 getLogger().error(errorMessage); 048 throw new ProcessingException(errorMessage, e); 049 } 050 051 super.setup(new SourceResolverWrapper(runtimeResolver), cocoonObjectModel, src, par); 052 } 053 054 class SourceResolverWrapper implements org.apache.cocoon.environment.SourceResolver 055 { 056 org.apache.excalibur.source.SourceResolver _res; 057 058 /** 059 * Create a wrapper 060 * @param res The resolver to wrap 061 */ 062 public SourceResolverWrapper(org.apache.excalibur.source.SourceResolver res) 063 { 064 _res = res; 065 } 066 067 public Source resolve(String systemID) throws ProcessingException, SAXException, IOException 068 { 069 throw new ProcessingException("resolve not handled"); 070 } 071 072 public void release(org.apache.excalibur.source.Source eSource) 073 { 074 _res.release(eSource); 075 } 076 077 public org.apache.excalibur.source.Source resolveURI(String location) throws MalformedURLException, IOException 078 { 079 return _res.resolveURI(location); 080 } 081 082 public org.apache.excalibur.source.Source resolveURI(String location, String base, Map sParameters) throws MalformedURLException, IOException 083 { 084 return _res.resolveURI(location, base, sParameters); 085 } 086 } 087}