KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > structure > ScriptDefinition


1 /*
2  * Copyright (c) 2001-2005 by Genimen BV (www.genimen.com) All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, is permitted provided that the following conditions are met: -
6  * Redistributions of source code must retain the above copyright notice, this
7  * list of conditions and the following disclaimer. - Redistributions in binary
8  * form must reproduce the above copyright notice, this list of conditions and
9  * the following disclaimer in the documentation and/or other materials
10  * provided with the distribution. - All advertising materials mentioning
11  * features or use of this software must display the following acknowledgment:
12  * "This product includes Djeneric." - Products derived from this software may
13  * not be called "Djeneric" nor may "Djeneric" appear in their names without
14  * prior written permission of Genimen BV. - Redistributions of any form
15  * whatsoever must retain the following acknowledgment: "This product includes
16  * Djeneric."
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL GENIMEN BV, DJENERIC.ORG, OR CONTRIBUTORS
22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */

30 package com.genimen.djeneric.structure;
31
32 import java.io.UnsupportedEncodingException JavaDoc;
33
34 import com.genimen.djeneric.language.Messages;
35 import com.genimen.djeneric.util.DjBase64;
36
37 public class ScriptDefinition
38 {
39
40   String JavaDoc _title;
41   String JavaDoc _code;
42   boolean _markedForDelete = false;
43
44   public Object JavaDoc clone()
45   {
46     ScriptDefinition result = new ScriptDefinition();
47     result._title = _title;
48     result._code = _code;
49     result._markedForDelete = _markedForDelete;
50     return result;
51   }
52
53   public boolean equals(Object JavaDoc obj)
54   {
55     if (!(obj instanceof ScriptDefinition)) return false;
56
57     ScriptDefinition other = (ScriptDefinition) obj;
58
59     return safeCompare(_title, other._title) && safeCompare(_code, other._code);
60   }
61
62   public int hashCode()
63   {
64     int result = 0;
65     if (_title != null) result += _title.hashCode();
66     if (_code != null) result += _code.hashCode();
67
68     return result;
69   }
70
71   private boolean safeCompare(Object JavaDoc one, Object JavaDoc two)
72   {
73     if (one == null && two == null) return true;
74     if (one == null || two == null) return false;
75
76     return one.equals(two);
77   }
78
79   public ScriptDefinition()
80   {
81     _title = Messages.getString("ScriptDefinition.NewScript");
82     _code = "";
83   }
84
85   public ScriptDefinition(String JavaDoc name, String JavaDoc code)
86   {
87     _title = name;
88     _code = code;
89   }
90
91   public String JavaDoc getTitle()
92   {
93     return _title;
94   }
95
96   public void setTitle(String JavaDoc title)
97   {
98     if (title != null && title.trim().length() == 0) title = null;
99     _title = title;
100   }
101
102   public String JavaDoc toString()
103   {
104     return _title;
105   }
106
107   public boolean isMarkedForDelete()
108   {
109     return _markedForDelete;
110   }
111
112   public void setMarkedForDelete(boolean markedForDelete)
113   {
114     _markedForDelete = markedForDelete;
115   }
116
117   public String JavaDoc getCode()
118   {
119     return _code;
120   }
121
122   public void setCode(String JavaDoc string)
123   {
124     _code = string;
125   }
126
127   public String JavaDoc getBase64() throws UnsupportedEncodingException JavaDoc
128   {
129     StringBuffer JavaDoc result = new StringBuffer JavaDoc(10000);
130
131     String JavaDoc encoded = DjBase64.encode(getCode().getBytes());
132     int lineLength = 80;
133
134     int idx = 0;
135     while (idx < encoded.length())
136     {
137       int length = lineLength;
138       if (idx + length > encoded.length()) length = encoded.length() - idx;
139       result.append(encoded.subSequence(idx, idx + length));
140       result.append("\n");
141       idx += length;
142     }
143     return result.toString();
144   }
145
146   public void setBase64(String JavaDoc base64) throws UnsupportedEncodingException JavaDoc
147   {
148     setCode(new String JavaDoc(DjBase64.decode(base64)));
149   }
150
151 }
Popular Tags