Skip to content

Commit

Permalink
#11303: Get Velocity root folder method created. Classes that had the…
Browse files Browse the repository at this point in the history
… hardcoded path were modified.
  • Loading branch information
Daniel Laguna authored and Daniel Laguna committed Apr 18, 2017
1 parent fe3cb7c commit 9507077
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 82 deletions.
8 changes: 4 additions & 4 deletions dotCMS/src/main/java/com/dotmarketing/osgi/ActivatorUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.dotcms.repackage.org.apache.struts.config.ModuleConfig;
import com.dotcms.repackage.org.apache.struts.config.impl.ModuleConfigImpl;
import com.dotmarketing.util.Config;
import com.dotmarketing.util.VelocityUtil;
import com.liferay.portal.util.Constants;
import com.liferay.util.FileUtil;
import org.apache.felix.http.api.ExtHttpService;
Expand All @@ -23,9 +24,8 @@

class ActivatorUtil {

static final String PATH_SEPARATOR = "/";
static final String PATH_SEPARATOR = "/";
static final String OSGI_FOLDER = "/osgi";
static final String VELOCITY_FOLDER = "/WEB-INF/velocity";

static String getBundleFolder ( BundleContext context, String separator ) {

Expand Down Expand Up @@ -75,7 +75,7 @@ static void cleanResources ( BundleContext context ) {
}

//Now cleaning the resources under the velocity folder
resourcesPath = servletContext.getRealPath( VELOCITY_FOLDER + getBundleFolder( context, "/" ) );
resourcesPath = servletContext.getRealPath( VelocityUtil.getVelocityRootPath() + getBundleFolder( context, "/" ) );
resources = new File( resourcesPath );
if ( resources.exists() ) {
FileUtil.deltree( resources );
Expand All @@ -92,7 +92,7 @@ static void cleanResources ( BundleContext context ) {
static void moveVelocityResources ( BundleContext context, String referenceResourcePath ) throws Exception {

ServletContext servletContext = Config.CONTEXT;
String destinationPath = servletContext.getRealPath( VELOCITY_FOLDER + getBundleFolder( context, "/" ) );
String destinationPath = servletContext.getRealPath( VelocityUtil.getVelocityRootPath() + getBundleFolder( context, "/" ) );

moveResources( context, referenceResourcePath, destinationPath );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.dotmarketing.util.ConfigUtils;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.UtilMethods;
import com.dotmarketing.util.VelocityUtil;
import com.dotmarketing.velocity.DotResourceCache;
import com.liferay.util.FileUtil;

Expand Down Expand Up @@ -285,11 +286,6 @@ public static InputStream buildVelocity(Container container, Identifier identifi

try {
String folderPath = (!EDIT_MODE) ? "live" + File.separator: "working" + File.separator;
String velocityRootPath = Config.getStringProperty("VELOCITY_ROOT");
if (velocityRootPath.startsWith("/WEB-INF")) {
velocityRootPath = FileUtil.getRealPath(velocityRootPath);
}
velocityRootPath += File.separator;
String filePath = folderPath + identifier.getInode() + "." + Config.getStringProperty("VELOCITY_CONTAINER_EXTENSION");

if(Config.getBooleanProperty("SHOW_VELOCITYFILES", false)){
Expand Down Expand Up @@ -332,10 +328,7 @@ public static void removeContainerFile(Container container, boolean EDIT_MODE) t

public static void removeContainerFile (Container container, Identifier identifier, boolean EDIT_MODE) {
String folderPath = (!EDIT_MODE) ? "live" + java.io.File.separator: "working" + java.io.File.separator;
String velocityRootPath = Config.getStringProperty("VELOCITY_ROOT");
if (velocityRootPath.startsWith("/WEB-INF")) {
velocityRootPath = FileUtil.getRealPath(velocityRootPath);
}
String velocityRootPath = VelocityUtil.getVelocityRootPath();
velocityRootPath += java.io.File.separator;
String filePath = folderPath + identifier.getInode() + "." + Config.getStringProperty("VELOCITY_CONTAINER_EXTENSION");
java.io.File f = new java.io.File(velocityRootPath + filePath);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dotmarketing.services;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
Expand Down Expand Up @@ -34,6 +35,7 @@
import com.dotmarketing.util.InodeUtils;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.UtilMethods;
import com.dotmarketing.util.VelocityUtil;
import com.dotmarketing.velocity.DotResourceCache;
import com.liferay.portal.model.User;
import com.liferay.util.FileUtil;
Expand Down Expand Up @@ -402,14 +404,6 @@ else if (field.getFieldType().equals(Field.FieldType.BINARY.toString())) {

if(Config.getBooleanProperty("SHOW_VELOCITYFILES", false)){
try {

String velocityRootPath=Config.getStringProperty("VELOCITY_ROOT");

if (velocityRootPath.startsWith("/WEB-INF")) {
velocityRootPath=FileUtil.getRealPath(velocityRootPath);
}
velocityRootPath += java.io.File.separator;

String veloExt=Config.getStringProperty("VELOCITY_CONTENT_MAP_EXTENSION");
String baseFilename=String.format("%s_%d.%s", content.getIdentifier(), content.getLanguageId(), veloExt);

Expand Down Expand Up @@ -466,7 +460,9 @@ private static void removeContentletMapFile(Contentlet asset, boolean EDIT_MODE)

private static void removeContentletMapFile(Contentlet asset, Identifier identifier, boolean EDIT_MODE) {
String folderPath=(!EDIT_MODE) ? "live/" : "working/";
String velocityRoot=FileUtil.getRealPath("/WEB-INF/velocity/") + folderPath;

String velocityRootPath = VelocityUtil.getVelocityRootPath();
String velocityRoot = velocityRootPath + File.separator + folderPath;

String filePath= folderPath + identifier.getInode() + "_" + asset.getLanguageId() + "." + Config.getStringProperty("VELOCITY_CONTENT_MAP_EXTENSION");
java.io.File f=new java.io.File (velocityRoot + filePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.dotmarketing.util.InodeUtils;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.UtilMethods;
import com.dotmarketing.util.VelocityUtil;
import com.dotmarketing.velocity.DotResourceCache;
import com.dotmarketing.viewtools.LanguageWebAPI;
import com.liferay.portal.model.User;
Expand Down Expand Up @@ -478,14 +479,6 @@ else if (field.getFieldType().equals(Field.FieldType.CATEGORY.toString())) {

if(Config.getBooleanProperty("SHOW_VELOCITYFILES", false)){
try {

String velocityRootPath= Config.getStringProperty("VELOCITY_ROOT");

if (velocityRootPath.startsWith("/WEB-INF")) {
velocityRootPath= FileUtil.getRealPath(velocityRootPath);
}
velocityRootPath += java.io.File.separator;

String veloExt= Config.getStringProperty("VELOCITY_CONTENT_EXTENSION");
String baseFilename= String.format("%s_%d.%s", identifier.getInode(), content.getLanguageId(), veloExt);

Expand Down Expand Up @@ -554,10 +547,7 @@ private static void removeContentletFile(Contentlet asset, Identifier identifier
CacheLocator.getContentletCache().remove(asset.getInode());

String folderPath= (!EDIT_MODE) ? "live" + java.io.File.separator : "working" + java.io.File.separator;
String velocityRootPath= Config.getStringProperty("VELOCITY_ROOT");
if (velocityRootPath.startsWith("/WEB-INF")) {
velocityRootPath= FileUtil.getRealPath(velocityRootPath);
}
String velocityRootPath = VelocityUtil.getVelocityRootPath();
velocityRootPath += java.io.File.separator;

Set<Long> langs = new HashSet<Long>();
Expand Down
12 changes: 2 additions & 10 deletions dotCMS/src/main/java/com/dotmarketing/services/FieldServices.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.dotmarketing.util.ConfigUtils;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.UtilMethods;
import com.dotmarketing.util.VelocityUtil;
import com.dotmarketing.velocity.DotResourceCache;
import com.liferay.util.FileUtil;

Expand Down Expand Up @@ -66,12 +67,6 @@ public static InputStream buildVelocity(String fieldInode, String contentInode,
}

if(Config.getBooleanProperty("SHOW_VELOCITYFILES", false)){
String velocityRootPath = Config.getStringProperty("VELOCITY_ROOT");
if (velocityRootPath.startsWith("/WEB-INF")) {
velocityRootPath = FileUtil.getRealPath(velocityRootPath);
}
velocityRootPath += java.io.File.separator;

String folderPath = (!EDIT_MODE) ? "live" + java.io.File.separator: "working" + java.io.File.separator;
String filePath=folderPath + contentInode + "_" + fieldInode + "." + Config.getStringProperty("VELOCITY_FIELD_EXTENSION");
//Specify a proper character encoding
Expand Down Expand Up @@ -99,10 +94,7 @@ public static InputStream buildVelocity(String fieldInode, String contentInode,
}

public static void removeFieldFile (String fieldInode, String contentInode, boolean EDIT_MODE) {
String velocityRootPath = Config.getStringProperty("VELOCITY_ROOT");
if (velocityRootPath.startsWith("/WEB-INF")) {
velocityRootPath = FileUtil.getRealPath(velocityRootPath);
}
String velocityRootPath = VelocityUtil.getVelocityRootPath();
velocityRootPath += java.io.File.separator;
String folderPath = (!EDIT_MODE) ? "live" + java.io.File.separator: "working" + java.io.File.separator;
String filePath=folderPath + contentInode + "_" + fieldInode + "." + Config.getStringProperty("VELOCITY_FIELD_EXTENSION");
Expand Down
16 changes: 5 additions & 11 deletions dotCMS/src/main/java/com/dotmarketing/services/HostServices.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.dotmarketing.util.ConfigUtils;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.UtilMethods;
import com.dotmarketing.util.VelocityUtil;
import com.dotmarketing.velocity.DotResourceCache;
import com.liferay.portal.model.User;
import com.liferay.util.FileUtil;
Expand Down Expand Up @@ -73,13 +74,9 @@ public static InputStream buildStream(Host host, boolean EDIT_MODE) throws DotDa

if(Config.getBooleanProperty("SHOW_VELOCITYFILES", false)){
String realFolderPath = (!EDIT_MODE) ? "live" + java.io.File.separator: "working" + java.io.File.separator;
String velocityRootPath = Config.getStringProperty("VELOCITY_ROOT");
String filePath = realFolderPath + host.getIdentifier() + "." + Config.getStringProperty("VELOCITY_HOST_EXTENSION");
if (velocityRootPath.startsWith("/WEB-INF")) {
velocityRootPath = FileUtil.getRealPath(velocityRootPath);
}
velocityRootPath += java.io.File.separator;


String filePath = realFolderPath + host.getIdentifier() + "." + Config.getStringProperty("VELOCITY_HOST_EXTENSION");

java.io.BufferedOutputStream tmpOut = new java.io.BufferedOutputStream(new java.io.FileOutputStream(new java.io.File(ConfigUtils.getDynamicVelocityPath()+java.io.File.separator + filePath)));
//Specify a proper character encoding
OutputStreamWriter out = new OutputStreamWriter(tmpOut, UtilMethods.getCharsetConfiguration());
Expand Down Expand Up @@ -112,10 +109,7 @@ public static void unpublishPageFile(Host host) {

public static void removeHostFile (Host host, boolean EDIT_MODE) {
String folderPath = (!EDIT_MODE) ? "live" + java.io.File.separator: "working" + java.io.File.separator;
String velocityRootPath = Config.getStringProperty("VELOCITY_ROOT");
if (velocityRootPath.startsWith("/WEB-INF")) {
velocityRootPath = FileUtil.getRealPath(velocityRootPath);
}
String velocityRootPath = VelocityUtil.getVelocityRootPath();
String filePath = folderPath + host.getIdentifier() + "." + Config.getStringProperty("VELOCITY_HOST_EXTENSION");
velocityRootPath += java.io.File.separator;
java.io.File f = new java.io.File(velocityRootPath + filePath);
Expand Down
13 changes: 3 additions & 10 deletions dotCMS/src/main/java/com/dotmarketing/services/PageServices.java
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,9 @@ public static InputStream buildStream(IHTMLPage htmlPage, Identifier identifier,
String languageStr = htmlPage.isContent() ? "_" + ((Contentlet)htmlPage).getLanguageId():"";

String realFolderPath = (!EDIT_MODE) ? "live" + java.io.File.separator: "working" + java.io.File.separator;
String velocityRootPath = Config.getStringProperty("VELOCITY_ROOT");

String filePath = realFolderPath + identifier.getInode() + languageStr + "." + Config.getStringProperty("VELOCITY_HTMLPAGE_EXTENSION","dotpage");
if (velocityRootPath.startsWith("/WEB-INF")) {
velocityRootPath = com.liferay.util.FileUtil.getRealPath(velocityRootPath);
}
velocityRootPath += java.io.File.separator;


java.io.BufferedOutputStream tmpOut = new java.io.BufferedOutputStream(new java.io.FileOutputStream(new java.io.File(ConfigUtils.getDynamicVelocityPath()+java.io.File.separator + filePath)));
//Specify a proper character encoding
OutputStreamWriter out = new OutputStreamWriter(tmpOut, UtilMethods.getCharsetConfiguration());
Expand All @@ -387,10 +383,7 @@ public static InputStream buildStream(IHTMLPage htmlPage, Identifier identifier,

public static void removePageFile (IHTMLPage htmlPage, Identifier identifier, boolean EDIT_MODE) {
String folderPath = (!EDIT_MODE) ? "live" + java.io.File.separator: "working" + java.io.File.separator;
String velocityRootPath = Config.getStringProperty("VELOCITY_ROOT");
if (velocityRootPath.startsWith("/WEB-INF")) {
velocityRootPath = com.liferay.util.FileUtil.getRealPath(velocityRootPath);
}
String velocityRootPath = VelocityUtil.getVelocityRootPath();
String languageStr = htmlPage.isContent() ? "_" + ((Contentlet)htmlPage).getLanguageId():"";
String filePath = folderPath + identifier.getInode() + languageStr + "." + Config.getStringProperty("VELOCITY_HTMLPAGE_EXTENSION","dotpage");
velocityRootPath += java.io.File.separator;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dotmarketing.services;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
Expand All @@ -16,6 +17,7 @@
import com.dotmarketing.util.ConfigUtils;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.UtilMethods;
import com.dotmarketing.util.VelocityUtil;
import com.dotmarketing.velocity.DotResourceCache;
import com.liferay.util.FileUtil;

Expand Down Expand Up @@ -151,11 +153,6 @@ public static InputStream buildVelocity(Structure structure,boolean EDIT_MODE) {

try {
if(Config.getBooleanProperty("SHOW_VELOCITYFILES", false)){
String velocityRootPath = Config.getStringProperty("VELOCITY_ROOT");
if (velocityRootPath.startsWith("/WEB-INF")) {
velocityRootPath = FileUtil.getRealPath(velocityRootPath);
}
velocityRootPath += java.io.File.separator;

String relativePath = "/working/" + structure.getInode() + "." + Config.getStringProperty("VELOCITY_STRUCTURE_EXTENSION");

Expand All @@ -181,7 +178,9 @@ public static InputStream buildVelocity(Structure structure,boolean EDIT_MODE) {
public static void removeStructureFile(Structure structure) {
String folderPath = "working/";
String filePath=folderPath + structure.getInode() + "." + Config.getStringProperty("VELOCITY_STRUCTURE_EXTENSION");
String absolutPath = FileUtil.getRealPath("/WEB-INF/velocity/" +filePath);

String velocityRootPath = VelocityUtil.getVelocityRootPath();
String absolutPath = velocityRootPath + File.separator + filePath;
java.io.File f = new java.io.File(absolutPath);
f.delete();
DotResourceCache vc = CacheLocator.getVeloctyResourceCache();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.dotmarketing.util.Constants;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.UtilMethods;
import com.dotmarketing.util.VelocityUtil;
import com.dotmarketing.velocity.DotResourceCache;
import com.liferay.util.FileUtil;

Expand Down Expand Up @@ -55,12 +56,6 @@ public static InputStream buildVelocity(Template template, Identifier identifier
InputStream result;
StringBuilder templateBody = new StringBuilder();
try {
String velocityRootPath = Config.getStringProperty("VELOCITY_ROOT");
if (velocityRootPath.startsWith("/WEB-INF")) {
velocityRootPath = FileUtil.getRealPath(velocityRootPath);
}
velocityRootPath += java.io.File.separator;

String folderPath = (!EDIT_MODE) ? "live" + java.io.File.separator: "working" + java.io.File.separator;
String filePath=folderPath + identifier.getInode() + "." + Config.getStringProperty("VELOCITY_TEMPLATE_EXTENSION");

Expand Down Expand Up @@ -112,10 +107,7 @@ public static void removeTemplateFile(Template asset, boolean EDIT_MODE) throws
}

public static void removeTemplateFile (Template asset, Identifier identifier, boolean EDIT_MODE) {
String velocityRootPath = Config.getStringProperty("VELOCITY_ROOT");
if (velocityRootPath.startsWith("/WEB-INF")) {
velocityRootPath = FileUtil.getRealPath(velocityRootPath);
}
String velocityRootPath = VelocityUtil.getVelocityRootPath();
velocityRootPath += java.io.File.separator;

String folderPath = (!EDIT_MODE) ? "live" + java.io.File.separator: "working" + java.io.File.separator;
Expand Down
22 changes: 21 additions & 1 deletion dotCMS/src/main/java/com/dotmarketing/util/VelocityUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import com.dotmarketing.velocity.VelocityServlet;
import com.dotmarketing.viewtools.RequestWrapper;
import com.liferay.portal.model.Company;
import com.liferay.util.SystemProperties;
import com.liferay.util.*;


public class VelocityUtil {
Expand Down Expand Up @@ -588,4 +588,24 @@ public static IHTMLPage getPage(Identifier id, HttpServletRequest request, boole
return htmlPage;
}

/**
* Gets the Velocity Root Path. Looks for it on the Config, if not found the it get defaulted to /WEB-INF/velocity
*
* @return String
*/
public static String getVelocityRootPath() {
Logger.debug(VelocityUtil.class, "Fetching the velocity ROOT path...");

String velocityRootPath;

velocityRootPath = Config.getStringProperty("VELOCITY_ROOT", "/WEB-INF/velocity");
if (velocityRootPath.startsWith("/WEB-INF")) {
Logger.debug(VelocityUtil.class, "Velocity ROOT Path not found, defaulting it to '/WEB-INF/velocity'");
velocityRootPath = com.liferay.util.FileUtil.getRealPath(velocityRootPath);
}

Logger.debug(VelocityUtil.class, String.format("Velocity ROOT path found: %s", velocityRootPath));
return velocityRootPath;
}

}

0 comments on commit 9507077

Please sign in to comment.