/hostadmiral/trunk/src/ak/strutsx/taglib/EmptyTag.java |
---|
4,53 → 4,53 |
* Copyleft Anatoli Klassen (anatoli@aksoft.net) |
*/ |
package ak.strutsx.taglib; |
import java.util.Iterator; |
import java.util.Collection; |
import java.util.Map; |
import javax.servlet.jsp.JspException; |
import org.apache.struts.util.RequestUtils; |
import org.apache.struts.taglib.logic.ConditionalTagBase; |
public class EmptyTag |
extends ConditionalTagBase |
{ |
protected boolean condition() |
throws JspException |
{ |
return condition(true); |
} |
protected boolean condition(boolean desired) |
throws JspException |
{ |
if(this.name == null) { |
JspException e = new JspException(messages.getMessage("empty.noNameAttribute")); |
RequestUtils.saveException(pageContext, e); |
throw e; |
} |
boolean empty = true; |
Object value = null; |
if(this.property == null) |
value = RequestUtils.lookup(pageContext, name, scope); |
else |
value = RequestUtils.lookup(pageContext, name, property, scope); |
if(value != null) { |
if(value instanceof String) |
empty = (((String)value).length() < 1); |
else if(value instanceof Collection) |
empty = ((Collection)value).isEmpty(); |
else if(value instanceof Map) |
empty = ((Map)value).isEmpty(); |
else if(value instanceof Iterator) |
empty = !((Iterator)value).hasNext(); |
else |
empty = false; |
} |
return (empty == desired); |
} |
} |
import java.util.Iterator; |
import java.util.Collection; |
import java.util.Map; |
import javax.servlet.jsp.JspException; |
import org.apache.struts.util.RequestUtils; |
import org.apache.struts.taglib.logic.ConditionalTagBase; |
public class EmptyTag |
extends ConditionalTagBase |
{ |
protected boolean condition() |
throws JspException |
{ |
return condition(true); |
} |
protected boolean condition(boolean desired) |
throws JspException |
{ |
if(this.name == null) { |
JspException e = new JspException(messages.getMessage("empty.noNameAttribute")); |
RequestUtils.saveException(pageContext, e); |
throw e; |
} |
boolean empty = true; |
Object value = null; |
if(this.property == null) |
value = RequestUtils.lookup(pageContext, name, scope); |
else |
value = RequestUtils.lookup(pageContext, name, property, scope); |
if(value != null) { |
if(value instanceof String) |
empty = (((String)value).length() < 1); |
else if(value instanceof Collection) |
empty = ((Collection)value).isEmpty(); |
else if(value instanceof Map) |
empty = ((Map)value).isEmpty(); |
else if(value instanceof Iterator) |
empty = !((Iterator)value).hasNext(); |
else |
empty = false; |
} |
return (empty == desired); |
} |
} |
/hostadmiral/trunk/src/ak/strutsx/taglib/NotEmptyTag.java |
---|
4,15 → 4,15 |
* Copyleft Anatoli Klassen (anatoli@aksoft.net) |
*/ |
package ak.strutsx.taglib; |
import javax.servlet.jsp.JspException; |
public class NotEmptyTag |
extends EmptyTag |
{ |
protected boolean condition() |
throws JspException |
{ |
return condition(false); |
} |
} |
import javax.servlet.jsp.JspException; |
public class NotEmptyTag |
extends EmptyTag |
{ |
protected boolean condition() |
throws JspException |
{ |
return condition(false); |
} |
} |
/hostadmiral/trunk/src/ak/strutsx/taglib/RootTag.java |
---|
4,34 → 4,34 |
* Copyleft Anatoli Klassen (anatoli@aksoft.net) |
*/ |
package ak.strutsx.taglib; |
import java.io.IOException; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.jsp.JspException; |
import javax.servlet.jsp.JspWriter; |
import javax.servlet.jsp.PageContext; |
import javax.servlet.jsp.tagext.TagSupport; |
import org.apache.struts.Globals; |
import org.apache.struts.util.MessageResources; |
import org.apache.struts.util.RequestUtils; |
public class RootTag |
extends TagSupport |
{ |
public int doStartTag() |
throws JspException |
{ |
HttpServletRequest request = (HttpServletRequest)pageContext.getRequest(); |
try { |
pageContext.getOut().write(request.getContextPath()); |
} |
catch(IOException ex) { |
throw new JspException("Cannot write to output" + ex); |
} |
return EVAL_BODY_INCLUDE; |
} |
} |
import java.io.IOException; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.jsp.JspException; |
import javax.servlet.jsp.JspWriter; |
import javax.servlet.jsp.PageContext; |
import javax.servlet.jsp.tagext.TagSupport; |
import org.apache.struts.Globals; |
import org.apache.struts.util.MessageResources; |
import org.apache.struts.util.RequestUtils; |
public class RootTag |
extends TagSupport |
{ |
public int doStartTag() |
throws JspException |
{ |
HttpServletRequest request = (HttpServletRequest)pageContext.getRequest(); |
try { |
pageContext.getOut().write(request.getContextPath()); |
} |
catch(IOException ex) { |
throw new JspException("Cannot write to output" + ex); |
} |
return EVAL_BODY_INCLUDE; |
} |
} |
/hostadmiral/trunk/src/ak/strutsx/taglib/MessageTag.java |
---|
4,88 → 4,88 |
* Copyleft Anatoli Klassen (anatoli@aksoft.net) |
*/ |
package ak.strutsx.taglib; |
import java.util.Locale; |
import javax.servlet.jsp.JspException; |
import javax.servlet.jsp.tagext.TagSupport; |
import org.apache.struts.Globals; |
import org.apache.struts.util.MessageResources; |
import org.apache.struts.util.RequestUtils; |
import org.apache.struts.util.ResponseUtils; |
public class MessageTag |
extends org.apache.struts.taglib.bean.MessageTag |
{ |
protected String valuesName = null; |
public String getValuesName() |
{ |
return this.valuesName; |
} |
public void setValuesName(String valuesName) |
{ |
this.valuesName = valuesName; |
} |
protected String valuesProperty = null; |
public String getValuesProperty() |
{ |
return this.valuesProperty; |
} |
public void setValuesProperty(String valuesProperty) |
{ |
this.valuesProperty = valuesProperty; |
} |
public int doStartTag() |
throws JspException |
{ |
String key = this.key; |
if(key == null) { |
Object value = RequestUtils.lookup(pageContext, name, property, scope); |
if(value != null && !(value instanceof String)) { |
JspException e = new JspException(messages.getMessage("message.property", key)); |
RequestUtils.saveException(pageContext, e); |
throw e; |
} |
key = (String)value; |
} |
Object[] values = null; |
if(valuesName != null || valuesProperty != null) { |
Object valuesObj = RequestUtils.lookup(pageContext, |
(valuesName == null) ? name : valuesName, valuesProperty, scope); |
if(valuesObj != null && !(valuesObj instanceof Object[])) { |
JspException e = new JspException("Properties are not an array"); |
RequestUtils.saveException(pageContext, e); |
throw e; |
} |
values = (Object[])valuesObj; |
} |
String message = RequestUtils.message(pageContext, this.bundle, |
this.localeKey, key, values); |
if(message == null) { |
JspException e = new JspException |
(messages.getMessage("message.message", "\"" + key + "\"")); |
RequestUtils.saveException(pageContext, e); |
throw e; |
} |
ResponseUtils.write(pageContext, message); |
return SKIP_BODY; |
} |
public void release() |
{ |
super.release(); |
valuesName = null; |
valuesProperty = null; |
} |
} |
import java.util.Locale; |
import javax.servlet.jsp.JspException; |
import javax.servlet.jsp.tagext.TagSupport; |
import org.apache.struts.Globals; |
import org.apache.struts.util.MessageResources; |
import org.apache.struts.util.RequestUtils; |
import org.apache.struts.util.ResponseUtils; |
public class MessageTag |
extends org.apache.struts.taglib.bean.MessageTag |
{ |
protected String valuesName = null; |
public String getValuesName() |
{ |
return this.valuesName; |
} |
public void setValuesName(String valuesName) |
{ |
this.valuesName = valuesName; |
} |
protected String valuesProperty = null; |
public String getValuesProperty() |
{ |
return this.valuesProperty; |
} |
public void setValuesProperty(String valuesProperty) |
{ |
this.valuesProperty = valuesProperty; |
} |
public int doStartTag() |
throws JspException |
{ |
String key = this.key; |
if(key == null) { |
Object value = RequestUtils.lookup(pageContext, name, property, scope); |
if(value != null && !(value instanceof String)) { |
JspException e = new JspException(messages.getMessage("message.property", key)); |
RequestUtils.saveException(pageContext, e); |
throw e; |
} |
key = (String)value; |
} |
Object[] values = null; |
if(valuesName != null || valuesProperty != null) { |
Object valuesObj = RequestUtils.lookup(pageContext, |
(valuesName == null) ? name : valuesName, valuesProperty, scope); |
if(valuesObj != null && !(valuesObj instanceof Object[])) { |
JspException e = new JspException("Properties are not an array"); |
RequestUtils.saveException(pageContext, e); |
throw e; |
} |
values = (Object[])valuesObj; |
} |
String message = RequestUtils.message(pageContext, this.bundle, |
this.localeKey, key, values); |
if(message == null) { |
JspException e = new JspException |
(messages.getMessage("message.message", "\"" + key + "\"")); |
RequestUtils.saveException(pageContext, e); |
throw e; |
} |
ResponseUtils.write(pageContext, message); |
return SKIP_BODY; |
} |
public void release() |
{ |
super.release(); |
valuesName = null; |
valuesProperty = null; |
} |
} |
/hostadmiral/trunk/src/ak/strutsx/taglib/ErrorsIteratorTag.java |
---|
5,42 → 5,42 |
*/ |
package ak.strutsx.taglib; |
import javax.servlet.jsp.JspException; |
import javax.servlet.jsp.JspException; |
import org.apache.struts.action.ActionErrors; |
import org.apache.struts.taglib.html.ErrorsTag; |
import org.apache.struts.util.RequestUtils; |
import org.apache.struts.action.ActionErrors; |
import org.apache.struts.taglib.html.ErrorsTag; |
import org.apache.struts.util.RequestUtils; |
public class ErrorsIteratorTag |
extends ErrorsTag |
extends ErrorsTag |
{ |
protected String id = null; |
protected String id = null; |
public String getId() |
{ |
return this.id; |
} |
{ |
return this.id; |
} |
public void setId(String id) |
{ |
this.id = id; |
} |
{ |
this.id = id; |
} |
public int doStartTag() |
public int doStartTag() |
throws JspException |
{ |
ActionErrors errors = RequestUtils.getActionErrors(pageContext, name); |
if(errors != null) |
{ |
ActionErrors errors = RequestUtils.getActionErrors(pageContext, name); |
if(errors != null) |
pageContext.setAttribute(id, (property == null) ? errors.get() : errors.get(property)); |
return EVAL_BODY_INCLUDE; |
} |
public void release() |
{ |
super.release(); |
id = null; |
} |
} |
return EVAL_BODY_INCLUDE; |
} |
public void release() |
{ |
super.release(); |
id = null; |
} |
} |