Folgende Änderungen im Modul sci-organization:

- Konfigurationsklasse hinzugefügt
- SciProject
  * Description und Funding zusammengefasst
  * Die Beschreibung kann wie bei ccm-types-article als Datei hochgeladen werden.


git-svn-id: https://svn.libreccm.org/ccm/trunk@568 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2010-10-10 14:31:31 +00:00
parent 8387aa52c4
commit d0e92f426e
11 changed files with 379 additions and 155 deletions

View File

@ -27,13 +27,6 @@
component="com.arsdigita.cms.contenttypes.ui.SciProjectDescriptionStep"
ordering="2"/>
<ctd:authoring-step
labelKey="sciorganization.ui.project_funding.title"
labelBundle="com.arsdigita.cms.contenttypes.ui.SciProjectResources"
descriptionKey="sciorganization.ui.project_funding.title.funding"
component="com.arsdigita.cms.contenttypes.ui.SciProjectFundingStep"
ordering="3"/>
<ctd:include href="/WEB-INF/content-types/assign-categories-step.xml"/>
</ctd:authoring-kit>

View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<registry>
<!-- <config class="com.arsdigita.cms.SciOrganizationConfig" storage="ccm-sci-types-organization/sciorganizations.properties"/> -->
<config class="com.arsdigita.cms.contenttypes.SciOrganizationConfig"
storage="ccm-sci-types-organization/sciorganization.properties"/>
</registry>

View File

@ -0,0 +1,59 @@
package com.arsdigita.cms.contenttypes;
import com.arsdigita.runtime.AbstractConfig;
import com.arsdigita.util.parameter.BooleanParameter;
import com.arsdigita.util.parameter.Parameter;
/**
*
* @author Jens Pelzetter
*/
public class SciOrganizationConfig extends AbstractConfig {
private final Parameter m_projectFundingHide;
private final Parameter m_projectFundingDhtml;
private final Parameter m_projectMaterialsHide;
private final Parameter m_organizationPersonsHide;
public SciOrganizationConfig() {
m_projectFundingHide = new BooleanParameter(
"com.arsdigita.cms.contenttypes.sciproject.funding_hide",
Parameter.REQUIRED,
Boolean.FALSE);
m_projectFundingDhtml = new BooleanParameter(
"com.arsdigita.cms.contenttypes.sciproject.funding_dhtml",
Parameter.REQUIRED,
Boolean.FALSE);
m_projectMaterialsHide = new BooleanParameter(
"com.arsdigita.cms.contenttypes.sciproject.materials_hide",
Parameter.REQUIRED,
Boolean.FALSE);
m_organizationPersonsHide = new BooleanParameter(
"com.arsdigita.cms.contenttypes.sciorganization.persons_hide",
Parameter.REQUIRED,
Boolean.TRUE);
register(m_projectFundingHide);
register(m_projectFundingDhtml);
register(m_projectMaterialsHide);
register(m_organizationPersonsHide);
loadInfo();
}
public final boolean getProjectFundingHide() {
return (Boolean) get(m_projectFundingHide);
}
public final boolean getProjectFundingDhtml() {
return (Boolean) get(m_projectFundingDhtml);
}
public final boolean getProjectMaterialsHide() {
return (Boolean) get(m_projectMaterialsHide);
}
public final boolean getOrganizationPersonsHide() {
return (Boolean) get(m_organizationPersonsHide);
}
}

View File

@ -0,0 +1,19 @@
com.arsdigita.cms.contenttypes.sciproject.funding_hide.title = Hide funding text input
com.arsdigita.cms.contenttypes.sciproject.funding_hide.purpose = Hide the funding text inpu
com.arsdigita.cms.contenttypes.sciproject.funding_hide.example = false
com.arsdigita.cms.contenttypes.sciproject.funding_hide.format = [boolean]
com.arsdigita.cms.contenttypes.sciproject.funding_dhtml.title = Toggles the DHTML for funding
com.arsdigita.cms.contenttypes.sciproject.funding_dhtml.purpose = Toggles the DHTML editor
com.arsdigita.cms.contenttypes.sciproject.funding_dhtml.example = false
com.arsdigita.cms.contenttypes.sciproject.funding_dhtml.format = [boolean]
com.arsdigita.cms.contenttypes.sciproject.materials_hide.title = Hides the step for linking materials with a project
com.arsdigita.cms.contenttypes.sciproject.materials_hide.purpose = Hides the step for linking materials with a project
com.arsdigita.cms.contenttypes.sciproject.materials_hide.example = false
com.arsdigita.cms.contenttypes.sciproject.materials_hide.format = [boolean]
com.arsdigita.cms.contenttypes.sciorganization.persons_hide.title = Hides the persons step for SciOrganization
com.arsdigita.cms.contenttypes.sciorganization.persons_hide.purpose = Hides the persons step for SciOrganization
com.arsdigita.cms.contenttypes.sciorganization.persons_hide.example = true
com.arsdigita.cms.contenttypes.sciorganization.persons_hide.format = [boolean]

View File

@ -48,6 +48,13 @@ public class SciProject extends GenericOrganizationalUnit {
public static final String BASE_DATA_OBJECT_TYPE =
"com.arsdigita.cms.contenttypes.SciProject";
private static final SciOrganizationConfig s_config =
new SciOrganizationConfig();
static {
s_config.load();
}
public SciProject() {
super(BASE_DATA_OBJECT_TYPE);
}
@ -68,6 +75,10 @@ public class SciProject extends GenericOrganizationalUnit {
super(type);
}
public static final SciOrganizationConfig getConfig() {
return s_config;
}
public Date getBegin() {
return (Date) get(BEGIN);
}

View File

@ -2,10 +2,12 @@ package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.event.FormInitListener;
import com.arsdigita.bebop.event.FormProcessListener;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.form.TextArea;
import com.arsdigita.bebop.parameters.ParameterModel;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.ItemSelectionModel;
@ -17,23 +19,43 @@ import com.arsdigita.cms.ui.authoring.BasicItemForm;
*
* @author Jens Pelzetter
*/
public class SciProjectEditDescForm
public class SciProjectDescriptionEditForm
extends BasicItemForm
implements FormProcessListener,
FormInitListener {
public SciProjectEditDescForm(ItemSelectionModel itemModel) {
public SciProjectDescriptionEditForm(ItemSelectionModel itemModel) {
super("sciprojectEditDescForm", itemModel);
}
@Override
protected void addWidgets() {
add(new Label(SciOrganizationGlobalizationUtil.globalize(
"sciorganizazion.ui.project.description")));
ParameterModel descParam = new StringParameter(
SciProject.PROJECT_DESCRIPTION);
CMSDHTMLEditor desc = new CMSDHTMLEditor(descParam);
desc.setCols(75);
desc.setRows(25);
add(desc);
if (!SciProject.getConfig().getProjectFundingHide()) {
add(new Label(SciOrganizationGlobalizationUtil.globalize(
"sciorganizazion.ui.project.funding")));
ParameterModel fundingParam = new StringParameter(
SciProject.FUNDING);
TextArea funding;
if (SciProject.getConfig().getProjectFundingDhtml()) {
funding = new CMSDHTMLEditor(fundingParam);
} else {
funding = new TextArea(fundingParam);
}
funding.setCols(75);
funding.setRows(25);
add(funding);
}
}
@Override
@ -46,6 +68,9 @@ public class SciProjectEditDescForm
data.put(SciProject.PROJECT_DESCRIPTION,
project.getProjectDescription());
if (!SciProject.getConfig().getProjectFundingHide()) {
data.put(SciProject.FUNDING, project.getFunding());
}
setVisible(state, true);
}
@ -62,6 +87,10 @@ public class SciProjectEditDescForm
isSelected(state)) {
project.setProjectDescription((String) data.get(
SciProject.PROJECT_DESCRIPTION));
if (!SciProject.getConfig().getProjectFundingHide()) {
project.setFunding((String) data.get(
SciProject.FUNDING));
}
project.save();

View File

@ -1,6 +1,7 @@
package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.Form;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.contenttypes.SciProject;
import com.arsdigita.cms.ui.authoring.AuthoringKitWizard;
@ -16,6 +17,7 @@ import com.arsdigita.toolbox.ui.DomainObjectPropertySheet;
public class SciProjectDescriptionStep extends SimpleEditStep {
private String EDIT_PROJECT_DESC_SHEET_NAME = "editProjectDesc";
private String UPLOAD_PROJECT_DESC_SHEET_NAME = "uploadProjectDesc";
public SciProjectDescriptionStep(ItemSelectionModel itemModel,
AuthoringKitWizard parent) {
@ -27,13 +29,22 @@ public class SciProjectDescriptionStep extends SimpleEditStep {
String prefix) {
super(itemModel, parent, prefix);
BasicItemForm editDescForm = new SciProjectEditDescForm(itemModel);
BasicItemForm editDescForm =
new SciProjectDescriptionEditForm(itemModel);
add(EDIT_PROJECT_DESC_SHEET_NAME,
(String) SciOrganizationGlobalizationUtil.globalize(
"sciorganization.ui.project.edit_desc").localize(),
new WorkflowLockedComponentAccess(editDescForm, itemModel),
editDescForm.getSaveCancelSection().getCancelButton());
SciProjectDescriptionUploadForm uploadDescForm =
new SciProjectDescriptionUploadForm(itemModel);
add(UPLOAD_PROJECT_DESC_SHEET_NAME,
(String) SciOrganizationGlobalizationUtil.globalize(
"sciorganization.ui.project.upload_desc").localize(),
new WorkflowLockedComponentAccess(uploadDescForm, itemModel),
uploadDescForm.getSaveCancelSection().getCancelButton());
setDisplayComponent(
getSciProjectEditDescSheet(itemModel));
@ -45,8 +56,11 @@ public class SciProjectDescriptionStep extends SimpleEditStep {
itemModel);
sheet.add(SciOrganizationGlobalizationUtil.globalize(
"sciorganizaztion.ui.project.desc"),
"sciorganization.ui.project.desc"),
SciProject.PROJECT_DESCRIPTION);
sheet.add(SciOrganizationGlobalizationUtil.globalize(
"sciorganization.ui.project.funding"),
SciProject.FUNDING);
return sheet;
}

View File

@ -0,0 +1,236 @@
package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.bebop.BoxPanel;
import com.arsdigita.bebop.Form;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.RequestLocal;
import com.arsdigita.bebop.SaveCancelSection;
import com.arsdigita.bebop.event.FormInitListener;
import com.arsdigita.bebop.event.FormProcessListener;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.event.FormValidationListener;
import com.arsdigita.bebop.form.FormErrorDisplay;
import com.arsdigita.bebop.parameters.NotNullValidationListener;
import com.arsdigita.bebop.util.GlobalizationUtil;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.contenttypes.SciProject;
import com.arsdigita.cms.ui.FileUploadSection;
import com.arsdigita.globalization.Globalization;
import com.arsdigita.kernel.Kernel;
import com.arsdigita.mimetypes.MimeType;
import com.arsdigita.mimetypes.MimeTypeStatus;
import com.arsdigita.mimetypes.TextMimeType;
import com.arsdigita.mimetypes.converters.ConvertFormat;
import com.arsdigita.util.UncheckedWrapperException;
import java.io.File;
import java.io.FileInputStream;
import java.io.UnsupportedEncodingException;
import org.apache.log4j.Logger;
/**
*
* @author Jens Pelzetter
*/
public class SciProjectDescriptionUploadForm
extends Form
implements FormInitListener,
FormProcessListener,
FormValidationListener {
private ItemSelectionModel m_itemModel;
private FileUploadSection m_fileUploadSection;
private SaveCancelSection m_saveCancelSection;
private RequestLocal m_fileUploadContent;
private RequestLocal m_fileUploadContentUsedInso;
private Logger s_log = Logger.getLogger(
SciProjectDescriptionUploadForm.class);
public SciProjectDescriptionUploadForm(ItemSelectionModel itemModel) {
super("sciprojectUploadDescFrom", new BoxPanel(BoxPanel.VERTICAL));
m_itemModel = itemModel;
setMethod(Form.POST);
setEncType("multipart/form-data");
m_fileUploadContent = new RequestLocal();
m_fileUploadContentUsedInso = new RequestLocal();
addWidgets();
}
protected void addWidgets() {
add(new Label(SciOrganizationGlobalizationUtil.globalize(
"sciorganization.ui.project.description.upload")));
m_fileUploadSection = new FileUploadSection(
SciOrganizationGlobalizationUtil.globalize(
"sciorganization.ui.project.description.upload.mimetype"),
"mime",
"text/plain");
m_fileUploadSection.getFileUploadWidget().addValidationListener(
new NotNullValidationListener());
m_fileUploadSection.getMimeTypeWidget().setDefaultValue(
FileUploadSection.GUESS_MIME);
add(m_fileUploadSection);
m_saveCancelSection = new SaveCancelSection();
add(m_saveCancelSection);
add(new FormErrorDisplay(this));
this.addValidationListener(this);
this.addProcessListener(this);
}
/**
* @return the save/cancel section for this form
*/
public SaveCancelSection getSaveCancelSection() {
return m_saveCancelSection;
}
@Override
public void init(FormSectionEvent fse) throws FormProcessException {
PageState state = fse.getPageState();
setVisible(state, true);
}
/**
* Validate file upload
* @param e
* @throws FormProcessException
*/
@Override
public void validate(FormSectionEvent e) throws FormProcessException {
MimeType mime = m_fileUploadSection.getMimeType(e);
boolean textType = mime.getPrefix().equals(TextMimeType.TEXT_PREFIX);
validateFileType(mime, textType);
// Convert the file to HTML, if possible
File file = m_fileUploadSection.getFile(e);
byte[] file_bytes = readFileBytes(file);
boolean[] used_inso = new boolean[1];
String file_content = convertBytes(file_bytes, textType, used_inso);
if (TextMimeType.MIME_TEXT_HTML.equals(mime.getMimeType())) {
file_content = extractHTMLBody(file_content);
}
PageState state = e.getPageState();
m_fileUploadContent.set(state, file_content);
m_fileUploadContentUsedInso.set(state, used_inso[0]);
}
@Override
public void process(FormSectionEvent fse) throws FormProcessException {
s_log.debug("Processing upload...");
PageState state = fse.getPageState();
//File file = m_fileUploadSection.getFile(fse);
SciProject project = (SciProject) m_itemModel.getSelectedObject(state);
String uploadContent = (String) m_fileUploadContent.get(state);
//boolean usedInso = (Boolean) m_fileUploadContentUsedInso.get(state);
s_log.debug(String.format("Setting project description to: %s",
uploadContent));
project.setProjectDescription(uploadContent);
s_log.debug("Saving project.");
project.save();
}
private void validateFileType(MimeType mime, boolean textType)
throws FormProcessException {
boolean validType = textType || ((mime instanceof TextMimeType) && ((TextMimeType) mime).
allowINSOConvert().booleanValue());
if (!validType) {
throw new FormProcessException("Cannot load " + "files of type " + mime.
getMimeType() + " into the article body.");
} else {
boolean insoWorks = MimeTypeStatus.getMimeTypeStatus().
getInsoFilterWorks().intValue() == 1;
if (!textType && !insoWorks) {
// Can't convert. inso filter is not working. Give message.
throw new FormProcessException(
"Could not convert to html "
+ "format because interMedia INSO filter is not installed.");
}
}
}
/**
* read in the content of the file (in bytes).
*/
private byte[] readFileBytes(File file) throws FormProcessException {
byte[] file_bytes;
try {
FileInputStream fs = new FileInputStream(file);
file_bytes = new byte[fs.available()];
fs.read(file_bytes);
fs.close();
} catch (Exception e) {
throw new FormProcessException(
((String) GlobalizationUtil.globalize(
"cms.ui.authoring.unable_to_load_file").
localize()).concat(e.getMessage()));
}
return file_bytes;
}
/**
* Convert bytes to String, possibly using INSO filter to convert to
* HTML type
*/
private String convertBytes(byte[] file_bytes, boolean text_type,
boolean[] used_inso)
throws FormProcessException {
String file_content;
// If mime type is not text type, try to convert to html
if (!text_type) {
file_content = ConvertFormat.toHTML(file_bytes);
if (file_content != null) {
// Converted successfully, flag type should be html
used_inso[0] = true;
} else {
throw new FormProcessException(
"Could not convert to html format. "
+ "interMedia INSO filter conversion failed.");
}
} else {
// Text type, no need to convert
String enc = Globalization.getDefaultCharset(Kernel.getContext().
getLocale());
try {
file_content = new String(file_bytes, enc);
} catch (UnsupportedEncodingException ex) {
throw new UncheckedWrapperException("cannot convert to encoding "
+ enc, ex);
}
used_inso[0] = false;
}
return file_content;
}
/**
* Extract the contents of the html Body tag.
* (Done to prevent base and other header tags
* from interfering with page display).
*/
private String extractHTMLBody(String htmlText)
throws FormProcessException {
String lc = htmlText.toLowerCase();
int bodyStart = lc.indexOf("<body");
int bodyStart_v = lc.indexOf(">", bodyStart);
int bodyEnd = lc.indexOf("</body>", bodyStart_v);
if (bodyStart == -1 || bodyEnd == -1) {
final String errMsg =
"The file (which should be type "
+ "HTML) is missing the <body> or </body> tag.";
throw new FormProcessException(errMsg);
}
return htmlText.substring(bodyStart_v + 1, bodyEnd);
}
}

View File

@ -1,67 +0,0 @@
package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.event.FormInitListener;
import com.arsdigita.bebop.event.FormProcessListener;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.parameters.ParameterModel;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.contenttypes.SciProject;
import com.arsdigita.cms.ui.CMSDHTMLEditor;
import com.arsdigita.cms.ui.authoring.BasicItemForm;
/**
*
* @author Jens Pelzetter
*/
public class SciProjectFundingForm
extends BasicItemForm
implements FormProcessListener,
FormInitListener {
public SciProjectFundingForm(ItemSelectionModel itemModel) {
super("sciprojectEditFundingForm", itemModel);
}
@Override
protected void addWidgets() {
ParameterModel fundingParam = new StringParameter(
SciProject.FUNDING);
CMSDHTMLEditor funding = new CMSDHTMLEditor(fundingParam);
funding.setCols(75);
funding.setRows(25);
add(funding);
}
@Override
public void init(FormSectionEvent fse) throws FormProcessException {
PageState state = fse.getPageState();
FormData data = fse.getFormData();
SciProject project = (SciProject) getItemSelectionModel().
getSelectedObject(state);
data.put(SciProject.FUNDING, project.getFunding());
}
@Override
public void process(FormSectionEvent fse) throws FormProcessException {
PageState state = fse.getPageState();
FormData data = fse.getFormData();
SciProject project = (SciProject) getItemSelectionModel().
getSelectedObject(state);
if ((project != null) && this.getSaveCancelSection().getSaveButton().
isSelected(state)) {
project.setFunding((String) data.get(SciProject.FUNDING));
project.save();
init(fse);
}
}
}

View File

@ -1,52 +0,0 @@
package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.bebop.Component;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.contenttypes.SciProject;
import com.arsdigita.cms.ui.authoring.AuthoringKitWizard;
import com.arsdigita.cms.ui.authoring.BasicItemForm;
import com.arsdigita.cms.ui.authoring.SimpleEditStep;
import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess;
import com.arsdigita.toolbox.ui.DomainObjectPropertySheet;
/**
*
* @author Jens Pelzetter
*/
public class SciProjectFundingStep extends SimpleEditStep {
private String EDIT_FUNDING_SHEET_NAME = "editFunding";
public SciProjectFundingStep(ItemSelectionModel itemModel,
AuthoringKitWizard parent) {
this(itemModel, parent, null);
}
public SciProjectFundingStep(ItemSelectionModel itemModel,
AuthoringKitWizard parent,
String prefix) {
super(itemModel, parent, prefix);
BasicItemForm editFundingForm = new SciProjectFundingForm(itemModel);
add(EDIT_FUNDING_SHEET_NAME,
(String) SciOrganizationGlobalizationUtil.globalize(
"sciorganization.ui.project.edit_funding").localize(),
new WorkflowLockedComponentAccess(editFundingForm, itemModel),
editFundingForm.getSaveCancelSection().getCancelButton());
setDisplayComponent(
getSciProjectFundingSheet(itemModel));
}
public static Component getSciProjectFundingSheet(
ItemSelectionModel itemModel) {
DomainObjectPropertySheet sheet = new DomainObjectPropertySheet(
itemModel);
sheet.add(SciOrganizationGlobalizationUtil.globalize(
"sciorganization.ui.project.funding"),
SciProject.FUNDING);
return sheet;
}
}

View File

@ -14,7 +14,6 @@ import com.arsdigita.bebop.parameters.ParameterModel;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.contenttypes.SciProject;
import com.arsdigita.cms.ui.CMSDHTMLEditor;
import java.util.Calendar;
import java.util.GregorianCalendar;
@ -64,27 +63,9 @@ public class SciProjectPropertyForm
ParameterModel shortDescParam = new StringParameter(
SciProject.PROJECT_SHORT_DESCRIPTION);
TextArea shortDesc = new TextArea(shortDescParam);
shortDesc.setCols(60);
shortDesc.setRows(20);
shortDesc.setCols(75);
shortDesc.setRows(5);
add(shortDesc);
/*add(new Label(SciOrganizationGlobalizationUtil.globalize(
"sciorganization.ui.project.description")));
ParameterModel descParam = new StringParameter(
SciProject.PROJECT_DESCRIPTION);
CMSDHTMLEditor desc = new CMSDHTMLEditor(descParam);
desc.setCols(75);
desc.setRows(25);
add(desc);*/
/*add(new Label(SciOrganizationGlobalizationUtil.globalize(
"sciorganization.ui.project.funding")));
ParameterModel fundingParam = new StringParameter(
SciProject.FUNDING);
CMSDHTMLEditor funding = new CMSDHTMLEditor(fundingParam);
funding.setCols(60);
funding.setRows(18);
add(funding);*/
}
@Override