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: PSResource.java 512838 2007-02-28 16:42:28Z jeremias $ */
19:
20: package org.apache.xmlgraphics.ps;
21:
22: /**
23: * Represents a PostScript resource (file, font, procset etc.).
24: */
25: public class PSResource {
26:
27: /** a file resource */
28: public static final String TYPE_FILE = "file";
29: /** a font resource */
30: public static final String TYPE_FONT = "font";
31: /** a procset resource */
32: public static final String TYPE_PROCSET = "procset";
33: /** a procset resource */
34: public static final String TYPE_PATTERN = "pattern";
35: /** a procset resource */
36: public static final String TYPE_FORM = "form";
37: /** a procset resource */
38: public static final String TYPE_ENCODING = "encoding";
39:
40: private String type;
41: private String name;
42:
43: /**
44: * Main constructor
45: * @param type type of the resource
46: * @param name name of the resource
47: */
48: public PSResource(String type, String name) {
49: this .type = type;
50: this .name = name;
51: }
52:
53: /** @return the type of the resource */
54: public String getType() {
55: return this .type;
56: }
57:
58: /** @return the name of the resource */
59: public String getName() {
60: return this .name;
61: }
62:
63: /** @return the <resource> specification as defined in DSC v3.0 spec. */
64: public String getResourceSpecification() {
65: StringBuffer sb = new StringBuffer();
66: sb.append(getType()).append(" ").append(
67: PSGenerator.convertStringToDSC(getName()));
68: return sb.toString();
69: }
70:
71: /** @see java.lang.Object#equals(java.lang.Object) */
72: public boolean equals(Object obj) {
73: if (obj == this ) {
74: return true;
75: } else if (obj instanceof PSResource) {
76: PSResource other = (PSResource) obj;
77: return other.toString().equals(toString());
78: } else {
79: return false;
80: }
81: }
82:
83: /** @see java.lang.Object#hashCode() */
84: public int hashCode() {
85: return toString().hashCode();
86: }
87:
88: /** @see java.lang.Object#toString() */
89: public String toString() {
90: return getResourceSpecification();
91: }
92: }
|