picturedetailtag.java
来自「一个免费wap站」· Java 代码 · 共 136 行
JAVA
136 行
package com.eline.wap.catalog.taglib.wml;
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
import com.blue.imageio.ImageGenerator;
import com.blue.imageio.Size;
import com.eline.wap.catalog.client.CatalogHelper;
import com.eline.wap.catalog.exceptions.CatalogException;
import com.eline.wap.catalog.model.Item;
import com.eline.wap.catalog.model.SingleItem;
import com.eline.wap.catalog.util.ImageProcessor;
import com.eline.wap.cmi.exceptions.CMIException;
import com.eline.wap.cmi.model.MobileCapability;
import com.eline.wap.cmi.util.BrowserCapabilities;
import com.eline.wap.common.util.AppLogger;
import com.eline.wap.resource.client.PictureHelper;
import com.eline.wap.resource.model.Picture;
public class PictureDetailTag extends TagSupport {
/**
*
*/
private static final long serialVersionUID = -1096132425690169410L;
private int catalogId;
private Item item = null;
private Picture picture = null;
private String previewURL = null;
private String downloadURL = null;
public int doStartTag() throws JspException {
try {
CatalogHelper catalogHelper = new CatalogHelper();
PictureHelper pictureHelper = new PictureHelper();
item = catalogHelper.getItem(catalogId);
if (item == null
|| !(item instanceof SingleItem)
|| ((SingleItem) item).getSingleAttribute() != SingleItem.SINGLE_PICTURE)
throw new CatalogException("Invalid item specified.");
picture = pictureHelper.getPicture(((SingleItem) item).getResourceId());
} catch (Exception e) {
// throw new JspException(e.getMessage());
writeErrorBody(e.getMessage());
return SKIP_BODY;
}
return EVAL_BODY_INCLUDE;
}
private void writeErrorBody(String message) {
JspWriter out = pageContext.getOut();
try {
out.println("<b>Sorry, Error occures!</b><br/>");
if (message != null && message.length() > 0)
out.println("message: " + message);
} catch (IOException e) {}
}
public int doEndTag() throws JspException {
picture = null;
previewURL = null;
downloadURL = null;
return EVAL_PAGE;
}
public void setCatalogId(int catalogId) {
this.catalogId = catalogId;
}
public Item getItem() {
return item;
}
public Picture getPicture() {
return picture;
}
public String getPreviewPictureURL() {
if (previewURL == null) {
try {
ImageProcessor processor = new ImageProcessor(pageContext, picture);
previewURL = processor.getPreviewImageURL();
} catch (CatalogException e) {
AppLogger.error("PictureDetailTag.getPreviewPictureURL() CatalogException : " + e.getMessage());
return null;
}
}
return previewURL;
}
public MobileCapability getMobileCapability() {
MobileCapability result = null;
try {
BrowserCapabilities capabilities = new BrowserCapabilities(pageContext);
result = capabilities.getCurrent();
} catch (CMIException e) {}
return result;
}
public String getDownloadPictureURL() {
if (downloadURL == null) {
try {
BrowserCapabilities capabilities = new BrowserCapabilities(pageContext);
String extension = capabilities.getCurrent().getPreferredImageMime();
String mime = extension.equalsIgnoreCase("jpg") ? ImageGenerator.MIME_JPG
: extension.equalsIgnoreCase("gif") ? ImageGenerator.MIME_GIF
: ImageGenerator.MIME_PNG;
Size size = new Size();
size.setWidth(capabilities.getCurrent().getScreenPixelsWidth());
size.setHeight(capabilities.getCurrent().getScreenPixelsHeight());
ImageProcessor processor = new ImageProcessor(pageContext, picture);
downloadURL = processor.getImageURL(size, mime);
} catch (CMIException e) {
AppLogger.error("PictureDetailTag.getPreviewPictureURL() CMIException : " + e.getMessage());
return null;
} catch (CatalogException e) {
AppLogger.error("PictureDetailTag.getPreviewPictureURL() CatalogException : " + e.getMessage());
return null;
}
}
return downloadURL;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?