[BLOSSOM-1] Template annotation should allow specifying "class" Created: 01/Jul/10  Updated: 06/Dec/14  Resolved: 24/Aug/10

Status: Closed
Project: Blossom
Component/s: None
Affects Version/s: None
Fix Version/s: 1.1.1

Type: New Feature Priority: Minor
Reporter: Tobias Mattsson Assignee: Tobias Mattsson
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File blossom-template-class-patch.txt     Text File is-available-annotation-patch-v2.txt     Text File is-available-annotation-patch.txt    
Template:
Patch included:
Yes
Acceptance criteria:
Empty
Date of First Response:

 Description   

Transferred from Sourceforge

Original description:

Magnolia templates support a node named "class" that contains the fully qualified class name to be instantiated for that particular template. This is useful, for example, if you want to override the default isAvailable() method.

The Blossom @Template annotation should allow specifying this value and subsequently configuring it on the blossom generated template.

Followup comments:

Good suggestion, though even cooler would be to have isAvailable() directly
on the controller.

For now you can subclass DefaultBlossomTemplateRegistry and overload
writeTemplateDefinition() to add the custom properties that you need.

Replace <blossom:configuration /> with

<bean class="se.issi.magnolia.module.blossom.BlossomConfiguration">
<property name="templateRegistry">
<bean class="some.package.MyCustomTemplateRegistry" />
</property>
</bean>



 Comments   
Comment by Thomas Duffey [ 08/Jul/10 ]

Example usage for attached patch:

@Template(value = "My Template", clazz = "com.foo.MyTemplate")

Comment by Thomas Duffey [ 08/Jul/10 ]

If I subclass DefaultBlossomTemplateRegistry I still need the attached patch applied so I can specify the "clazz" attribute with the @Template annotation.

If you can provide some direction for having isAvailable() directly on the controller I would be happy to give it a whirl.

Comment by Tobias Mattsson [ 08/Jul/10 ]

My idea is to make DefaultBlossomTemplateRegistry always set the class in repository. The class should be a subclass of Template that when isAvailable() is called finds the BlossomTemplateDescription from the TemplateRegistry and invokes a method on the handler/controller. I'm not sure yet what the best way of declaring that method is. Either using an annotation or implementing an interface.

The solution with an interface would look something like:

@Template
public class MyTemplate implements ConditionallyAvailableTemplate {
public boolean isAvailable(Content content)

{ /* something interesting */ }

}

public class BlossomTemplate extends Template {
public boolean isAvailable(Content content) {
BlossomTemplateDescription description = BlossomModule.getTemplateRegistry().getTemplate(getName());
if (description.getHandler() instanceof ConditionallyAvailableTemplate)
return ((ConditionallyAvailableTemplate)description.getHandler()).isAvailable(content);
else
return super.isAvailable(content);
}
}

in DefaultTemplateRegistry the class that's written to repository is BlossomTemplate.class.getName()

Comment by Thomas Duffey [ 09/Jul/10 ]

The attached patch against trunk allows you to specify a method in your controller like:

@IsAvailable
public static boolean isAvailable(Content node) {
...
}

When available, this method will be used instead of the default Magnolia isAvailable() method. I have two gripes:

1) Without some Maven or other magic there is no way I know of to ensure that the @IsAvailable annotated method actually follows the required signature pattern.

2) There is no way to fall back to the default isAvailable() method within your @IsAvailable annotated method.

That said, it seems to work. Please let me know what you think, I would like to get some version of this feature into the official module.

Comment by Tobias Mattsson [ 09/Jul/10 ]

I like it. It will get included in the next version.

Comment by Thomas Duffey [ 09/Jul/10 ]

OK, if you don't mind please give me the weekend to test and do some minor cleanup. I'll submit a new patch following the same idea if anything comes up.

Comment by Thomas Duffey [ 09/Jul/10 ]

Please use this patch. @IsAvailable method signatures are now a bit more flexible and can accept zero, one or two parameters in any order:

info.magnolia.module.templating.Template (The template being checked)
info.magnolia.core.cms.Content (Content node for page in AdminCentral)

Some examples:

@IsAvailable
public boolean isAvailable()

{ return true; }

@IsAvailable
public boolean isAvailable(Content node)

{ ... }

@IsAvailable
public boolean isAvailable(Template template, Content node) { ... }

If an unknown parameter type is found on an @IsAvailable annotated method then an error is logged and the template will not be available.

Comment by Thomas Duffey [ 12/Aug/10 ]

Tobias, any update on this? We have the V2 patch in production and working well...

Comment by Tobias Mattsson [ 23/Aug/10 ]

It's coming along now. Could you elaborate on why you want to have a reference to BlossomTemplate as a possible argument to the method? I don't see the point.

Comment by Tobias Mattsson [ 24/Aug/10 ]

Implemented with a new annotation called @Available. The annotated method must return boolean and can take an argument of type Content. An annotated method in a super class is detected and used.

Comment by Thomas Duffey [ 24/Aug/10 ]

In hindsight I don't think having access to the BlossomTemplate is very useful. Thanks for integrating this.

Comment by Jan Haderka [ 06/Dec/14 ]

Bulk close of old resolved issues.

Generated at Sun Feb 11 23:29:08 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.