mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
ALF-11514: ALL LANG - Following_email Templates updated/localised
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@32412 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.admin.patch.impl;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.admin.patch.AbstractPatch;
|
||||
import org.alfresco.service.cmr.model.FileFolderService;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public abstract class GenericEMailTemplateUpdatePatch extends AbstractPatch
|
||||
{
|
||||
protected static final String[] LOCALES = new String[] {"de", "es", "fr", "it", "ja"};
|
||||
|
||||
protected ContentService contentService;
|
||||
|
||||
protected FileFolderService fileFolderService;
|
||||
|
||||
private boolean createSiblingIfMissing = true;
|
||||
|
||||
public void setContentService(ContentService contentService)
|
||||
{
|
||||
this.contentService = contentService;
|
||||
}
|
||||
|
||||
public void setFileFolderService(FileFolderService fileFolderService)
|
||||
{
|
||||
this.fileFolderService = fileFolderService;
|
||||
}
|
||||
|
||||
public void setCreateSiblingIfMissing(boolean createSiblingIfMissing)
|
||||
{
|
||||
this.createSiblingIfMissing = createSiblingIfMissing;
|
||||
}
|
||||
|
||||
protected void updateTemplates() throws Exception
|
||||
{
|
||||
NodeRef baseTemplate = getBaseTemplate();
|
||||
if (nodeService.exists(baseTemplate) == true)
|
||||
{
|
||||
updateContent(baseTemplate, getPath(), getBaseFileName());
|
||||
|
||||
for (String siblingFile : getSiblingFiles())
|
||||
{
|
||||
updateSiblingContent(baseTemplate, getPath(), siblingFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract NodeRef getBaseTemplate();
|
||||
|
||||
protected abstract String getPath();
|
||||
|
||||
protected abstract String getBaseFileName();
|
||||
|
||||
protected String[] getLocales()
|
||||
{
|
||||
return LOCALES;
|
||||
}
|
||||
|
||||
protected List<String> getSiblingFiles()
|
||||
{
|
||||
List<String> siblingFiles = new ArrayList<String>(LOCALES.length);
|
||||
for (String locale : LOCALES)
|
||||
{
|
||||
siblingFiles.add(makeSiblingFileName(getBaseFileName(), locale));
|
||||
}
|
||||
return siblingFiles;
|
||||
}
|
||||
|
||||
private String makeSiblingFileName(String baseFileName, String locale)
|
||||
{
|
||||
int index = baseFileName.lastIndexOf(".");
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(baseFileName.substring(0, index))
|
||||
.append("_")
|
||||
.append(locale)
|
||||
.append(baseFileName.substring(index));
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private void updateSiblingContent(NodeRef nodeRef, String path, String fileName)
|
||||
{
|
||||
NodeRef parent = nodeService.getPrimaryParent(nodeRef).getParentRef();
|
||||
if (parent != null)
|
||||
{
|
||||
NodeRef sibling = fileFolderService.searchSimple(parent, fileName);
|
||||
if (sibling != null)
|
||||
{
|
||||
updateContent(sibling, path, fileName);
|
||||
}
|
||||
else if (createSiblingIfMissing == true)
|
||||
{
|
||||
sibling = fileFolderService.create(parent, fileName, ContentModel.TYPE_CONTENT).getNodeRef();
|
||||
updateContent(sibling, path, fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateContent(NodeRef nodeRef, String path, String fileName)
|
||||
{
|
||||
// Make versionable
|
||||
nodeService.addAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE, null);
|
||||
|
||||
// Update content
|
||||
InputStream is = this.getClass().getClassLoader().getResourceAsStream(path + fileName);
|
||||
if (is != null)
|
||||
{
|
||||
ContentWriter contentWriter = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
|
||||
contentWriter.putContent(is);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.admin.patch.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.repo.model.Repository;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
/**
|
||||
* Update following email templates patch
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class UpdateFollowingEmailTemplatesPatch extends GenericEMailTemplateUpdatePatch
|
||||
{
|
||||
private Repository repository;
|
||||
|
||||
private static final String PATH = "alfresco/templates/following-email-templates/";
|
||||
private static final String BASE_FILE = "following-email.html.ftl";
|
||||
private static final String XPATH = "/app:company_home/app:dictionary/app:email_templates/app:following/cm:following-email.html.ftl";
|
||||
|
||||
public void setRepository(Repository repository)
|
||||
{
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getPath()
|
||||
{
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBaseFileName()
|
||||
{
|
||||
return BASE_FILE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NodeRef getBaseTemplate()
|
||||
{
|
||||
List<NodeRef> refs = searchService.selectNodes(
|
||||
repository.getRootHome(),
|
||||
XPATH,
|
||||
null,
|
||||
namespaceService,
|
||||
false);
|
||||
if (refs.size() != 1)
|
||||
{
|
||||
throw new AlfrescoRuntimeException(I18NUtil.getMessage("patch.updateFollowingEmailTemplatesPatch.error"));
|
||||
}
|
||||
return refs.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.admin.patch.AbstractPatch#applyInternal()
|
||||
*/
|
||||
@Override
|
||||
protected String applyInternal() throws Exception
|
||||
{
|
||||
updateTemplates();
|
||||
return I18NUtil.getMessage("patch.updateFollowingEmailTemplatesPatch.result");
|
||||
}
|
||||
}
|
@@ -18,14 +18,7 @@
|
||||
*/
|
||||
package org.alfresco.repo.admin.patch.impl;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.admin.patch.AbstractPatch;
|
||||
import org.alfresco.repo.workflow.WorkflowNotificationUtils;
|
||||
import org.alfresco.service.cmr.model.FileFolderService;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
@@ -34,75 +27,36 @@ import org.springframework.extensions.surf.util.I18NUtil;
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class UpdateWorkflowNotificationTemplatesPatch extends AbstractPatch
|
||||
public class UpdateWorkflowNotificationTemplatesPatch extends GenericEMailTemplateUpdatePatch
|
||||
{
|
||||
private ContentService contentService;
|
||||
|
||||
private FileFolderService fileFolderService;
|
||||
|
||||
private static final String PATH = "alfresco/bootstrap/notification/";
|
||||
private static final String BASE_FILE = "wf-email.html.ftl";
|
||||
private static final String DE_FILE = "wf-email.html_de.ftl";
|
||||
private static final String ES_FILE = "wf-email.html_es.ftl";
|
||||
private static final String FR_FILE = "wf-email.html_fr.ftl";
|
||||
private static final String IT_FILE = "wf-email.html_it.ftl";
|
||||
private static final String JA_FILE = "wf-email.html_ja.ftl";
|
||||
|
||||
public void setContentService(ContentService contentService)
|
||||
@Override
|
||||
protected String getPath()
|
||||
{
|
||||
this.contentService = contentService;
|
||||
return PATH;
|
||||
}
|
||||
|
||||
public void setFileFolderService(FileFolderService fileFolderService)
|
||||
@Override
|
||||
protected String getBaseFileName()
|
||||
{
|
||||
this.fileFolderService = fileFolderService;
|
||||
return BASE_FILE;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected NodeRef getBaseTemplate()
|
||||
{
|
||||
return WorkflowNotificationUtils.WF_ASSIGNED_TEMPLATE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.admin.patch.AbstractPatch#applyInternal()
|
||||
*/
|
||||
@Override
|
||||
protected String applyInternal() throws Exception
|
||||
{
|
||||
NodeRef baseTemplate = WorkflowNotificationUtils.WF_ASSIGNED_TEMPLATE;
|
||||
if (nodeService.exists(baseTemplate) == true)
|
||||
{
|
||||
updateContent(baseTemplate, PATH, BASE_FILE);
|
||||
updateSiblingContent(baseTemplate, PATH, DE_FILE);
|
||||
updateSiblingContent(baseTemplate, PATH, ES_FILE);
|
||||
updateSiblingContent(baseTemplate, PATH, FR_FILE);
|
||||
updateSiblingContent(baseTemplate, PATH, IT_FILE);
|
||||
updateSiblingContent(baseTemplate, PATH, JA_FILE);
|
||||
}
|
||||
|
||||
{
|
||||
updateTemplates();
|
||||
return I18NUtil.getMessage("patch.updateWorkflowNotificationTemplates.result");
|
||||
}
|
||||
|
||||
private void updateSiblingContent(NodeRef nodeRef, String path, String fileName)
|
||||
{
|
||||
NodeRef parent = nodeService.getPrimaryParent(nodeRef).getParentRef();
|
||||
if (parent != null)
|
||||
{
|
||||
NodeRef sibling = fileFolderService.searchSimple(parent, fileName);
|
||||
if (sibling != null)
|
||||
{
|
||||
updateContent(sibling, path, fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateContent(NodeRef nodeRef, String path, String fileName)
|
||||
{
|
||||
// Make versionable
|
||||
nodeService.addAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE, null);
|
||||
|
||||
// Update content
|
||||
InputStream is = this.getClass().getClassLoader().getResourceAsStream(path + fileName);
|
||||
if (is != null)
|
||||
{
|
||||
ContentWriter contentWriter = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
|
||||
contentWriter.putContent(is);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user