/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/LocaleOptionsTag.java |
---|
0,0 → 1,50 |
// based on jakarta struts taglib |
package ak.hostadmiral.core.taglib; |
import java.util.Locale; |
import javax.servlet.jsp.JspException; |
import org.apache.struts.taglib.html.Constants; |
import org.apache.struts.taglib.html.SelectTag; |
import org.apache.struts.taglib.html.OptionsTag; |
import org.apache.struts.util.MessageResources; |
import org.apache.struts.util.ResponseUtils; |
import ak.hostadmiral.core.Locales; |
import ak.hostadmiral.core.model.User; |
import ak.hostadmiral.core.servlet.SessionKeys; |
public class LocaleOptionsTag extends OptionsTag |
{ |
protected static MessageResources pageMessages = |
MessageResources.getMessageResources("ak.hostadmiral.core.resources.PageMessages"); |
public int doEndTag() throws JspException |
{ |
SelectTag selectTag = (SelectTag) pageContext.getAttribute(Constants.SELECT_KEY); |
if (selectTag == null) { |
throw new JspException(messages.getMessage("optionsTag.select")); |
} |
User user = (User)pageContext.getSession().getAttribute(SessionKeys.USER); |
if(user == null) throw new JspException("no user found"); |
Locale userLocale = user.getLocale(); |
StringBuffer sb = new StringBuffer(); |
Locale[] locales = Locales.getLocales(); |
for(int i = 0; i < locales.length; i++) { |
Locale locale = locales[i]; |
String stringValue = locale.toString(); |
String label = locale.getDisplayLanguage(userLocale); |
String country = locale.getDisplayCountry(userLocale); |
if(country != null && !country.equals("")) |
label += " / " + country; // FIXME: move the slash to JSP? |
addOption(sb, stringValue, label, selectTag.isMatched(stringValue)); |
} |
ResponseUtils.write(pageContext, sb.toString()); |
return EVAL_PAGE; |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/permission/RightTagBase.java |
---|
0,0 → 1,65 |
package ak.hostadmiral.core.taglib.permission; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.jsp.JspException; |
import javax.servlet.jsp.tagext.TagSupport; |
import org.apache.struts.util.RequestUtils; |
import ak.hostadmiral.core.model.User; |
import ak.hostadmiral.core.model.ModelObject; |
import ak.hostadmiral.core.servlet.SessionKeys; |
public abstract class RightTagBase |
extends TagSupport |
{ |
protected User user; |
protected ModelObject object; |
protected String name; |
public String getName() |
{ |
return name; |
} |
public void setName(String name) |
{ |
this.name = name; |
} |
public void release() |
{ |
super.release(); |
name = null; |
user = null; |
} |
public int doStartTag() |
throws JspException |
{ |
user = (User)RequestUtils.lookup(pageContext, SessionKeys.USER, "session"); |
Object obj = RequestUtils.lookup(pageContext, name, null); |
if(obj == null) |
throw new JspException(name + " is null"); |
if(!(obj instanceof ModelObject)) |
throw new JspException(name + " must be a ModelObject, but is " + obj.getClass()); |
object = (ModelObject)obj; |
if(condition()) |
return EVAL_BODY_INCLUDE; |
else |
return SKIP_BODY; |
} |
public int doEndTag() |
throws JspException |
{ |
return EVAL_PAGE; |
} |
protected abstract boolean condition() |
throws JspException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/permission/EditableTag.java |
---|
0,0 → 1,13 |
package ak.hostadmiral.core.taglib.permission; |
import javax.servlet.jsp.JspException; |
public class EditableTag |
extends RightTagBase |
{ |
protected boolean condition() |
throws JspException |
{ |
return object.editableBy(user); |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/permission/NotEditableTag.java |
---|
0,0 → 1,13 |
package ak.hostadmiral.core.taglib.permission; |
import javax.servlet.jsp.JspException; |
public class NotEditableTag |
extends RightTagBase |
{ |
protected boolean condition() |
throws JspException |
{ |
return !object.editableBy(user); |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/permission/MethodTagBase.java |
---|
0,0 → 1,63 |
package ak.hostadmiral.core.taglib.permission; |
import java.lang.reflect.Method; |
import javax.servlet.jsp.JspException; |
import ak.hostadmiral.core.model.User; |
import org.apache.struts.util.RequestUtils; |
public abstract class MethodTagBase |
extends RightTagBase |
{ |
protected String method; |
public String getMethod() |
{ |
return method; |
} |
public void setMethod(String method) |
{ |
this.method = method; |
} |
public void release() |
{ |
super.release(); |
method = null; |
} |
protected boolean condition() |
throws JspException |
{ |
Method m; |
Object value; |
// find method |
try { |
m = object.getClass().getMethod(method, new Class[] { User.class } ); |
} |
catch(NoSuchMethodException ex) { |
throw new JspException("Method " + method |
+ " with parameter of type user not found"); |
} |
// invoke it |
try { |
value = m.invoke(object, new Object[] { user } ); |
} |
catch(Exception ex) { |
throw new JspException("Cannot call " + method + ": " + ex.getMessage()); |
} |
// check value type |
if(!(value instanceof Boolean)) |
throw new JspException("Return type of method " + method |
+ " must be java.lang.Boolean"); |
return condition(((Boolean)value).booleanValue()); |
} |
protected abstract boolean condition(boolean value) |
throws JspException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/permission/NoRightsTag.java |
---|
0,0 → 1,15 |
package ak.hostadmiral.core.taglib.permission; |
import javax.servlet.jsp.JspException; |
import org.apache.struts.util.RequestUtils; |
public class NoRightsTag |
extends MethodTagBase |
{ |
protected boolean condition(boolean value) |
throws JspException |
{ |
return !value; |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/permission/ViewableTag.java |
---|
0,0 → 1,13 |
package ak.hostadmiral.core.taglib.permission; |
import javax.servlet.jsp.JspException; |
public class ViewableTag |
extends RightTagBase |
{ |
protected boolean condition() |
throws JspException |
{ |
return object.viewableBy(user); |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/permission/NotViewableTag.java |
---|
0,0 → 1,13 |
package ak.hostadmiral.core.taglib.permission; |
import javax.servlet.jsp.JspException; |
public class NotViewableTag |
extends RightTagBase |
{ |
protected boolean condition() |
throws JspException |
{ |
return !object.viewableBy(user); |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/permission/RightsTag.java |
---|
0,0 → 1,15 |
package ak.hostadmiral.core.taglib.permission; |
import javax.servlet.jsp.JspException; |
import org.apache.struts.util.RequestUtils; |
public class RightsTag |
extends MethodTagBase |
{ |
protected boolean condition(boolean value) |
throws JspException |
{ |
return value; |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/permission/DeleteableTag.java |
---|
0,0 → 1,13 |
package ak.hostadmiral.core.taglib.permission; |
import javax.servlet.jsp.JspException; |
public class DeleteableTag |
extends RightTagBase |
{ |
protected boolean condition() |
throws JspException |
{ |
return object.deleteableBy(user); |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/permission/NotDeleteableTag.java |
---|
0,0 → 1,13 |
package ak.hostadmiral.core.taglib.permission; |
import javax.servlet.jsp.JspException; |
public class NotDeleteableTag |
extends RightTagBase |
{ |
protected boolean condition() |
throws JspException |
{ |
return !object.deleteableBy(user); |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/CountryTag.java |
---|
0,0 → 1,30 |
package ak.hostadmiral.core.taglib; |
import java.io.IOException; |
import javax.servlet.jsp.JspException; |
import javax.servlet.jsp.tagext.TagSupport; |
import ak.hostadmiral.core.model.User; |
import ak.hostadmiral.core.servlet.SessionKeys; |
public class CountryTag |
extends TagSupport |
{ |
public int doStartTag() |
throws JspException |
{ |
User user = (User)pageContext.getSession().getAttribute(SessionKeys.USER); |
if(user == null) |
throw new JspException("no user found"); |
try { |
pageContext.getOut().print(user.getLocale().getDisplayCountry(user.getLocale())); |
} |
catch(IOException ex) { |
throw new JspException("Cannot write out: " + ex.getMessage()); |
} |
return SKIP_BODY; |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/LanguageTag.java |
---|
0,0 → 1,30 |
package ak.hostadmiral.core.taglib; |
import java.io.IOException; |
import javax.servlet.jsp.JspException; |
import javax.servlet.jsp.tagext.TagSupport; |
import ak.hostadmiral.core.model.User; |
import ak.hostadmiral.core.servlet.SessionKeys; |
public class LanguageTag |
extends TagSupport |
{ |
public int doStartTag() |
throws JspException |
{ |
User user = (User)pageContext.getSession().getAttribute(SessionKeys.USER); |
if(user == null) |
throw new JspException("no user found"); |
try { |
pageContext.getOut().print(user.getLocale().getDisplayLanguage(user.getLocale())); |
} |
catch(IOException ex) { |
throw new JspException("Cannot write out: " + ex.getMessage()); |
} |
return SKIP_BODY; |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/ModelObjectOptionsTag.java |
---|
0,0 → 1,71 |
// based on jakarta struts taglib |
package ak.hostadmiral.core.taglib; |
import java.lang.reflect.InvocationTargetException; |
import java.util.Iterator; |
import javax.servlet.jsp.JspException; |
import org.apache.commons.beanutils.PropertyUtils; |
import org.apache.struts.taglib.html.Constants; |
import org.apache.struts.taglib.html.SelectTag; |
import org.apache.struts.taglib.html.OptionsTag; |
import org.apache.struts.util.MessageResources; |
import org.apache.struts.util.ResponseUtils; |
import ak.hostadmiral.core.model.ModelObject; |
public class ModelObjectOptionsTag extends OptionsTag |
{ |
protected static MessageResources coreMessages = |
MessageResources.getMessageResources("ak.hostadmiral.core.resources.CoreMessages"); |
public int doEndTag() throws JspException |
{ |
SelectTag selectTag = (SelectTag) pageContext.getAttribute(Constants.SELECT_KEY); |
if (selectTag == null) { |
throw new JspException(messages.getMessage("optionsTag.select")); |
} |
StringBuffer sb = new StringBuffer(); |
if (collection != null) { |
Iterator collIterator = getIterator(collection, null); |
while (collIterator.hasNext()) { |
Object bean = collIterator.next(); |
Object value = null; |
if(!(bean instanceof ModelObject)) |
throw new JspException("Not a ModelObject"); |
ModelObject model = (ModelObject)bean; |
try { |
value = PropertyUtils.getProperty(bean, property); |
if (value == null) { |
value = ""; |
} |
} catch (IllegalAccessException e) { |
throw new JspException( |
messages.getMessage("getter.access", property, collection)); |
} catch (InvocationTargetException e) { |
Throwable t = e.getTargetException(); |
throw new JspException( |
messages.getMessage("getter.result", property, t.toString())); |
} catch (NoSuchMethodException e) { |
throw new JspException( |
messages.getMessage("getter.method", property, collection)); |
} |
String identKey = model.getIdentKey(); |
Object[] identParams = model.getIdentParams(); |
String label = coreMessages.getMessage(identKey, identParams); |
String stringValue = value.toString(); |
addOption(sb, stringValue, label, selectTag.isMatched(stringValue)); |
} |
} |
ResponseUtils.write(pageContext, sb.toString()); |
return EVAL_PAGE; |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/list/CurrentPageTag.java |
---|
0,0 → 1,45 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.jsp.JspException; |
import javax.servlet.jsp.tagext.TagSupport; |
import org.apache.struts.util.ResponseUtils; |
import org.apache.struts.util.RequestUtils; |
import ak.hostadmiral.util.CollectionInfo; |
public class CurrentPageTag |
extends TagSupport |
{ |
protected String infoBean = null; |
public String getInfoBean() |
{ |
return this.infoBean; |
} |
public void setInfoBean(String infoBean) |
{ |
this.infoBean = infoBean; |
} |
protected String infoProperty = null; |
public String getInfoProperty() |
{ |
return this.infoProperty; |
} |
public void setInfoProperty(String infoProperty) |
{ |
this.infoProperty = infoProperty; |
} |
public int doStartTag() throws JspException |
{ |
CollectionInfo info = (CollectionInfo) |
RequestUtils.lookup(pageContext, infoBean, infoProperty, null); |
ResponseUtils.write(pageContext, Integer.toString(info.getCurrentPage() + 1)); |
return SKIP_BODY; |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/list/HasFirstPageTag.java |
---|
0,0 → 1,16 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.jsp.JspException; |
import ak.hostadmiral.util.CollectionInfo; |
public class HasFirstPageTag |
extends ExistTagBase |
{ |
protected boolean condition() |
throws JspException |
{ |
CollectionInfo info = getCollectionInfo(); |
return (info != null) && (info.getTotalPages() > 0); |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/list/NoFirstPageTag.java |
---|
0,0 → 1,13 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.jsp.JspException; |
public class NoFirstPageTag |
extends HasFirstPageTag |
{ |
protected boolean condition() |
throws JspException |
{ |
return !super.condition(); |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/list/FirstPageTag.java |
---|
0,0 → 1,14 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.jsp.JspException; |
import ak.hostadmiral.util.CollectionInfo; |
public class FirstPageTag |
extends PageTagBase |
{ |
protected int getDisplayPage() |
throws JspException |
{ |
return 0; |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/list/ExistTagBase.java |
---|
0,0 → 1,64 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.jsp.JspException; |
import javax.servlet.jsp.tagext.TagSupport; |
import org.apache.struts.util.RequestUtils; |
import ak.hostadmiral.util.CollectionInfo; |
public abstract class ExistTagBase |
extends TagSupport |
{ |
protected String infoBean = null; |
public String getInfoBean() |
{ |
return this.infoBean; |
} |
public void setInfoBean(String infoBean) |
{ |
this.infoBean = infoBean; |
} |
protected String infoProperty = null; |
public String getInfoProperty() |
{ |
return this.infoProperty; |
} |
public void setInfoProperty(String infoProperty) |
{ |
this.infoProperty = infoProperty; |
} |
public int doStartTag() throws JspException |
{ |
if(condition()) |
return EVAL_BODY_INCLUDE; |
else |
return SKIP_BODY; |
} |
public int doEndTag() throws JspException |
{ |
return EVAL_PAGE; |
} |
protected abstract boolean condition() throws JspException; |
protected CollectionInfo getCollectionInfo() |
throws JspException |
{ |
return (CollectionInfo) |
RequestUtils.lookup(pageContext, infoBean, infoProperty, null); |
} |
public void release() |
{ |
super.release(); |
infoBean = null; |
infoProperty = null; |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/list/PageLinkTag.java |
---|
0,0 → 1,64 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.jsp.JspException; |
import javax.servlet.jsp.tagext.Tag; |
import org.apache.struts.taglib.html.LinkTag; |
import ak.backpath.BackPath; |
import ak.hostadmiral.util.CollectionInfo; |
public class PageLinkTag |
extends LinkTag |
{ |
public static String BACKPATH_KEY = BackPath.DEFAULT_KEY + "_list"; |
public static String PAGE_PARAM_NAME = "pg"; |
protected PageIterateTag parent; |
protected void findParent() |
throws JspException |
{ |
Tag p = getParent(); |
while(p != null && !(p instanceof PageIterateTag)) |
p = p.getParent(); |
if(p == null) |
throw new JspException("This tag must be inside PageIterateTag"); |
parent = (PageIterateTag)p; |
} |
protected BackPath findBackPath() |
throws JspException |
{ |
try { |
return BackPath.findBackPath((HttpServletRequest)pageContext.getRequest(), |
BACKPATH_KEY, BackPath.DEFAULT_PARAM, |
new String[] { "backpath", PAGE_PARAM_NAME }, |
BackPath.DEFAULT_ZIP); |
} |
catch(Exception ex) { |
throw new JspException(ex); |
} |
} |
protected String calculateURL() |
throws JspException |
{ |
String urlStr = findBackPath().getCurrentUrl(); |
if(urlStr == null) return "/"; |
StringBuffer url = new StringBuffer(urlStr); |
boolean hasParams = (url.indexOf("?") > 0); |
findParent(); |
if(hasParams) |
url.append("&").append(PAGE_PARAM_NAME + "=").append(parent.getDisplayPage()); |
else |
url.append("?").append(PAGE_PARAM_NAME + "=").append(parent.getDisplayPage()); |
return url.toString(); |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/list/PageIterateTag.java |
---|
0,0 → 1,119 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.jsp.JspException; |
import javax.servlet.jsp.tagext.BodyTagSupport; |
import org.apache.struts.util.RequestUtils; |
import org.apache.struts.util.ResponseUtils; |
import ak.hostadmiral.util.CollectionInfo; |
public class PageIterateTag |
extends BodyTagSupport |
{ |
protected String infoBean = null; |
public String getInfoBean() |
{ |
return this.infoBean; |
} |
public void setInfoBean(String infoBean) |
{ |
this.infoBean = infoBean; |
} |
protected String infoProperty = null; |
public String getInfoProperty() |
{ |
return this.infoProperty; |
} |
public void setInfoProperty(String infoProperty) |
{ |
this.infoProperty = infoProperty; |
} |
protected int max = 0; |
public String getMax() |
{ |
return Integer.toString(this.max); |
} |
public void setMax(String max) |
{ |
this.max = Integer.parseInt(max); |
} |
protected int displayPage; |
public int getDisplayPage() |
{ |
return this.displayPage; |
} |
protected CollectionInfo collectionInfo; |
public CollectionInfo getCollectionInfo() |
{ |
return this.collectionInfo; |
} |
public int doStartTag() throws JspException |
{ |
collectionInfo = findCollectionInfo(); |
displayPage = (max == 0) ? 0 |
: Math.max(0, collectionInfo.getCurrentPage() - max/2); |
if(collectionInfo == null) return SKIP_BODY; |
if(collectionInfo.getTotalPages() > 0) |
return EVAL_BODY_TAG; |
else |
return SKIP_BODY; |
} |
public int doAfterBody() throws JspException |
{ |
// Render the output from this iteration to the output stream |
if(bodyContent != null) { |
ResponseUtils.writePrevious(pageContext, bodyContent.getString()); |
bodyContent.clearBody(); |
} |
displayPage++; |
if(max == 0 && displayPage < collectionInfo.getTotalPages()) { |
return EVAL_BODY_TAG; |
} |
else if(max > 0 && displayPage < collectionInfo.getTotalPages() |
&& displayPage < collectionInfo.getCurrentPage() + max/2) |
{ |
return EVAL_BODY_TAG; |
} |
else { |
return SKIP_BODY; |
} |
} |
public int doEndTag() throws JspException |
{ |
return EVAL_PAGE; |
} |
protected CollectionInfo findCollectionInfo() |
throws JspException |
{ |
return (CollectionInfo) |
RequestUtils.lookup(pageContext, infoBean, infoProperty, null); |
} |
public void release() |
{ |
super.release(); |
infoBean = null; |
infoProperty = null; |
max = 0; |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/list/HasLastPageTag.java |
---|
0,0 → 1,16 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.jsp.JspException; |
import ak.hostadmiral.util.CollectionInfo; |
public class HasLastPageTag |
extends ExistTagBase |
{ |
protected boolean condition() |
throws JspException |
{ |
CollectionInfo info = getCollectionInfo(); |
return (info != null) && (info.getTotalPages() > 0); |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/list/NoLastPageTag.java |
---|
0,0 → 1,13 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.jsp.JspException; |
public class NoLastPageTag |
extends HasLastPageTag |
{ |
protected boolean condition() |
throws JspException |
{ |
return !super.condition(); |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/list/NotCurrentPageTag.java |
---|
0,0 → 1,22 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.jsp.JspException; |
public class NotCurrentPageTag |
extends IterateSubtagBase |
{ |
public int doStartTag() throws JspException |
{ |
findParent(); |
if(parent.getCollectionInfo().getCurrentPage() != parent.getDisplayPage()) |
return EVAL_BODY_INCLUDE; |
else |
return SKIP_BODY; |
} |
public int doEndTag() throws JspException |
{ |
return EVAL_PAGE; |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/list/LastPageTag.java |
---|
0,0 → 1,19 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.jsp.JspException; |
import ak.hostadmiral.util.CollectionInfo; |
public class LastPageTag |
extends PageTagBase |
{ |
protected int getDisplayPage() |
throws JspException |
{ |
CollectionInfo info = getCollectionInfo(); |
if(info == null) |
return 0; |
else |
return info.getLastPage(); |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/list/DisplayPageTag.java |
---|
0,0 → 1,17 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.jsp.JspException; |
import org.apache.struts.util.ResponseUtils; |
public class DisplayPageTag |
extends IterateSubtagBase |
{ |
public int doStartTag() throws JspException |
{ |
findParent(); |
ResponseUtils.write(pageContext, Integer.toString(parent.getDisplayPage() + 1)); |
return SKIP_BODY; |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/list/IterateSubtagBase.java |
---|
0,0 → 1,25 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.jsp.JspException; |
import javax.servlet.jsp.tagext.Tag; |
import javax.servlet.jsp.tagext.TagSupport; |
public abstract class IterateSubtagBase |
extends TagSupport |
{ |
protected PageIterateTag parent; |
protected void findParent() |
throws JspException |
{ |
Tag p = getParent(); |
while(p != null && !(p instanceof PageIterateTag)) |
p = p.getParent(); |
if(p == null) |
throw new JspException("This tag must be inside PageIterateTag"); |
parent = (PageIterateTag)p; |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/list/HasPrevPageTag.java |
---|
0,0 → 1,16 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.jsp.JspException; |
import ak.hostadmiral.util.CollectionInfo; |
public class HasPrevPageTag |
extends ExistTagBase |
{ |
protected boolean condition() |
throws JspException |
{ |
CollectionInfo info = getCollectionInfo(); |
return (info != null) && (info.getCurrentPage() > 0); |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/list/NoPrevPageTag.java |
---|
0,0 → 1,13 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.jsp.JspException; |
public class NoPrevPageTag |
extends HasPrevPageTag |
{ |
protected boolean condition() |
throws JspException |
{ |
return !super.condition(); |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/list/PageTagBase.java |
---|
0,0 → 1,87 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.jsp.JspException; |
import org.apache.struts.taglib.html.LinkTag; |
import org.apache.struts.util.RequestUtils; |
import ak.backpath.BackPath; |
import ak.hostadmiral.util.CollectionInfo; |
public abstract class PageTagBase |
extends LinkTag |
{ |
public static String BACKPATH_KEY = BackPath.DEFAULT_KEY + "_list"; |
public static String PAGE_PARAM_NAME = "pg"; |
protected String infoBean = null; |
public String getInfoBean() |
{ |
return this.infoBean; |
} |
public void setInfoBean(String infoBean) |
{ |
this.infoBean = infoBean; |
} |
protected String infoProperty = null; |
public String getInfoProperty() |
{ |
return this.infoProperty; |
} |
public void setInfoProperty(String infoProperty) |
{ |
this.infoProperty = infoProperty; |
} |
protected BackPath findBackPath() |
throws JspException |
{ |
try { |
return BackPath.findBackPath((HttpServletRequest)pageContext.getRequest(), |
BACKPATH_KEY, BackPath.DEFAULT_PARAM, |
new String[] { "backpath", PAGE_PARAM_NAME }, |
BackPath.DEFAULT_ZIP); |
} |
catch(Exception ex) { |
throw new JspException(ex); |
} |
} |
protected String calculateURL() |
throws JspException |
{ |
String urlStr = findBackPath().getCurrentUrl(); |
if(urlStr == null) return "/"; |
StringBuffer url = new StringBuffer(urlStr); |
boolean hasParams = (url.indexOf("?") > 0); |
if(hasParams) |
url.append("&").append(PAGE_PARAM_NAME + "=").append(getDisplayPage()); |
else |
url.append("?").append(PAGE_PARAM_NAME + "=").append(getDisplayPage()); |
return url.toString(); |
} |
protected abstract int getDisplayPage() |
throws JspException; |
protected CollectionInfo getCollectionInfo() |
throws JspException |
{ |
return (CollectionInfo) |
RequestUtils.lookup(pageContext, infoBean, infoProperty, null); |
} |
public void release() |
{ |
super.release(); |
infoBean = null; |
infoProperty = null; |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/list/HasNextPageTag.java |
---|
0,0 → 1,16 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.jsp.JspException; |
import ak.hostadmiral.util.CollectionInfo; |
public class HasNextPageTag |
extends ExistTagBase |
{ |
protected boolean condition() |
throws JspException |
{ |
CollectionInfo info = getCollectionInfo(); |
return (info != null) && (info.getCurrentPage() < info.getTotalPages() - 1); |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/list/NoNextPageTag.java |
---|
0,0 → 1,13 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.jsp.JspException; |
public class NoNextPageTag |
extends HasNextPageTag |
{ |
protected boolean condition() |
throws JspException |
{ |
return !super.condition(); |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/list/PrevPageTag.java |
---|
0,0 → 1,19 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.jsp.JspException; |
import ak.hostadmiral.util.CollectionInfo; |
public class PrevPageTag |
extends PageTagBase |
{ |
protected int getDisplayPage() |
throws JspException |
{ |
CollectionInfo info = getCollectionInfo(); |
if(info == null) |
return 0; |
else |
return info.getPrevPage(); |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/list/IsCurrentPageTag.java |
---|
0,0 → 1,22 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.jsp.JspException; |
public class IsCurrentPageTag |
extends IterateSubtagBase |
{ |
public int doStartTag() throws JspException |
{ |
findParent(); |
if(parent.getCollectionInfo().getCurrentPage() == parent.getDisplayPage()) |
return EVAL_BODY_INCLUDE; |
else |
return SKIP_BODY; |
} |
public int doEndTag() throws JspException |
{ |
return EVAL_PAGE; |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/list/NextPageTag.java |
---|
0,0 → 1,19 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.jsp.JspException; |
import ak.hostadmiral.util.CollectionInfo; |
public class NextPageTag |
extends PageTagBase |
{ |
protected int getDisplayPage() |
throws JspException |
{ |
CollectionInfo info = getCollectionInfo(); |
if(info == null) |
return 0; |
else |
return info.getNextPage(); |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/WriteTag.java |
---|
0,0 → 1,50 |
// based on struts write tag |
package ak.hostadmiral.core.taglib; |
import javax.servlet.jsp.JspException; |
import org.apache.struts.util.RequestUtils; |
import org.apache.struts.util.ResponseUtils; |
public class WriteTag |
extends org.apache.struts.taglib.bean.WriteTag |
{ |
protected String defValue; |
public String getDefault() |
{ |
return defValue; |
} |
public void setDefault(String defValue) |
{ |
this.defValue = defValue; |
} |
public int doStartTag() |
throws JspException |
{ |
Object value; |
if(ignore && RequestUtils.lookup(pageContext, name, scope) == null) |
value = null; |
else |
value = RequestUtils.lookup(pageContext, name, property, scope); |
if(value == null) value = defValue; |
if(value != null) { |
if(filter) |
ResponseUtils.write(pageContext, ResponseUtils.filter(formatValue(value))); |
else |
ResponseUtils.write(pageContext, formatValue(value)); |
} |
return SKIP_BODY; |
} |
public void release() |
{ |
super.release(); |
defValue = null; |
} |
} |