001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.jetspeed.serializer.objects;
019:
020: import org.apache.commons.lang.StringEscapeUtils;
021:
022: import javolution.xml.XMLFormat;
023: import javolution.xml.stream.XMLStreamException;
024:
025: public class JSSeedData extends JSSnapshot {
026:
027: public static final int softwareVersion = 1;
028:
029: public static final int softwareSubVersion = 0;
030:
031: private String encryption;
032:
033: private JSMimeTypes mimeTypes;
034:
035: private JSMediaTypes mediaTypes;
036:
037: private JSClients clients;
038:
039: private JSCapabilities capabilities;
040:
041: private JSRoles roles;
042:
043: private JSGroups groups;
044:
045: private JSUsers users;
046:
047: private JSPermissions permissions;
048:
049: private JSProfilingRules rules;
050:
051: private String defaultRule;
052:
053: /**
054: * check the software version and subvversion against the saved
055: * version...and verify whether it is compatible...
056: *
057: * @return the current software can process this file
058: */
059: public boolean checkVersion() {
060: return true;
061: }
062:
063: /**
064: * @return Returns the softwareSubVersion.
065: */
066: public int getSoftwareSubVersion() {
067: return softwareSubVersion;
068: }
069:
070: /**
071: * @return Returns the softwareVersion.
072: */
073: public int getSoftwareVersion() {
074: return softwareVersion;
075: }
076:
077: public JSSeedData() {
078: super ();
079: System.out.println("JSSeedData Class created");
080: }
081:
082: public JSSeedData(String name) {
083: super ();
084:
085: mimeTypes = new JSMimeTypes();
086: mediaTypes = new JSMediaTypes();
087: clients = new JSClients();
088: capabilities = new JSCapabilities();
089: roles = new JSRoles();
090: groups = new JSGroups();
091: users = new JSUsers();
092: permissions = new JSPermissions();
093: rules = new JSProfilingRules();
094: }
095:
096: /***************************************************************************
097: * SERIALIZER
098: */
099: protected static final XMLFormat XML = new XMLFormat(
100: JSSeedData.class) {
101:
102: public void write(Object o, OutputElement xml)
103: throws XMLStreamException {
104:
105: try {
106:
107: JSSnapshot.XML.write(o, xml);
108:
109: JSSeedData g = (JSSeedData) o;
110:
111: xml.add(g.getDefaultRule(), "default_rule",
112: String.class);
113:
114: xml.add(g.encryption, "encryption", String.class);
115:
116: /** implicitly named (through binding) fields here */
117:
118: xml.add(g.getMimeTypes());
119: xml.add(g.getMediaTypes());
120: xml.add(g.getCapabilities());
121: xml.add(g.getClients());
122:
123: xml.add(g.getRoles());
124: xml.add(g.getGroups());
125: xml.add(g.getUsers());
126:
127: xml.add(g.getPermissions());
128: xml.add(g.getRules());
129:
130: } catch (Exception e) {
131: e.printStackTrace();
132: }
133: }
134:
135: public void read(InputElement xml, Object o) {
136: try {
137: JSSnapshot.XML.read(xml, o); // Calls parent read.
138: JSSeedData g = (JSSeedData) o;
139: Object o1 = xml.get("default_rule", String.class);
140: if (o1 instanceof String)
141: g.defaultRule = StringEscapeUtils
142: .unescapeHtml((String) o1);
143: o1 = xml.get("encryption", String.class);
144: if (o1 instanceof String)
145: g.encryption = StringEscapeUtils
146: .unescapeHtml((String) o1);
147:
148: while (xml.hasNext()) {
149: o1 = xml.getNext(); // mime
150:
151: if (o1 instanceof JSMimeTypes)
152: g.mimeTypes = (JSMimeTypes) o1;
153: else if (o1 instanceof JSMediaTypes)
154: g.mediaTypes = (JSMediaTypes) o1;
155: else if (o1 instanceof JSClients)
156: g.clients = (JSClients) o1;
157: else if (o1 instanceof JSCapabilities)
158: g.capabilities = (JSCapabilities) o1;
159: else if (o1 instanceof JSRoles)
160: g.roles = (JSRoles) o1;
161: else if (o1 instanceof JSGroups)
162: g.groups = (JSGroups) o1;
163: else if (o1 instanceof JSUsers)
164: g.users = (JSUsers) o1;
165: else if (o1 instanceof JSPermissions)
166: g.permissions = (JSPermissions) o1;
167: else if (o1 instanceof JSProfilingRules)
168: g.rules = (JSProfilingRules) o1;
169: }
170: } catch (Exception e) {
171: e.printStackTrace();
172: }
173: }
174: };
175:
176: /**
177: * @return Returns the groups.
178: */
179: public JSGroups getGroups() {
180: return groups;
181: }
182:
183: /**
184: * @param groups
185: * The groups to set.
186: */
187: public void setGroups(JSGroups groups) {
188: this .groups = groups;
189: }
190:
191: /**
192: * @return Returns the roles.
193: */
194: public JSRoles getRoles() {
195: return roles;
196: }
197:
198: /**
199: * @param roles
200: * The roles to set.
201: */
202: public void setRoles(JSRoles roles) {
203: this .roles = roles;
204: }
205:
206: /**
207: * @return Returns the roles.
208: */
209: public JSUsers getUsers() {
210: return users;
211: }
212:
213: /**
214: * @return Returns the encryption.
215: */
216: public String getEncryption() {
217: return encryption;
218: }
219:
220: /**
221: * @param encryption
222: * The encryption to set.
223: */
224: public void setEncryption(String encryption) {
225: this .encryption = encryption;
226: }
227:
228: /**
229: * @return Returns the capabilities.
230: */
231: public JSCapabilities getCapabilities() {
232: return capabilities;
233: }
234:
235: /**
236: * @param capabilities
237: * The capabilities to set.
238: */
239: public void setCapabilities(JSCapabilities capabilities) {
240: this .capabilities = capabilities;
241: }
242:
243: /**
244: * @return Returns the clients.
245: */
246: public JSClients getClients() {
247: return clients;
248: }
249:
250: /**
251: * @param clients
252: * The clients to set.
253: */
254: public void setClients(JSClients clients) {
255: this .clients = clients;
256: }
257:
258: /**
259: * @return Returns the mediaTypes.
260: */
261: public JSMediaTypes getMediaTypes() {
262: return mediaTypes;
263: }
264:
265: /**
266: * @param mediaTypes
267: * The mediaTypes to set.
268: */
269: public void setMediaTypes(JSMediaTypes mediaTypes) {
270: this .mediaTypes = mediaTypes;
271: }
272:
273: /**
274: * @return Returns the mimeTypes.
275: */
276: public JSMimeTypes getMimeTypes() {
277: return mimeTypes;
278: }
279:
280: /**
281: * @param mimeTypes
282: * The mimeTypes to set.
283: */
284: public void setMimeTypes(JSMimeTypes mimeTypes) {
285: this .mimeTypes = mimeTypes;
286: }
287:
288: /**
289: * @param users
290: * The users to set.
291: */
292: public void setUsers(JSUsers users) {
293: this .users = users;
294: }
295:
296: /**
297: * @return Returns the permissions.
298: */
299: public JSPermissions getPermissions() {
300: return permissions;
301: }
302:
303: /**
304: * @param permissions
305: * The permissions to set.
306: */
307: public void setPermissions(JSPermissions permissions) {
308: this .permissions = permissions;
309: }
310:
311: /**
312: * @return Returns the rules.
313: */
314: public JSProfilingRules getRules() {
315: return rules;
316: }
317:
318: /**
319: * @param rules
320: * The rules to set.
321: */
322: public void setRules(JSProfilingRules rules) {
323: this .rules = rules;
324: }
325:
326: /**
327: * @return Returns the defaultRule.
328: */
329: public String getDefaultRule() {
330: return defaultRule;
331: }
332:
333: /**
334: * @param defaultRule
335: * The defaultRule to set.
336: */
337: public void setDefaultRule(String defaultRule) {
338: this.defaultRule = defaultRule;
339: }
340:
341: }
|