01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.transformation;
18:
19: import java.io.IOException;
20: import java.io.Serializable;
21: import java.util.Map;
22:
23: import org.apache.avalon.framework.CascadingRuntimeException;
24: import org.apache.avalon.framework.parameters.ParameterException;
25: import org.apache.avalon.framework.parameters.Parameters;
26: import org.apache.cocoon.ProcessingException;
27: import org.apache.cocoon.caching.CacheableProcessingComponent;
28: import org.apache.cocoon.environment.SourceResolver;
29: import org.apache.cocoon.generation.IncrementGenerator;
30: import org.apache.cocoon.xml.XMLConsumer;
31: import org.apache.excalibur.source.SourceValidity;
32: import org.apache.excalibur.source.impl.validity.NOPValidity;
33: import org.xml.sax.Attributes;
34: import org.xml.sax.SAXException;
35:
36: /**
37: * Increment context attribute "count" for testing purposes.
38: *
39: * This transformer always returns a VALID validity, and the cache key is given as
40: * a sitemap parameter.
41: *
42: * @version $Id: IncrementTransformer.java 433543 2006-08-22 06:22:54Z crossley $
43: */
44: public class IncrementTransformer extends AbstractTransformer implements
45: CacheableProcessingComponent {
46: XMLConsumer consumer;
47: Map objectModel;
48: String key;
49:
50: public void setup(SourceResolver resolver, Map objectModel,
51: String src, Parameters par) throws ProcessingException,
52: SAXException, IOException {
53: this .objectModel = objectModel;
54: try {
55: this .key = par.getParameter("key");
56: } catch (ParameterException e) {
57: throw new CascadingRuntimeException(
58: "Could not find parameter key", e);
59: }
60: }
61:
62: public Serializable getKey() {
63: return key;
64: }
65:
66: public SourceValidity getValidity() {
67: return NOPValidity.SHARED_INSTANCE;
68: }
69:
70: public void startElement(String uri, String loc, String raw,
71: Attributes a) throws SAXException {
72: IncrementGenerator.increment(objectModel, "count");
73: super.startElement(uri, loc, raw, a);
74: }
75: }
|