Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jgambarios authored May 24, 2017
1 parent 843682b commit 0b4ff63
Showing 1 changed file with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package com.dotmarketing.velocity.directive;

import java.io.Writer;

import javax.servlet.http.HttpServletRequest;

import org.apache.velocity.context.Context;
import org.apache.velocity.exception.ResourceNotFoundException;

import com.dotmarketing.beans.Host;
import com.dotmarketing.beans.Identifier;
import com.dotmarketing.business.APILocator;
Expand All @@ -17,7 +10,13 @@
import com.dotmarketing.portlets.contentlet.model.ContentletVersionInfo;
import com.dotmarketing.portlets.fileassets.business.FileAsset;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.UtilMethods;
import com.liferay.portal.model.User;
import org.apache.velocity.context.Context;
import org.apache.velocity.exception.ResourceNotFoundException;

import javax.servlet.http.HttpServletRequest;
import java.io.Writer;


public class DotParse extends DotDirective {
Expand Down Expand Up @@ -61,6 +60,22 @@ String resolveTemplatePath(final Context context, final Writer writer, final Ren
long lang = params.language.getId();
Identifier id = APILocator.getIdentifierAPI().find(host, templatePath);

//Verify if we found a resource with the given path
if ( null == id || !UtilMethods.isSet(id.getId()) ) {

String errorMessage = String.format("No resource found for [%s]", templatePath);

/*
In Edit mode we are allow to fail and be noisy, but on Preview and Live mode we just want to
continue with the render of the page, on the DotDirective.render we are catching ResourceNotFoundException's
and on the catch we continue with the render.
*/
if ( params.editMode ) {
throw new DotStateException(errorMessage);
} else {
throw new ResourceNotFoundException(errorMessage);
}
}

ContentletVersionInfo cv = APILocator.getVersionableAPI().getContentletVersionInfo(id.getId(), lang);

Expand All @@ -72,9 +87,10 @@ String resolveTemplatePath(final Context context, final Writer writer, final Ren
}
String inode = ((live) ? cv.getLiveInode() : cv.getWorkingInode());

if( null == inode) {
String errorMessage = (live) ? "Not found live version of "+templatePath : "Not found working version of "+templatePath;
throw new ResourceNotFoundException(errorMessage);
//We found the resource but not the version we are looking for
if ( null == inode ) {
String errorMessage = String.format("Not found %s version of [%s]", (live) ? "Live" : "Working", templatePath);
throw new ResourceNotFoundException(errorMessage);
}

Contentlet c = APILocator.getContentletAPI().find(inode, params.user, params.live);
Expand Down

0 comments on commit 0b4ff63

Please sign in to comment.