1 16 package org.apache.cocoon.components; 17 18 import org.apache.avalon.framework.component.ComponentManager; 19 import org.apache.cocoon.Processor; 20 import org.apache.cocoon.environment.Environment; 21 import org.apache.cocoon.xml.XMLConsumer; 22 23 import org.apache.commons.collections.ArrayStack; 24 import org.xml.sax.Attributes ; 25 import org.xml.sax.Locator ; 26 import org.xml.sax.SAXException ; 27 28 36 final class EnvironmentStack extends ArrayStack 37 implements Cloneable { 38 39 int offset; 40 41 int getOffset() { 42 return this.offset; 43 } 44 45 void setOffset(int value) { 46 this.offset = value; 47 } 48 49 Item getCurrent() { 50 return (Item)this.get(offset); 51 } 52 53 public Object clone() { 54 EnvironmentStack old = (EnvironmentStack) super.clone(); 55 old.offset = offset; 56 return old; 57 } 58 59 XMLConsumer getEnvironmentAwareConsumerWrapper(XMLConsumer consumer, 60 int oldOffset) { 61 return new EnvironmentChanger(consumer, this, oldOffset, this.offset); 62 } 63 64 static final class Item { 65 public final Environment env; 66 public final Processor processor; 67 public final ComponentManager manager; 68 public final int offset; 69 70 public Item(Environment env, Processor processor, ComponentManager manager, int offset) { 71 this.env = env; 72 this.processor = processor; 73 this.manager = manager; 74 this.offset = offset; 75 } 76 } 77 } 78 79 80 88 final class EnvironmentChanger implements XMLConsumer { 89 90 final XMLConsumer consumer; 91 final EnvironmentStack stack; 92 final int oldOffset; 93 final int newOffset; 94 95 EnvironmentChanger(XMLConsumer consumer, EnvironmentStack es, 96 int oldOffset, int newOffset) { 97 this.consumer = consumer; 98 this.stack = es; 99 this.oldOffset = oldOffset; 100 this.newOffset = newOffset; 101 } 102 103 public void setDocumentLocator(Locator locator) { 104 this.stack.setOffset(this.oldOffset); 105 this.consumer.setDocumentLocator(locator); 106 this.stack.setOffset(this.newOffset); 107 } 108 109 public void startDocument() 110 throws SAXException { 111 this.stack.setOffset(this.oldOffset); 112 this.consumer.startDocument(); 113 this.stack.setOffset(this.newOffset); 114 } 115 116 public void endDocument() 117 throws SAXException { 118 this.stack.setOffset(this.oldOffset); 119 this.consumer.endDocument(); 120 this.stack.setOffset(this.newOffset); 121 } 122 123 public void startPrefixMapping(String prefix, String uri) 124 throws SAXException { 125 this.stack.setOffset(this.oldOffset); 126 this.consumer.startPrefixMapping(prefix, uri); 127 this.stack.setOffset(this.newOffset); 128 } 129 130 public void endPrefixMapping(String prefix) 131 throws SAXException { 132 this.stack.setOffset(this.oldOffset); 133 this.consumer.endPrefixMapping(prefix); 134 this.stack.setOffset(this.newOffset); 135 } 136 137 public void startElement(String uri, String loc, String raw, Attributes a) 138 throws SAXException { 139 this.stack.setOffset(this.oldOffset); 140 this.consumer.startElement(uri, loc, raw, a); 141 this.stack.setOffset(this.newOffset); 142 } 143 144 145 public void endElement(String uri, String loc, String raw) 146 throws SAXException { 147 this.stack.setOffset(this.oldOffset); 148 this.consumer.endElement(uri, loc, raw); 149 this.stack.setOffset(this.newOffset); 150 } 151 152 public void characters(char c[], int start, int len) 153 throws SAXException { 154 this.stack.setOffset(this.oldOffset); 155 this.consumer.characters(c, start, len); 156 this.stack.setOffset(this.newOffset); 157 } 158 159 public void ignorableWhitespace(char c[], int start, int len) 160 throws SAXException { 161 this.stack.setOffset(this.oldOffset); 162 this.consumer.ignorableWhitespace(c, start, len); 163 this.stack.setOffset(this.newOffset); 164 } 165 166 public void processingInstruction(String target, String data) 167 throws SAXException { 168 this.stack.setOffset(this.oldOffset); 169 this.consumer.processingInstruction(target, data); 170 this.stack.setOffset(this.newOffset); 171 } 172 173 public void skippedEntity(String name) 174 throws SAXException { 175 this.stack.setOffset(this.oldOffset); 176 this.consumer.skippedEntity(name); 177 this.stack.setOffset(this.newOffset); 178 } 179 180 public void startDTD(String name, String publicId, String systemId) 181 throws SAXException { 182 this.stack.setOffset(this.oldOffset); 183 this.consumer.startDTD(name, publicId, systemId); 184 this.stack.setOffset(this.newOffset); 185 } 186 187 public void endDTD() 188 throws SAXException { 189 this.stack.setOffset(this.oldOffset); 190 this.consumer.endDTD(); 191 this.stack.setOffset(this.newOffset); 192 } 193 194 public void startEntity(String name) 195 throws SAXException { 196 this.stack.setOffset(this.oldOffset); 197 this.consumer.startEntity(name); 198 this.stack.setOffset(this.newOffset); 199 } 200 201 public void endEntity(String name) 202 throws SAXException { 203 this.stack.setOffset(this.oldOffset); 204 this.consumer.endEntity(name); 205 this.stack.setOffset(this.newOffset); 206 } 207 208 public void startCDATA() 209 throws SAXException { 210 this.stack.setOffset(this.oldOffset); 211 this.consumer.startCDATA(); 212 this.stack.setOffset(this.newOffset); 213 } 214 215 public void endCDATA() 216 throws SAXException { 217 this.stack.setOffset(this.oldOffset); 218 this.consumer.endCDATA(); 219 this.stack.setOffset(this.newOffset); 220 } 221 222 public void comment(char ch[], int start, int len) 223 throws SAXException { 224 this.stack.setOffset(this.oldOffset); 225 this.consumer.comment(ch, start, len); 226 this.stack.setOffset(this.newOffset); 227 } 228 } 229 | Popular Tags |