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.events;
21:
22: import java.io.IOException;
23:
24: import org.apache.xmlgraphics.ps.DSCConstants;
25: import org.apache.xmlgraphics.ps.PSGenerator;
26:
27: /**
28: * Represents a %%LanguageLevel DSC comment
29: */
30: public class DSCCommentLanguageLevel extends AbstractDSCComment {
31:
32: private int level;
33:
34: /**
35: * Creates a new instance.
36: */
37: public DSCCommentLanguageLevel() {
38: }
39:
40: /**
41: * Creates a new instance
42: * @param level the PostScript language level (usually 2 or 3)
43: */
44: public DSCCommentLanguageLevel(int level) {
45: this .level = level;
46: }
47:
48: /**
49: * Returns the PostScript language level (usually 2 or 3).
50: * @return the language level
51: */
52: public int getLanguageLevel() {
53: return this .level;
54: }
55:
56: /**
57: * @see org.apache.xmlgraphics.ps.dsc.events.DSCComment#getName()
58: */
59: public String getName() {
60: return DSCConstants.LANGUAGE_LEVEL;
61: }
62:
63: /**
64: * @see org.apache.xmlgraphics.ps.dsc.events.DSCComment#hasValues()
65: */
66: public boolean hasValues() {
67: return true;
68: }
69:
70: /**
71: * @see org.apache.xmlgraphics.ps.dsc.events.DSCComment#parseValue(java.lang.String)
72: */
73: public void parseValue(String value) {
74: this .level = Integer.parseInt(value);
75: }
76:
77: /**
78: * @see org.apache.xmlgraphics.ps.dsc.events.DSCEvent#generate(org.apache.xmlgraphics.ps.PSGenerator)
79: */
80: public void generate(PSGenerator gen) throws IOException {
81: if (level <= 0) {
82: throw new IllegalStateException(
83: "Language Level was not properly set");
84: }
85: gen.writeDSCComment(getName(), new Integer(getLanguageLevel()));
86: }
87:
88: }
|