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.cms.transformation; 017 018import java.io.IOException; 019import java.util.Map; 020 021import org.apache.avalon.excalibur.pool.Recyclable; 022import org.apache.avalon.framework.parameters.Parameters; 023import org.apache.avalon.framework.service.ServiceException; 024import org.apache.avalon.framework.service.ServiceManager; 025import org.apache.avalon.framework.service.Serviceable; 026import org.apache.cocoon.ProcessingException; 027import org.apache.cocoon.environment.SourceResolver; 028import org.apache.cocoon.transformation.Transformer; 029import org.apache.cocoon.xml.XMLConsumer; 030import org.xml.sax.Attributes; 031import org.xml.sax.ContentHandler; 032import org.xml.sax.Locator; 033import org.xml.sax.SAXException; 034import org.xml.sax.ext.LexicalHandler; 035 036/** 037 * This abstract cocoon transformer have its content and lexical handler configurable 038 */ 039public abstract class AbstractEnhancementTransformer implements Transformer, Serviceable, Recyclable 040{ 041 /** The service manager */ 042 protected ServiceManager _manager; 043 /** The content handler */ 044 protected ContentHandler _contentHandler; 045 /** The lexical handler */ 046 protected LexicalHandler _lexicalHandler; 047 048 @Override 049 public void recycle() 050 { 051 _contentHandler = null; 052 _lexicalHandler = null; 053 } 054 055 @Override 056 public abstract void setConsumer(XMLConsumer consumer); 057 058 059 public void service(ServiceManager manager) throws ServiceException 060 { 061 _manager = manager; 062 } 063 064 @Override 065 public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) throws ProcessingException, SAXException, IOException 066 { 067 // empty 068 } 069 070 @Override 071 public void startDocument() throws SAXException 072 { 073 _contentHandler.startDocument(); 074 } 075 @Override 076 public void endDocument() throws SAXException 077 { 078 _contentHandler.endDocument(); 079 } 080 081 @Override 082 public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException 083 { 084 _contentHandler.startElement(uri, localName, qName, atts); 085 } 086 @Override 087 public void endElement(String uri, String localName, String qName) throws SAXException 088 { 089 _contentHandler.endElement(uri, localName, qName); 090 } 091 092 @Override 093 public void characters(char[] ch, int start, int length) throws SAXException 094 { 095 _contentHandler.characters(ch, start, length); 096 } 097 @Override 098 public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException 099 { 100 _contentHandler.ignorableWhitespace(ch, start, length); 101 } 102 103 @Override 104 public void startPrefixMapping(String prefix, String uri) throws SAXException 105 { 106 _contentHandler.startPrefixMapping(prefix, uri); 107 } 108 @Override 109 public void endPrefixMapping(String prefix) throws SAXException 110 { 111 _contentHandler.endPrefixMapping(prefix); 112 } 113 114 @Override 115 public void processingInstruction(String target, String data) throws SAXException 116 { 117 _contentHandler.processingInstruction(target, data); 118 } 119 120 @Override 121 public void setDocumentLocator(Locator locator) 122 { 123 _contentHandler.setDocumentLocator(locator); 124 } 125 126 @Override 127 public void skippedEntity(String name) throws SAXException 128 { 129 _contentHandler.skippedEntity(name); 130 } 131 132 @Override 133 public void comment(char[] ch, int start, int length) throws SAXException 134 { 135 _lexicalHandler.comment(ch, start, length); 136 } 137 138 @Override 139 public void startCDATA() throws SAXException 140 { 141 _lexicalHandler.startCDATA(); 142 } 143 @Override 144 public void endCDATA() throws SAXException 145 { 146 _lexicalHandler.endCDATA(); 147 } 148 149 @Override 150 public void startDTD(String name, String publicId, String systemId) throws SAXException 151 { 152 _lexicalHandler.startDTD(name, publicId, systemId); 153 } 154 @Override 155 public void endDTD() throws SAXException 156 { 157 _lexicalHandler.endDTD(); 158 } 159 160 @Override 161 public void startEntity(String name) throws SAXException 162 { 163 _lexicalHandler.startEntity(name); 164 } 165 @Override 166 public void endEntity(String name) throws SAXException 167 { 168 _lexicalHandler.endEntity(name); 169 } 170}