Skip to content

Commit

Permalink
Issue 11362 killing macros (#11382)
Browse files Browse the repository at this point in the history
* #11315 fixes remove on put anitpattern

* #11362 replaces dotParse and parseContainer macros with Directives

* #11362 removing old macros

* #11362 adding runtime exception versions of popular methods

* #11362 fixing service methods

* #11362 working like a charm

* #11362 replacing stringbuffers with budilers

* #11362 reverting ReleaseInfo
  • Loading branch information
wezell authored and jgambarios committed Apr 28, 2017
1 parent e31007e commit fccff5a
Show file tree
Hide file tree
Showing 48 changed files with 527 additions and 376 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@
*/
public class ESContentFactoryImpl extends ContentletFactory {

private ContentletCache cc = CacheLocator.getContentletCache();
private ESClient client = null;
private LanguageAPI langAPI = APILocator.getLanguageAPI();
private ContentletCache cc ;
private ESClient client;
private LanguageAPI langAPI;

private static final Contentlet cache404Content= new Contentlet();
public static final String CACHE_404_CONTENTLET="CACHE_404_CONTENTLET";
Expand All @@ -106,6 +106,8 @@ public class ESContentFactoryImpl extends ContentletFactory {
* Elastic index.
*/
public ESContentFactoryImpl() {
cc = CacheLocator.getContentletCache();
langAPI = APILocator.getLanguageAPI();
client = new ESClient();
cache404Content.setInode(CACHE_404_CONTENTLET);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ public interface HostWebAPI extends HostAPI {
public Host getCurrentHost(ActionRequest req) throws DotDataException, DotSecurityException, PortalException, SystemException;

public Host getCurrentHost(HttpServletRequest req) throws DotDataException, DotSecurityException, PortalException, SystemException;

public Host getHost(HttpServletRequest request);

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import javax.servlet.http.HttpSession;

import com.dotmarketing.beans.Host;
import com.dotmarketing.business.DotStateException;
import com.dotmarketing.exception.DotDataException;
import com.dotmarketing.exception.DotSecurityException;
import com.dotmarketing.portlets.contentlet.business.HostAPIImpl;
Expand All @@ -35,6 +36,19 @@ public Host getCurrentHost(ActionRequest req) throws DotDataException, DotSecuri
return getCurrentHost(((ActionRequestImpl)req).getHttpServletRequest());
}

@Override
public Host getHost(HttpServletRequest request) {
try{
return getCurrentHost(request);
}catch(Exception e){
throw new DotStateException(e);
}


}



public Host getCurrentHost(HttpServletRequest request) throws DotDataException, DotSecurityException, PortalException, SystemException {
Host host = null;
HttpSession session = request.getSession(false);
Expand Down
10 changes: 10 additions & 0 deletions dotCMS/src/main/java/com/dotmarketing/business/web/UserWebAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,14 @@ public interface UserWebAPI extends UserAPI {
* @throws PortalException
*/
public abstract boolean isLoggedToFrontend(HttpServletRequest req) throws DotRuntimeException, PortalException, SystemException;

/**
* Returns user if available in the request, throws DotStateException
* @param req
* @return
* @throws DotRuntimeException
* @throws SystemException
* @throws PortalException
*/
public User getUser(HttpServletRequest request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.dotmarketing.business.APILocator;
import com.dotmarketing.business.DotStateException;
import com.dotmarketing.business.UserAPIImpl;
import com.dotmarketing.exception.DotRuntimeException;
import com.dotmarketing.util.WebKeys;
Expand All @@ -19,7 +21,23 @@ public class UserWebAPIImpl extends UserAPIImpl implements UserWebAPI {
public UserWebAPIImpl() {

}


@Override
public User getUser(HttpServletRequest request) {
try{
User user = PortalUtil.getUser(request);
if(user == null){
user = this.getLoggedInUser(request.getSession(false));
}
if(user==null){
user = APILocator.getUserAPI().getAnonymousUser();
}
return user;
}catch(Exception e){
throw new DotStateException(e);
}
}

@Override
public User getLoggedInUser(HttpServletRequest request)
throws DotRuntimeException, PortalException, SystemException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public static InputStream buildVelocity(Container container, Identifier identifi

sb.append("#set($CONTENT_INODE = '')");
sb.append("#if($contentletId != '') ");
sb.append("#getContentDetail($contentletId) ");
sb.append("#contentDetail($contentletId) ");
sb.append("#end");
sb.append("#if($CONTENT_INODE != '')");

Expand Down Expand Up @@ -234,7 +234,7 @@ public static InputStream buildVelocity(Container container, Identifier identifi
if(!containsEndTag)
{
sb.append("#if($EDIT_MODE && ${contentletId.indexOf(\".structure\")}==-1)");
sb.append("#getContentDetail($contentletId)");
sb.append("#contentDetail($contentletId)");
sb.append("$velutil.mergeTemplate('static/preview_mode/content_controls.vtl')");
sb.append("#end ");
sb.append("#if($EDIT_MODE) ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public static InputStream buildStream(IHTMLPage htmlPage, Identifier identifier,

Host host = APILocator.getHTMLPageAssetAPI().getParentHost(htmlPage);
sb.append("#if(!$doNotParseTemplate)");
sb.append("$velutil.mergeTemplate('" ).append( folderPath ).append( host.getIdentifier() ).append( "." ).append( Config.getStringProperty("VELOCITY_HOST_EXTENSION", "html") ).append( "')");
sb.append("#parse('" ).append( folderPath ).append( host.getIdentifier() ).append( "." ).append( Config.getStringProperty("VELOCITY_HOST_EXTENSION", "html") ).append( "')");
sb.append(" #end ");


Expand Down Expand Up @@ -343,9 +343,9 @@ public static InputStream buildStream(IHTMLPage htmlPage, Identifier identifier,
sb.append( "#set ($dotTheme = $templatetool.theme(\"" ).append( cmsTemplate.getTheme() ).append( "\",\"" ).append( host.getIdentifier() ).append( "\"))" );
sb.append( "#set ($dotThemeLayout = $templatetool.themeLayout(\"" ).append( cmsTemplate.getInode() ).append( "\" ))" );
//Merging our template
sb.append( "$velutil.mergeTemplate(\"$dotTheme.templatePath\")" );
sb.append( "#parse(\"$dotTheme.templatePath\")" );
} else {
sb.append( "$velutil.mergeTemplate('" ).append( folderPath ).append( iden.getInode() ).append( "." ).append( Config.getStringProperty( "VELOCITY_TEMPLATE_EXTENSION","template" ) ).append( "')" );
sb.append( "#parse('" ).append( folderPath ).append( iden.getInode() ).append( "." ).append( Config.getStringProperty( "VELOCITY_TEMPLATE_EXTENSION","template" ) ).append( "')" );
}
sb.append("#end");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dotmarketing.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
Expand All @@ -26,10 +27,26 @@ public static boolean isEditMode( HttpSession session ){
boolean timemachine = session.getAttribute("tm_date")!=null;
return !timemachine && ADMIN_MODE && (session.getAttribute(com.dotmarketing.util.WebKeys.EDIT_MODE_SESSION) != null);
}


public static boolean isEditMode( HttpServletRequest request ){
return isEditMode(request.getSession(false));
}
public static boolean isPreviewMode( HttpServletRequest request ){
return isPreviewMode(request.getSession(false));
}
public static boolean isAdminMode( HttpServletRequest request ){
return isAdminMode(request.getSession(false));
}

public static boolean isPageMode(HttpSession session) {

return !isAdminMode(session);

}

public static boolean isLive( HttpServletRequest request ){
HttpSession session = request.getSession(false);
if(session==null) return true;
return !( isAdminMode(session) && (isEditMode(session) || isPreviewMode(session)));
}


}
118 changes: 0 additions & 118 deletions dotCMS/src/main/java/com/dotmarketing/velocity/DotParseDirective.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.dotmarketing.velocity.directive;

import java.io.Writer;

import org.apache.velocity.context.Context;

import com.dotmarketing.business.APILocator;
import com.dotmarketing.business.DotStateException;
import com.dotmarketing.exception.DotDataException;
import com.dotmarketing.exception.DotRuntimeException;
import com.dotmarketing.portlets.contentlet.model.ContentletVersionInfo;
import com.dotmarketing.util.Config;

public class ContentletDetail extends DotDirective {



private static final long serialVersionUID = 1L;
final static String EXTENSION = Config.getStringProperty("VELOCITY_CONTENT_EXTENSION", "content");


@Override
public String getName() {
return "contentDetail";
}



@Override
String resolveTemplatePath(final Context context, final Writer writer, final RenderParams params, final String argument) {

ContentletVersionInfo cv = null;

try {
cv = APILocator.getVersionableAPI().getContentletVersionInfo(argument, params.language.getId());
if (cv == null) {
long defualtLang = APILocator.getLanguageAPI().getDefaultLanguage().getId();
if (defualtLang != params.language.getId()) {
cv = APILocator.getVersionableAPI().getContentletVersionInfo(argument, defualtLang);
}
}
} catch (DotStateException | DotDataException e1) {
throw new DotRuntimeException(e1);
}


return (params.live)
? "/live/" + argument + "_" + cv.getLang() + "." + EXTENSION
: "/working/" + argument + "_" + cv.getLang() + "." + EXTENSION;



}
}

0 comments on commit fccff5a

Please sign in to comment.