Skip to content

Commit

Permalink
Merge pull request #1976 from dotCMS/issue-1975-themes-do-not-preview…
Browse files Browse the repository at this point in the history
…-across-hosts

closes #1975
  • Loading branch information
wezell committed Jan 30, 2013
2 parents 1bc964d + eb4adde commit b68019c
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -149,7 +152,6 @@ public Template copy(Template sourceTemplate, Host destination, boolean forceOve
newTemplate.setIdentifier(newIdentifier.getInode());
// persists the webasset
save(newTemplate);

List<Container> destinationContainers = getContainersInTemplate(newTemplate, user, respectFrontendRoles);
associateContainers(destinationContainers, newTemplate);

Expand Down Expand Up @@ -311,7 +313,7 @@ public List<Container> getContainersInTemplate(Template template, User user, boo


private String replaceWithNewContainerIds(String body, List<ContainerRemapTuple> containerMappings) {

if(body ==null) return body;
Pattern oldContainerReferencesRegex = Pattern.compile("#parse\\s*\\(\\s*\\$container([^\\s]+)\\s*\\)");
Pattern newContainerReferencesRegex = Pattern.compile("#parseContainer\\s*\\(\\s*['\"]*([^'\")]+)['\"]*\\s*\\)");

Expand Down Expand Up @@ -341,6 +343,32 @@ private String replaceWithNewContainerIds(String body, List<ContainerRemapTuple>
}
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();
}

Expand Down
33 changes: 33 additions & 0 deletions src/com/dotmarketing/viewtools/DotTemplateTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,41 @@ public static Map<String, Object> theme ( String themeFolderInode, String hostId
*/
public static Map<String, Object> 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 );
}

Expand Down

0 comments on commit b68019c

Please sign in to comment.