From: <luc...@us...> - 2010-03-02 21:32:30
|
Revision: 2084 http://openutils.svn.sourceforge.net/openutils/?rev=2084&view=rev Author: lucaboati Date: 2010-03-02 21:32:19 +0000 (Tue, 02 Mar 2010) Log Message: ----------- [MGNLSTRIPES-1] add an annotation on stripes action to define which mgnl dialog binds to the action Modified Paths: -------------- trunk/openutils-mgnlstripes/src/main/java/it/openutils/magnoliastripes/MgnlActionResolver.java Added Paths: ----------- trunk/openutils-mgnlstripes/src/main/java/it/openutils/magnoliastripes/annotations/ trunk/openutils-mgnlstripes/src/main/java/it/openutils/magnoliastripes/annotations/Dialog.java Modified: trunk/openutils-mgnlstripes/src/main/java/it/openutils/magnoliastripes/MgnlActionResolver.java =================================================================== --- trunk/openutils-mgnlstripes/src/main/java/it/openutils/magnoliastripes/MgnlActionResolver.java 2010-03-02 11:04:18 UTC (rev 2083) +++ trunk/openutils-mgnlstripes/src/main/java/it/openutils/magnoliastripes/MgnlActionResolver.java 2010-03-02 21:32:19 UTC (rev 2084) @@ -3,24 +3,24 @@ * Magnolia Stripes module (http://www.openmindlab.com/lab/products/mgnlstripes.html) * Copyright(C) null-2010, Openmind S.r.l. http://www.openmindonline.it * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program 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 General Public License for more details. + * This program 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 General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ - package it.openutils.magnoliastripes; import info.magnolia.module.templating.Paragraph; import info.magnolia.module.templating.ParagraphManager; +import it.openutils.magnoliastripes.annotations.Dialog; import java.util.HashSet; import java.util.Set; @@ -34,8 +34,8 @@ /** - * ActionResolver that extends <code>NameBasedActionResolver</code>, registering any found Stripe action as a Magnolia - * paragraph. + * ActionResolver that extends <code>NameBasedActionResolver</code>, registering any found Stripe action as a + * Magnolia paragraph. * @author fgiust * @version $Id: $ */ @@ -63,13 +63,45 @@ // Only process the class if it's properly annotated if (binding != null) { - String dialogName = actionNameToParagraphName(binding); - collectStripesParagraphs(dialogName, binding); + String paragraphName = actionNameToParagraphName(binding); + String dialogName = annotationDialogToParagraphName(clazz); + if (StringUtils.isBlank(dialogName)) + { + dialogName = paragraphName; + } + collectStripesParagraphs(paragraphName, dialogName, binding); super.addActionBean(clazz); } } /** + * Generate a paragraph name from "Dialog" Annotation. + * @param binding Stripe action binding + * @return paragraph name + */ + protected String annotationDialogToParagraphName(Class< ? extends ActionBean> clazz) + { + return processDialogAnnotation(clazz); + } + + protected String processDialogAnnotation(Class< ? extends ActionBean> clazz) + { + // check that class is annotated + Dialog annotation = clazz.getAnnotation(Dialog.class); + if (annotation == null) + { + return null; + } + // check that value is not null or empty + String pattern = annotation.value(); + if (StringUtils.isBlank(pattern)) + { + return null; + } + return pattern; + } + + /** * Generate a paragraph name from a Stripes binding. This method will take the last token after "/", strip any * extension and convert everything to lowercase. * @param binding Stripe action binding @@ -89,20 +121,20 @@ * @param binding Stripes action binding */ @SuppressWarnings("unchecked") - private void collectStripesParagraphs(String name, String binding) + private void collectStripesParagraphs(String paragraphName, String dialogName, String binding) { Paragraph paragraph = new Paragraph(); - paragraph.setName(name); - paragraph.setTitle("paragraph." + name + ".title"); - paragraph.setDescription("paragraph." + name + ".description"); - paragraph.setDialog(name); + paragraph.setName(paragraphName); + paragraph.setTitle("paragraph." + paragraphName + ".title"); + paragraph.setDescription("paragraph." + paragraphName + ".description"); + paragraph.setDialog(dialogName); paragraph.setTemplatePath(binding); paragraph.setType("stripes"); paragraph.setI18nBasename(StripesModule.getInstance().getI18nbasename()); paragraphs.add(paragraph); - log.info("Registering stripes paragraph {}", paragraph.getName()); //$NON-NLS-1$ + log.info("Registering stripes paragraph {} with dialog {}", paragraph.getName(), paragraph.getDialog()); //$NON-NLS-1$ /$NON-NLS-2$ ParagraphManager.getInstance().getParagraphs().put(paragraph.getName(), paragraph); } @@ -116,4 +148,9 @@ } } + public static Set<Paragraph> getParagraphs() + { + return paragraphs; + } + } Added: trunk/openutils-mgnlstripes/src/main/java/it/openutils/magnoliastripes/annotations/Dialog.java =================================================================== --- trunk/openutils-mgnlstripes/src/main/java/it/openutils/magnoliastripes/annotations/Dialog.java (rev 0) +++ trunk/openutils-mgnlstripes/src/main/java/it/openutils/magnoliastripes/annotations/Dialog.java 2010-03-02 21:32:19 UTC (rev 2084) @@ -0,0 +1,36 @@ +/** + * + * Magnolia Stripes module (http://www.openmindlab.com/lab/products/mgnlstripes.html) + * Copyright(C) null-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +package it.openutils.magnoliastripes.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + + +/** + * @author luca boati + * @version $Id: $ + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE }) +public @interface Dialog { + + String value(); +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |