KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > generation > SWFGenerator


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.cocoon.generation;
18
19 import de.tivano.flash.swf.parser.SWFReader;
20 import de.tivano.flash.swf.parser.SWFVerboseDefineFont2Reader;
21 import de.tivano.flash.swf.parser.SWFVerboseDefineFontReader;
22
23 import org.apache.avalon.framework.parameters.Parameters;
24 import org.apache.cocoon.ProcessingException;
25 import org.apache.cocoon.environment.SourceResolver;
26 import org.apache.excalibur.source.SourceException;
27 import org.xml.sax.InputSource JavaDoc;
28 import org.xml.sax.SAXException JavaDoc;
29
30 import java.io.IOException JavaDoc;
31 import java.util.Map JavaDoc;
32
33 /**
34  * uses the project http://developer.berlios.de/projects/spark-xml/
35  *
36  * @author <a HREF="mailto:tcurdt@apache.org">Torsten Curdt</a>
37  * @version CVS $Id: SWFGenerator.java 30932 2004-07-29 17:35:38Z vgritsenko $
38  */

39 public class SWFGenerator extends FileGenerator {
40     
41     private boolean pVerbose = false;
42     private SWFReader parser;
43
44     public void setup(SourceResolver resolver, Map JavaDoc objectModel, String JavaDoc src, Parameters par)
45     throws ProcessingException, SAXException JavaDoc, IOException JavaDoc {
46         super.setup(resolver, objectModel, src, par);
47         parser = new SWFReader();
48         if (pVerbose) {
49             parser.registerTagReader(48, new SWFVerboseDefineFont2Reader());
50             parser.registerTagReader(10, new SWFVerboseDefineFontReader());
51         }
52     }
53
54     public void generate()
55     throws IOException JavaDoc, SAXException JavaDoc, ProcessingException {
56
57         try {
58             if (this.getLogger().isDebugEnabled()) {
59                 this.getLogger().debug("processing file " + super.source);
60                 this.getLogger().debug("file resolved to " + this.inputSource.getURI());
61             }
62
63             this.parser.setContentHandler(super.xmlConsumer);
64             this.parser.parse(new InputSource JavaDoc(this.inputSource.getInputStream()));
65
66         } catch (SourceException e) {
67             throw new ProcessingException("Could not read resource "
68                                               + this.inputSource.getURI(), e);
69         } catch (SAXException JavaDoc e) {
70             final Exception JavaDoc cause = e.getException();
71             if( cause != null ) {
72                 this.getLogger().debug("Got SAXException; Rethrowing cause exception", e);
73                 if ( cause instanceof ProcessingException )
74                     throw (ProcessingException)cause;
75                 if ( cause instanceof IOException JavaDoc )
76                     throw (IOException JavaDoc)cause;
77                 if ( cause instanceof SAXException JavaDoc )
78                     throw (SAXException JavaDoc)cause;
79                 throw new ProcessingException("Could not read resource "
80                                               + this.inputSource.getURI(), cause);
81             }
82             throw e;
83         }
84     }
85
86 }
87
Popular Tags