在一个可从您的网页上查阅的物体中加以校正。 这里的例子就是,它已经做到:
package com.someco.web.jscript;
import org.alfresco.repo.jscript.ScriptNode;
import org.alfresco.repo.processor.BaseProcessorExtension;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.ml.MultilingualContentService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.Locale;
public final class MultilingualScript extends BaseProcessorExtension
{
private static final Log logger = LogFactory.getLog(MultilingualScript.class);
private MultilingualContentService multilingualContentService;
private ServiceRegistry serviceRegistry;
public MultilingualScript()
{
if (logger.isDebugEnabled()) {
logger.debug("MultilingualScript Constructor Called");
}
}
//path = path of the original document
//language = required language
//returns the noderef for the translation content for the given language
public ScriptNode multilingualContent(String path, String language, ScriptNode companyHome) {
if (logger.isDebugEnabled()) {
logger.debug("MultilingualScript - parameters - " + path + " , " + language);
}
NodeRef nodeRef = new ScriptNode(companyHome.getNodeRef(), serviceRegistry)
.childByNamePath(path).getNodeRef();
nodeRef = multilingualContentService.getTranslationForLocale(nodeRef, new Locale(language) );
return new ScriptNode(nodeRef, serviceRegistry);
}
public MultilingualContentService getMultilingualContentService() {
return multilingualContentService;
}
public void setMultilingualContentService(
MultilingualContentService multilingualContentService) {
this.multilingualContentService = multilingualContentService;
}
public ServiceRegistry getServiceRegistry() {
return serviceRegistry;
}
public void setServiceRegistry(ServiceRegistry serviceRegistry) {
this.serviceRegistry = serviceRegistry;
}
}
The Spring bean:
<bean id="multilingualScript" parent="baseJavaScriptExtension" class="com.someco.web.jscript.MultilingualScript">
<property name="extensionName">
<value>multilingual</value>
</property>
<property name="serviceRegistry">
<ref bean="ServiceRegistry" />
</property>
<property name="multilingualContentService">
<ref bean="MultilingualContentService" />
</property>
</bean>
最后,用它来做:
var multilingualArticle = multilingual.multilingualContent("/myarticle", "es", companyhome);