Verbesserung Localization xmlfeed und setHint() mit GlobalizedMessage.

git-svn-id: https://svn.libreccm.org/ccm/trunk@2240 8810af33-2d31-482b-a856-94f89814c4df
master
pb 2013-07-02 10:32:58 +00:00
parent 27aed37070
commit 42a4e3f278
10 changed files with 188 additions and 45 deletions

View File

@ -1,21 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<ctd:content-types xmlns:ctd="http://xmlns.redhat.com/cms/content-types" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.redhat.com/cms/content-types content-types.xsd">
<ctd:content-types xmlns:ctd="http://xmlns.redhat.com/cms/content-types"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.redhat.com/cms/content-types content-types.xsd">
<ctd:content-type label="XML Feed"
description="Form for querying a remote XML service"
objectType="com.arsdigita.cms.contenttypes.xmlfeed.XMLFeed"
classname="com.arsdigita.cms.contenttypes.xmlfeed.XMLFeed">
<ctd:authoring-kit createComponent="com.arsdigita.cms.ui.authoring.PageCreate">
<ctd:authoring-step label="Basic Properties"
description="Edit the basic properties"
component="com.arsdigita.cms.contenttypes.xmlfeed.ui.XMLFeedProperties" />
<ctd:authoring-step label="Styling"
description="The XSL file that transforms the XML feed into bebop XML or HTML."
component="com.arsdigita.cms.contenttypes.xmlfeed.ui.XSLFileProperties" />
<ctd:authoring-step label="Query Form"
description="The form that supplies the query fields."
component="com.arsdigita.cms.ui.formbuilder.FormControls" />
<ctd:include href="/WEB-INF/content-types/shared.xml"/>
<ctd:authoring-step
label="Basic Properties"
labelKey="cms.contenttypes.shared.basic_properties.title"
labelBundle="com.arsdigita.cms.CMSResources"
descriptionKey="cms.contenttypes.shared.basic_properties.description"
descriptionBundle="com.arsdigita.cms.CMSResources"
description="Edit the basic properties"
component="com.arsdigita.cms.contenttypes.xmlfeed.ui.XMLFeedProperties"
ordering="1"/>
<!-- Styling Step label="Styling" -->
<ctd:authoring-step
labelKey="xmlfeed.authoring.styling_step.title"
labelBundle="com.arsdigita.cms.contenttypes.xmlfeed.XMLFeedResources"
descriptionKey="xmlfeed.authoring.styling_step.description"
descriptionBundle="com.arsdigita.cms.contenttypes.xmlfeed.XMLFeedResources"
component="com.arsdigita.cms.contenttypes.xmlfeed.ui.XSLFileProperties"
ordering="2"/>
<!-- Query Form Step label="Query Form" -->
<ctd:authoring-step
labelKey="xmlfeed.authoring.query_form_step.title"
labelBundle="com.arsdigita.cms.contenttypes.xmlfeed.XMLFeedResources"
descriptionKey="xmlfeed.authoring.query_form.description"
descriptionBundle="com.arsdigita.cms.contenttypes.xmlfeed.XMLFeedResources"
component="com.arsdigita.cms.ui.formbuilder.FormControls"
ordering="3" />
<ctd:include href="/WEB-INF/content-types/shared.xml"/>
</ctd:authoring-kit>
</ctd:content-type>
</ctd:content-types>

View File

@ -0,0 +1,13 @@
cms.contenttypes.ui.xmlfeed.xsl_file_upload=Upload the XSL file
cms.contenttypes.ui.xmlfeed.xsl_file=XSL File
#URL:
cms.contenttypes.ui.xmlfeed.feed_url=Feed URL:
cms.contenttypes.ui.xmlfeed.url=URL:
cms.contenttypes.ui.xmlfeed.feed_url_hint=Enter the URL of the feed, eg http://freesoftware.org/xml/education.php
cms.contenttypes.ui.xmlfeed.xsl_file_type=File Type
xmlfeed.authoring.styling_step.title=Edit Styling
xmlfeed.authoring.styling_step.description=Upload the XSL file that transforms the XML feed into bebop XML or HTML.
xmlfeed.authoring.query_form_step.title=Edit Query Form
xmlfeed.authoring.query_form.description=The form that supplies the query fields.
cms.contenttypes.ui.xmlfeed.xsl_file_type_error=File is not the correct type.
cms.contenttypes.ui.xmlfeed.xsl_file_validation_error=Cannot verify the file is valid, please try again.

View File

@ -0,0 +1,13 @@
cms.contenttypes.ui.xmlfeed.xsl_file_upload=XSL Datei hochladen
cms.contenttypes.ui.xmlfeed.xsl_file=XSL Datei
#URL:
cms.contenttypes.ui.xmlfeed.feed_url=Feed URL:
cms.contenttypes.ui.xmlfeed.url=URL:
cms.contenttypes.ui.xmlfeed.feed_url_hint=Geben Sie die URL des Feed, z.B. http://freesoftware.org/xml/education.php
cms.contenttypes.ui.xmlfeed.xsl_file_type=Datei Typ
xmlfeed.authoring.styling_step.title=Design bearbeiten
xmlfeed.authoring.styling_step.description=XSL Datei hochladen, die den XML Feed in Bebop xml oder HTML transformiert.
xmlfeed.authoring.query_form_step.title=Abfrageformular bearbeiten
xmlfeed.authoring.query_form.description=Das Formular, das die Eingabefelder f\u00fcr die Abfrage enth\u00e4lt.
cms.contenttypes.ui.xmlfeed.xsl_file_type_error=Der Dateityp ist falsch.
cms.contenttypes.ui.xmlfeed.xsl_file_validation_error=Dateityp kann nicht best\u00e4tigt werden, bitte erneut probieren.

View File

@ -131,7 +131,7 @@ public class RetrieveListener implements FormProcessListener{
String value = (String) data.get(field);
if (s_log.isDebugEnabled()) {
s_log.debug("Addng parameter " + field + " -> " + value);
s_log.debug("Adding parameter " + field + " -> " + value);
}
params.setParameter(field.trim(), value.trim());
}

View File

@ -30,6 +30,7 @@ import com.arsdigita.cms.ui.authoring.AuthoringKitWizard;
import com.arsdigita.cms.ui.authoring.BasicPageForm;
import com.arsdigita.cms.ui.formbuilder.FormProperties;
import com.arsdigita.cms.contenttypes.xmlfeed.XMLFeed;
import com.arsdigita.cms.contenttypes.xmlfeed.util.XMLFeedGlobalizationUtil;
public class XMLFeedProperties extends FormProperties {
@ -62,10 +63,11 @@ public class XMLFeedProperties extends FormProperties {
super.addWidgets();
m_url = new TextField(new StringParameter("url"));
m_url.setHint("Enter the URL of the feed, " +
"eg http://upmystreet.co.uk/xml/education.php3");
m_url.setHint(XMLFeedGlobalizationUtil.globalize(
"cms.contenttypes.ui.xmlfeed.feed_url_hint"));
m_url.setSize(50);
add(new Label("Feed URL:"));
add(new Label(XMLFeedGlobalizationUtil.globalize(
"cms.contenttypes.ui.xmlfeed.feed_url")) );
add(m_url);
}
@ -91,7 +93,9 @@ public class XMLFeedProperties extends FormProperties {
public XMLFeedPropertySheet(ItemSelectionModel model) {
super(model);
add("URL:", XMLFeed.URL);
add(XMLFeedGlobalizationUtil.globalize(
"cms.contenttypes.ui.xmlfeed.url"),
XMLFeed.URL);
}
}

View File

@ -17,7 +17,6 @@
package com.arsdigita.cms.contenttypes.xmlfeed.ui;
import com.arsdigita.cms.contenttypes.xmlfeed.XMLFeed;
import com.arsdigita.bebop.ColumnPanel;
import com.arsdigita.bebop.Form;
@ -26,43 +25,32 @@ import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.Resettable;
import com.arsdigita.bebop.SaveCancelSection;
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.form.Option;
import com.arsdigita.bebop.form.SingleSelect;
import com.arsdigita.bebop.parameters.NotNullValidationListener;
import com.arsdigita.cms.FileAsset;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.mimetypes.MimeType;
import com.arsdigita.cms.contenttypes.xmlfeed.XMLFeed;
import com.arsdigita.cms.contenttypes.xmlfeed.util.XMLFeedGlobalizationUtil;
import com.arsdigita.cms.ui.FileUploadSection;
import com.arsdigita.cms.ui.SecurityPropertyEditor;
import com.arsdigita.cms.ui.authoring.AuthoringKitWizard;
import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess;
import com.arsdigita.toolbox.ui.DomainObjectPropertySheet;
import com.arsdigita.mimetypes.MimeType;
import com.arsdigita.templating.XSLTemplate;
import com.arsdigita.templating.Templating;
import com.arsdigita.toolbox.ui.DomainObjectPropertySheet;
import com.arsdigita.util.UncheckedWrapperException;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.MalformedURLException;
import org.apache.log4j.Logger;
@ -78,13 +66,13 @@ import org.apache.log4j.Logger;
* {@link com.arsdigita.aplaws.xmlfeed.XmlFeedInitializer XmlFeedInitializer}
* </p>
*
* @see com.arsdigita.aplaws.xmlfeed.XmlFeedInitializer
*
* @author <a href="mailto:miles@runtime-collective.com">Miles Barr</a>
* @version $Id: XSLFileProperties.java 755 2005-09-02 13:42:47Z sskracic $
*
* @see com.arsdigita.aplaws.xmlfeed.XmlFeedInitializer
*/
public final class XSLFileProperties extends SecurityPropertyEditor
implements Resettable {
implements Resettable {
/** The logger object for this class. */
private static Logger s_log = Logger.getLogger(XSLFileProperties.class);
@ -114,14 +102,18 @@ public final class XSLFileProperties extends SecurityPropertyEditor
// Set up the form that actually allows the uploading of the XSL
XSLFilePropertiesForm form = new XSLFilePropertiesForm(itemModel);
add(FILE_UPLOAD, "Upload the XSL file",
add(FILE_UPLOAD,
XMLFeedGlobalizationUtil.globalize(
"cms.contenttypes.ui.xmlfeed.xsl_file_upload"),
new WorkflowLockedComponentAccess(form, itemModel),
form.getSaveCancelSection().getCancelButton());
// Specify full path to properties of the XSL file.
DomainObjectPropertySheet sheet =
new DomainObjectPropertySheet(itemModel);
sheet.add("XSL File", XMLFeed.XSL_FILE + ".name");
sheet.add(XMLFeedGlobalizationUtil.globalize(
"cms.contenttypes.ui.xmlfeed.xsl_file"),
XMLFeed.XSL_FILE + ".name");
setDisplayComponent(sheet);
@ -200,7 +192,11 @@ public final class XSLFileProperties extends SecurityPropertyEditor
// Set up the file upload widget.
m_fileUploadSection =
new FileUploadSection("File Type","application", MIME_TYPE);
new FileUploadSection(
XMLFeedGlobalizationUtil.globalize(
"cms.contenttypes.ui.xmlfeed.xsl_file_type"),
"application",
MIME_TYPE);
m_fileUploadSection.getFileUploadWidget()
.addValidationListener(new NotNullValidationListener());
@ -297,6 +293,7 @@ public final class XSLFileProperties extends SecurityPropertyEditor
* the form of a standard url.
*/
public void validate(FormSectionEvent e) throws FormProcessException {
FormData data = e.getFormData();
// Verify the file is an XML document.
@ -306,7 +303,10 @@ public final class XSLFileProperties extends SecurityPropertyEditor
XSLTemplate xsl = Templating.getTemplate(url);
} catch (UncheckedWrapperException ex) {
s_log.error("cannot instantiate XSL file", ex);
data.addError("Cannot verify the file is valid, please try again.");
data.addError(XMLFeedGlobalizationUtil.globalize(
"cms.contenttypes.ui.xmlfeed.xsl_file_validation_error")
// "Cannot verify the file is valid, please try again."
);
} catch (MalformedURLException ex) {
throw new UncheckedWrapperException("bad filename " + file, ex);
}
@ -319,7 +319,10 @@ public final class XSLFileProperties extends SecurityPropertyEditor
boolean isCorrectType = MIME_TYPE.equals(mime.getPrefix());
if (!isCorrectType) {
data.addError("File is not the correct type.");
data.addError(XMLFeedGlobalizationUtil.globalize(
"cms.contenttypes.ui.xmlfeed.xsl_file_type_error") );
// "File is not the correct type.");
}
}
}

View File

@ -0,0 +1,71 @@
/*
* Copyright (C) 2013 Peter Boy, University of Bremen. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* 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.cms.contenttypes.xmlfeed.util;
import com.arsdigita.globalization.Globalized;
import com.arsdigita.globalization.GlobalizedMessage;
/**
* Compilation of methods to simplify the handling of globalizing keys.
* Basically it adds the name of package's resource bundle files to the
* globalize methods and forwards to GlobalizedMessage, shortening the
* method invocation in the various application classes.
*
* @author pb <pb@zes.uni-bremen.de>
*/
public class XMLFeedGlobalizationUtil {
/** Name of Java resource files to handle XMLFeed's globalisation. */
final public static String BUNDLE_NAME =
"com.arsdigita.cms.contenttypes.xmlfeed.XMLFeedResources";
/** Name of Java resource files to handle CMS globalisation. */
final public static String ALTERNATE_BUNDLE_NAME =
"com.arsdigita.cms.CMSResources";
/**
* Returns a globalized message using the appropriate bundle.
* If the key string contains the modules name xmlfeed the package specific
* bundle is used, otherwise the CMS ResourceBundle.
*/
public static GlobalizedMessage globalize(String key) {
if (key.indexOf(".xmlfeed.") > 0) {
return new GlobalizedMessage(key, BUNDLE_NAME);
} else {
return new GlobalizedMessage(key, ALTERNATE_BUNDLE_NAME);
}
}
/**
* Returns a globalized message object, using the approprate bundle,
* takeing in an Object[] of arguments to interpolate into the retrieved
* message using the MessageFormat class.
* If the key string contains the modules name xmlfeed the package specific
* bundle is used, otherwise the CMS ResourceBundle.
*/
public static GlobalizedMessage globalize(String key, Object[] args) {
if (key.indexOf(".xmlfeed.") > 0) {
return new GlobalizedMessage(key, BUNDLE_NAME, args);
} else {
return new GlobalizedMessage(key, ALTERNATE_BUNDLE_NAME, args);
}
}
}

View File

@ -189,7 +189,10 @@ public class FileUploadSection extends FormSection {
add(new Label(mimeLabel, false));
m_mimeWidget = new SingleSelect(getMimeTypeWidgetName());
addMimeOptions(m_mimeWidget, mimePrefix);
m_mimeWidget.addOption(new Option(GUESS_MIME, new Label(GlobalizationUtil.globalize("cms.ui.authoring.file_upload.auto_detect"))));
m_mimeWidget.addOption(new
Option(GUESS_MIME,
new Label(GlobalizationUtil.globalize(
"cms.ui.authoring.file_upload.auto_detect"))));
m_mimeWidget.setDefaultValue(GUESS_MIME);
add(m_mimeWidget);
@ -270,8 +273,8 @@ public class FileUploadSection extends FormSection {
* @param mimeLabel The label for the mime type widget
*
* @param mimePrefix Populate the mime type widget with all
* mime types that match the prefix. Some of the possible
* prefixes are "text", "image", "binary", etc.
* mime types that match the prefix. Some of the possible
* prefixes are "text", "image", "binary", etc.
*
* @param defaultMimeType The default mime type that should be
* assumed if the guessing fails
@ -301,7 +304,8 @@ public class FileUploadSection extends FormSection {
* assumed if the guessing fails
*
*/
public FileUploadSection(GlobalizedMessage mimeLabel, String mimePrefix,
public FileUploadSection(GlobalizedMessage mimeLabel,
String mimePrefix,
String defaultMimeType) {
this(mimeLabel, mimePrefix, defaultMimeType, "");
}

View File

@ -317,6 +317,7 @@ public class FormData implements Map, Cloneable {
*
* @param message a String of the error message
* @pre message != null
* @deprecated refactor and use addError(GlobalizedMessage) instead
*/
public void addError(String message) {
addError(new GlobalizedMessage(message));

View File

@ -376,10 +376,20 @@ public abstract class Widget extends BlockStylable implements Cloneable,
/**
* Sets a popup hint for the widget.
* @deprecated refactor to use a GlobalizedMessage instead and use
* setHint(GlobalizedMessage hint)
*/
public void setHint(String hint) {
Assert.isUnlocked(this);
setAttribute("title", hint);
setAttribute("hint", hint);
}
/**
* Sets a popup hint for the widget.
*/
public void setHint(GlobalizedMessage hint) {
Assert.isUnlocked(this);
setAttribute("hint", (String)hint.localize() );
}