package org.hccp.pdf; import java.util.Vector; /** * * The body of a PDF file consists of a sequence of indirect * objects representing the contents of a document. * * @see IndirectObject * @see DocumentObject **/ public class Body implements DocumentObject { private Vector bodyObjects; /** * * This method is used to add a {@link DocumentObject} to this * Body. * * @see DocumentObject * * **/ public void addObject(DocumentObject documentobject) { bodyObjects.addElement(documentobject); } /** * This method cycles through it's collected objects, calling getValue() on each, * returning the ASCII encoded PDF representation of the object and child objects. **/ public String getValue() { StringBuffer sb = new StringBuffer(); for(int i = 0; i < bodyObjects.size(); i++) { sb.append(((DocumentObject)bodyObjects.elementAt(i)).getValue()); } return sb.toString(); } /** * * This method returns the total size as a {@link Numeric}, in bytes, of this * Body's collected objects, * * @return a {@link Numeric} representation of the Body size * * **/ public Numeric getSize() { int i = 0; for(int j = 0; j < bodyObjects.size(); j++) { i += ((DocumentObject)bodyObjects.elementAt(j)).getValue().getBytes().length; } return new Numeric(i); } /** * * This method returns a Vector of this Body's collected objects. * * @return a Vector of this Body's collected objects * * @see DocumentObject * **/ public Vector getBodyObjects() { return bodyObjects; } public Body() { bodyObjects = new Vector(); } }