I'd like to use the Freemarker templating engine from within a controller's webscript to process some expression.
I've seen Alfresco provide the document.processTemplate("template content here") API.
The documentation says: "Executes a template from the repository against the current Document node"
Let's say I don't have any specific document to use, I just want to execute the templating engine and retrieve the output. What's the best way to do it?
Should I use some sort of temporary or "proxy" document? What's the easiest way to do so?
Not quite understandning what you are after here, I however think this is possible (not sure why anyone would like to do it though.)
You write your own class extending the BaseTemplateProcessorExtension, in that class you could write a method performing the stuff you want.
public class MyTemplateProcessorExtension extends BaseTemplateProcessorExtension {
public String myMethod(){
return "Hello World";
}
}
Declare it the following way in your spring config.
<bean id="templateHelper" parent="baseTemplateImplementation" class="my.alfresco.repo.template.TemplateHelper">
<property name="extensionName" value="templateHelper" />
</bean>
Then you can call it from your freemarker with:
${templateHelper.myMethod()}
The freemarker template calling "myMethod" should be a node in the repository (it should be possible to place it in the classpath as well, however I never had any success with this), since the processTemplate needs a nodeRef to the template itself.
Ok, please beware. I don't recommend this approach for anyone :)
I don't think it's possible to not use a document. So use a folder like data dictionary or create a dummy document with no content you always use.
The main purpose of alfresco is managing document.What kind of output you will produce without having value of any metadata of document in the template.This is the main reason behind this is not supported in alfresco, template engine is designed in such a way so that we can process any document.
Related
After upgrading to Intershop CM 7.10.18.1, we are getting NullPtr exceptions while opening store detail page in backoffice.
ISML template for store details is EditStore_52.isml, which includes ISCountrySelectBox module, which futhermore calls getCountryNamesAndCodes() method.
That method fails with NullPtr exception because of underlined call which returns null.
We are wondering whether this is a bug and whether the intended code was supposed to be:
countriesMap.put(country.getId(), country.getDisplayName(currentLocale));
Please advise on workaround for this situation.
The following is a stack trace for exception.
Intershop delivers address data which can be imported/export through Operations backoffice (e.g. Login at https://localhost:8443/INTERSHOP/web/WFS/SLDSystem using Organization Operations). Out of the box such address data looks like this:
<country>
<id>DE</id>
<custom-attributes>
<custom-attribute dt:dt="string" name="displayName" xml:lang="de-DE">Deutschland</custom-attribute>
<custom-attribute dt:dt="string" name="displayName" xml:lang="fr-FR">Allemagne</custom-attribute>
<custom-attribute dt:dt="string" name="displayName" xml:lang="en-US">Germany</custom-attribute>
</custom-attributes>
</country>
As you can see, it only contains displayName attribute values for de-DE, fr-FR and en-US. A possible workaround in your case would be to export data, include missing attribute values and import it again.
Please note: The work to deliver a fix for this is already in progress. I'm sorry for the inconvenience.
The more convenient way (because editing xml import files is tedious) would be to replace the erroneous implementation using guice module override. In a nutshell:
Copy paste the original implementation of class com.intershop.component.region.internal.geoobject.LocalizedCountryNamesProviderImpl into a class of your own in your custom cartridge. For example: I just created a class AppSFLocalizedCountryNamesProviderImpl in cartridge app_sf_responsive to test this.
Adapt above method according to your needs
Create an override module (See Cookbook - Dependency Injection and ObjectGraphs). Following my example the modules configure operation should look like this:
#Override
protected void configure()
{
bind(LocalizedCountryNamesProvider.class).to(AppSFLocalizedCountryNamesProviderImpl.class);
bindProvider(com.intershop.component.foundation.capi.localization.LocalizedCountryNamesProvider.class)
.to(AppSFLocalizedCountryNamesProviderImpl.class);
}
Publish your cartridge, Restart your server
I'm using Alfresco 5. I have create a custom type (parent type is cm:folder) and
added an entry for this type in the Document Library "Create" menu.
I would like to override the default folder create function so that I can do
some custom processing.
I would like to create some content within the new folder each time.
You can use alfresco behaviour/policies for your requirement.
For creating policy you need to create below things.
1.Spring Bean in context file
2.One class which implements onCreateNode from org.alfresco.repo.node.NodeServicePolicies
For more information regarding policies read below blog written by Jeff Potts
http://ecmarchitect.com/alfresco-developer-series-tutorials/behaviors/tutorial/tutorial.html
Apart from behaviour/policies easier option would be using rule and script.
You can create a rule which will be executed on creation of new
folder.
Create alfresco java script which will do processing you required on creation of
new folder.
Hook up script with rule.
Flash builder lets me insert metadata for events fired by a class, example:
[Event("myEvent", "flash.events.Event")]
public class MyClass() {
}
Is there any way to do the same for Exceptions?
Currently I have checked here, and can't see it documented. Perhaps it's not even worthwhile, what are your thoughts.
There are ways to create your own metadata; and add that into your app at compile time. Use the keep-as3-metadata compiler argument.
It will be up to you to write code to do something with it at runtime; or to build IDE extensions to make use of the code while writing the code.
To access such metadata at runtime, you'll need to perform some type of introspection. Here are some docs and another StackOverflow Question about this.
Many Flex Frameworks make use of custom metadata.
1) We are using OpenEJB (both embedded and standalone) with a few deployed EJBs. We would like to specify some simple static business rules and values (example: icon_size=200). Normally, we would put them in a regular properties file (example: rules.properties). Since we shouldn't access the file system directly while inside the application server, is is possible to place those key-value pairs somewhere inside the ejb-jar.xml?
2) If not, is there a standard mechanism to do this? What is it?
Thanks
Use env-entry. In XML:
<env-entry>
<env-entry-name>icon_size</env-entry-name>
<env-entry-type>java.lang.Integer</env-entry-type>
<env-entry-value>200</env-entry-value>
</env-entry>
In annotation:
#Resource(name="icon_size")
int icon_size;
I personally just use a .properties file; well a TernarySearchTree which reads in .properties and .XML files and allows quick retrieval. These files are available at application level. However you can in EJB 3 inject env-entry elements into your EJB. This link explains it in good detail Injection of env entry
There are some OpenEJB extensions here that might be useful.
env-entries.properties
Check out the Custom Injection example which is basically allows the <env-entry> to be specified as plain properties in a META-INF/env-entries.properties file. Nice for collapsing all those name & value pairs into a simple properties file. Internally, we just generate the xml for you using those properties. The default type is always java.lang.String, which is good for this next part.
java.beans.PropertyEditor support
Any <env-entry> which is of <env-entry-type> java.lang.String will automatically have its type converted using the VM java.beans.PropertyEditor for the target type. That's also how Spring does the converting. There are few built-in converters, such as #Resource java.util.Date myDate and #Resource java.io.File myFile
I have a class in my asp.net proj, I would like to get access GetGlobalResourceObject (that page exposes), from anywhere in the site, possible?
In other words I wanna access the global resources from a class that is not a page I don't care how.
Answer:
Yes, as following pseudo:
Resources.<The name of the resources file name>.<your resource key>;
Example:
lblTitle.Text = Resources.MySettings.WebsiteTitle;
Resources is an Visual-Studio auto generated namespace that exposes all the global resource classes and props in the project.
You should use
HttpContext.GetGlobalResourceObject("myResourceKey")
...because that way it will still work when using a custom ResourceProvider. The default type-generator for Resource files explicitely uses the Resx provider and won't work if you implement something like a database provider.
On some farms you'll need to wrap the call to
HttpContext.GetGlobalResourceObject("myResourceKey")
inside a try/catch block to get it over the "Could not find any resources appropriate for the specified culture or the neutral culture" error.
If you are in the site you have access to HttpContext and can use:
HttpContext.GetGlobalResourceObject("myResourceKey")
I kinda took this from the resource designer,
ResourceManager temp =
new ResourceManager("Resources.<<resource name>>",
System.Reflection.Assembly.Load("App_GlobalResources"));