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.sitemap;
18:
19: import java.util.Map;
20: import java.io.IOException;
21:
22: import org.apache.avalon.framework.parameters.Parameters;
23: import org.apache.cocoon.components.notification.Notifying;
24: import org.apache.cocoon.components.notification.Notifier;
25: import org.apache.cocoon.generation.AbstractGenerator;
26: import org.apache.cocoon.environment.SourceResolver;
27: import org.apache.cocoon.ProcessingException;
28: import org.apache.cocoon.Constants;
29:
30: import org.xml.sax.SAXException;
31:
32: /**
33: * Generates an XML representation of the current notification.
34: *
35: * @author <a href="mailto:barozzi@nicolaken.com">Nicola Ken Barozzi</a>
36: * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
37: * @author <a href="mailto:proyal@managingpartners.com">Peter Royal</a>
38: * @version CVS $Id: NotifyingGenerator.java 433543 2006-08-22 06:22:54Z crossley $
39: */
40: public class NotifyingGenerator extends AbstractGenerator {
41:
42: /**
43: * The <code>Notification</code> to report.
44: */
45: private Notifying notification;
46:
47: public void setup(SourceResolver resolver, Map objectModel,
48: String src, Parameters par) throws ProcessingException,
49: SAXException, IOException {
50: super .setup(resolver, objectModel, src, par);
51:
52: this .notification = (Notifying) objectModel
53: .get(Constants.NOTIFYING_OBJECT);
54:
55: if (this .notification == null) {
56: throw new ProcessingException(
57: "Expected Constants.NOTIFYING_OBJECT not found in object model");
58: }
59: }
60:
61: /**
62: * Generate the notification information in XML format.
63: *
64: * @throws SAXException when there is a problem creating the
65: * output SAX events.
66: */
67: public void generate() throws SAXException {
68: Notifier.notify(notification, this .contentHandler, "text/xml");
69: }
70:
71: /**
72: * Recycle
73: */
74: public void recycle() {
75: super.recycle();
76: this.notification = null;
77: }
78: }
|