[jboss-user] [JBoss jBPM] - Re: showing image of current process stage

yairfr do-not-reply at jboss.com
Mon Aug 6 10:25:45 EDT 2007


here it is.
you need to print via JSPout the output. to see.
th function get the process instance id


  | 	public StringBuffer showProcessImage (long processInstanceId) {
  | 	  	byte[] gpdBytes = null;
  | 	  	byte[] imageBytes = null;
  | 	  	Token currentToken=null;
  | 	  	String currentTokenColor = "red";
  | 		long taskInstanceId=0;
  | 		StringBuffer Sb = new StringBuffer();
  | 		TaskInstance taskInstance=null;
  | 		JbpmContext context = conf.createJbpmContext();
  | 	    GraphSession graphSession = context.getGraphSession();
  | 	    ProcessInstance pi = graphSession.loadProcessInstance(processInstanceId);
  |   		
  |   		TaskMgmtInstance tmi = pi.getTaskMgmtInstance();
  |   		try {
  | 		Collection tis = tmi.getUnfinishedTasks(pi.getRootToken());
  | 		
  | 		Iterator taskInstances = tis.iterator();
  | 		if (taskInstances.hasNext()) {
  | 			TaskInstance ti = (TaskInstance)taskInstances.next();
  | 			taskInstanceId = ti.getId();
  | 			taskInstance = context.getTaskMgmtSession().loadTaskInstance(taskInstanceId);
  | 		}
  | 		else //process has finished
  | 		{
  | 			Collection allTasks = tmi.getTaskInstances();
  | 			Iterator AlltaskInstances = allTasks.iterator();
  | 			TaskInstance LastInstance=null;
  | 			while (AlltaskInstances.hasNext()) {
  | 				 LastInstance = (TaskInstance)AlltaskInstances.next();
  | 			}
  | 			taskInstanceId = LastInstance.getId();
  | 			taskInstance = context.getTaskMgmtSession().loadTaskInstance(taskInstanceId);
  | 		}
  | 		
  | 		currentToken = taskInstance.getToken();
  | 		ProcessDefinition processDefinition = currentToken.getProcessInstance().getProcessDefinition();
  |   		//String NodeName = currentToken.getProcessInstance().getRootToken().getNode().getName();
  | 		
  | 		FileDefinition fileDefinition = processDefinition.getFileDefinition();
  |  		if (fileDefinition == null) {
  |             fileDefinition = new FileDefinition();
  |            processDefinition.addDefinition(fileDefinition);
  |         }
  | 		
  |  		String Path =  Configuration.instance().GetParameter("","ProcessPath");
  |  		
  |         Path += processDefinition.getName();
  | 
  |   	    addFileResourceToFileDefinition(fileDefinition, Path, "processimage.jpg");
  |   		addFileResourceToFileDefinition(fileDefinition, Path, "gpd.xml");
  |  		
  |  		
  |   		if (new File(Path + "\\gpd.xml").exists())
  |   		{
  |   		//if(fileDefinition!=null)
  |   		//{
  |   			//gpdBytes = fileDefinition.getBytes("gpd.xml");
  |   			gpdBytes = processDefinition.getFileDefinition().getBytes("gpd.xml");
  |   			imageBytes = processDefinition.getFileDefinition().getBytes("processimage.jpg");
  | 
  | 	  		if (gpdBytes != null && imageBytes != null) {
  | 	  			int borderWidth = 4;
  | 	  			Element rootDiagramElement = DocumentHelper.parseText(new String(gpdBytes)).getRootElement();
  | 	  			int[] boxConstraint;
  | 	  			int[] imageDimension = extractImageDimension(rootDiagramElement);
  | 	  			//String imageLink = "processimage?definitionId="+ processDefinition.getId();
  | 	  			String imageLink = Path + "\\processimage.jpg";
  | 	
  | 	  		
  | 	  		//jspOut.println("</div>");
  | 	  			//}
  | 	  		//else {
  | 	  		boxConstraint = extractBoxConstraint(rootDiagramElement,currentToken);
  | 	  		
  | 	  		Sb.append("<script language='javascript'>");
  | 	  		Sb.append("window.contentHeight = " + imageDimension[1] +";");
  | 	  		Sb.append("window.contentWidth=" + imageDimension[0]+";");
  | 	  		Sb.append("</script>");
  | 	  		Sb.append("<table border=0 cellspacing=0 cellpadding=0 width="
  | 	  				+ imageDimension[0]
  | 	  				  				+ " height="
  | 	  				  				+ imageDimension[1] + ">");
  | 	  		Sb.append("  <tr>");
  | 	  		Sb.append("    <td width=" + imageDimension[0]
  | 	  		                      	  				+ " height=" + imageDimension[1]
  | 	  		                      	  				    	  				+ " style=\"background-image:url(" + imageLink
  | 	  		                      	  				    	  				+ ")\" valign=top>");
  | 	  		Sb.append("      <table border=0 cellspacing=0 cellpadding=0>");
  | 	  		Sb.append("        <tr>");
  | 	  		Sb.append("          <td width="
  | 	  				+ (boxConstraint[0] - borderWidth)
  | 	  				+ " height="
  | 	  				+ (boxConstraint[1] - borderWidth)
  | 	  				+ " style=\"background-color:transparent;\"></td>");
  | 	  		
  | 
  | 	  		Sb.append("        </tr>");
  | 	  		Sb.append("        <tr>");
  | 	  		Sb.append("          <td style=\"background-color:transparent;\"></td>");
  | 	  		Sb.append("          <td style=\"border-color:"
  | 	  				+ currentTokenColor
  | 	  				+ "; border-width:"
  | 	  				+ borderWidth
  | 	  				+ "px; border-style:groove; background-color:transparent;\" width="
  | 	  				+ boxConstraint[2]
  | 	  				+ " height="
  | 	  				+ (boxConstraint[3] + (2 * borderWidth))
  | 	  				+ ">&nbsp;</td>");
  | 	  		Sb.append("        </tr>");
  | 	  		Sb.append("      </table>");
  | 	  		Sb.append("    </td>");
  | 	  		Sb.append("  </tr>");
  | 	  		Sb.append("</table>");
  |   			}
  |   		 }
  |   		}
  |   		catch (Exception e) {
  | 	  		e.printStackTrace();
  | 	  		//throw new JspException("table couldn't be displayed", e);
  | 	  	}
  |   		
  | 		context.close();
  | 		
  | 		taskInstanceId = -1;
  | 	  	gpdBytes = null;
  | 	  	imageBytes = null;
  | 	  	currentToken = null;
  | 		return Sb;
  | 	}
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4071207#4071207

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4071207



More information about the jboss-user mailing list