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:
18: package org.apache.cocoon.generation;
19:
20: import de.tivano.flash.swf.parser.SWFReader;
21: import de.tivano.flash.swf.parser.SWFVerboseDefineFont2Reader;
22: import de.tivano.flash.swf.parser.SWFVerboseDefineFontReader;
23:
24: import org.apache.avalon.framework.parameters.Parameters;
25: import org.apache.cocoon.ProcessingException;
26: import org.apache.cocoon.environment.SourceResolver;
27: import org.apache.excalibur.source.SourceException;
28: import org.xml.sax.InputSource;
29: import org.xml.sax.SAXException;
30:
31: import java.io.IOException;
32: import java.util.Map;
33:
34: /**
35: * uses the project http://developer.berlios.de/projects/spark-xml/
36: *
37: * @author <a href="mailto:tcurdt@apache.org">Torsten Curdt</a>
38: * @version CVS $Id: SWFGenerator.java 433543 2006-08-22 06:22:54Z crossley $
39: */
40: public class SWFGenerator extends FileGenerator {
41:
42: private boolean pVerbose = false;
43: private SWFReader parser;
44:
45: public void setup(SourceResolver resolver, Map objectModel,
46: String src, Parameters par) throws ProcessingException,
47: SAXException, IOException {
48: super .setup(resolver, objectModel, src, par);
49: parser = new SWFReader();
50: if (pVerbose) {
51: parser.registerTagReader(48,
52: new SWFVerboseDefineFont2Reader());
53: parser.registerTagReader(10,
54: new SWFVerboseDefineFontReader());
55: }
56: }
57:
58: public void generate() throws IOException, SAXException,
59: ProcessingException {
60:
61: try {
62: if (this .getLogger().isDebugEnabled()) {
63: this .getLogger().debug(
64: "processing file " + super .source);
65: this .getLogger()
66: .debug(
67: "file resolved to "
68: + this .inputSource.getURI());
69: }
70:
71: this .parser.setContentHandler(super .xmlConsumer);
72: this .parser.parse(new InputSource(this .inputSource
73: .getInputStream()));
74:
75: } catch (SourceException e) {
76: throw new ProcessingException("Could not read resource "
77: + this .inputSource.getURI(), e);
78: } catch (SAXException e) {
79: final Exception cause = e.getException();
80: if (cause != null) {
81: this .getLogger().debug(
82: "Got SAXException; Rethrowing cause exception",
83: e);
84: if (cause instanceof ProcessingException)
85: throw (ProcessingException) cause;
86: if (cause instanceof IOException)
87: throw (IOException) cause;
88: if (cause instanceof SAXException)
89: throw (SAXException) cause;
90: throw new ProcessingException(
91: "Could not read resource "
92: + this.inputSource.getURI(), cause);
93: }
94: throw e;
95: }
96: }
97:
98: }
|