2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
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.
18
/* $Id: DSCCommentBeginDocument.java 727407 2008-12-17 15:05:45Z jeremias $ */
20
package org.apache.xmlgraphics.ps.dsc.events;
22
import java.io.IOException;
23
import java.util.Iterator;
24
import java.util.List;
26
import org.apache.xmlgraphics.ps.DSCConstants;
27
import org.apache.xmlgraphics.ps.PSGenerator;
28
import org.apache.xmlgraphics.ps.PSResource;
31
* Represents a %BeginDocument DSC comment.
33
public class DSCCommentBeginDocument extends AbstractDSCComment {
35
private PSResource resource;
36
private Float version;
40
* Creates a new instance
42
public DSCCommentBeginDocument() {
47
* Creates a new instance for a given PSResource instance
48
* @param resource the resource
50
public DSCCommentBeginDocument(PSResource resource) {
51
this.resource = resource;
52
if (resource != null && !PSResource.TYPE_FILE.equals(resource.getType())) {
53
throw new IllegalArgumentException("Resource must be of type 'file'");
58
* Creates a new instance for a given PSResource instance
59
* @param resource the resource
60
* @param version the version of the resource (or null)
61
* @param type the type of resource (or null)
63
public DSCCommentBeginDocument(PSResource resource, Float version, String type) {
65
this.version = version;
70
* Returns the resource version.
71
* @return the resource version (or null if not applicable)
73
public Float getVersion() {
78
* Returns the resource type
79
* @return the resource type (or null if not applicable)
81
public String getType() {
86
public String getName() {
87
return DSCConstants.BEGIN_DOCUMENT;
91
* Returns the associated PSResource.
92
* @return the resource
94
public PSResource getResource() {
99
public boolean hasValues() {
104
public void parseValue(String value) {
105
List params = splitParams(value);
106
Iterator iter = params.iterator();
107
String name = (String)iter.next();
108
this.resource = new PSResource(PSResource.TYPE_FILE, name);
109
if (iter.hasNext()) {
110
this.version = new Float(iter.next().toString());
112
if (iter.hasNext()) {
113
this.type = (String)iter.next();
119
public void generate(PSGenerator gen) throws IOException {
120
List params = new java.util.ArrayList();
121
params.add(getResource().getName());
122
if (getVersion() != null) {
123
params.add(getVersion());
124
if (getType() != null) {
125
params.add(getType());
128
gen.writeDSCComment(getName(), params.toArray());