1 16 package org.outerj.daisy.frontend.editor; 17 18 import org.apache.cocoon.forms.formmodel.Form; 19 import org.apache.avalon.framework.service.ServiceManager; 20 import org.apache.avalon.framework.context.Context; 21 import org.outerj.daisy.frontend.util.FormHelper; 22 import org.outerj.daisy.repository.Part; 23 import org.outerj.daisy.repository.Document; 24 import org.outerj.daisy.repository.Repository; 25 import org.outerj.daisy.repository.schema.PartTypeUse; 26 27 import java.util.Map ; 28 29 public class PlainTextPartEditor implements PartEditor { 30 private ServiceManager serviceManager; 31 32 private PlainTextPartEditor(ServiceManager serviceManager) { 33 this.serviceManager = serviceManager; 34 } 35 36 public static class Factory implements PartEditorFactory { 37 public PartEditor getPartEditor(Map properties, ServiceManager serviceManager, Context context) { 38 return new PlainTextPartEditor(serviceManager); 39 } 40 } 41 42 public Form getForm(PartTypeUse partTypeUse, DocumentEditorForm documentEditorForm, Repository repository) throws Exception { 43 Form form = FormHelper.createForm(serviceManager, "resources/form/parteditor_plaintext_definition.xml"); 44 form.getChild("plaintext").addValidator(new PartRequiredValidator(documentEditorForm, partTypeUse.isRequired(), false)); 45 form.getChild("mimetype").setValue("text/plain"); 46 return form; 47 } 48 49 public String getFormTemplate() { 50 return "resources/form/parteditor_plaintext_template.xml"; 51 } 52 53 public void load(Form form, Document document, Part part, Repository repository) throws Exception { 54 form.getChild("mimetype").setValue(part.getMimeType()); 55 PartEditorHelper.load(form, part, "plaintext"); 56 } 57 58 public void save(Form form, Document document) throws Exception { 59 PartEditorHelper.save(form, document, "plaintext", (String )form.getChild("mimetype").getValue()); 60 } 61 62 } 63 | Popular Tags |