总体流程:创建Image项,从数据库中读取Image,创建临时Image文件,设置Image属性
1. 创建Image项,Image ID:为HeaderImage
2. 首先我们要获得存储Image数据的VO
public void InitUserInfoQuery(String UserName){
UserInfoVOImpl vo = getUserInfoVO1();
vo.setWhereClauseParam(0, UserName);
vo.executeQuery();
}
public String initImg(String path){
UserInfoVOImpl vo = getUserInfoVO1();
Row row = vo.next();
String fullpath=null ;
if (row !=null)
{
BlobDomain blobdomain = (BlobDomain)row.getAttribute("HeaderImg");
if(blobdomain != null)
{
fullpath= createFile(path, blobdomain, (String)row.getAttribute("HeaderImgName"));
row.setAttribute("ImageSource", fullpath);
}
}
return fullpath;
}
这里获得了当前通过查询获得了当前 UserInfoVO对应行所对应的存储Image数据的属性HeaderImg的值。
3. 然后通过读出的值创建临时文件
public void fromInputToOutput(InputStream inputstream, OutputStream outputstream)
throws IOException
{
byte abyte0[] = new byte[255];
for(int i = 255; i == 255;)
{
i = inputstream.read(abyte0);
if(i < 0)
break;
outputstream.write(abyte0, 0, i);
}
outputstream.close();
inputstream.close();
}
public String createFile(String s, BlobDomain blobdomain, String s1)
{
File file = new File(s);
if(!file.exists())
file.mkdirs();
File file1 = new File(s, s1);
System.out.println("File Path"+file1.getPath());
try
{
fromInputToOutput(blobdomain.getBinaryStream(), new FileOutputStream(file1));
}catch(IOException ioexception)
{
ioexception.printStackTrace();
}
System.out.println("File "+file1.getName());
return "./fwk/t/"+ file1.getName();
}
4. 最后在processRequest设置相应的属性
OAImageBean aimagebean=(OAImageBean)webBean.findIndexedChildRecursive("HeaderImage");
Serializable[] params = {pageContext.getTemporaryImageLocation()};
Serializable returPath= am.invokeMethod("initImg",params);
if(oaimagebean != null)
{
oaimagebean.setAttributeValue(UIConstants.SOURCE_ATTR, returPath.toString());
oaimagebean.setWidth(120);
oaimagebean.setHeight(120);
oaimagebean.setBorderWidth(1);
}
总结:
难点在于临时文件的创建,及临时路径的设置
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/13615639/viewspace-609846/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/13615639/viewspace-609846/