?? imgtag.java
字號:
public void setSrcKey(String srcKey) {
this.srcKey = srcKey;
}
/**
* Client-side image map declaration.
*/
protected String usemap = null;
public String getUsemap() {
return (this.usemap);
}
public void setUsemap(String usemap) {
this.usemap = usemap;
}
/**
* The vertical spacing around the image.
*/
protected String vspace = null;
public String getVspace() {
return (this.vspace);
}
public void setVspace(String vspace) {
this.vspace = vspace;
}
/**
* The image width.
*/
protected String width = null;
public String getWidth() {
return (this.width);
}
public void setWidth(String width) {
this.width = width;
}
protected boolean useLocalEncoding = false;
public boolean isUseLocalEncoding() {
return useLocalEncoding;
}
public void setUseLocalEncoding(boolean b) {
useLocalEncoding = b;
}
// --------------------------------------------------------- Public Methods
/**
* Render the beginning of the IMG tag.
*
* @exception JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException {
// Evaluate the body of this tag
return (EVAL_BODY_TAG);
}
/**
* Render the end of the IMG tag.
*
* @exception JspException if a JSP exception has occurred
*/
public int doEndTag() throws JspException {
// Generate the name definition or image element
HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
StringBuffer results = new StringBuffer("<img");
String tmp = src();
String srcurl = url(tmp);
if (srcurl != null) {
prepareAttribute(results, "src", response.encodeURL(srcurl));
}
String lowsrcurl = url(this.lowsrc);
if (lowsrcurl != null) {
prepareAttribute(results, "lowsrcurl", response.encodeURL(lowsrcurl));
}
prepareAttribute(results, "name", getImageName());
prepareAttribute(results, "height", getHeight());
prepareAttribute(results, "width", getWidth());
prepareAttribute(results, "align", getAlign());
prepareAttribute(results, "border", getBorder());
prepareAttribute(results, "hspace", getHspace());
prepareAttribute(results, "vspace", getVspace());
prepareAttribute(results, "ismap", getIsmap());
prepareAttribute(results, "usemap", getUsemap());
results.append(prepareStyles());
results.append(prepareEventHandlers());
prepareOtherAttributes(results);
results.append(getElementClose());
TagUtils.getInstance().write(pageContext, results.toString());
return (EVAL_PAGE);
}
/**
* Release any acquired resources.
*/
public void release() {
super.release();
border = null;
height = null;
hspace = null;
imageName = null;
ismap = null;
lowsrc = null;
name = null;
page = null;
pageKey = null;
action = null;
paramId = null;
paramName = null;
paramProperty = null;
paramScope = null;
property = null;
scope = null;
src = null;
srcKey = null;
usemap = null;
vspace = null;
width = null;
}
// ------------------------------------------------------ Protected Methods
/**
* Convenience method to throw a "imgTag.src" exception.
* @throws JspException
*/
private void throwImgTagSrcException() throws JspException {
JspException e = new JspException(messages.getMessage("imgTag.src"));
TagUtils.getInstance().saveException(pageContext, e);
throw e;
}
/**
* Convenience method to test whether this is the default module
* or if contestRelative has been set.
* @param config Our Moduleconfig
* @return True if this is the default module or contextRelative is set
*/
private boolean srcDefaultReference(ModuleConfig config) {
return (config == null || isContextRelativeSet());
}
/**
* Return the base source URL that will be rendered in the <code>src</code>
* property for this generated element, or <code>null</code> if there is
* no such URL.
*
* @exception JspException if an error occurs
*/
protected String src() throws JspException {
// Deal with a direct context-relative page that has been specified
if (this.page != null) {
if ((this.src != null) || (this.srcKey != null) || (this.pageKey != null)) {
throwImgTagSrcException();
}
ModuleConfig config =
ModuleUtils.getInstance().getModuleConfig(
this.module,
(HttpServletRequest) pageContext.getRequest(),
pageContext.getServletContext());
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
if (srcDefaultReference(config)) {
return (request.getContextPath() + this.page);
} else {
return (request.getContextPath() + config.getPrefix() + this.page);
}
}
// Deal with an indirect context-relative page that has been specified
if (this.pageKey != null) {
if ((this.src != null) || (this.srcKey != null)) {
throwImgTagSrcException();
}
ModuleConfig config =
ModuleUtils.getInstance().getModuleConfig(
this.module,
(HttpServletRequest) pageContext.getRequest(),
pageContext.getServletContext());
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
if (srcDefaultReference(config)) {
return (
request.getContextPath()
+ TagUtils.getInstance().message(
pageContext,
getBundle(),
getLocale(),
this.pageKey));
} else {
return (
request.getContextPath()
+ config.getPrefix()
+ TagUtils.getInstance().message(
pageContext,
getBundle(),
getLocale(),
this.pageKey));
}
}
if (this.action != null) {
if ((this.src != null) || (this.srcKey != null)) {
throwImgTagSrcException();
}
return TagUtils.getInstance().getActionMappingURL(action, module, pageContext, isContextRelativeSet());
}
// Deal with an absolute source that has been specified
if (this.src != null) {
if (this.srcKey != null) {
throwImgTagSrcException();
}
return (this.src);
}
// Deal with an indirect source that has been specified
if (this.srcKey == null) {
throwImgTagSrcException();
}
return TagUtils.getInstance().message(
pageContext,
getBundle(),
getLocale(),
this.srcKey);
}
/**
* Return the specified src URL, modified as necessary with optional
* request parameters.
*
* @param url The URL to be modified (or null if this url will not be used)
*
* @exception JspException if an error occurs preparing the URL
*/
protected String url(String url) throws JspException {
if (url == null) {
return (url);
}
String charEncoding = "UTF-8";
if(useLocalEncoding){
charEncoding = pageContext.getResponse().getCharacterEncoding();
}
// Start with an unadorned URL as specified
StringBuffer src = new StringBuffer(url);
// Append a single-parameter name and value, if requested
if ((paramId != null) && (paramName != null)) {
if (src.toString().indexOf('?') < 0) {
src.append('?');
} else {
src.append("&");
}
src.append(paramId);
src.append('=');
Object value = TagUtils.getInstance().lookup(pageContext, paramName, paramProperty, paramScope);
if (value != null)
src.append(TagUtils.getInstance().encodeURL(value.toString(), charEncoding));
}
// Just return the URL if there is no bean to look up
if ((property != null) && (name == null)) {
JspException e = new JspException(messages.getMessage("getter.name"));
TagUtils.getInstance().saveException(pageContext, e);
throw e;
}
if (name == null) {
return (src.toString());
}
// Look up the map we will be using
Object mapObject = TagUtils.getInstance().lookup(pageContext, name, property, scope);
Map map = null;
try {
map = (Map) mapObject;
} catch (ClassCastException e) {
TagUtils.getInstance().saveException(pageContext, e);
throw new JspException(messages.getMessage("imgTag.type"));
}
// Append the required query parameters
boolean question = (src.toString().indexOf("?") >= 0);
Iterator keys = map.keySet().iterator();
while (keys.hasNext()) {
String key = (String) keys.next();
Object value = map.get(key);
if (value == null) {
if (question) {
src.append("&");
} else {
src.append('?');
question = true;
}
src.append(key);
src.append('=');
// Interpret null as "no value specified"
} else if (value instanceof String[]) {
String values[] = (String[]) value;
for (int i = 0; i < values.length; i++) {
if (question) {
src.append("&");
} else {
src.append('?');
question = true;
}
src.append(key);
src.append('=');
src.append(TagUtils.getInstance().encodeURL(values[i], charEncoding));
}
} else {
if (question) {
src.append("&");
} else {
src.append('?');
question = true;
}
src.append(key);
src.append('=');
src.append(TagUtils.getInstance().encodeURL(value.toString(), charEncoding));
}
}
// Return the final result
return (src.toString());
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -