Author: cmailleux
Date: Thu Jul 12 16:57:36 2007
New Revision: 17967
URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D17967&repname=
=3Djahia
Log:
Port of commit [1706] Resolve issue ESI-282
Modified:
trunk/core/src/java/org/jahia/taglibs/esi/JesiTemplateTag.java
Modified: trunk/core/src/java/org/jahia/taglibs/esi/JesiTemplateTag.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/core/src/java/o=
rg/jahia/taglibs/esi/JesiTemplateTag.java&rev=3D17967&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/core/src/java/org/jahia/taglibs/esi/JesiTemplateTag.java (origina=
l)
+++ trunk/core/src/java/org/jahia/taglibs/esi/JesiTemplateTag.java Thu Jul =
12 16:57:36 2007
@@ -18,31 +18,30 @@
package org.jahia.taglibs.esi;
=
=
-
-
-import java.io.IOException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.jsp.*;
import org.jahia.bin.Jahia;
+import org.jahia.params.ParamBean;
+import org.jahia.params.ProcessingContext;
import org.jahia.registries.ServicesRegistry;
-import java.util.Date;
-import java.util.Map;
-import java.util.Iterator;
-import java.util.HashMap;
-import java.text.DateFormat;
import org.jahia.resourcebundle.JahiaResourceBundle;
-import org.jahia.services.esi.tagstack.Template;
-import org.jahia.services.esi.tagstack.JesiObject;
import org.jahia.services.esi.EsiService;
-import org.jahia.params.ParamBean;
-import org.jahia.params.ProcessingContext;
+import org.jahia.services.esi.tagstack.JesiObject;
+import org.jahia.services.esi.tagstack.Template;
import org.jboss.cache.CacheException;
=
-public class JesiTemplateTag extends JesiBodyTag
-{
- private static org.apache.log4j.Logger logger =3D
- org.apache.log4j.Logger.getLogger(JesiTemplateTag.class);
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.jsp.JspTagException;
+import javax.servlet.jsp.JspWriter;
+import javax.servlet.jsp.PageContext;
+import java.io.IOException;
+import java.text.DateFormat;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+public class JesiTemplateTag extends JesiBodyTag {
+ private static org.apache.log4j.Logger logger =3D org.apache.log4j.Log=
ger.getLogger(JesiTemplateTag.class);
=
int fragmentCount;
int requestedFragment;
@@ -57,25 +56,21 @@
int detectedEnclosedStagedOnlyAlwaysInvalidateFrags =3D JesiConst.UNIN=
IT;
Date startTime;
=
- public JesiTemplateTag()
- {
- detectedEnclosedStagedOnlyAlwaysInvalidateFrags =3D JesiConst.UNIN=
IT;
+ public JesiTemplateTag() {
detectedEnclosedAlwaysInvalidateFrags =3D false;
aclGroupedTemplate =3D false;
tpl =3D null;
- firstExecute=3D false;
+ firstExecute =3D false;
requestFromSurrogate_10 =3D false;
fragmentCount =3D 0;
requestedFragment =3D JesiConst.NO_FRAGMENTS;
requestedFragmentBody =3D null;
controlSet =3D false;
- requestedFragmentBody=3Dnull;
- URL=3Dnull;
+ requestedFragmentBody =3D null;
+ URL =3D null;
}
=
- public int doStartTag()
- throws JspTagException
- {
+ public int doStartTag() throws JspTagException {
=
startTime =3D new Date();
=
@@ -84,197 +79,128 @@
return javax.servlet.jsp.tagext.Tag.EVAL_BODY_INCLUDE;//1; //s=
hould be EVAL_BODY_BUFFERED
}
//various sanity checks:
- if(pageContext.getAttribute("jesitag.templatetag", PageContext.REQ=
UEST_SCOPE) !=3D null)
- {
+ if (pageContext.getAttribute("jesitag.templatetag", PageContext.RE=
QUEST_SCOPE) !=3D null) {
release();
- if(pageContext.getAttribute(JesiConst.TEMPLATE_IN_USE, PageCon=
text.REQUEST_SCOPE) !=3D null)
- throw new JspTagException(
- JahiaResourceBundle.getResource("", "org.jahia.esi=
.nested_template", Jahia.getThreadParamBean().getLocale(), Jahia.getThreadP=
aramBean())
- );
- else
- throw new JspTagException(
- JahiaResourceBundle.getResource("", "org.jahia.esi=
.multiple_template", Jahia.getThreadParamBean().getLocale(), Jahia.getThrea=
dParamBean())
- );
+ if (pageContext.getAttribute(JesiConst.TEMPLATE_IN_USE, PageCo=
ntext.REQUEST_SCOPE) !=3D null)
+ throw new JspTagException(JahiaResourceBundle.getResource(=
"",
+ =
"org.jahia.esi.nested_template",
+ =
Jahia.getThreadParamBean().getLocale(),
+ =
Jahia.getThreadParamBean()));
+ else throw new JspTagException(JahiaResourceBundle.getResource=
("",
+ =
"org.jahia.esi.multiple_template",
+ =
Jahia.getThreadParamBean().getLocale(),
+ =
Jahia.getThreadParamBean()));
}
- pageContext.setAttribute("jesitag.templatetag", this,PageContext.R=
EQUEST_SCOPE);
+ pageContext.setAttribute("jesitag.templatetag", this, PageContext.=
REQUEST_SCOPE);
pageContext.setAttribute(JesiConst.TEMPLATE_IN_USE, this, PageCont=
ext.REQUEST_SCOPE);
=
- if(pageContext.getAttribute("jesitag.controltag", PageContext.REQU=
EST_SCOPE) !=3D null)
- controlSet =3D true;
+ if (pageContext.getAttribute("jesitag.controltag", PageContext.REQ=
UEST_SCOPE) !=3D null) controlSet =3D true;
=
- HttpServletRequest req =3D (HttpServletRequest)pageContext.getRequ=
est();
+ HttpServletRequest req =3D (HttpServletRequest) pageContext.getReq=
uest();
requestedFragment =3D JesiConst.NO_FRAGMENTS;//-1
=
- try
- {
+ try {
pageContext.getOut().clearBuffer();
+ } catch (IOException ioexception) {
+ logger.warn("IOException during clearing of output jsp buffer"=
, ioexception);
}
- catch(IOException ioexception) { }
=
- this.URL =3D (String) req.getAttribute(JesiConst.INTERPRETED_PROXY=
_REQUEST_URL_SESSIONKEY);
+ URL =3D (String) req.getAttribute(JesiConst.INTERPRETED_PROXY_REQU=
EST_URL_SESSIONKEY);
//add template to invalidation hashmap
//we want to do this even when ESI isn't supported for this reques=
t, so that all compiled
//pages register their templates with the ESI cache, since future =
requests with ESI-support
//will need this information.
- this.tpl =3D ServicesRegistry.getInstance().getEsiService().addTem=
plate (Jahia.getThreadParamBean().getSiteID(),
- Jahia.getThreadParamBean().getPageID(), this.URL);
- if (logger.isDebugEnabled())
- logger.debug("[esi]: Inside Template on page:"+Jahia.=
getThreadParamBean().getPageID() +" for request url:" + URL);
+ tpl =3D ServicesRegistry.getInstance()
+ .getEsiService()
+ .addTemplate(Jahia.getThreadParamBean().getSiteID(), Jahia=
.getThreadParamBean().getPageID(), URL);
+ if (logger.isDebugEnabled()) logger.debug("[esi]: Inside Template=
on page:" +
+ Jahia.getThreadParamBean=
().getPageID() +
+ " for request url:" +
+ URL);
=
- //System.err.println("wwww Template.URL : "+this.URL);
+ //System.err.println("wwww Template.URL : "+URL);
requestFromSurrogate_10 =3D JesiTag.requestFromSurrogate_10(req);
=
//If no support for ESI, then skip this tag and just return its bo=
dy
- if(!JesiTag.requestFromSurrogate_10(req))
- return javax.servlet.jsp.tagext.Tag.EVAL_BODY_INCLUDE;//1
+ if (!JesiTag.requestFromSurrogate_10(req)) return javax.servlet.js=
p.tagext.Tag.EVAL_BODY_INCLUDE;//1
=
HttpServletResponse httpResponse =3D ((HttpServletResponse) pageCo=
ntext.getResponse());
ProcessingContext pc =3D Jahia.getThreadParamBean();
=
- if (Jahia.getSettings().isEsiEnableTemplateCaching()
- && !JesiConst.UNSET.equals(this.aclGroup)) {
- this.aclGroupedTemplate=3D true;
- if (logger.isDebugEnabled())
- logger.debug("aclGrouped Template detected");
+ if (Jahia.getSettings().isEsiEnableTemplateCaching() && !JesiConst=
.UNSET.equals(aclGroup)) {
+ aclGroupedTemplate =3D true;
+ if (logger.isDebugEnabled()) logger.debug("aclGrouped Template=
detected");
=
- if (!"true".equals(this.aclGroup))
- logger.warn("aclGroup=3D'true' is only supported argument,=
not current aclGroup=3D"+this.aclGroup);
+ if (!"true".equals(aclGroup))
+ logger.warn("aclGroup=3D'true' is only supported argument,=
not current aclGroup=3D" + aclGroup);
}
=
try {
- this.firstExecute =3D this.tpl.isFirstExecute(pc.getOperationM=
ode());
- } catch(CacheException e) {
- logger.error("Could not get firstExecute ",e);
+ firstExecute =3D tpl.isFirstExecute(pc.getOperationMode());
+ } catch (CacheException e) {
+ logger.error("Could not get firstExecute ", e);
}
=
//Is request asking for a Fragment?
try {
//Yes
- this.requestedFragment =3D Integer.parseInt(req.getParameter(J=
esiConst.FRAGMENT_URL_MARKER));
+ requestedFragment =3D Integer.parseInt(req.getParameter(JesiCo=
nst.FRAGMENT_URL_MARKER));
//save request debug info
- req.setAttribute(JesiConst.ESI_REQUEST_TYPE_INFO,"Fragment#"+r=
equestedFragment);
- }
- catch(NumberFormatException ex) {
+ req.setAttribute(JesiConst.ESI_REQUEST_TYPE_INFO, "Fragment#" =
+ requestedFragment);
+ } catch (NumberFormatException ex) {
//No
- this.requestedFragment =3D JesiConst.NO_FRAGMENTS;//-1
-
- //tag this response with the appropriate Template header
- httpResponse.setHeader(JesiConst.ESI_TEMPLATE_HEADER, "yes");
-
- String aclGroupHeaderVal =3Dnull;
- //this should really be in doEndTag() but response is committe=
d by then, so have to do it here.
- //(the disavantage is that we cannot cache first run of this t=
emplate)
- if(this.requestFromSurrogate_10 && this.aclGroupedTemplate) {
- //if this is an aclGroup-shared template, then set the app=
ropriate userACL header
- //which shows if there are any specific user acls on this =
page.
- if (Jahia.getSettings().isEsiEnableTemplateCaching()
- && !this.firstExecute) { //if this is the first ti=
me we execute this template, we don't know the user ACLs yet, so just don't=
set the header just yet
-
- //are there any User ACLs specifically assigned to thi=
s page?
- Map aclUsernames =3D tpl.getAclUserNames();
- if (aclUsernames!=3Dnull && !aclUsernames.isEmpty()) {
- StringBuffer sb =3D new StringBuffer();
- Iterator usersIt =3D aclUsernames.keySet().iterato=
r();
- while (usersIt.hasNext()) {
- String userName =3D (String) usersIt.next();
- userName =3D ServicesRegistry.getInstance().ge=
tEsiURLGeneratorService().encodeString(userName);
- sb.append(userName).append(JesiConst.USERACLS_=
SEPARATOR);
- }
- aclGroupHeaderVal =3D sb.toString();
- }
- else
- aclGroupHeaderVal =3D JesiConst.NO_USERACLS_DETECT=
ED;
-
- httpResponse.setHeader(JesiConst.ACLGROUP_TEMPLATE_USE=
RACLS_HEADER,aclGroupHeaderVal);
-
- if (httpResponse.isCommitted())
- logger.warn("Could not add "+JesiConst.ACLGROUP_TE=
MPLATE_USERACLS_HEADER+" because request was committed already.");
-
- if (logger.isDebugEnabled())
- logger.debug("Set " + JesiConst.ACLGROUP_TEMPLATE_=
USERACLS_HEADER+" header : "+aclGroupHeaderVal);
-
- StringBuffer aclGroupFragmentUserACLsHeaderVal =3D new=
StringBuffer();
- HashMap hm =3D tpl.getFragmentUserACLs();
- Iterator hmIter =3D hm.keySet().iterator();
- while (hmIter.hasNext()) {
- String fragHeaderName =3D (String) hmIter.next();
- String fragHeaderVal =3D (String) hm.get(fragHea=
derName);
-
- aclGroupFragmentUserACLsHeaderVal.append(fragHeade=
rName)
- .append(":")
- .append(fragHeade=
rVal)
- .append(";");
- }
- //TODO: if (aclGroupFragmentUserACLsHeaderVal.length()=
=3D=3D0) {
-
- httpResponse.setHeader(JesiConst.ACLGROUP_FRAGMENT=
_USERACLS_HEADER,
- aclGroupFragmentUserACLsHea=
derVal.toString());
-
- if (logger.isDebugEnabled())
- logger.debug("Set header [" +JesiConst.ACLGROU=
P_FRAGMENT_USERACLS_HEADER +"=3D"+aclGroupFragmentUserACLsHeaderVal.toStrin=
g() +"]");
- }
- //still notify ESI server that this is an aclGrouped-share=
d template
- else
- httpResponse.setHeader(JesiConst.ACLGROUP_TEMPLATE_NOT=
IFIER_HEADER,"yes");
-
+ requestedFragment =3D JesiConst.NO_FRAGMENTS;//-1
+ if (Jahia.getSettings().isEsiEnableTemplateCaching() && !first=
Execute) {
+ addAclTemplateHeaderToResponse(httpResponse, req);
}
-
- //save request debug info
- String skeletonDesc =3D (aclGroupHeaderVal!=3Dnull)?"Skeleton-=
aclGroup":"Skeleton";
- req.setAttribute(JesiConst.ESI_REQUEST_TYPE_INFO,skeletonDesc);
}
=
//If it's not requesting a fragment and Control tag isn't present,=
then set HTTP ESI headers
- if(requestedFragment =3D=3D JesiConst.NO_FRAGMENTS
- && !controlSet) //since we use the control tag Surrigate c=
ontrol header instead
+ if (requestedFragment =3D=3D JesiConst.NO_FRAGMENTS &&
+ !controlSet)//since we use the control tag Surrigate control h=
eader instead
httpResponse.setHeader(JesiConst.SURROGATE_CONTROL_HEADER, mak=
eSurrogateControl());
=
//If it's requesting a fragment, then don't buffer the body
//If it's NOT requesting a fragment, then buffer the body for furt=
her processing
//Tag.EVAL_BODY_INCLUDE Body is evaluated and
passed through to =
current out.
//BodyTag.EVAL_BODY_BUFFERED Creates a BodyContent object that cap=
tures the processing of the body, for manipulation by the tag handler.
- return
- requestedFragment !=3D
- JesiConst.NO_FRAGMENTS ?
- javax.servlet.jsp.tagext.BodyTag.EVAL_BODY_BUFFERED
- : javax.servlet.jsp.tagext.Tag.EVAL_BODY_INCLUDE;
+ return requestedFragment !=3D JesiConst.NO_FRAGMENTS ? EVAL_BODY_B=
UFFERED : EVAL_BODY_INCLUDE;
}
=
- public int doEndTag()
- throws JspTagException
- {
+ public int doEndTag() throws JspTagException {
//If ESI not activated in jahia.properties, do nothing
if (!Jahia.getSettings().isEsiCacheActivated()) {
release();
- return javax.servlet.jsp.tagext.Tag.EVAL_PAGE;//6;
+ return EVAL_PAGE;//6;
}
=
ProcessingContext pc =3D Jahia.getThreadParamBean();
=
//Check that the total number of Fragments on this Template reflec=
ts same the total number
//of Fragments stored in the "Fragments" HashMap, if not delete an=
y excess Fragment entries
- ServicesRegistry.getInstance().getEsiService().deleteOldFragments (
- Jahia.getThreadParamBean().getSiteID(), //could get this i=
nfo from Template obj in tagStack
- Jahia.getThreadParamBean().getPageID(), //could get this i=
nfo from Template obj in tagStack
- getFragmentCount());
+ ServicesRegistry.getInstance().getEsiService().deleteOldFragments(=
Jahia.getThreadParamBean().getSiteID(),
+ =
//could get this info from Template obj in tagStack
+ =
Jahia.getThreadParamBean().getPageID(),
+ =
//could get this info from Template obj in tagStack
+ =
getFragmentCount());
=
=
-
- HttpServletRequest req =3D (HttpServletRequest)pageContext.getRequ=
est();
+ HttpServletRequest req =3D (HttpServletRequest) pageContext.getReq=
uest();
//If ESI supported and it's requesting a fragment, then output the=
Fragment body
- if(requestFromSurrogate_10 && requestedFragment !=3D JesiConst.NO_=
FRAGMENTS) {
- try
- {
+ if (requestFromSurrogate_10 && requestedFragment !=3D JesiConst.NO=
_FRAGMENTS) {
+ try {
getBodyContent().getEnclosingWriter().print(requestedFragm=
entBody);
getBodyContent().clearBody();
- }
- catch(IOException ioexception)
- {
+ } catch (IOException ioexception) {
throw new JspTagException(ioexception.toString());
}
}
=
- if(requestFromSurrogate_10 && requestedFragment =3D=3D JesiConst.N=
O_FRAGMENTS) {
+ if (requestFromSurrogate_10 && requestedFragment =3D=3D JesiConst.=
NO_FRAGMENTS) {
+ HttpServletResponse httpServletResponse =3D (HttpServletRespon=
se) pageContext.getResponse();
+
+ if (!httpServletResponse.isCommitted() && firstExecute && Jahi=
a.getSettings().isEsiEnableTemplateCaching())
+ addAclTemplateHeaderToResponse(httpServletResponse, req);
=
if (Jahia.getSettings().getEsiDisplayFragmentDelimiters()) {
//For debug purposes only
@@ -282,40 +208,56 @@
if (Jahia.getSettings().getEsiDisplayContentIDs()) {
StringBuffer contentIDs =3D new StringBuffer();
contentIDs.append("<p>Referenced Content : ");
- contentIDs.append("<br>ctnListID0s: ");contentIDs.appe=
nd(EsiService.printDetailedContents(tpl.getContainerListID0s()));
- contentIDs.append("<br>ctnLists: ");contentIDs.append(=
EsiService.printDetailedContents(tpl.getContainerLists()));
- contentIDs.append("<br>ctns: ");contentIDs.append(EsiS=
ervice.printDetailedContents(tpl.getContainers()));
- contentIDs.append("<br>fields: ");contentIDs.append(Es=
iService.printDetailedContents(tpl.getFields()));
- contentIDs.append("<br>pages: ");contentIDs.append(Esi=
Service.printDetailedContents(tpl.getPages()));
+ contentIDs.append("<br>ctnListID0s: ");
+ contentIDs.append(EsiService.printDetailedContents(tpl=
.getContainerListID0s()));
+ contentIDs.append("<br>ctnLists: ");
+ contentIDs.append(EsiService.printDetailedContents(tpl=
.getContainerLists()));
+ contentIDs.append("<br>ctns: ");
+ contentIDs.append(EsiService.printDetailedContents(tpl=
.getContainers()));
+ contentIDs.append("<br>fields: ");
+ contentIDs.append(EsiService.printDetailedContents(tpl=
.getFields()));
+ contentIDs.append("<br>pages: ");
+ contentIDs.append(EsiService.printDetailedContents(tpl=
.getPages()));
contentIDs.append("</p>");
ctIDs =3D contentIDs.toString();
}
=
//calculate next update time
- String UpdateTime =3D null;
+ String UpdateTime;
if (!JesiConst.UNSET.equals(expiration)) {
Date now =3D (new Date());
- now.setTime(now.getTime() +
- (Long.parseLong(expiration)) * 1000); //since =
expiration in seconds
- UpdateTime =3D "<fieldset><b> ESI Template : Next upd=
ate time at " +
- DateFormat.getTimeInstance().format(now) + " (=
generated at "+ DateFormat.getTimeInstance().format(new Date())+")"+ "</fie=
ldset>";
- } else UpdateTime =3D "<fieldset><b> ESI Template : No Ex=
piration Delay set."+ " (generated at "+ DateFormat.getTimeInstance().forma=
t(new Date())+")"+" </b> "+ctIDs +" </fieldset>";
-
+ now.setTime(now.getTime() + (Long.parseLong(expiration=
)) * 1000);//since expiration in seconds
+ UpdateTime =3D
+ "<fieldset><b> ESI Template : Next update tim=
e at " +
+ DateFormat.getTimeInstance().format(now) +
+ " (generated at " +
+ DateFormat.getTimeInstance().format(new Date()=
) +
+ ")" +
+ "</fieldset>";
+ }
+ else UpdateTime =3D
+ "<fieldset><b> ESI Template : No Expiration Delay=
set." +
+ " (generated at " +
+ DateFormat.getTimeInstance().format(new Date()) +
+ ")" +
+ " </b> " +
+ ctIDs +
+ " </fieldset>";
=
=
JspWriter out =3D pageContext.getOut();
- try { out.print(UpdateTime); }
- catch(IOException ioexception)
- {
+ try {
+ out.print(UpdateTime);
+ } catch (IOException ioexception) {
//logger.error("[esi]: [esi]: IO exception while try=
ing to display ESI Template tag " + ioe);
}
}
//reset first execute
- if (this.firstExecute) {
+ if (firstExecute) {
try {
- this.tpl.setFirstExecute(false , pc.getOperationMode()=
);
- } catch(CacheException e) {
- logger.error("Could not set firstExecute ",e);
+ tpl.setFirstExecute(false, pc.getOperationMode());
+ } catch (CacheException e) {
+ logger.error("Could not set firstExecute ", e);
}
}
=
@@ -338,16 +280,18 @@
//From now on, any content access (i.e. getContainer() ) will add =
itself
//to the previous tag in the tagStack.
=
- JesiObject jesiObj =3D ServicesRegistry.getInstance().getEsiServic=
e().getTackStack().pop("Template", pc.getPageID());
+ JesiObject jesiObj =3D
+ ServicesRegistry.getInstance().getEsiService().getTackStac=
k().pop("Template", pc.getPageID());
=
//remove all the content which wasn't redetected in this pass over=
this template's content
//(if we don't redetected, then it was probably removed, so no poi=
nt in referencing it anymore)
- if (ProcessingContext.EDIT.equals(pc.getOperationMode())
- && !this.firstExecute) //don't do this on first execute, o=
nly on subsequent runs
+ if (ProcessingContext.EDIT.equals(pc.getOperationMode()) &&
+ !firstExecute)//don't do this on first execute, only on subseq=
uent runs
jesiObj.removeOldContent(startTime);
=
if (!ServicesRegistry.getInstance().getEsiService().getTackStack()=
.isEmpty()) {
- logger.info("tagStack isn't empty when it should. Clearing man=
ually. "+ServicesRegistry.getInstance().getEsiService().getTackStack());
+ logger.info("tagStack isn't empty when it should. Clearing man=
ually. " +
+ ServicesRegistry.getInstance().getEsiService().get=
TackStack());
//so clearing tagStack manually as it will be used by next thr=
ead
ServicesRegistry.getInstance().getEsiService().getTackStack().=
clear();
}
@@ -358,13 +302,12 @@
}
=
=
- public void release()
- {
+ public void release() {
startTime =3D null;
detectedEnclosedAlwaysInvalidateFrags =3D false;
detectedEnclosedStagedOnlyAlwaysInvalidateFrags =3D JesiConst.UNIN=
IT;
aclGroupedTemplate =3D false;
- firstExecute=3D false;
+ firstExecute =3D false;
requestFromSurrogate_10 =3D false;
fragmentCount =3D 0;
requestedFragment =3D JesiConst.NO_FRAGMENTS;//-1
@@ -374,45 +317,41 @@
super.release();
}
=
- public int getFragmentCount()
- {
+ public int getFragmentCount() {
return fragmentCount;
}
=
- void incrementFragmentCount()
- {
+ void incrementFragmentCount() {
fragmentCount++;
}
=
- int getRequestedFragment()
- {
+ int getRequestedFragment() {
return requestedFragment;
}
=
- void setRequestedFragmentBody(String s)
- {
+ void setRequestedFragmentBody(String s) {
requestedFragmentBody =3D s;
}
=
- String getRequestedFragmentBody()
- {
+ String getRequestedFragmentBody() {
return requestedFragmentBody;
}
=
- protected String makeSurrogateControl()
- throws JspTagException
- {
+ protected String makeSurrogateControl() throws JspTagException {
//TODO: WARNING: this is temporary and should be removed
//TODO: WARNING: (if we are using cookies then this code will not =
run since attribute won't be set)
- //TODO: WARNING: when using header-based invalidation, we will be =
able to invalidate these pid-less pages (in cookie modes only, not with url=
s with no jesi/ marker)
+ //TODO: WARNING: when using header-based invalidation, we will be =
able to invalidate these pid-less pages
+ // (in cookie modes only, not with urls with no jesi/ marker)
//don't cache this template if it doesn't have a /jesi/ marker in =
it
- Boolean dontCache =3D (Boolean)
- ((ParamBean)Jahia.getThreadParamBean()).getRealRequest()
- .getAttribute("esi.page.with.no.jesi.marker");
- if (dontCache!=3Dnull && dontCache.booleanValue() ) {
+ Boolean dontCache =3D (Boolean) ((ParamBean) Jahia.getThreadParamB=
ean()).getRealRequest()
+ .getAttribute("esi.page.with.no.jesi.marker");
+ if (dontCache !=3D null && dontCache.booleanValue()) {
String noCacheHeader =3D "content=3D\"ESI/1.0\",no-store";
- if (logger.isDebugEnabled())
- logger.debug("[esi]: no /jesi/ marker found so not caching=
this template in ESI cache. Template on page:"+Jahia.getThreadParamBean().=
getPageID() +" for request url:" + URL);
+ if (logger.isDebugEnabled()) logger.debug(
+ "[esi]: no /jesi/ marker found so not caching this tem=
plate in ESI cache. Template on page:" +
+ Jahia.getThreadParamBean().getPageID() +
+ " for request url:" +
+ URL);
setTagHeader(noCacheHeader);
return noCacheHeader;
}
@@ -420,4 +359,70 @@
return super.makeSurrogateControl();
}
=
+ private void addAclTemplateHeaderToResponse(HttpServletResponse httpRe=
sponse, HttpServletRequest req) {
+ //tag this response with the appropriate Template header
+ httpResponse.setHeader(JesiConst.ESI_TEMPLATE_HEADER, "yes");
+
+ String aclGroupHeaderVal =3D null;
+ //this should really be in doEndTag() but response is committed by=
then, so have to do it here.
+ //(the disavantage is that we cannot cache first run of this templ=
ate)
+ if (requestFromSurrogate_10 && aclGroupedTemplate) {
+ //if this is an aclGroup-shared template, then set the appropr=
iate userACL header
+ //which shows if there are any specific user acls on this page.
+ if (Jahia.getSettings()
+ .isEsiEnableTemplateCaching()) {//if this is the first=
time we execute this template, we don't know the user ACLs yet, so just do=
n't set the header just yet
+
+ //are there any User ACLs specifically assigned to this pa=
ge?
+ Map aclUsernames =3D tpl.getAclUserNames();
+ if (aclUsernames !=3D null && !aclUsernames.isEmpty()) {
+ StringBuffer sb =3D new StringBuffer();
+ Iterator usersIt =3D aclUsernames.keySet().iterator();
+ while (usersIt.hasNext()) {
+ String userName =3D (String) usersIt.next();
+ userName =3D ServicesRegistry.getInstance().getEsi=
URLGeneratorService().encodeString(userName);
+ sb.append(userName).append(JesiConst.USERACLS_SEPA=
RATOR);
+ }
+ aclGroupHeaderVal =3D sb.toString();
+ }
+ else aclGroupHeaderVal =3D JesiConst.NO_USERACLS_DETECTED;
+
+ httpResponse.setHeader(JesiConst.ACLGROUP_TEMPLATE_USERACL=
S_HEADER, aclGroupHeaderVal);
+
+ if (httpResponse.isCommitted()) logger.warn("Could not add=
" + JesiConst
+ .ACLGROUP_TEMPLATE_USERACLS_HEADER + " because req=
uest was committed already.");
+
+ if (logger.isDebugEnabled()) logger.debug("Set " + JesiCon=
st
+ .ACLGROUP_TEMPLATE_USERACLS_HEADER + " header : " =
+ aclGroupHeaderVal);
+
+ StringBuffer aclGroupFragmentUserACLsHeaderVal =3D new Str=
ingBuffer();
+ HashMap hm =3D tpl.getFragmentUserACLs();
+ Iterator hmIter =3D hm.keySet().iterator();
+ while (hmIter.hasNext()) {
+ String fragHeaderName =3D (String) hmIter.next();
+ String fragHeaderVal =3D (String) hm.get(fragHeaderNam=
e);
+
+ aclGroupFragmentUserACLsHeaderVal.append(fragHeaderNam=
e)
+ .append(":")
+ .append(fragHeaderVal)
+ .append(";");
+ }
+ //TODO: if (aclGroupFragmentUserACLsHeaderVal.length()=3D=
=3D0) {
+
+ httpResponse.setHeader(JesiConst.ACLGROUP_FRAGMENT_USERACL=
S_HEADER,
+ aclGroupFragmentUserACLsHeaderVal.t=
oString());
+
+ if (logger.isDebugEnabled()) logger.debug("Set header [" +=
JesiConst
+ .ACLGROUP_FRAGMENT_USERACLS_HEADER + "=3D" + aclGr=
oupFragmentUserACLsHeaderVal
+ .toString() + "]");
+ }
+ //still notify ESI server that this is an aclGrouped-shared te=
mplate
+ else httpResponse.setHeader(JesiConst.ACLGROUP_TEMPLATE_NOTIFI=
ER_HEADER, "yes");
+
+ }
+
+ //save request debug info
+ String skeletonDesc =3D (aclGroupHeaderVal !=3D null) ? "Skeleton-=
aclGroup" : "Skeleton";
+ req.setAttribute(JesiConst.ESI_REQUEST_TYPE_INFO, skeletonDesc);
+ }
+
}
_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list