aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/knowcenter/wag/egov/egiz/pdf/SplitStrings.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/knowcenter/wag/egov/egiz/pdf/SplitStrings.java')
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/pdf/SplitStrings.java162
1 files changed, 162 insertions, 0 deletions
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/SplitStrings.java b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/SplitStrings.java
new file mode 100644
index 0000000..e3f75f1
--- /dev/null
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/SplitStrings.java
@@ -0,0 +1,162 @@
+/**
+ * <copyright> Copyright (c) 2006 by Know-Center, Graz, Austria </copyright>
+ *
+ * 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: SplitStrings.java,v 1.1 2006/08/30 14:02:35 wprinz Exp $
+ */
+package at.knowcenter.wag.egov.egiz.pdf;
+
+import java.util.List;
+
+
+/**
+ * Class that helps filling out the placeholders.
+ *
+ * <p>
+ * This class treats a sequence of placeholder StringInfos like a continuous
+ * data area that can be filled out regarding the boundaries.
+ * </p>
+ *
+ * @author wprinz
+ */
+public class SplitStrings
+{
+ /**
+ * The byte used to fill unused bytes in the placeholders.
+ */
+ public static final byte FILL_BYTE = 0;
+
+ /**
+ * The underlying PDF.
+ */
+ protected byte[] pdf = null;
+
+ /**
+ * The strings to be filled out.
+ */
+ protected StringInfo[] strings = null;
+
+ /**
+ * The current string which is written to.
+ */
+ protected int cur_string = 0;
+
+ /**
+ * The current write position within the current string.
+ */
+ protected int cur_pos = 0;
+
+ /**
+ * Constructor.
+ *
+ * @param pdf
+ * The underlying PDF.
+ * @param strings
+ * The strings to be filled out.
+ */
+ public SplitStrings(byte[] pdf, List strings)
+ {
+ this.pdf = pdf;
+ this.strings = new StringInfo[strings.size()];
+ for (int i = 0; i < strings.size(); i++)
+ {
+ StringInfo si = (StringInfo) strings.get(i);
+ this.strings[i] = si;
+ }
+ }
+
+ /**
+ * Returns how many bytes are still available in the current string.
+ *
+ * @return Returns the number of bytes that are still available. (positive
+ * integer, or zero if none are available)
+ */
+ public int getAvailable()
+ {
+ return this.strings[this.cur_string].string_length - this.cur_pos;
+ }
+
+ /**
+ * Tells, if the whole data would fit into the current string.
+ *
+ * @param data
+ * The data to be matched for fitting
+ * @return Returns true, if the whole data fits, false otherwise.
+ */
+ public boolean fits(byte[] data)
+ {
+ return getAvailable() >= data.length;
+ }
+
+ /**
+ * Writes the data into the current string.
+ *
+ * <p>
+ * Note that the data must fit in.
+ * </p>
+ * @param data The data to be written.
+ */
+ public void write(byte[] data)
+ {
+ if (!fits(data))
+ {
+ throw new IllegalArgumentException("The data doesn't fit in.");
+ }
+
+ System.arraycopy(data, 0, pdf, this.strings[this.cur_string].string_start + this.cur_pos, data.length);
+
+ this.cur_pos += data.length;
+ }
+
+ /**
+ * Fills the current string with the fill character and moves on to the next
+ * string.
+ *
+ */
+ public void newline()
+ {
+ int end = this.strings[this.cur_string].string_start + this.strings[this.cur_string].string_length;
+ for (int i = this.strings[this.cur_string].string_start + this.cur_pos; i < end; i++)
+ {
+ pdf[i] = FILL_BYTE;
+ }
+
+ this.cur_string++;
+ this.cur_pos = 0;
+ }
+
+ /**
+ * Fills all rest bytes with the fill character.
+ *
+ * <p>
+ * This should be called when everything is finished to fill all strings properly.
+ * </p>
+ */
+ public void fillRest()
+ {
+ while (this.cur_string < this.strings.length)
+ {
+ newline();
+ }
+ }
+
+ /**
+ * Tells, if the current line is valid.
+ * @return Returns true, if this is a line that can be written to.
+ */
+ public boolean isValidLine ()
+ {
+ return this.cur_string < this.strings.length;
+ }
+}