[jboss-cvs] jboss-seam/src/pdf/org/jboss/seam/pdf/ui ...
Norman Richards
norman.richards at jboss.com
Mon Dec 25 11:17:54 EST 2006
User: nrichards
Date: 06/12/25 11:17:54
Modified: src/pdf/org/jboss/seam/pdf/ui
ITextComponent.java UIAnchor.java UIDocument.java
UIFont.java UIImage.java UIList.java
UIListItem.java UIPage.java UIParagraph.java
Added: src/pdf/org/jboss/seam/pdf/ui UICell.java
UIChapter.java UISection.java UITable.java
Log:
chapter,section,table,cell
Revision Changes Path
1.2 +43 -11 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.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- ITextComponent.java 24 Dec 2006 16:21:33 -0000 1.1
+++ ITextComponent.java 25 Dec 2006 16:17:54 -0000 1.2
@@ -34,6 +34,10 @@
abstract public void createITextObject();
/**
+ * remove the itext objext
+ */
+ abstract public void removeITextObject();
+ /**
* subcomponents should implement this
*/
abstract public void add(Object other);
@@ -127,6 +131,7 @@
if (obj != null) {
addToITextParent(getITextObject());
}
+ removeITextObject();
}
@Override
@@ -136,6 +141,23 @@
for (UIComponent child: (List<UIComponent>) this.getChildren()) {
// ugly hack to be able to capture facelets text
if (child.getFamily().equals("facelets.LiteralText")) {
+ String text = replaceEntities(extractText(context, child));
+ Font font = getFont();
+ if (font == null) {
+ Chunk chunk = new Chunk(text);
+ add(chunk);
+ } else {
+ add(new Chunk(text, getFont()));
+ }
+ } else {
+ encode(context, child);
+ }
+ }
+ }
+
+ public String extractText(FacesContext context, UIComponent child)
+ throws IOException
+ {
ResponseWriter response = context.getResponseWriter();
StringWriter stringWriter = new StringWriter();
ResponseWriter cachingResponseWriter = response.cloneWithWriter(stringWriter);
@@ -145,18 +167,28 @@
context.setResponseWriter(response);
- String text = stringWriter.getBuffer().toString();
- Font font = getFont();
- if (font == null) {
- Chunk chunk = new Chunk(text);
- //chunk.setBackground(new Color(140,50,50));
- add(chunk);
- } else {
- add(new Chunk(text, getFont()));
+ return stringWriter.getBuffer().toString();
}
- } else {
- encode(context, child);
+
+ /**
+ * facelets automatically escapes text, so we have to undo the
+ * the damage here. This is just a placeholder for something
+ * more intelligent. The replacement strategy here is not
+ * sufficient.
+ */
+ private String replaceEntities(String text) {
+ StringBuffer buffer = new StringBuffer(text);
+
+ replaceAll(buffer, """, "\"");
+ // XXX - etc....
+
+ return buffer.toString();
}
+
+ private void replaceAll(StringBuffer buffer, String original, String changeTo) {
+ int pos;
+ while ((pos = buffer.indexOf(original)) != -1) {
+ buffer.replace(pos,pos+original.length(), changeTo);
}
}
1.2 +4 -0 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.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- UIAnchor.java 24 Dec 2006 22:54:32 -0000 1.1
+++ UIAnchor.java 25 Dec 2006 16:17:54 -0000 1.2
@@ -30,6 +30,10 @@
return anchor;
}
+ public void removeITextObject() {
+ anchor = null;
+ }
+
public void createITextObject() {
anchor = new Anchor();
1.2 +5 -1 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.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- UIDocument.java 24 Dec 2006 16:21:33 -0000 1.1
+++ UIDocument.java 25 Dec 2006 16:17:54 -0000 1.2
@@ -25,7 +25,11 @@
}
public void createITextObject() {
- document=new Document();
+ document = new Document();
+ }
+
+ public void removeITextObject() {
+ document = null;
}
public void add(Object o) {
1.2 +4 -0 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.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- UIFont.java 24 Dec 2006 16:21:33 -0000 1.1
+++ UIFont.java 25 Dec 2006 16:17:54 -0000 1.2
@@ -41,6 +41,10 @@
return null; // we don't add to this component, so skip
}
+ public void removeITextObject() {
+ font = null;
+ }
+
public void createITextObject() {
font = new Font(family, size);
if (style != null) {
1.3 +26 -3 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.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- UIImage.java 24 Dec 2006 19:29:01 -0000 1.2
+++ UIImage.java 25 Dec 2006 16:17:54 -0000 1.3
@@ -27,6 +27,9 @@
String alignment;
String alt;
+ Boolean wrap;
+ Boolean underlying;
+
public void setResource(String resource) {
this.resource = resource;
}
@@ -51,11 +54,22 @@
this.alt = alt;
}
+ public void setWrap(Boolean wrap) {
+ this.wrap = wrap;
+ }
+
+ public void setUnderlying(Boolean underlying) {
+ this.underlying = underlying;
+ }
+
+
public Object getITextObject() {
return image;
}
-
+ public void removeITextObject() {
+ image = null;
+ }
public void createITextObject() {
@@ -77,9 +91,18 @@
image.scaleAbsolute(width, height);
}
+ int alignmentValue =0;
if (alignment != null) {
- image.setAlignment(ITextUtils.alignmentValue(alignment));
+ alignmentValue = (ITextUtils.alignmentValue(alignment));
+ }
+ if (wrap!=null && wrap.booleanValue()) {
+ alignmentValue |= Image.TEXTWRAP;
}
+ if (underlying!= null && underlying.booleanValue()) {
+ alignmentValue |= Image.UNDERLYING;
+ }
+
+ image.setAlignment(alignmentValue);
if (alt != null) {
image.setAlt(alt);
1.3 +52 -11 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.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- UIList.java 24 Dec 2006 19:29:01 -0000 1.2
+++ UIList.java 25 Dec 2006 16:17:54 -0000 1.3
@@ -14,30 +14,71 @@
{
public static final String COMPONENT_TYPE = "org.jboss.seam.pdf.ui.UIList";
- List list;
+ public static final String STYLE_NUMBERED = "NUMBERED";
+ public static final String STYLE_LETTERED = "LETTERED";
+ public static final String STYLE_GREEK = "GREEK";
+ public static final String STYLE_ROMAN = "ROMAN";
- boolean numbered = false;
- boolean lettered = false;
- float indent = 20f;
+ List list;
- public void setNumbered(boolean numbered) {
- this.numbered = numbered;
- }
+ String style;
+ String listSymbol;
+ float indent = 20;;
+ Boolean lowerCase = false;
- public void setLettered(boolean lettered) {
- this.lettered = lettered;
+ public void setStyle(String style) {
+ this.style = style;
}
public void setIndent(float indent) {
this.indent = indent;
}
+ public void setListSymbol(String listSymbol) {
+ this.listSymbol = listSymbol;
+ }
+
+ /* for ROMAN,GREEK */
+ public void setLowerCase(Boolean lowerCase) {
+ this.lowerCase = lowerCase;
+ }
+
public Object getITextObject() {
return list;
}
+ public void removeITextObject() {
+ list = null;
+ }
+
public void createITextObject() {
- list = new List(numbered, lettered, indent);
+ if (style != null) {
+ if (style.equalsIgnoreCase(STYLE_ROMAN)) {
+ list = new RomanList((int) indent); // int? bug in text?
+ if (lowerCase != null) {
+ ((RomanList) list).setRomanLower(lowerCase);
+ }
+ } else if (style.equalsIgnoreCase(STYLE_GREEK)) {
+ list = new GreekList((int)indent); // int? bug in itext?
+
+ if (lowerCase != null) {
+ ((GreekList) list).setGreekLower(lowerCase);
+ }
+ } else if (style.equalsIgnoreCase(STYLE_NUMBERED)) {
+ list = new List(true, indent);
+ //setFirst(int)
+ } else if (style.equalsIgnoreCase(STYLE_LETTERED)) {
+ list = new List(false, true, indent);
+ //setFirst(char)
+ }
+ }
+
+ if (list == null) {
+ list = new List(false, indent);
+ if (listSymbol!=null) {
+ list.setListSymbol(listSymbol);
+ }
+ }
}
public void add(Object o) {
1.2 +4 -0 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.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- UIListItem.java 24 Dec 2006 16:21:33 -0000 1.1
+++ UIListItem.java 25 Dec 2006 16:17:54 -0000 1.2
@@ -24,6 +24,10 @@
listItem = new ListItem();
}
+ public void removeITextObject() {
+ listItem = null;
+ }
+
public void add(Object o) {
listItem.add(o);
}
1.2 +4 -0 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.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- UIPage.java 24 Dec 2006 16:21:33 -0000 1.1
+++ UIPage.java 25 Dec 2006 16:17:54 -0000 1.2
@@ -18,6 +18,10 @@
return null;
}
+ public void removeITextObject() {
+
+ }
+
public void createITextObject() {
}
1.3 +4 -0 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.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- UIParagraph.java 24 Dec 2006 22:54:32 -0000 1.2
+++ UIParagraph.java 25 Dec 2006 16:17:54 -0000 1.3
@@ -66,6 +66,10 @@
return paragraph;
}
+ public void removeITextObject() {
+ paragraph = null;
+ }
+
public void createITextObject() {
Font font = getFont();
if (font == null) {
1.1 date: 2006/12/25 16:17:54; author: nrichards; state: Exp;jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UICell.java
Index: UICell.java
===================================================================
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 UICell
extends ITextComponent
{
public static final String COMPONENT_TYPE = "org.jboss.seam.pdf.ui.UICell";
PdfPCell cell;
public Object getITextObject() {
return cell;
}
public void removeITextObject() {
cell = null;
}
public void createITextObject() {
cell = new PdfPCell();
}
public void add(Object o) {
if (o instanceof Element) {
cell.addElement((Element) o);
} else {
throw new RuntimeException("Can't add " + o.getClass().getName() +
" to cell");
}
}
}
1.1 date: 2006/12/25 16:17:54; author: nrichards; state: Exp;jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIChapter.java
Index: UIChapter.java
===================================================================
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 UIChapter
extends ITextComponent
{
public static final String COMPONENT_TYPE = "org.jboss.seam.pdf.ui.UIChapter";
Chapter chapter;
public Chapter getChapter() {
return chapter;
}
public Object getITextObject() {
return chapter;
}
public void removeITextObject() {
chapter = null;
}
public void createITextObject() {
chapter = new Chapter("*chapter title*",1);
}
public void add(Object o) {
chapter.add(o);
}
}
1.1 date: 2006/12/25 16:17:54; author: nrichards; state: Exp;jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UISection.java
Index: UISection.java
===================================================================
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 UISection
extends ITextComponent
{
public static final String COMPONENT_TYPE = "org.jboss.seam.pdf.ui.UISection";
Section section;
public Object getITextObject() {
return section;
}
public void removeITextObject() {
section = null;
}
public void createITextObject() {
Chapter chapter = ((UIChapter)findITextParent(this, UIChapter.class)).getChapter();
section = chapter.addSection(new Paragraph("*fake title*"), 1);
section.setTitle(new Paragraph("*section title*"));
}
public void add(Object o) {
section.add(o);
}
}
1.1 date: 2006/12/25 16:17:54; author: nrichards; state: Exp;jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UITable.java
Index: UITable.java
===================================================================
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 UITable
extends ITextComponent
{
public static final String COMPONENT_TYPE = "org.jboss.seam.pdf.ui.UITable";
PdfPTable table;
int columns = 1;
Integer headerRows = 0;
Integer footerRows = 0;
public void setColumns(int columns) {
this.columns = columns;
}
public void setHeaderRows(Integer headerRows) {
this.headerRows = headerRows;
}
public void setFooterRows(Integer footerRows) {
this.footerRows = footerRows;
}
public Object getITextObject() {
return table;
}
public void removeITextObject() {
table = null;
}
public void createITextObject() {
table = new PdfPTable(columns);
if (headerRows != null) {
table.setHeaderRows(headerRows.intValue());
}
if (footerRows != null) {
table.setFooterRows(footerRows.intValue());
}
}
public void add(Object o) {
if (o instanceof PdfPCell) {
table.addCell((PdfPCell) o);
} else {
throw new RuntimeException("Can't add " + o.getClass().getName() +
" to table");
}
}
}
More information about the jboss-cvs-commits
mailing list