From eb4adde40a89accad7db5c8d10841f182382a994 Mon Sep 17 00:00:00 2001 From: Will Ezell Date: Wed, 30 Jan 2013 18:45:34 -0500 Subject: [PATCH] closes #1975 --- .../templates/business/TemplateAPIImpl.java | 36 ++++++++++++++++--- .../viewtools/DotTemplateTool.java | 33 +++++++++++++++++ 2 files changed, 65 insertions(+), 4 deletions(-) diff --git a/src/com/dotmarketing/portlets/templates/business/TemplateAPIImpl.java b/src/com/dotmarketing/portlets/templates/business/TemplateAPIImpl.java index b84bfc4f15ee..3ae64063b664 100644 --- a/src/com/dotmarketing/portlets/templates/business/TemplateAPIImpl.java +++ b/src/com/dotmarketing/portlets/templates/business/TemplateAPIImpl.java @@ -128,19 +128,22 @@ public Template copy(Template sourceTemplate, Host destination, boolean forceOve newTemplate = FactoryLocator.getTemplateFactory().findWorkingTemplateByName(sourceTemplate.getTitle(), destination); if (newTemplate == null) { isNew = true; + newTemplate =templateFactory.copyTemplate(sourceTemplate, destination); } } else { isNew = true; + newTemplate =templateFactory.copyTemplate(sourceTemplate, destination); } - newTemplate =templateFactory.copyTemplate(sourceTemplate, destination); + newTemplate.setModDate(new Date()); newTemplate.setModUser(user.getUserId()); updateParseContainerSyntax(newTemplate); newTemplate.setBody(replaceWithNewContainerIds(newTemplate.getBody(), containerMappings)); - + newTemplate.setDrawedBody(replaceWithNewContainerIds(newTemplate.getDrawedBody(), containerMappings)); + if (isNew) { // creates new identifier for this webasset and persists it Identifier newIdentifier = com.dotmarketing.business.APILocator.getIdentifierAPI().createNew(newTemplate, destination); @@ -149,7 +152,6 @@ public Template copy(Template sourceTemplate, Host destination, boolean forceOve newTemplate.setIdentifier(newIdentifier.getInode()); // persists the webasset save(newTemplate); - List destinationContainers = getContainersInTemplate(newTemplate, user, respectFrontendRoles); associateContainers(destinationContainers, newTemplate); @@ -311,7 +313,7 @@ public List getContainersInTemplate(Template template, User user, boo private String replaceWithNewContainerIds(String body, List containerMappings) { - + if(body ==null) return body; Pattern oldContainerReferencesRegex = Pattern.compile("#parse\\s*\\(\\s*\\$container([^\\s]+)\\s*\\)"); Pattern newContainerReferencesRegex = Pattern.compile("#parseContainer\\s*\\(\\s*['\"]*([^'\")]+)['\"]*\\s*\\)"); @@ -341,6 +343,32 @@ private String replaceWithNewContainerIds(String body, List } matcher.appendTail(newBody); + + // if we are updating container references + if(containerMappings != null && containerMappings.size() > 0){ + Pattern uuid = Pattern.compile("[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}"); + + + body = newBody.toString(); + newBody = new StringBuffer(); + matcher = uuid.matcher(body); + while(matcher.find()) { + String containerId = matcher.group(0); + for(ContainerRemapTuple tuple : containerMappings) { + if(tuple.getSourceContainer().getIdentifier().equals(containerId)) { + matcher.appendReplacement(newBody, tuple.getDestinationContainer().getIdentifier() ); + break; + } + } + } + matcher.appendTail(newBody); + } + + + + + + return newBody.toString(); } diff --git a/src/com/dotmarketing/viewtools/DotTemplateTool.java b/src/com/dotmarketing/viewtools/DotTemplateTool.java index 8818ca079ec9..092516b81d62 100644 --- a/src/com/dotmarketing/viewtools/DotTemplateTool.java +++ b/src/com/dotmarketing/viewtools/DotTemplateTool.java @@ -134,8 +134,41 @@ public static Map theme ( String themeFolderInode, String hostId */ public static Map themeByPath ( String themeFolderPath, String hostId ) throws DotDataException, DotSecurityException { + + + if(themeFolderPath ==null ){ + return null; + } + + + // get theme host + if(themeFolderPath.startsWith("//")){ + String[] uriArray = themeFolderPath.split("/"); + String hostName = uriArray[2]; + + hostId = APILocator.getHostAPI().resolveHostName(hostName, APILocator.getUserAPI().getSystemUser(), true).getIdentifier(); + + java.io.StringWriter sw = new java.io.StringWriter(); + + for(int i= 3;i< uriArray.length;i++){ + sw.append("/"); + sw.append(uriArray[i]); + + } + themeFolderPath = sw.toString(); + + } + + + //Get the theme folder Folder themeFolder = APILocator.getFolderAPI().findFolderByPath( themeFolderPath, hostId, APILocator.getUserAPI().getSystemUser(), false ); + + + + + + return setThemeData( themeFolder, hostId ); }