~hjd/ubuntu/wily/xmlgraphics-commons/debian-merged

« back to all changes in this revision

Viewing changes to src/java/org/apache/xmlgraphics/ps/dsc/events/DSCCommentBeginDocument.java

  • Committer: Bazaar Package Importer
  • Author(s): Vincent Fourmond
  • Date: 2011-02-11 14:15:14 UTC
  • mfrom: (8.1.2 experimental)
  • Revision ID: james.westby@ubuntu.com-20110211141514-h67achft6x31gju1
Tags: 1.4.dfsg-3
Uploading to unstable, hoping we won't break too many things ;-)...

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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
 
8
 *
 
9
 *      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: DSCCommentBeginDocument.java 727407 2008-12-17 15:05:45Z jeremias $ */
 
19
 
 
20
package org.apache.xmlgraphics.ps.dsc.events;
 
21
 
 
22
import java.io.IOException;
 
23
import java.util.Iterator;
 
24
import java.util.List;
 
25
 
 
26
import org.apache.xmlgraphics.ps.DSCConstants;
 
27
import org.apache.xmlgraphics.ps.PSGenerator;
 
28
import org.apache.xmlgraphics.ps.PSResource;
 
29
 
 
30
/**
 
31
 * Represents a %BeginDocument DSC comment.
 
32
 */
 
33
public class DSCCommentBeginDocument extends AbstractDSCComment {
 
34
 
 
35
    private PSResource resource;
 
36
    private Float version;
 
37
    private String type;
 
38
 
 
39
    /**
 
40
     * Creates a new instance
 
41
     */
 
42
    public DSCCommentBeginDocument() {
 
43
        super();
 
44
    }
 
45
 
 
46
    /**
 
47
     * Creates a new instance for a given PSResource instance
 
48
     * @param resource the resource
 
49
     */
 
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'");
 
54
        }
 
55
    }
 
56
 
 
57
    /**
 
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)
 
62
     */
 
63
    public DSCCommentBeginDocument(PSResource resource, Float version, String type) {
 
64
        this(resource);
 
65
        this.version = version;
 
66
        this.type = type;
 
67
    }
 
68
 
 
69
    /**
 
70
     * Returns the resource version.
 
71
     * @return the resource version (or null if not applicable)
 
72
     */
 
73
    public Float getVersion() {
 
74
        return this.version;
 
75
    }
 
76
 
 
77
    /**
 
78
     * Returns the resource type
 
79
     * @return the resource type (or null if not applicable)
 
80
     */
 
81
    public String getType() {
 
82
        return this.type;
 
83
    }
 
84
 
 
85
    /** {@inheritDoc} */
 
86
    public String getName() {
 
87
        return DSCConstants.BEGIN_DOCUMENT;
 
88
    }
 
89
 
 
90
    /**
 
91
     * Returns the associated PSResource.
 
92
     * @return the resource
 
93
     */
 
94
    public PSResource getResource() {
 
95
        return this.resource;
 
96
    }
 
97
 
 
98
    /** {@inheritDoc} */
 
99
    public boolean hasValues() {
 
100
        return true;
 
101
    }
 
102
 
 
103
    /** {@inheritDoc} */
 
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());
 
111
            this.type = null;
 
112
            if (iter.hasNext()) {
 
113
                this.type = (String)iter.next();
 
114
            }
 
115
        }
 
116
    }
 
117
 
 
118
    /** {@inheritDoc} */
 
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());
 
126
            }
 
127
        }
 
128
        gen.writeDSCComment(getName(), params.toArray());
 
129
    }
 
130
 
 
131
}