[opencms-dev] Locale macro in XSD schema

Arturo Martín Lladó arturo.martin.llado at gmail.com
Wed Mar 13 15:14:01 CET 2013


Glad to know :-)

Cheers!

--
Arturo Martín Lladó


2013/3/13 Christoph Fröhlich <cfauto at folge2.de>:
> Great. You made my day :)
>
> Am 04.03.2013 um 09:20 schrieb Arturo Martín Lladó
> <arturo.martin.llado at gmail.com>:
>
> Hi,
>
> I want to apologize about this issue. I was compiling my custum widget
> linking against OpenCms 8.5 JARs. That was the reason I couldn't get
> the breakpoints of some methods working on debug mode...
>
> I solved the locale issue this way:
>
> 1. In the XSD schema I added this:
>
> <xsd:annotation>
> <xsd:appinfo>
>    <resourcebundles>
>                <xmlbundle name="mypackage.contrato.xml">
>                    <bundle locale="ca">
>                        <resource
> key="mypackage.contrato.language">ca</resource>
>                    </bundle>
>                    <bundle locale="es">
>                        <resource
> key="mypackage.contrato.language">es</resource>
>                    </bundle>
>                </xmlbundle>
>            </resourcebundles>
> [...]
>
> <layouts>
>    <layout element="tipoContrato" widget="LocaleCategoryWidget"
> configuration="category=/_categories/%(key.mypackage.contrato.language)/tipoContrato/"
> />
> [...]
>
> 2. And this is the code for my custum category widget, extending from
> CmsCategoryWidget:
>
> public class CmsLocaleCategoryWidget extends CmsCategoryWidget {
>
> /**
> * Creates a new category widget.<p>
> */
>    public CmsLocaleCategoryWidget() {
>        // empty constructor is required for class registration
>        super();
>    }
>
>    /**
> * Creates a category widget with the specified options.<p>
> *
> * @param configuration the configuration for the widget
> */
>    public CmsLocaleCategoryWidget(String configuration) {
>        super(configuration);
>    }
>
> /**
> * @see org.opencms.widgets.I_CmsWidget#newInstance()
> */
>    public I_CmsWidget newInstance() {
>        return new CmsLocaleCategoryWidget(getConfiguration());
>    }
>
> /**
> * @see
> org.opencms.widgets.I_CmsADEWidget#getConfiguration(org.opencms.file.CmsObject,
> org.opencms.xml.types.A_CmsXmlContentValue,
> org.opencms.i18n.CmsMessages, org.opencms.file.CmsResource,
> java.util.Locale)
> */
>    public String getConfiguration(
>        CmsObject cms,
>        A_CmsXmlContentValue schemaType,
>        CmsMessages messages,
>        CmsResource resource,
>        Locale contentLocale) {
>
>     String result = super.getConfiguration(cms, schemaType, messages,
> resource, contentLocale);
>
>        ResourceBundle bundle =
> schemaType.getContentDefinition().getContentHandler().
> getMessages(contentLocale).getResourceBundle();
>        Set<String> keySet = bundle.keySet();
>
>        for (String bundleKey : keySet) {
>
>         // Resourcebundle's keys for OpenCms are specified this way:
> %(key.name.of.string)
>         String xsdKey = "%(key." + bundleKey +  ")";
>
>         if ( result.contains(xsdKey) )
>         result = result.replace(xsdKey, bundle.getString(bundleKey));
>
>        }
>
>        return result;
>
>    }
>
> }
>
> 3. Now, when editing the content, the starting category is shown
> according the locale we are editing at the moment
> (/_categories/es/tipoContrato/ or /_categories/ca/tipoContrato).
>
> I hope this can help to someone.
>
> Thanks a lot again, list.
>
> ================
> Arturo Martín Lladó
> ================
>
> 2013/2/18 Arturo Martín Lladó <arturo.martin.llado at gmail.com>:
>
> Hi again, Christoph:
>
> Thank you for your help!
>
> Now more things are happening, but the method getStartingCategory()
> stills not being called.
> I see that the methods that are being called using the widget are:
>
> - Empty constructor.
> - setConfiguration(java.lang.String configuration)
> - getConfiguration()
>
> I guess that I can do what I need inside setConfiguration. I'll keep
> you posted :-)
>
> Kind regards,
> Arturo.
>
> 2013/2/18 Christoph Fröhlich <cfauto at folge2.de>:
>
> Hi Arturo,
>
> sorry. I forgot that you have to overwrite
>
> newInstance()
>
> as well.
>
> /**
> * @see org.opencms.widgets.I_CmsWidget#newInstance()
> */
> public I_CmsWidget newInstance() {
>
> return new CmsLocaleCategoryWidget();
> }
>
> I hope this should do the trick.
>
> Regards
> Christoph
>
> Am 18.02.2013 um 12:05 schrieb Arturo Martín Lladó
> <arturo.martin.llado at gmail.com>:
>
> Hi, Christoph:
>
> It's really wierd. I have subclassed the widget like this:
>
> [...]
>
> public class CmsLocaleCategoryWidget extends CmsCategoryWidget {
>
> private static Log LOG = CmsLog.getLog(CmsLocaleCategoryWidget.class);
>
> public String getStartingCategory(CmsObject cms, java.lang.String
> referencePath) {
>
> LOG.error("== getStartingCategory, referencePath =>" + referencePath);
> LOG.error("== getStartingCategory =>" +
> super.getStartingCategory(cms, referencePath));
> return super.getStartingCategory(cms, referencePath);
>
> }
>
> }
>
> I also changed the XSD and opencms-vfs.xml in order to use the new widget.
>
> The "new" widget is rendered ok, showing categories, but I see no
> output in opencms.log. Even starting Tomcat on debug mode and adding a
> breakpoint on the method does not trigger anything. No stop in the
> method. It seems the method is not being called. I just don't get
> it...
>
> Thank you anyway for the help, Christoph. It is very welcome :-)
>
> Cheers.
>
> 2013/2/16 Christoph Fröhlich <cfauto at folge2.de>:
>
> HI Arturo,
>
> maybe you can create a custom widget by subclassing
> org.opencms.widgets.CmsCategoryWidget
>
>
> In the method
> getStartingCategory(CmsObject, String)
>
> you have access to the current locale. I think this should enable you to
> construct locale dependent starting categories.
>
> Regards
> Christoph
>
> Am 15.02.2013 um 17:51 schrieb Rüdiger Kurz <r.kurz at alkacon.com>:
>
> Hi,
>
> OK, enable the content managers to create categories and localize the
> display values is an argument. Anyway it would be better using the same
> taxonomy.
>
> If you have only two locales an 'ugly' workaround would be using two
> properties: simple and straight, but technical not clean. So why don't
> create an 'config' XSD that has multiple nested elements holding a category
> together with its display name. This will make it easy to edit the localized
> display values in a comfortable way for content managers and it would be
> technically clean.
>
> You could initialize this content with a Java Bean or what ever you need to
> make access easier than writing scriplet code.
>
> @Tobias, sorry but your mail comes in while I've already used the word
> 'ugly', anyway the property variant is simple and straight.
>
> regards
> Rüdiger
>
>
> Am 15.02.2013 17:18, schrieb Arturo Martín Lladó:
>
> Hi, Rüdiger.
>
> I can say it's a very original solution :-)
>
> Unfortunately, the categories should be administrated (and localized,
> they are siblings with different Title property) by the final users,
> and the edition of a Java properties file it's not a solution suitable
> for them.
>
> That's why we have a categories taxonomy like this:
>
> =====
> /_categories
>   ca
>       categories with locale "ca" configured as property by the parent
>       [...]
>   es
>       categories with locale "es" configured as property by the parent
>       [...]
> =====
>
> and that's why we'd like to offer to the final user a default category
> pointed using de "configuration" attribute of the CategoryWidget.
>
> Thank you anyway, Rüdiger. I really appreciate your help and any other
> tip about this problem will be very welcome.
>
> I guess that support for macros processing on the "configuration"
> attribute of the layout widgets could be part of the wishlist of the
> next release of OpenCms :-)
>
> Again, thanks for your help and have a nice weekend.
>
> Regards.
>
> 2013/2/15 Rüdiger Kurz <r.kurz at alkacon.com>:
>
> Hi,
>
> think you are right with your assumption. What you're trying to archive is
> localization of categories. I might be wrong, but I think that localizing
> categories,tags,facets,... does not make that much sense, since the 'tags'
> should be the same for one content. (Categories are assigned to VFS
> resources not to the real-localized content).
>
> However, I would try to use the same taxonomy for all languages and then
> localize its output at rendering time: The messages.properties could have
> entries per category path, using dots instead slashes and then on JSP side
> you will replace the slashes pf the category path with dotes and try then to
> receive the localized value.
>
> What do you think?
>
> Am 15.02.2013 16:49, schrieb Arturo Martín Lladó:
>
> Hi, Rüdiger.
>
> I tried with this:
>
>           <resourcebundles>
>                <xmlbundle name="element.workplace.xml">
>                    <bundle locale="ca">
>                        <resource
> key="package.element.language">ca</resource>
>                    </bundle>
>                    <bundle locale="es">
>                        <resource
> key="package.element.language">es</resource>
>                    </bundle>
>                </xmlbundle>
>            </resourcebundles>
>
> The value stored in %(key.package.element.language) is displayed OK in
> the default values of OpenCmsString fields, but it seems to be ignored
> in the attribute "configuration" of a CategoryWidget.
>
> Is this the expected behaviour? Maybe macros are not processed in
> <layout> elements?
>
> Kind regards.
>
> 2013/2/15 Rüdiger Kurz <r.kurz at alkacon.com>:
>
>
> Hi,
>
> it's me again. You can access localized message bundles with:
> %(key.your.label)
>
> imagine a XSD:
>
> <resourcebundle name="your.package.workplace"/>
> [...]
> <layout element="Elem"
>        widget="CategoryWidget"
>        configuration="... %(key.language) ..." />
>
> and a workplace_en.properties
> containing:
> language=en
>
> and a workplace_de.properties
> containing:
> language=de
>
> This should do the trick.
>
> regards
> Rüdiger
>
>
> Am 15.02.2013 14:39, schrieb Rüdiger Kurz:
>
> sorry not quiet sure if this works inside the XSD, but inside the
> content editor you can use it.
>
> Am 15.02.2013 14:37, schrieb Rüdiger Kurz:
>
>
>
> yes, %(request.locale)
>
> Am 15.02.2013 14:27, schrieb Arturo Martín Lladó:
>
>
>
> Hi, list.
>
> Is there available any locale macro for using it in XSD schemas?
>
> I'd like to do something like this:
>
>    <layouts>
>                 [...]
>                 <layout element="Categoria" widget="CategoryWidget"
>
>
> configuration="category=/_categories/__LOCALE_MACRO___/tipoDocumento/|onlyleafs=true"/>
>
>
>    </layouts>
>
> This is because our categories tree is organized this way:
> /sites/default/_categories/__LOCALE__/...
>
> Kind regards.
>
>
>
>
>
> --
> Rüdiger Kurz
>
> -------------------
>
> Alkacon Software GmbH - The OpenCms Experts
> Rüdiger Kurz
> An der Wachsfabrik 13
> 50996 Koeln, DE
>
> Tel: +49 (0)2236 3826-16
> Fax: +49 (0)2236 3826-20
> Email: r.kurz at alkacon.com
>
> http://www.alkacon.com
> http://www.opencms.org
>
> Geschäftsführer: Alexander Kandzior, Amtsgericht Köln, HRB 54613
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev
>
>
>
>
>
>
>
>
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev
>
>
>
>
>
>
>
> --
> Arturo Martín Lladó
>
>
> -------------------------------------------------
> Christoph Fröhlich
> Folge 3 GmbH
> Neuer Pferdemarkt 1
> 20359 Hamburg
>
> +49 +40  79 69 48 78
> cf at folge3.de
> http://www.folge3.de
> -------------------------------------------------
> Geschäftsführer: Christoph Fröhlich, Anja Künzel
> Handelsregister: HRB 105806, Amtsgericht Hamburg
>
>
>
>
>
>
>
>
>
>
> --
> Arturo Martín Lladó
>
>
> -------------------------------------------------
> Christoph Fröhlich
> Folge 3 GmbH
> Neuer Pferdemarkt 1
> 20359 Hamburg
>
> +49 +40  79 69 48 78
> cf at folge3.de
> http://www.folge3.de
> -------------------------------------------------
> Geschäftsführer: Christoph Fröhlich, Anja Künzel
> Handelsregister: HRB 105806, Amtsgericht Hamburg
>



More information about the opencms-dev mailing list