-----------------------------------------------------------------------------------------------------------
public void service(HttpServletRequest request, HttpServletResponse response)
throws IOException {
response.setContentType("text/html; charset=utf-8");
response.getWriter().println(handleRequest(request));
}
public void printInput(HttpServletRequest request) throws IOException {
InputStream inputStream = request.getInputStream();
StringBuffer buffer = new StringBuffer();
int read;
while ((read = inputStream.read()) != -1) {
buffer.append((char) read);
}
log.debug(buffer.toString());
}
private String handleRequest(HttpServletRequest request) {
if (!FileUpload.isMultipartContent(request)) {
log.debug("Not a multipart request");
return "Not a multipart request";
}
try {
DiskFileUpload fileUpload = new DiskFileUpload();
List list = fileUpload.parseRequest(request);
Iterator iterator = list.iterator();
if (!iterator.hasNext()) {
log.debug("No process file in the request");
return "No process file in the request";
}
FileItem fileItem = (FileItem) iterator.next();
if (fileItem.getContentType().indexOf(
"application/x-zip-compressed") == -1) {
log.debug("Not a process archive");
return "Not a process archive";
}
return doDeployment(fileItem);
} catch (FileUploadException e) {
e.printStackTrace();
return "FileUploadException";
}
}
private String doDeployment(FileItem fileItem) {
System.out.println("文件" + fileItem.getName());
try {
ZipInputStream zipInputStream = new ZipInputStream(fileItem
.getInputStream());
//
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
// 添加代碼
if (jbpmContext == null) {
JbpmConfiguration config = JbpmConfiguration.getInstance();
jbpmContext = config.createJbpmContext();
}
//
ProcessDefinition processDefinition = ProcessDefinition
.parseParZipInputStream(zipInputStream);
log.debug("創(chuàng)建Created a processdefinition : "
+ processDefinition.getName());
jbpmContext.deployProcessDefinition(processDefinition);
zipInputStream.close();
jbpmContext.close();
return "上傳 " + processDefinition.getName() + " 成功";
} catch (IOException e) {
return "IOException";
}
}
private static Log log = LogFactory.getLog(UploadServlet.class);
}
-----------------------------------------------------------------------------------------------------------
the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
*/
package org.jbpm.webapp.tag;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.XPath;
import org.dom4j.xpath.DefaultXPath;
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
import org.jbpm.file.def.FileDefinition;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.Token;
import org.jbpm.taskmgmt.exe.TaskInstance;
public class ProcessImageTag extends TagSupport {
private static final long serialVersionUID = 1L;
private long taskInstanceId = -1;
private long tokenInstanceId = -1;
private byte[] gpdBytes = null;
private byte[] imageBytes = null;
private Token currentToken = null;
private ProcessDefinition processDefinition = null;
static String currentTokenColor = "red";
static String childTokenColor = "blue";
static String tokenNameColor = "blue";
public void release() {
taskInstanceId = -1;
gpdBytes = null;
imageBytes = null;
currentToken = null;
}
public int doEndTag() throws JspException {
try {
initialize();
retrieveByteArrays();
if (gpdBytes != null && imageBytes != null) {
writeTable();
}
} catch (IOException e) {
e.printStackTrace();
throw new JspException("table couldn't be displayed", e);
} catch (DocumentException e) {
e.printStackTrace();
throw new JspException("table couldn't be displayed", e);
}
release();
return EVAL_PAGE;
}
private void retrieveByteArrays() {
try {
FileDefinition fileDefinition = processDefinition
.getFileDefinition();
gpdBytes = fileDefinition.getBytes("gpd.xml");
imageBytes = fileDefinition.getBytes("processimage.jpg");
} catch (Exception e) {
e.printStackTrace();
}
}
private void writeTable() throws IOException, DocumentException {
int borderWidth = 4;
Element rootDiagramElement = DocumentHelper.parseText(
new String(gpdBytes)).getRootElement();
int[] boxConstraint;
int[] imageDimension = extractImageDimension(rootDiagramElement);
String imageLink = "processimage?definitionId="
+ processDefinition.getId();
JspWriter jspOut = pageContext.getOut();
if (tokenInstanceId > 0) {
List allTokens = new ArrayList();
walkTokens(currentToken, allTokens);
jspOut
.println("<div style='position:relative; background-image:url("
+ imageLink
+ "); width: "
+ imageDimension[0]
+ "px; height: " + imageDimension[1] + "px;'>");
for (int i = 0; i < allTokens.size(); i++) {
Token token = (Token) allTokens.get(i);
// check how many tokens are on teh same level (= having the
// same parent)
int offset = i;
if (i > 0) {
while (offset > 0
&& ((Token) allTokens.get(offset - 1)).getParent()
.equals(token.getParent())) {
offset--;
}
}
boxConstraint = extractBoxConstraint(rootDiagramElement, token);
// Adjust for borders
// boxConstraint[2]-=borderWidth*2;
// boxConstraint[3]-=borderWidth*2;
jspOut.println("<div style='position:absolute; left: "
+ boxConstraint[0] + "px; top: " + boxConstraint[1]
+ "px; ");
if (i == (allTokens.size() - 1)) {
jspOut.println("border: " + currentTokenColor);
} else {
jspOut.println("border: " + childTokenColor);
}
jspOut.println(" " + borderWidth + "px groove; " + "width: "
+ boxConstraint[2] + "px; height: " + boxConstraint[3]
+ "px;'>");
if (token.getName() != null) {
jspOut.println("<span style='color:" + tokenNameColor
+ ";font-style:italic;position:absolute;left:"
+ (boxConstraint[2] + 10) + "px;top:"
+ ((i - offset) * 20) + ";'> "
+ token.getName() + "</span>");
}
jspOut.println("</div>");
}
jspOut.println("</div>");
} else {
boxConstraint = extractBoxConstraint(rootDiagramElement);
jspOut.println("<table border=0 cellspacing=0 cellpadding=0 width="
+ imageDimension[0] + " height=" + imageDimension[1] + ">");
jspOut.println(" <tr>");
jspOut.println(" <td width=" + imageDimension[0] + " height="
+ imageDimension[1] + " style=\"background-image:url("
+ imageLink + ")\" valign=top>");
jspOut
.println(" <table border=0 cellspacing=0 cellpadding=0>");
jspOut.println(" <tr>");
jspOut.println(" <td width="
+ (boxConstraint[0] - borderWidth) + " height="
+ (boxConstraint[1] - borderWidth)
+ " style=\"background-color:transparent;\"></td>");
jspOut.println(" </tr>");
jspOut.println(" <tr>");
jspOut
.println(" <td style=\"background-