/** * Copyright (c) 2006 by Know-Center, Graz, Austria * * This software is the confidential and proprietary information of Know-Center, * Graz, Austria. You shall not disclose such Confidential Information and shall * use it only in accordance with the terms of the license agreement you entered * into with Know-Center. * * KNOW-CENTER MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR * NON-INFRINGEMENT. KNOW-CENTER SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY * LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. * * $Id: StringInfo.java,v 1.2 2006/10/11 07:57:58 wprinz Exp $ */ package at.knowcenter.wag.egov.egiz.pdf; import java.io.Serializable; import java.io.UnsupportedEncodingException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * Specifies a certain data area within the pdf. * *

* Actually this is a byte range, which is used to hold the placeholder ranges * for later replacement. *

* * @author wprinz */ public class StringInfo implements Serializable { /** * SVUID. */ private static final long serialVersionUID = 5834801907046737048L; protected static Log logger = LogFactory.getLog(StringInfo.class); /** * The PDF document this range belongs to. */ protected byte[] pdf = null; /** * The start offset of the range. */ public int string_start = -1; /** * The length of the range. */ public int string_length = -1; /** * Copies the bytes of this range to a new byte array. * * @return Returns the new byte array. */ public byte[] copyStringBytes() { byte[] bytes = new byte[this.string_length]; System.arraycopy(this.pdf, this.string_start, bytes, 0, this.string_length); return bytes; } /** * Converts the range into a String. * * @return Returns the String. * @throws UnsupportedEncodingException * Forwarded exception. */ public String getString(String encoding) throws UnsupportedEncodingException { byte[] bytes = copyStringBytes(); return new String(bytes, encoding); } public String toString() { try { return "(" + this.string_start + "," + this.string_length + ")" + getString("ISO-8859-1"); } catch (UnsupportedEncodingException e) { logger.error(e.getMessage(), e); return "(" + this.string_start + "," + this.string_length + ")"; } } }