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.runtime.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.xml.sax.SAXException; 028 029/** 030 * Use ametys resolver 031 */ 032@SuppressWarnings("deprecation") 033public class TraxTransformer extends org.apache.cocoon.transformation.TraxTransformer 034{ 035 @Override 036 public void setup(SourceResolver resolver, Map cocoonObjectModel, String src, Parameters par) throws SAXException, ProcessingException, IOException 037 { 038 org.apache.excalibur.source.SourceResolver runtimeResolver; 039 try 040 { 041 runtimeResolver = (org.apache.excalibur.source.SourceResolver) manager.lookup(org.apache.excalibur.source.SourceResolver.ROLE); 042 } 043 catch (ServiceException e) 044 { 045 String errorMessage = "The runtime TraxTransformer cannot be setup : the runtime source resolver cannot be retrived"; 046 getLogger().error(errorMessage); 047 throw new ProcessingException(errorMessage, e); 048 } 049 050 super.setup(new SourceResolverWrapper(runtimeResolver), cocoonObjectModel, src, par); 051 } 052 053 class SourceResolverWrapper implements org.apache.cocoon.environment.SourceResolver 054 { 055 org.apache.excalibur.source.SourceResolver _res; 056 057 /** 058 * Create a wrapper 059 * @param res The resolver to wrap 060 */ 061 public SourceResolverWrapper(org.apache.excalibur.source.SourceResolver res) 062 { 063 _res = res; 064 } 065 066 public Source resolve(String systemID) throws ProcessingException, SAXException, IOException 067 { 068 throw new ProcessingException("resolve not handled"); 069 } 070 071 public void release(org.apache.excalibur.source.Source eSource) 072 { 073 _res.release(eSource); 074 } 075 076 public org.apache.excalibur.source.Source resolveURI(String location) throws MalformedURLException, IOException 077 { 078 return _res.resolveURI(location); 079 } 080 081 public org.apache.excalibur.source.Source resolveURI(String location, String base, Map sParameters) throws MalformedURLException, IOException 082 { 083 return _res.resolveURI(location, base, sParameters); 084 } 085 } 086}