[jboss-cvs] jboss-seam/src/pdf/org/jboss/seam/pdf/ui ...
Norman Richards
norman.richards at jboss.com
Mon Jan 1 22:40:33 EST 2007
User: nrichards
Date: 07/01/01 22:40:33
Modified: src/pdf/org/jboss/seam/pdf/ui
ITextComponent.java UIAnchor.java UICell.java
UIChapter.java UIDocument.java UIFont.java
UIImage.java UIList.java UIListItem.java
UIPage.java UIParagraph.java UISection.java
UITable.java
Log:
support metadata
Revision Changes Path
1.5 +14 -2 jboss-seam/src/pdf/org/jboss/seam/pdf/ui/ITextComponent.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ITextComponent.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/pdf/org/jboss/seam/pdf/ui/ITextComponent.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- ITextComponent.java 1 Jan 2007 00:27:48 -0000 1.4
+++ ITextComponent.java 2 Jan 2007 03:40:32 -0000 1.5
@@ -3,6 +3,7 @@
import javax.faces.*;
import javax.faces.context.*;
import javax.faces.component.*;
+import javax.faces.el.ValueBinding;
import java.io.*;
import java.util.Collection;
@@ -30,7 +31,7 @@
/**
* signal that the component should create it's managed object
*/
- abstract public void createITextObject();
+ abstract public void createITextObject(FacesContext context);
/**
* remove the itext objext
@@ -116,6 +117,17 @@
}
+ public Object valueBinding(FacesContext context,
+ String property,
+ Object defaultValue) {
+ Object value = defaultValue;
+ ValueBinding binding = getValueBinding(property);
+ if (binding != null) {
+ value = binding.getValue(context);
+ }
+ return value;
+ }
+
// ------------------------------------------------------
@Override
@@ -133,7 +145,7 @@
public void encodeBegin(FacesContext context)
throws IOException
{
- createITextObject();
+ createITextObject(context);
}
@Override
1.4 +1 -1 jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIAnchor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: UIAnchor.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIAnchor.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- UIAnchor.java 1 Jan 2007 00:27:48 -0000 1.3
+++ UIAnchor.java 2 Jan 2007 03:40:32 -0000 1.4
@@ -34,7 +34,7 @@
anchor = null;
}
- public void createITextObject() {
+ public void createITextObject(FacesContext context) {
anchor = new Anchor();
if (name != null) {
1.5 +7 -2 jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UICell.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: UICell.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UICell.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- UICell.java 1 Jan 2007 00:27:48 -0000 1.4
+++ UICell.java 2 Jan 2007 03:40:32 -0000 1.5
@@ -7,6 +7,8 @@
import java.awt.Color;
+import javax.faces.context.FacesContext;
+
public class UICell
extends ITextComponent
{
@@ -197,7 +199,7 @@
cell = null;
}
- public void createITextObject() {
+ public void createITextObject(FacesContext context) {
PdfPCell defaultCell = getDefaultCellFromTable();
if (defaultCell != null) {
cell = new PdfPCell(defaultCell);
@@ -318,7 +320,10 @@
}
public void handleAdd(Object o) {
- if (o instanceof Element) {
+ if (o instanceof Phrase) {
+ cell.setPhrase((Phrase) o);
+ } else if (o instanceof Element) {
+ // calling addElement negates setPhrase, etc...
cell.addElement((Element) o);
} else {
throw new RuntimeException("Can't add " + o.getClass().getName() +
1.3 +1 -1 jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIChapter.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: UIChapter.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIChapter.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- UIChapter.java 1 Jan 2007 00:27:48 -0000 1.2
+++ UIChapter.java 2 Jan 2007 03:40:32 -0000 1.3
@@ -27,7 +27,7 @@
chapter = null;
}
- public void createITextObject() {
+ public void createITextObject(FacesContext context) {
chapter = new Chapter("*chapter title*",1);
}
1.4 +103 -6 jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIDocument.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: UIDocument.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIDocument.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- UIDocument.java 1 Jan 2007 00:27:48 -0000 1.3
+++ UIDocument.java 2 Jan 2007 03:40:32 -0000 1.4
@@ -1,12 +1,10 @@
package org.jboss.seam.pdf.ui;
+import org.jboss.seam.pdf.ITextUtils;
import org.jboss.seam.pdf.PDFStore;
import javax.faces.context.*;
-import javax.faces.component.*;
-
import java.io.*;
-import java.util.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
@@ -20,12 +18,104 @@
ByteArrayOutputStream stream;
String id;
+ String title;
+ String subject;
+ String keywords;
+ String author;
+ String creator;
+
+ String pageSize;
+ String margins;
+ Boolean marginMirroring;
+
+
+ public void setMargins(String margins) {
+ this.margins = margins;
+ }
+
+ public void setPageSize(String pageSize) {
+ this.pageSize = pageSize;
+ }
+
+ public void setMarginMirroring(Boolean marginMirroring) {
+ this.marginMirroring = marginMirroring;
+ }
+
+ public void setAuthor(String author) {
+ this.author = author;
+ }
+
+ public void setCreator(String creator) {
+ this.creator = creator;
+ }
+
+ public void setKeywords(String keywords) {
+ this.keywords = keywords;
+ }
+
+ public void setSubject(String subject) {
+ this.subject = subject;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
public Object getITextObject() {
return document;
}
- public void createITextObject() {
+ public void createITextObject(FacesContext context) {
document = new Document();
+
+ // most of this needs to be done BEFORE document.open();
+
+ pageSize = (String) valueBinding(context, "pageSize", pageSize);
+ if (pageSize != null) {
+ document.setPageSize(ITextUtils.pageSizeValue(pageSize));
+ }
+
+ margins = (String) valueBinding(context, "margins", margins);
+ if (margins != null) {
+ float[] vals = ITextUtils.stringToFloatArray(margins);
+ if (vals.length != 4) {
+ throw new RuntimeException("margins must contain 4 float values");
+ }
+
+ document.setMargins(vals[0], vals[1], vals[2], vals[3]);
+ }
+
+ marginMirroring = (Boolean) valueBinding(context, "marginMirroring", marginMirroring);
+ if (marginMirroring != null) {
+ document.setMarginMirroring(marginMirroring);
+ }
+ }
+
+ private void initMetaData(FacesContext context) {
+ title = (String) valueBinding(context, "title", title);
+ if (title != null) {
+ document.addTitle(title);
+ }
+
+ subject = (String) valueBinding(context, "subject", subject);
+ if (subject != null) {
+ document.addSubject(subject);
+ }
+
+ keywords = (String) valueBinding(context, "keywords", keywords);
+ if (keywords != null) {
+ document.addKeywords(keywords);
+ }
+
+ author = (String) valueBinding(context, "author", author);
+ if (author != null) {
+ document.addAuthor(author);
+ }
+
+ creator = (String) valueBinding(context, "creator", creator);
+ if (creator != null) {
+ document.addCreator(creator);
+ }
}
public void removeITextObject() {
@@ -48,13 +138,16 @@
public void encodeBegin(FacesContext context)
throws IOException
{
+ super.encodeBegin(context);
+
id = PDFStore.instance().newId();
- document = new Document();
stream = new ByteArrayOutputStream();
try {
PdfWriter.getInstance(document, stream);
+ initMetaData(context);
+
document.open();
} catch (DocumentException e) {
throw new RuntimeException(e);
@@ -84,5 +177,9 @@
ResponseWriter response = context.getResponseWriter();
response.endElement("body");
response.endElement("html");
+
+ removeITextObject();
}
+
+
}
1.4 +1 -1 jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIFont.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: UIFont.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIFont.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- UIFont.java 1 Jan 2007 00:27:48 -0000 1.3
+++ UIFont.java 2 Jan 2007 03:40:32 -0000 1.4
@@ -45,7 +45,7 @@
font = null;
}
- public void createITextObject() {
+ public void createITextObject(FacesContext context) {
font = new Font(family, size);
if (style != null) {
font.setStyle(style);
1.5 +1 -1 jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIImage.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: UIImage.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIImage.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- UIImage.java 1 Jan 2007 00:27:48 -0000 1.4
+++ UIImage.java 2 Jan 2007 03:40:32 -0000 1.5
@@ -71,7 +71,7 @@
image = null;
}
- public void createITextObject() {
+ public void createITextObject(FacesContext context) {
URL url = Thread.currentThread().getContextClassLoader().getResource(resource);
if (url == null) {
1.5 +1 -1 jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIList.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: UIList.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIList.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- UIList.java 1 Jan 2007 00:27:48 -0000 1.4
+++ UIList.java 2 Jan 2007 03:40:32 -0000 1.5
@@ -51,7 +51,7 @@
list = null;
}
- public void createITextObject() {
+ public void createITextObject(FacesContext context) {
if (style != null) {
if (style.equalsIgnoreCase(STYLE_ROMAN)) {
list = new RomanList((int) indent); // int? bug in text?
1.4 +1 -1 jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIListItem.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: UIListItem.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIListItem.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- UIListItem.java 1 Jan 2007 00:27:48 -0000 1.3
+++ UIListItem.java 2 Jan 2007 03:40:32 -0000 1.4
@@ -20,7 +20,7 @@
return listItem;
}
- public void createITextObject() {
+ public void createITextObject(FacesContext context) {
listItem = new ListItem();
}
1.4 +3 -6 jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIPage.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: UIPage.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIPage.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- UIPage.java 1 Jan 2007 00:27:48 -0000 1.3
+++ UIPage.java 2 Jan 2007 03:40:32 -0000 1.4
@@ -1,18 +1,15 @@
package org.jboss.seam.pdf.ui;
-import javax.faces.event.*;
import javax.faces.context.*;
-import javax.faces.component.*;
-import javax.servlet.http.*;
+
import java.io.*;
import com.lowagie.text.*;
-import com.lowagie.text.pdf.*;
public class UIPage
extends ITextComponent
{
- public static final String COMPONENT_TYPE = "org.jboss.seam.pdf.ui.UIParagraph";
+ public static final String COMPONENT_TYPE = "org.jboss.seam.pdf.ui.UIPage";
public Object getITextObject() {
return null;
@@ -22,7 +19,7 @@
}
- public void createITextObject() {
+ public void createITextObject(FacesContext context) {
}
1.5 +1 -1 jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIParagraph.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: UIParagraph.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIParagraph.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- UIParagraph.java 1 Jan 2007 00:27:48 -0000 1.4
+++ UIParagraph.java 2 Jan 2007 03:40:32 -0000 1.5
@@ -70,7 +70,7 @@
paragraph = null;
}
- public void createITextObject() {
+ public void createITextObject(FacesContext context) {
Font font = getFont();
if (font == null) {
paragraph = new Paragraph();
1.3 +1 -1 jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UISection.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: UISection.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UISection.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- UISection.java 1 Jan 2007 00:27:48 -0000 1.2
+++ UISection.java 2 Jan 2007 03:40:32 -0000 1.3
@@ -24,7 +24,7 @@
section = null;
}
- public void createITextObject() {
+ public void createITextObject(FacesContext context) {
Chapter chapter = ((UIChapter)findITextParent(this, UIChapter.class)).getChapter();
section = chapter.addSection(new Paragraph("*fake title*"), 1);
section.setTitle(new Paragraph("*section title*"));
1.4 +5 -13 jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UITable.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: UITable.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UITable.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- UITable.java 1 Jan 2007 00:27:48 -0000 1.3
+++ UITable.java 2 Jan 2007 03:40:32 -0000 1.4
@@ -1,5 +1,7 @@
package org.jboss.seam.pdf.ui;
+import javax.faces.context.FacesContext;
+
import org.jboss.seam.pdf.ITextUtils;
import com.lowagie.text.*;
@@ -107,12 +109,12 @@
table = null;
}
- public void createITextObject() {
+ public void createITextObject(FacesContext context) {
table = new PdfPTable(columns);
if (widths != null) {
try {
- table.setWidths(stringToFloatArray(widths));
+ table.setWidths(ITextUtils.stringToFloatArray(widths));
} catch (DocumentException e) {
throw new RuntimeException(e);
}
@@ -162,16 +164,6 @@
}
}
- private float[] stringToFloatArray(String widths) {
- String[] parts = widths.split("\\s");
- float[] values = new float[parts.length];
- for (int i=0;i<parts.length;i++) {
- values[i] = Float.valueOf(parts[i]);
- }
-
- return values;
- }
-
public void handleAdd(Object o) {
if (o instanceof PdfPCell) {
table.addCell((PdfPCell) o);
More information about the jboss-cvs-commits
mailing list