001: /**
002: * LibreSource Community
003: * Copyright (C) 2004-2007 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This software is not a free software; you can modify it under the
007: * LibreSource Enterprise user license but you can't redistribute it.
008: * See licenses details in LSE-user-license.txt
009: *
010: * Initial authors :
011: *
012: * Guillaume Bort / INRIA
013: * Francois Charoy / Universite Nancy 2
014: * Julien Forest / Artenum
015: * Claude Godart / Universite Henry Poincare
016: * Florent Jouille / INRIA
017: * Sebastien Jourdain / INRIA / Artenum
018: * Yves Lerumeur / Artenum
019: * Pascal Molli / Universite Henry Poincare
020: * Gerald Oster / INRIA
021: * Mariarosa Penzi / Artenum
022: * Gerard Sookahet / Artenum
023: * Raphael Tani / INRIA
024: *
025: * Contributors :
026: *
027: * Stephane Bagnier / Artenum
028: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
029: */package org.libresource.form;
030:
031: import org.libresource.Libresource;
032:
033: import org.libresource.form.interfaces.LibresourceFormService;
034:
035: import org.libresource.xml.ImportExportLogger;
036: import org.libresource.xml.LibresourceImportHandler;
037:
038: import org.xml.sax.Attributes;
039:
040: import sun.misc.BASE64Decoder;
041:
042: import java.io.ByteArrayInputStream;
043: import java.io.ObjectInputStream;
044:
045: import java.net.URI;
046:
047: import java.util.Vector;
048:
049: /**
050: * Artenum Contribution
051: *
052: * @author <a href="mailto:jourdain@artenum.com">Sebastien Jourdain</a> - <a
053: * href="http://www.artenum.com">Artenum</a>
054: */
055: public class FormImportHandler extends LibresourceImportHandler {
056: private URI node;
057: private String name;
058: private String description;
059: private String resourceTypeToCreate;
060: private String destination;
061: private String redirect;
062: private Vector fields;
063: private boolean enteredInDefinition = false;
064: private StringBuffer tmpContent;
065: private LibresourceFormService libresourceFormService;
066:
067: public void handleBeginElement(String name, Attributes attributes,
068: ImportExportLogger logger) throws Exception {
069: if (name.equals("form:form")) {
070: enteredInDefinition = true;
071: }
072:
073: if (name.equals("form:name")) {
074: tmpContent = new StringBuffer();
075: }
076:
077: if (name.equals("form:description")) {
078: tmpContent = new StringBuffer();
079: }
080:
081: if (name.equals("form:resourceTypeToCreate")) {
082: tmpContent = new StringBuffer();
083: }
084:
085: if (name.equals("form:destination")) {
086: tmpContent = new StringBuffer();
087: }
088:
089: if (name.equals("form:redirect")) {
090: tmpContent = new StringBuffer();
091: }
092:
093: if (name.equals("form:fields")) {
094: tmpContent = new StringBuffer();
095: }
096: }
097:
098: public boolean handleEndElement(String name,
099: ImportExportLogger logger) throws Exception {
100: if (name.equals("form:form")) {
101: enteredInDefinition = false;
102: libresourceFormService.createForm(node, this .name);
103: libresourceFormService.editForm(node, this .name,
104: description, destination, resourceTypeToCreate,
105: redirect);
106:
107: // FIXME
108: libresourceFormService.setFormFields(node, fields);
109:
110: return true;
111: }
112:
113: if (name.equals("form:name")) {
114: this .name = tmpContent.toString().trim();
115:
116: return false;
117: }
118:
119: if (name.equals("form:description")) {
120: this .description = tmpContent.toString().trim();
121:
122: return false;
123: }
124:
125: if (name.equals("form:destination")) {
126: this .destination = tmpContent.toString().trim();
127:
128: return false;
129: }
130:
131: if (name.equals("form:resourceTypeToCreate")) {
132: this .resourceTypeToCreate = tmpContent.toString().trim();
133:
134: return false;
135: }
136:
137: if (name.equals("form:redirect")) {
138: this .redirect = tmpContent.toString().trim();
139:
140: return false;
141: }
142:
143: if (name.equals("form:fields")) {
144: ObjectInputStream stream = new ObjectInputStream(
145: new ByteArrayInputStream(new BASE64Decoder()
146: .decodeBuffer(tmpContent.toString().trim())));
147: this .fields = (Vector) stream.readObject();
148: stream.close();
149:
150: return false;
151: }
152:
153: // FIXME fields
154: return false;
155: }
156:
157: public void handleContent(String content, ImportExportLogger logger)
158: throws Exception {
159: if (tmpContent != null) {
160: tmpContent.append(content);
161: }
162: }
163:
164: public void init(URI node, ImportExportLogger logger)
165: throws Exception {
166: this .node = node;
167: enteredInDefinition = false;
168: tmpContent = null;
169: libresourceFormService = (LibresourceFormService) Libresource
170: .getService(FormConstants.SERVICE);
171: }
172: }
|