diff options
| author | knowcenter <knowcenter@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c> | 2007-03-02 08:34:25 +0000 | 
|---|---|---|
| committer | knowcenter <knowcenter@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c> | 2007-03-02 08:34:25 +0000 | 
| commit | 9aee23f6c0a745a83fdf195ab384fdfe7dd7f5e4 (patch) | |
| tree | adddcf6dfdfaa64502b5355d8a898b095ea43679 /src | |
| parent | ade592d842b1880b7f01b1c6ad4b382569d67014 (diff) | |
| download | pdf-as-3-9aee23f6c0a745a83fdf195ab384fdfe7dd7f5e4.tar.gz pdf-as-3-9aee23f6c0a745a83fdf195ab384fdfe7dd7f5e4.tar.bz2 pdf-as-3-9aee23f6c0a745a83fdf195ab384fdfe7dd7f5e4.zip | |
New posstring handling
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@41 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/java/at/knowcenter/wag/egov/egiz/pdf/TablePos.java | 216 | 
1 files changed, 196 insertions, 20 deletions
| diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/TablePos.java b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/TablePos.java index 6cfdded..df4f9cd 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/TablePos.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/TablePos.java @@ -18,12 +18,14 @@  package at.knowcenter.wag.egov.egiz.pdf;
  import java.io.Serializable;
 +import at.knowcenter.wag.egov.egiz.exceptions.PDFDocumentException;
  /**
   * Class that holds the exact position where the table should be written to the
   * document.
   * 
   * @author wprinz
 + * @author mruhmer
   */
  public class TablePos implements Serializable
  {
 @@ -36,41 +38,215 @@ public class TablePos implements Serializable    /**
     * The page on which the block should be displayed.
     * 
 -   * <p>
 -   * A value greater than or equal 1 means to absolutely position the signature
 -   * on that page.
 -   * </p>
 -   * <p>
 -   * A value of -1 means to append a new page to the document and absolutely
 -   * position the signature on the new page.
 -   * </p>
 -   * <p>
 -   * A value of -2 means to determine the length of the last page as without
 -   * absolute positioning, but ignore all text below a certain footer line. If
 -   * there is enough space between the end of the text and this footer line, the
 -   * signature should be positioned automatically in there. Otherwise it should
 -   * be placed on a new page.
 -   * </p>
     */
 -  public int page = 0;
 +  private int page = 0;
    /**
     * The x position.
     */
 -  public float pos_x = 0.0f;
 +  private float pos_x = 0.0f;
    /**
     * The y position.
     */
 -  public float pos_y = 0.0f;
 +  private float pos_y = 0.0f;
    /**
     * The width of the block.
     */
 -  public float width = 0.0f;
 -
 +  private float width = 0.0f;
    /**
     * The top y position of the footer line.
     */
    public float footer_line = 0.0f;
 +
 +  /**
 +   * The y position.
 +   */
 +  public String myposstring = "";
 +  
 +  private boolean newpage = false;
 +  private boolean autoX = true; 
 +  private boolean autoY = true;
 +  private boolean autoW = true;
 +  private boolean autoP = true;
 +  
 +  public boolean isXauto()
 +  {
 +	return this.autoX;
 +  }
 +  public boolean isYauto()
 +  {
 +	return this.autoY;
 +  } 
 +  public boolean isWauto()
 +  {
 +	return this.autoW;
 +  }
 +  public boolean isPauto()
 +  {
 +	return this.autoP;
 +  }
 +  public boolean isNewPage()
 +  {
 +	return this.newpage;
 +  }
 +  public int getPage()
 +  {
 +	return this.page;  
 +  }
 +  public float getFooterLine()
 +  {
 +	//ignore if newpage and y is not auto
 +	if (!this.autoY || this.newpage) 
 +	{
 +	  return 0.0f;
 +	}
 +	return this.footer_line;  
 +  } 
 +  public float getPosX()
 +  {
 +	return this.pos_x;  
 +  }  
 +  public float getPosY()
 +  {
 +	return this.pos_y;  
 +  } 
 +  public float getWidth()
 +  {
 +	return this.width;  
 +  }  
 +  public TablePos()
 +  {
 +    //nothing to do --> default
 +  } 
 +  
 +  /**
 +   * Constructor.
 +   * 
 +   * @param pos_string The pos instruction.
 +   *        format : [x:x_algo];[y:y_algo];[w:w_algo][p:p_algo];[f:f_algo]
 +   *        x_algo:='auto'     ... automatic positioning x
 +   *                floatvalue ... absolute x
 +   *        y_algo:='auto'     ... automatic positioning y
 +   *                floatvalue ... absolute y
 +   *        w_algo:='auto'     ... automatic width
 +   *                floatvalue ... absolute width    
 +   *        p_algo:='auto'     ... automatic last page
 +   *                'new'      ... new page  
 +   *                intvalue   ... pagenumber
 +   *        f_algo  floatvalue ... consider footerline (only if y_algo is auto and p_algo is not 'new')
 +   * @throws PDFDocumentException
 +   */
 +  public TablePos(String pos_string) throws PDFDocumentException
 +  {
 +    //parse posstring and throw exception
 +	//[x:x_algo];[y:y_algo];[w:w_algo][p:p_algo];[f:f_algo]
 +	
 +	String[] strs = pos_string.split(";");
 +	try
 +	{
 +	  for (int cmds = 0;cmds<strs.length;cmds++)
 +	  {
 +		 
 +		 String cmd_kvstring = strs[cmds];
 +		 String[] cmd_kv = cmd_kvstring.split(":");
 +		 if (cmd_kv.length != 2)
 +		 {
 +			 throw new PDFDocumentException(224, "Pos string (=" + pos_string + ") is invalid.");
 +		 }
 +		 String cmdstr =  cmd_kv[0];
 +		 if (cmdstr.length() != 1)
 +		 {
 +			 throw new PDFDocumentException(224, "Pos string (=" + pos_string + ") is invalid.");
 +		 }		 
 +		 char command = cmdstr.charAt(0);
 +	     String commandval= cmd_kv[1];
 +	     switch (command)
 +	     {
 +	     	case 'x': {
 +	     		         if (!commandval.equalsIgnoreCase("auto"))
 +	     		         {  
 +	     		        	float xval= Float.parseFloat(commandval);
 +	     		            if (xval<0)
 +	     		            {
 +	     		            	throw new PDFDocumentException(228, "Pos string (x:" + xval + ") is invalid.");
 +	     		            }	     		          
 +	     		        	this.pos_x = xval;
 +	     		        	this.autoX = false; 
 +	     		         }	     		         
 +	     		         break;
 +	     			  }	
 +	     	case 'y': {
 +		         		if (!commandval.equalsIgnoreCase("auto"))
 +		         		{
 +		         			float yval= Float.parseFloat(commandval);
 +	     		            if (yval<0)
 +	     		            {
 +	     		            	throw new PDFDocumentException(229, "Pos string (y:" + yval + ") is invalid.");
 +	     		            }			         			
 +		         			this.pos_y = yval;
 +		         			this.autoY = false; 
 +		         		}	     		         
 +		         		break;
 +	     			  }		
 +	     	case 'w': { 
 +         				if (!commandval.equalsIgnoreCase("auto"))
 +         				{    
 +		         			float wval= Float.parseFloat(commandval);
 +	     		            if (wval<=0)
 +	     		            {
 +	     		            	throw new PDFDocumentException(226, "pos.width (w:" + wval + ") must not be lower or equal 0.");
 +	     		            }        					
 +         					this.width = wval;
 +         					this.autoW = false; 
 +         				}	     		         
 +         				break;
 +      				  }
 +	     	case 'p': {
 + 						if (!commandval.equalsIgnoreCase("auto"))
 + 						{ 
 + 							if (commandval.equalsIgnoreCase("new"))
 + 							{ 								
 + 								this.newpage = true;
 + 							}
 + 							else
 + 							{
 + 								int pval = Integer.parseInt(commandval);
 + 								if (pval<1)
 + 								{
 + 									throw new PDFDocumentException(225, "Page (p:" + pval + ") must not be lower than 1.");
 + 								}
 + 								this.page = pval;
 + 								this.autoP = false;
 + 							}
 + 						}						     		       
 + 						break;
 +      				  }
 +	     	case 'f': {
 +	     		        float flval=Float.parseFloat(commandval);
 +     		            if (flval<=0)
 +     		            {
 +     		            	throw new PDFDocumentException(224, "Pos string (=" + pos_string + ") is invalid.");
 +     		            } 	     		        
 +	     				this.footer_line = flval;
 +	     				break;
 +	     			  }
 +	     	default : {
 +		                throw new PDFDocumentException(224, "Pos string (=" + pos_string + ") is invalid.");
 +	                  }
 +	     }
 +	  }
 +	  this.myposstring=pos_string;
 +    }
 +    catch (NumberFormatException e)
 +    {
 +      throw new PDFDocumentException(224, "Pos string (=" + pos_string + ") cannot be parsed.");
 +    }
 +  }
 +  public String toString()
 +  {  
 +	 String thatsme = "cmd:"+this.myposstring+" pos_x:"+this.pos_x+" pos_y:"+this.pos_y+" page:"+this.page+" width:"+this.width+" footer:"+this.footer_line+"\n "+" autoX:"+this.autoX+" autoY:"+this.autoY+" autoW:"+this.autoW+" Newpage:"+this.newpage+" autoP:"+this.autoP; 
 +	 return thatsme;
 +  }
  }
 | 
