001/* 002 * Copyright 2011 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.contenttype; 017 018import org.apache.avalon.framework.logger.AbstractLogEnabled; 019import org.xml.sax.Attributes; 020import org.xml.sax.ContentHandler; 021import org.xml.sax.Locator; 022import org.xml.sax.SAXException; 023import org.xml.sax.ext.LexicalHandler; 024 025import org.ametys.cms.repository.Content; 026import org.ametys.plugins.repository.TraversableAmetysObject; 027 028/** 029 * This class represent a handler from docbook RichText 030 */ 031public class DockbookUpdateHandler extends AbstractLogEnabled implements ContentHandler, LexicalHandler 032{ 033 /** The lexical handler */ 034 protected LexicalHandler _lexicalHandler; 035 /** The content handler where to write */ 036 protected ContentHandler _contentHandler; 037 038 /** The original content */ 039 protected Content _initialContent; 040 /** The created content after copy */ 041 protected Content _createdContent; 042 043 /** The path of the original content */ 044 protected String _initialContentPath; 045 046 /** The initial object which implied the content copy */ 047 protected TraversableAmetysObject _initialObject; 048 /** The created object which implied the content copy */ 049 protected TraversableAmetysObject _createdObject; 050 /** The path of the initial object */ 051 protected String _initialAOPath; 052 053 /** 054 * Set the target content handler 055 * @param contentHandler the target content handler 056 */ 057 public void setContentHandler(ContentHandler contentHandler) 058 { 059 _contentHandler = contentHandler; 060 } 061 062 /** 063 * Set the target lexical handler 064 * @param lexicalHandler the target lexical handler 065 */ 066 public void setLexicalHandler(LexicalHandler lexicalHandler) 067 { 068 _lexicalHandler = lexicalHandler; 069 } 070 071 /** 072 * Set the initial content copied 073 * @param initialContent the initial content 074 */ 075 public void setInitialContent (Content initialContent) 076 { 077 _initialContent = initialContent; 078 _initialContentPath = initialContent.getPath(); 079 } 080 081 /** 082 * Set the created content 083 * @param createdContent the created content after copy 084 */ 085 public void setCreatedContent (Content createdContent) 086 { 087 _createdContent = createdContent; 088 } 089 090 /** 091 * Set the initial object responsible for copy 092 * @param initialObject the initial object responsible for copy 093 */ 094 public void setInitialObject (TraversableAmetysObject initialObject) 095 { 096 _initialObject = initialObject; 097 _initialAOPath = initialObject.getPath(); 098 } 099 100 /** 101 * Set created object after copy 102 * @param createdObject the created object after copy 103 */ 104 public void setCreatedObject (TraversableAmetysObject createdObject) 105 { 106 _createdObject = createdObject; 107 } 108 109 @Override 110 public void startDocument() throws SAXException 111 { 112 _contentHandler.startDocument(); 113 } 114 @Override 115 public void endDocument() throws SAXException 116 { 117 _contentHandler.endDocument(); 118 } 119 120 @Override 121 public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException 122 { 123 _contentHandler.startElement(uri, localName, qName, atts); 124 } 125 @Override 126 public void endElement(String uri, String localName, String qName) throws SAXException 127 { 128 _contentHandler.endElement(uri, localName, qName); 129 } 130 131 @Override 132 public void characters(char[] ch, int start, int length) throws SAXException 133 { 134 _contentHandler.characters(ch, start, length); 135 } 136 @Override 137 public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException 138 { 139 _contentHandler.ignorableWhitespace(ch, start, length); 140 } 141 142 @Override 143 public void processingInstruction(String target, String data) throws SAXException 144 { 145 _contentHandler.processingInstruction(target, data); 146 } 147 @Override 148 public void setDocumentLocator(Locator locator) 149 { 150 _contentHandler.setDocumentLocator(locator); 151 } 152 @Override 153 public void skippedEntity(String name) throws SAXException 154 { 155 _contentHandler.skippedEntity(name); 156 } 157 158 @Override 159 public void startPrefixMapping(String prefix, String uri) throws SAXException 160 { 161 _contentHandler.startPrefixMapping(prefix, uri); 162 } 163 @Override 164 public void endPrefixMapping(String prefix) throws SAXException 165 { 166 _contentHandler.endPrefixMapping(prefix); 167 } 168 169 @Override 170 public void startEntity(String name) throws SAXException 171 { 172 _lexicalHandler.startEntity(name); 173 } 174 @Override 175 public void endEntity(String name) throws SAXException 176 { 177 _lexicalHandler.endEntity(name); 178 } 179 180 @Override 181 public void startCDATA() throws SAXException 182 { 183 _lexicalHandler.startCDATA(); 184 } 185 @Override 186 public void endCDATA() throws SAXException 187 { 188 _lexicalHandler.endCDATA(); 189 } 190 191 @Override 192 public void startDTD(String name, String publicId, String systemId) throws SAXException 193 { 194 _lexicalHandler.startDTD(name, publicId, systemId); 195 } 196 @Override 197 public void endDTD() throws SAXException 198 { 199 _lexicalHandler.endCDATA(); 200 } 201 202 @Override 203 public void comment(char[] ch, int start, int length) throws SAXException 204 { 205 _lexicalHandler.comment(ch, start, length); 206 } 207}