KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > krysalis > barcode > webapp > BarcodeRequestBean


1 /*
2  * $Id: BarcodeRequestBean.java,v 1.3 2003/06/15 16:37:58 jmaerki Exp $
3  * ============================================================================
4  * The Krysalis Patchy Software License, Version 1.1_01
5  * Copyright (c) 2002-2003 Nicola Ken Barozzi. All rights reserved.
6  *
7  * This Licence is compatible with the BSD licence as described and
8  * approved by http://www.opensource.org/, and is based on the
9  * Apache Software Licence Version 1.1.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  *
15  * 1. Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  *
18  * 2. Redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in
20  * the documentation and/or other materials provided with the
21  * distribution.
22  *
23  * 3. The end-user documentation included with the redistribution,
24  * if any, must include the following acknowledgment:
25  * "This product includes software developed for project
26  * Krysalis (http://www.krysalis.org/)."
27  * Alternately, this acknowledgment may appear in the software itself,
28  * if and wherever such third-party acknowledgments normally appear.
29  *
30  * 4. The names "Krysalis" and "Nicola Ken Barozzi" and
31  * "Krysalis Barcode" must not be used to endorse or promote products
32  * derived from this software without prior written permission. For
33  * written permission, please contact nicolaken@krysalis.org.
34  *
35  * 5. Products derived from this software may not be called "Krysalis",
36  * "Krysalis Barcode", nor may "Krysalis" appear in their name,
37  * without prior written permission of Nicola Ken Barozzi.
38  *
39  * 6. This software may contain voluntary contributions made by many
40  * individuals, who decided to donate the code to this project in
41  * respect of this licence, and was originally created by
42  * Jeremias Maerki <jeremias@maerki.org>.
43  *
44  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
45  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
46  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
47  * DISCLAIMED. IN NO EVENT SHALL THE KRYSALIS PROJECT OR
48  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
50  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
51  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
52  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
53  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
54  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55  * SUCH DAMAGE.
56  * ====================================================================
57  */

58 package org.krysalis.barcode.webapp;
59
60 import org.krysalis.barcode.servlet.BarcodeServlet;
61 import org.krysalis.barcode.tools.MimeTypes;
62
63 /**
64  * This is just a little helper bean for the JSP page.
65  *
66  * @author Jeremias Maerki
67  */

68 public class BarcodeRequestBean {
69
70     private String JavaDoc type;
71     private String JavaDoc msg;
72     private String JavaDoc height;
73     private String JavaDoc moduleWidth;
74     private String JavaDoc wideFactor;
75     private String JavaDoc quietZone;
76     private String JavaDoc humanReadable;
77     private String JavaDoc format;
78     private String JavaDoc resolution;
79     private boolean gray;
80
81     public String JavaDoc getType() {
82         return type;
83     }
84
85     public void setType(String JavaDoc string) {
86         type = string;
87     }
88
89     public String JavaDoc getHeight() {
90         return height;
91     }
92
93     public void setHeight(String JavaDoc string) {
94         height = string;
95     }
96
97     public String JavaDoc getMsg() {
98         return msg;
99     }
100
101     public void setMsg(String JavaDoc string) {
102         msg = string;
103     }
104
105     public String JavaDoc getModuleWidth() {
106         return moduleWidth;
107     }
108
109     public void setModuleWidth(String JavaDoc string) {
110         moduleWidth = string;
111     }
112
113     public String JavaDoc getWideFactor() {
114         return wideFactor;
115     }
116
117     public void setWideFactor(String JavaDoc string) {
118         wideFactor = string;
119     }
120
121     public String JavaDoc getQuietZone() {
122         return quietZone;
123     }
124
125     public void setQuietZone(String JavaDoc string) {
126         quietZone = string;
127     }
128
129     public String JavaDoc getHumanReadable() {
130         if ("[default]".equals(humanReadable)) {
131             return null;
132         } else {
133             return humanReadable;
134         }
135     }
136
137     public void setHumanReadable(String JavaDoc string) {
138         humanReadable = string;
139     }
140
141     public String JavaDoc getFormat() {
142         return this.format;
143     }
144
145     public boolean isSVG() {
146         return MimeTypes.MIME_SVG.equals(MimeTypes.expandFormat(getFormat()))
147             || (getFormat() == null)
148             || (getFormat().length() == 0);
149     }
150
151     public boolean isBitmap() {
152         return MimeTypes.isBitmapFormat(getFormat());
153     }
154     
155     public void setFormat(String JavaDoc string) {
156         this.format = string;
157     }
158
159     public String JavaDoc getResolution() {
160         return this.resolution;
161     }
162
163     public void setResolution(String JavaDoc string) {
164         this.resolution = string;
165     }
166
167     public boolean isGray() {
168         return this.gray;
169     }
170
171     public void setGray(boolean value) {
172         this.gray = value;
173     }
174
175     public String JavaDoc toURL() {
176         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(64);
177         sb.append("genbc?");
178     
179         //Type
180
String JavaDoc type = getType();
181         if (type == null) {
182             type = "code128";
183         }
184         sb.append(BarcodeServlet.BARCODE_TYPE);
185         sb.append("=");
186         sb.append(type);
187     
188         //Message
189
String JavaDoc msg = getMsg();
190         if (msg == null) {
191             msg = "123456";
192         }
193         sb.append("&");
194         sb.append(BarcodeServlet.BARCODE_MSG);
195         sb.append("=");
196         sb.append(java.net.URLEncoder.encode(msg));
197         //sb.append(java.net.URLEncoder.encode(msg, "UTF-8")); //works for JDK 1.4 only
198

199         //Height
200
String JavaDoc height = getHeight();
201         if (height != null) {
202             sb.append("&");
203             sb.append(BarcodeServlet.BARCODE_HEIGHT);
204             sb.append("=");
205             sb.append(height);
206         }
207
208         //Module Width
209
String JavaDoc moduleWidth = getModuleWidth();
210         if (moduleWidth != null) {
211             sb.append("&");
212             sb.append(BarcodeServlet.BARCODE_MODULE_WIDTH);
213             sb.append("=");
214             sb.append(moduleWidth);
215         }
216
217         //Wide Factor
218
String JavaDoc wideFactor = getWideFactor();
219         if (wideFactor != null) {
220             sb.append("&");
221             sb.append(BarcodeServlet.BARCODE_WIDE_FACTOR);
222             sb.append("=");
223             sb.append(wideFactor);
224         }
225
226         //Quiet Zone
227
String JavaDoc quietZone = getQuietZone();
228         if (quietZone != null) {
229             sb.append("&");
230             sb.append(BarcodeServlet.BARCODE_QUIET_ZONE);
231             sb.append("=");
232             sb.append(quietZone);
233         }
234
235         //Human Readable Part
236
String JavaDoc humanReadable = getHumanReadable();
237         if (humanReadable != null) {
238             sb.append("&");
239             sb.append(BarcodeServlet.BARCODE_HUMAN_READABLE_POS);
240             sb.append("=");
241             sb.append(humanReadable);
242         }
243         
244         //Output Format
245
String JavaDoc fmt = getFormat();
246         if (fmt != null && !isSVG()) {
247             sb.append("&");
248             sb.append(BarcodeServlet.BARCODE_FORMAT);
249             sb.append("=");
250             sb.append(fmt);
251         }
252         
253         //Output Format
254
String JavaDoc res = getResolution();
255         if (res != null && isBitmap()) {
256             sb.append("&");
257             sb.append(BarcodeServlet.BARCODE_IMAGE_RESOLUTION);
258             sb.append("=");
259             sb.append(res);
260         }
261         
262         //Output Format
263
boolean gray = isGray();
264         if (gray && isBitmap()) {
265             sb.append("&");
266             sb.append(BarcodeServlet.BARCODE_IMAGE_GRAYSCALE);
267             sb.append("=");
268             sb.append((isGray() ? "true" : "false"));
269         }
270         
271         return sb.toString();
272     }
273
274 }
275
Popular Tags