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: /* $Id$ */
19:
20: package org.apache.xmlgraphics.ps.dsc;
21:
22: import java.io.IOException;
23: import java.io.OutputStream;
24:
25: import org.apache.xmlgraphics.ps.DSCConstants;
26: import org.apache.xmlgraphics.ps.PSGenerator;
27: import org.apache.xmlgraphics.ps.dsc.events.DSCComment;
28:
29: /**
30: * Default implementation of a DSCHandler which simply passes through the PostScript content
31: * unchanged. Subclasses can implement different behaviour, for example to filter certain
32: * DSC comments or to insert PostScript code at specific places.
33: */
34: public class DefaultDSCHandler implements DSCHandler {
35:
36: protected OutputStream out;
37: protected PSGenerator gen;
38:
39: /**
40: * Creates a new instance.
41: * @param out OutputStream to pipe all received events to
42: */
43: public DefaultDSCHandler(OutputStream out) {
44: this .out = out;
45: this .gen = new PSGenerator(this .out);
46: }
47:
48: /** @see org.apache.xmlgraphics.ps.dsc.DSCHandler#startDocument(java.lang.String) */
49: public void startDocument(String header) throws IOException {
50: gen.writeln(header);
51: }
52:
53: /** @see org.apache.xmlgraphics.ps.dsc.DSCHandler#endDocument() */
54: public void endDocument() throws IOException {
55: gen.writeDSCComment(DSCConstants.EOF);
56: }
57:
58: /**
59: * @see org.apache.xmlgraphics.ps.dsc.DSCHandler#handleDSCComment(
60: * org.apache.xmlgraphics.ps.dsc.events.DSCComment)
61: */
62: public void handleDSCComment(DSCComment comment) throws IOException {
63: comment.generate(gen);
64:
65: }
66:
67: /** @see org.apache.xmlgraphics.ps.dsc.DSCHandler#line(java.lang.String) */
68: public void line(String line) throws IOException {
69: gen.writeln(line);
70: }
71:
72: /** @see org.apache.xmlgraphics.ps.dsc.DSCHandler#comment(java.lang.String) */
73: public void comment(String comment) throws IOException {
74: gen.commentln("%" + comment);
75: }
76:
77: }
|