Admin-Seite für Subsites benutzbar gemacht:

- Labels für die Formularfelder hinzugefügt
- ColumnPanel eingefügt, damit die Sachen untereinander stehen


git-svn-id: https://svn.libreccm.org/ccm/trunk@1858 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2012-09-12 07:22:36 +00:00
parent 79d89bfe00
commit 3157d2ea88
4 changed files with 221 additions and 158 deletions

View File

@ -15,9 +15,9 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.arsdigita.subsite.ui;
import com.arsdigita.bebop.ColumnPanel;
import com.arsdigita.bebop.Form;
import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.SaveCancelSection;
@ -37,6 +37,7 @@ import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.event.ParameterEvent;
import com.arsdigita.bebop.event.ParameterListener;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.parameters.NotNullValidationListener;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.bebop.parameters.ParameterData;
@ -65,7 +66,6 @@ import java.util.Iterator;
import org.apache.log4j.Logger;
/**
* Class creates the administration input form.
*
@ -76,10 +76,8 @@ public class SiteForm extends Form {
/** A logger instance. */
private static final Logger s_log = Logger.getLogger(SiteForm.class);
private SiteSelectionModel m_site;
private BigDecimal siteDefaultRootPageID;
/** Input field subsite title */
private TextField m_title;
private TextField m_hostname;
@ -89,15 +87,12 @@ public class SiteForm extends Form {
private CategoryPicker m_rootCategory;
private SingleSelect m_themes;
private SaveCancelSection m_buttons;
private final static String DEFAULT_APP = "DEFAULT_APP";
private final static String DEFAULT_APP_LABEL = "Site Wide Default ";
private final static String DEFAULT_STYLE = "DEFAULT_STYLE";
private final static String DEFAULT_STYLE_LABEL = "Site Wide Default ";
private final static String OTHER_STYLE = "OTHER_STYLE";
private final static String OTHER_STYLE_LABEL = "Other (type in box below)";
/**
* Constructor create input widgets and adds them to form.
@ -106,24 +101,26 @@ public class SiteForm extends Form {
* @param site
*/
public SiteForm(String name, SiteSelectionModel site) {
super(name, new SimpleContainer());
//super(name, new SimpleContainer());
super(name, new ColumnPanel(2));
setClassAttr("simpleForm");
setRedirecting(true);
m_site = site;
String defAppPath = UI.getRootPageURL() ;
s_log.debug("defAppPath is: " + defAppPath );
siteDefaultRootPageID =
Application.retrieveApplicationForPath(defAppPath )
.getID();
String defAppPath = UI.getRootPageURL();
s_log.debug("defAppPath is: " + defAppPath);
siteDefaultRootPageID =
Application.retrieveApplicationForPath(defAppPath)
.getID();
/* Setup text input field for subsite title property */
m_title = new TextField(new StringParameter("title"));
m_title.addValidationListener(new NotNullValidationListener());
m_title.setMetaDataAttribute("title", "Title");
m_title.setHint("Enter the title of the subsite, upto 80 characters");
m_title.setHint((String) SubsiteGlobalizationUtil.globalize("subsite.ui.title.hint").localize());
m_title.setSize(40);
add(new Label(SubsiteGlobalizationUtil.globalize("subsite.ui.title.label")));
add(m_title); // adds title input field to form
@ -133,52 +130,49 @@ public class SiteForm extends Form {
m_hostname.addValidationListener(new HostNameValidationListener());
m_hostname.setMetaDataAttribute("title", "Hostname");
m_hostname.setSize(40);
m_hostname.setHint(
"Enter the hostname for the subsite, eg business.example.com"
);
m_hostname.setHint((String) SubsiteGlobalizationUtil.globalize("subsite.ui.hostname.hint").localize());
add(new Label(SubsiteGlobalizationUtil.globalize("subsite.ui.hostname.label")));
add(m_hostname); // adds hostname input field to form
/* Setup text input area for description property */
m_description = new TextArea(new StringParameter("description"));
m_description.addValidationListener(new NotNullValidationListener());
m_description.setMetaDataAttribute("title", "Description");
m_description.setCols(45);
m_description.setRows(4);
m_description.setHint(
"Enter a short description for the subsite, upto 4000 characters"
);
m_description.setHint((String) SubsiteGlobalizationUtil.globalize("subsite.ui.description.hint").localize());
add(new Label(SubsiteGlobalizationUtil.globalize("subsite.ui.description.label")));
add(m_description); // adds description input field to form
/* Setup selection box for subsite start page (front page) Application
* by URL */
m_customFrontpageApp = new SingleSelect(
new StringParameter("customFrontpageApp"));
m_customFrontpageApp.setMetaDataAttribute("title",
"Front Page (url)");
new StringParameter("customFrontpageApp"));
m_customFrontpageApp.setMetaDataAttribute("title", "Front Page (url)");
// m_customFrontpageApp.setSize(40);
m_customFrontpageApp.setHint(
"Select the name (url) of the subsite custom homepage");
m_customFrontpageApp.setHint((String) SubsiteGlobalizationUtil.globalize("subsite.ui.customfrontpage.hint").
localize());
try {
m_customFrontpageApp.addPrintListener(new FrontpageAppListener());
} catch (TooManyListenersException ex) {
throw new UncheckedWrapperException("This cannot happen", ex);
}
add(new Label(SubsiteGlobalizationUtil.globalize("subsite.ui.customfrontpage.label")));
add(m_customFrontpageApp); // adds selectfield start page to form
/* Setup selection box for themes */
m_themes = new SingleSelect(new StringParameter("selectStyleDir"));
m_themes = new SingleSelect(new StringParameter("selectStyleDir"));
m_themes.setMetaDataAttribute("title", "XSLT Directory");
m_themes.setHint("Select an existing theme from the list, select" +
" 'Other' to type something below or select" +
" 'Site Wide Default' to get the default themes." );
m_themes.setHint((String) SubsiteGlobalizationUtil.globalize("subsite.ui.theme.hint").localize());
try {
m_themes.addPrintListener(new ThemesListener());
} catch (TooManyListenersException ex) {
throw new UncheckedWrapperException("This cannot happen", ex);
}
add(new Label(SubsiteGlobalizationUtil.globalize("subsite.ui.theme.label")));
add(m_themes); // adds themes selection box to form
@ -186,30 +180,32 @@ public class SiteForm extends Form {
m_styleDir = new TextField(new StringParameter("styleDir"));
m_styleDir.setMetaDataAttribute("title", "XSLT Directory (Other)");
m_styleDir.setSize(40);
m_styleDir.setHint( "Enter the directory for the custom XSLT styles, "
+"or leave blank for the default styling." );
m_styleDir.setHint("Enter the directory for the custom XSLT styles, or leave blank for the default styling.");
add(new Label(SubsiteGlobalizationUtil.globalize("subsite.ui.styledir.label")));
add(m_styleDir); // adds inputfield style dir to form
/* Setup selection box for cagtegory domain */
m_rootCategory = (CategoryPicker)Classes.newInstance(
Subsite.getConfig().getRootCategoryPicker(),
new Class[] { String.class },
new Object[] { "rootCategory" });
m_rootCategory = (CategoryPicker) Classes.newInstance(
Subsite.getConfig().getRootCategoryPicker(),
new Class[]{String.class},
new Object[]{"rootCategory"});
if (m_rootCategory instanceof Widget) {
((Widget)m_rootCategory)
.setMetaDataAttribute("title", "Root category");
((Widget)m_rootCategory)
.setHint("Select a root navigation category");
((Widget) m_rootCategory).setMetaDataAttribute("title", "Root category");
((Widget) m_rootCategory).setHint((String) SubsiteGlobalizationUtil.globalize(
"subsite.ui.root_category.hint").localize());
}
add(new Label(SubsiteGlobalizationUtil.globalize("subsite.ui.root_category.label")));
add(m_rootCategory); // adds domain category selection box to form
m_buttons = new SaveCancelSection();
m_buttons.getSaveButton().setButtonLabel(SubsiteGlobalizationUtil.globalize("subsite.ui.save"));
m_buttons.getSaveButton().setHint("Save the details in the form");
m_buttons.getCancelButton().setButtonLabel(SubsiteGlobalizationUtil.globalize("subsite.ui.cancel"));
m_buttons.getCancelButton().setHint("Abort changes & reset the form");
add(m_buttons);
addSubmissionListener(new SiteSubmissionListener());
addProcessListener(new SiteProcessListener());
@ -221,8 +217,9 @@ public class SiteForm extends Form {
*
*/
private class SiteSubmissionListener implements FormSubmissionListener {
public void submitted(FormSectionEvent e)
throws FormProcessException {
public void submitted(FormSectionEvent e)
throws FormProcessException {
PageState state = e.getPageState();
if (m_buttons.getCancelButton().isSelected(state)) {
@ -230,21 +227,22 @@ public class SiteForm extends Form {
throw new FormProcessException("cancel pressed");
}
}
}
/**
* Validate the subsite form user input.
*/
private class SiteValidationListener implements FormValidationListener {
public void validate(FormSectionEvent e) {
PageState state = e.getPageState();
if (!m_buttons.getCancelButton().isSelected(state)) {
FormData data = e.getFormData();
// make sure that if a theme was typed in that the "other"
// was selected in the theme selection box.
String styleDir = (String)m_styleDir.getValue(state);
String themeDir = (String)m_themes.getValue(state);
String styleDir = (String) m_styleDir.getValue(state);
String themeDir = (String) m_themes.getValue(state);
if (styleDir != null) {
styleDir = styleDir.trim();
}
@ -254,62 +252,56 @@ public class SiteForm extends Form {
// need to make sure the styleDir is null
if (OTHER_STYLE.equals(themeDir)) {
if (StringUtils.emptyString(styleDir)) {
data.addError(
"If you choose '" + OTHER_STYLE_LABEL +
"' for the XSL Directory Select then " +
"you need to provide a style in the Text Field");
data.addError(SubsiteGlobalizationUtil.globalize("subsite.ui.other_style_missing",
new String[]{OTHER_STYLE_LABEL}));
}
} else {
if (!StringUtils.emptyString(styleDir)) {
data.addError(
"In order to set a in the text field, " +
"the XSL Directory select box must say '" +
OTHER_STYLE_LABEL + "'");
data.addError(SubsiteGlobalizationUtil.globalize("subsite.ui.other_style_invalid",
new String[]{OTHER_STYLE_LABEL}));
}
}
/* Check whether a valid Root category has been selected. The
* default entry "-- pick one--" provides a null String
* ( null pointer exception). */
try {
Category testExist = m_rootCategory.getCategory(state);
String test = testExist.getDefaultDomainClass();
}
catch (Exception ex) {
data.addError(
"No valid category selected. Check category selection!");
} catch (Exception ex) {
data.addError(SubsiteGlobalizationUtil.globalize("subsite.ui.root_category_missing"));
}
} // End if (!m_buttons ...)
} // End validate(FormSectionEvent e)
}
/**
* Checks whether hostname is alreafy in use.
*/
private class HostNameValidationListener implements ParameterListener {
public void validate(ParameterEvent e) {
ParameterData data = e.getParameterData();
String hostname = (String)data.getValue();
String hostname = (String) data.getValue();
Site site = m_site.getSelectedSite(e.getPageState());
if (hostname != null && hostname.toString().length() > 0) {
DataCollection sites = SessionManager.getSession()
.retrieve(Site.BASE_DATA_OBJECT_TYPE);
sites.addEqualsFilter("lower("+Site.HOSTNAME+")",
.retrieve(Site.BASE_DATA_OBJECT_TYPE);
sites.addEqualsFilter("lower(" + Site.HOSTNAME + ")",
hostname.toLowerCase());
if (site != null) {
sites.addNotEqualsFilter(Site.ID, site.getID());
}
if (sites.size() > 0) {
data.addError(
"The host name " + hostname +
" is already used by another site");
data.addError(SubsiteGlobalizationUtil.globalize("subsite.ui.hostname_already_in_use"));
}
}
}
}
/**
@ -318,14 +310,14 @@ public class SiteForm extends Form {
* existing subsite or by creating a new one).
*/
private class SiteInitListener implements FormInitListener {
public void init(FormSectionEvent e)
throws FormProcessException {
public void init(FormSectionEvent e)
throws FormProcessException {
PageState state = e.getPageState();
Site site = m_site.getSelectedSite(state);
if (site == null) {
m_title.setValue(state, null);
m_hostname.setValue(state, null);
@ -338,16 +330,15 @@ public class SiteForm extends Form {
m_title.setValue(state, site.getTitle());
m_hostname.setValue(state, site.getHostname());
m_description.setValue(state, site.getDescription());
// BigDecimal siteDefaultRootPageID
BigDecimal currentFrontpageID = site.getFrontPage().getID();
s_log.debug(" Site default frontpage is: "+siteDefaultRootPageID
+", Current frontpage is: "+currentFrontpageID) ;
BigDecimal currentFrontpageID = site.getFrontPage().getID();
s_log.debug(" Site default frontpage is: " + siteDefaultRootPageID
+ ", Current frontpage is: " + currentFrontpageID);
m_customFrontpageApp.setValue(
state,
currentFrontpageID == siteDefaultRootPageID ?
DEFAULT_APP : currentFrontpageID.toString() );
currentFrontpageID == siteDefaultRootPageID ? DEFAULT_APP : currentFrontpageID.toString());
String styleURL = site.getStyleDirectory();
// if the value is in the config map, then styleDir is
// empty and themeDir gets the value. Otherwise, if the
@ -374,24 +365,25 @@ public class SiteForm extends Form {
m_rootCategory.setCategory(state, root);
}
}
}
/**
*
*/
private class SiteProcessListener implements FormProcessListener {
public void process(FormSectionEvent e)
throws FormProcessException {
public void process(FormSectionEvent e)
throws FormProcessException {
PageState state = e.getPageState();
Category root = m_rootCategory.getCategory(state);
Site site = m_site.getSelectedSite(state);
String style = (String)m_styleDir.getValue(state);
String theme = (String)m_themes.getValue(state);
String style = (String) m_styleDir.getValue(state);
String theme = (String) m_themes.getValue(state);
if (style != null) {
style = style.trim();
}
@ -401,121 +393,119 @@ public class SiteForm extends Form {
styleDir = theme;
}
}
/* Pre-process selected frontpage application: retrieve application */
String subsiteSelectedFrontpage = (String) m_customFrontpageApp
.getValue(state);
.getValue(state);
s_log.debug(" Site default frontpage ID is: " + siteDefaultRootPageID
+", selected frontpage Value is: "
+subsiteSelectedFrontpage) ;
Application frontpageApp ;
+ ", selected frontpage Value is: "
+ subsiteSelectedFrontpage);
Application frontpageApp;
if (subsiteSelectedFrontpage.equals(DEFAULT_APP)) {
s_log.debug("About to create frontpage app ID: " + DEFAULT_APP );
frontpageApp = Application
.retrieveApplication(siteDefaultRootPageID);
s_log.debug("About to create frontpage app ID: " + DEFAULT_APP);
frontpageApp = Application
.retrieveApplication(siteDefaultRootPageID);
} else {
s_log.debug("About to create frontpage app ID: "
+ subsiteSelectedFrontpage );
frontpageApp = Application
.retrieveApplication(new BigDecimal(subsiteSelectedFrontpage));
s_log.debug("About to create frontpage app ID: "
+ subsiteSelectedFrontpage);
frontpageApp = Application
.retrieveApplication(new BigDecimal(subsiteSelectedFrontpage));
}
Assert.exists(frontpageApp,Application.class);
s_log.debug("Created frontpage app ID: " + frontpageApp.getID() );
Assert.exists(frontpageApp, Application.class);
s_log.debug("Created frontpage app ID: " + frontpageApp.getID());
if (site == null) { // (sub)site not yet exists, create new one
if (!siteDefaultRootPageID.equals(frontpageApp.getID()) ) {
if (!siteDefaultRootPageID.equals(frontpageApp.getID())) {
// Previous version executed setRoot.... for newly created
// application, which were created for the purpose to serve
// as a dedicated front page application for the created
// subsite with an added comment:
// "NB, explicitly don't set cat on shared front page!"
s_log.debug("Front page application ID: "
+ frontpageApp.getID() );
s_log.debug("About to set cat on dedicated front page." );
Category.setRootForObject(frontpageApp,root);
s_log.debug("Front page application ID: "
+ frontpageApp.getID());
s_log.debug("About to set cat on dedicated front page.");
Category.setRootForObject(frontpageApp, root);
}
// actually create a new subsite
site = Site.create((String)m_title.getValue(state),
(String)m_description.getValue(state),
(String)m_hostname.getValue(state),
site = Site.create((String) m_title.getValue(state),
(String) m_description.getValue(state),
(String) m_hostname.getValue(state),
styleDir,
root,
frontpageApp);
} else { // (sub)site already exists, modify mutable configuration
site.setTitle((String)m_title.getValue(state));
site.setDescription((String)m_description.getValue(state));
site.setHostname((String)m_hostname.getValue(state));
site.setTitle((String) m_title.getValue(state));
site.setDescription((String) m_description.getValue(state));
site.setHostname((String) m_hostname.getValue(state));
site.setStyleDirectory(styleDir);
site.setRootCategory(root);
// XXX Check: Frontpage application was not mutable in previous
// version! Check if we explicitly have to handle cat whether
// or not frontpage is shared. See comment above!
site.setFrontPage(frontpageApp);
}
m_site.clearSelection(state);
Application app = Application
.retrieveApplicationForPath("/navigation/");
Category.setRootForObject(app,
root,
.retrieveApplicationForPath("/navigation/");
Category.setRootForObject(app,
root,
site.getTemplateContext().getContext());
}
}
/**
*
*/
private class FrontpageAppListener implements PrintListener {
public void prepare(PrintEvent e) {
final SingleSelect target = (SingleSelect)e.getTarget();
final SingleSelect target = (SingleSelect) e.getTarget();
// final PageState state = e.getPageState();
ApplicationCollection customApps ;
ApplicationCollection customApps;
// target.addOption(new Option(SELECT_APP, SELECT_APP_LABEL));
target.addOption(new Option(DEFAULT_APP, DEFAULT_APP_LABEL));
String[] customAppTypes = (String[])Subsite.getConfig()
.getFrontPageApplicationTypes();
if ( customAppTypes != null) {
for (int i=0; i < customAppTypes.length; i++) {
String[] customAppTypes = (String[]) Subsite.getConfig()
.getFrontPageApplicationTypes();
if (customAppTypes != null) {
for (int i = 0; i < customAppTypes.length; i++) {
customApps = Application.retrieveAllApplications(
customAppTypes[i]);
while(customApps.next()) {
/* Create an entry for each application, consisting
* of the (BigDecimal) ID as value and the URL as
* label. */
String appID = customApps.get(ACSObject.ID).toString() ;
target.addOption( new
Option(appID ,
( customApps.getPrimaryURL()
+"("+appID+")") ));
}
customAppTypes[i]);
while (customApps.next()) {
/* Create an entry for each application, consisting
* of the (BigDecimal) ID as value and the URL as
* label. */
String appID = customApps.get(ACSObject.ID).toString();
target.addOption(new Option(appID,
(customApps.getPrimaryURL()
+ "(" + appID + ")")));
}
}
}
}
}
/**
*
*/
private class ThemesListener implements PrintListener {
public void prepare(PrintEvent e) {
SingleSelect target = (SingleSelect)e.getTarget();
SingleSelect target = (SingleSelect) e.getTarget();
PageState state = e.getPageState();
Map themes = Subsite.getConfig().getThemes();
Set entrySet = themes.entrySet();
@ -523,7 +513,7 @@ public class SiteForm extends Form {
if (entrySet != null) {
Iterator entries = entrySet.iterator();
while (entries.hasNext()) {
Map.Entry entry = (Map.Entry)entries.next();
Map.Entry entry = (Map.Entry) entries.next();
target.addOption(new Option(entry.getKey().toString(),
entry.getValue().toString()),
state);
@ -531,6 +521,6 @@ public class SiteForm extends Form {
}
target.addOption(new Option(OTHER_STYLE, OTHER_STYLE_LABEL));
}
}
}

View File

@ -0,0 +1,27 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.arsdigita.subsite.ui;
import com.arsdigita.globalization.GlobalizedMessage;
/**
*
* @author Jens Pelzetter <jens@jp-digital.de>
* @version $Id$
*/
public class SubsiteGlobalizationUtil {
public static final String BUNDLE_NAME = "com.arsdigita.subsite.ui.SubsiteResources";
public static GlobalizedMessage globalize(final String key) {
return new GlobalizedMessage(key, BUNDLE_NAME);
}
public static GlobalizedMessage globalize(final String key,
final Object[] args) {
return new GlobalizedMessage(key, BUNDLE_NAME, args);
}
}

View File

@ -0,0 +1,23 @@
# To change this template, choose Tools | Templates
# and open the template in the editor.
subsite.ui.title.hint=Enter the title of the subsite, upto 80 characters
subsite.ui.title.label=Title
subsite.ui.hostname.hint=Enter the hostname for the subsite, eg business.example.com
subsite.ui.hostname.label=Hostname
subsite.ui.description.hint=Enter a short description for the subsite, up to 4000 characters
subsite.ui.description.label=Description
subsite.ui.customfrontpage.hint=Select the name (url) of the subsite custom homepage
subsite.ui.customfrontpage.label=Front Page
subsite.ui.theme.hint=Select an existing theme from the list, select 'Other' to type something below or select 'Site Wide Default' to get the default themes.
subsite.ui.theme.label=Theme
subsite.ui.styledir.hint=Enter the directory for the custom XSLT styles, or leave blank for the default styling.
subsite.ui.styledir.label=Custom XSL directory
subsite.ui.root_category.hint=Select a root navigation category for the subsite
subsite.ui.root_category.label=Root category
subsite.ui.save=Save
subsite.ui.cancel=Cancel
subsite.ui.other_style_missing=If you choose {0} for the theme you need to provide a style in the text field
subsite.ui.other_style_invalid=To set custom XSL directory select {0} in for the theme
subsite.ui.root_category_missing=No root category selected
subsite.ui.hostname_already_in\ use=The hostname {0} is already used by another subsite

View File

@ -0,0 +1,23 @@
# To change this template, choose Tools | Templates
# and open the template in the editor.
subsite.ui.title.hint=Geben Sie den Titel der Subsite ein. Der Titel darf max. 80 Zeichen lang sein.
subsite.ui.title.label=Titel
subsite.ui.hostname.hint=Geben Sie den hostname, z.B. business.example.com, ein
subsite.ui.hostname.label=Hostname
subsite.ui.description.hint=Geben sie hier eine kurze Beschreibung der Seite ein (max. 4000 Zeichen)
subsite.ui.description.label=Beschreibung
subsite.ui.customfrontpage.hint=W\u00e4hlen Sie den Startseite f\u00fcr die Subsite
subsite.ui.customfrontpage.label=Startseite
subsite.ui.theme.hint=W\u00e4hlen Sie ein existierendes Theme aus. Um ein anderes Theme im Eingabefeld anzugeben w\u00e4hlen 'Other'. Um das Standard-Theme zu verwenden w\u00e4hlen Sie 'Site-Wide-Default'
subsite.ui.theme.label=Theme
subsite.ui.styledir.hint=Geben Sie den Pfad zu einem Verzeichnis mit eigenen XSL-Styles an. Um die Standard-Styles zu verwenden, lassen Sie das Feld leer.
subsite.ui.styledir.label=Zus\u00e4tzliches XSL Verzeichnis
subsite.ui.root_category.hint=W\u00e4hlen Sie das Kategoriensystem f\u00fcr die Subsite
subsite.ui.root_category.label=Kategoriensystem
subsite.ui.save=Speichern
subsite.ui.cancel=Abbrechen
subsite.ui.other_style_missing=Wenn Sie {0} f\u00fcr das Theme w\u00e4hlen, m\u00fcssen Sie im Textfeld ein Theme angeben
subsite.ui.other_style_invalid=Um ein eigenes Verzeichnis mit XSL-Styles anzugeben, w\u00e4hlen Sie {0} f\u00fcr das Theme
subsite.ui.root_category_missing=Kein Kategoriensystem ausgew\u00e4hlt
subsite.ui.hostname_already_in\ use=Der Hostname {0} wird bereits von einer anderen Subsite verwendet