You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2020/01/30 21:52:57 UTC

[camel] branch master updated: CAMEL-14452: Use String for pageSize and font on PDF URI params

This is an automated email from the ASF dual-hosted git repository.

jamesnetherton pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new c654fa5  CAMEL-14452: Use String for pageSize and font on PDF URI params
c654fa5 is described below

commit c654fa56bd8c6bb51b89b5b35835793499e7a1d0
Author: James Netherton <ja...@gmail.com>
AuthorDate: Thu Jan 30 08:17:11 2020 +0000

    CAMEL-14452: Use String for pageSize and font on PDF URI params
---
 .../camel-pdf/src/main/docs/pdf-component.adoc     |  4 +--
 .../camel/component/pdf/PdfConfiguration.java      | 26 +++++++-----------
 .../camel/component/pdf/PdfCreationTest.java       |  2 +-
 .../endpoint/dsl/PdfEndpointBuilderFactory.java    | 32 ++--------------------
 .../modules/ROOT/pages/pdf-component.adoc          |  4 +--
 5 files changed, 17 insertions(+), 51 deletions(-)

diff --git a/components/camel-pdf/src/main/docs/pdf-component.adoc b/components/camel-pdf/src/main/docs/pdf-component.adoc
index 10e7847..907d233 100644
--- a/components/camel-pdf/src/main/docs/pdf-component.adoc
+++ b/components/camel-pdf/src/main/docs/pdf-component.adoc
@@ -78,14 +78,14 @@ with the following path and query parameters:
 [width="100%",cols="2,5,^1,2",options="header"]
 |===
 | Name | Description | Default | Type
-| *font* (producer) | Font | Helvetica | PDFont
+| *font* (producer) | Font | Helvetica | String
 | *fontSize* (producer) | Font size in pixels | 14 | float
 | *lazyStartProducer* (producer) | Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and [...]
 | *marginBottom* (producer) | Margin bottom in pixels | 20 | int
 | *marginLeft* (producer) | Margin left in pixels | 20 | int
 | *marginRight* (producer) | Margin right in pixels | 40 | int
 | *marginTop* (producer) | Margin top in pixels | 20 | int
-| *pageSize* (producer) | Page size | A4 | PDRectangle
+| *pageSize* (producer) | Page size | A4 | String
 | *textProcessingFactory* (producer) | Text processing to use. autoFormatting: Text is getting sliced by words, then max amount of words that fits in the line will be written into pdf document. With this strategy all words that doesn't fit in the line will be moved to the new line. lineTermination: Builds set of classes for line-termination writing strategy. Text getting sliced by line termination symbol and then it will be written regardless it fits in the line or not. | lineTermination [...]
 | *basicPropertyBinding* (advanced) | Whether the endpoint should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities | false | boolean
 | *synchronous* (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean
diff --git a/components/camel-pdf/src/main/java/org/apache/camel/component/pdf/PdfConfiguration.java b/components/camel-pdf/src/main/java/org/apache/camel/component/pdf/PdfConfiguration.java
index 93b08df..30fcf98 100644
--- a/components/camel-pdf/src/main/java/org/apache/camel/component/pdf/PdfConfiguration.java
+++ b/components/camel-pdf/src/main/java/org/apache/camel/component/pdf/PdfConfiguration.java
@@ -25,7 +25,6 @@ import org.apache.camel.spi.UriParams;
 import org.apache.camel.spi.UriPath;
 import org.apache.pdfbox.pdmodel.common.PDRectangle;
 import org.apache.pdfbox.pdmodel.font.PDFont;
-import org.apache.pdfbox.pdmodel.font.PDType1Font;
 
 import static org.apache.camel.component.pdf.PdfPageSizeConstant.PAGE_SIZE_A0;
 import static org.apache.camel.component.pdf.PdfPageSizeConstant.PAGE_SIZE_A1;
@@ -68,9 +67,12 @@ public class PdfConfiguration {
     @UriParam(defaultValue = "14")
     private float fontSize = 14;
     @UriParam(defaultValue = "A4", enums = "LETTER,LEGAL,A0,A1,A2,A3,A4,A5,A6")
-    private PDRectangle pageSize = PDRectangle.A4;
-    @UriParam(defaultValue = "Helvetica")
-    private PDFont font = PDType1Font.HELVETICA;
+    private String pageSize = PAGE_SIZE_A4;
+    @UriParam(defaultValue = "Helvetica", enums = "Courier,Courier-Bold,Courier-Oblique,Courier-BoldOblique,"
+            + "Helvetica,Helvetica-Bold,Helvetica-Oblique,Helvetica-BoldOblique,"
+            + "Times-Roman,Times-Bold,Times-Italic,Times-BoldItalic,"
+            + "Symbol,ZapfDingbats")
+    private String font = "Helvetica";
     @UriParam(defaultValue = "lineTermination")
     private TextProcessingFactory textProcessingFactory = TextProcessingFactory.lineTermination;
 
@@ -142,33 +144,25 @@ public class PdfConfiguration {
     }
 
     public PDRectangle getPageSize() {
-        return pageSize;
+        return PAGE_MAP.get(pageSize);
     }
 
     /**
      * Page size
      */
-    public void setPageSize(PDRectangle pageSize) {
-        this.pageSize = pageSize;
-    }
-
     public void setPageSize(String pageSize) {
-        setPageSize(PAGE_MAP.get(pageSize));
+        this.pageSize = pageSize;
     }
 
     public PDFont getFont() {
-        return font;
+        return Standard14Fonts.getByName(font);
     }
 
     /**
      * Font
      */
-    public void setFont(PDFont font) {
-        this.font = font;
-    }
-
     public void setFont(String font) {
-        setFont(Standard14Fonts.getByName(font));
+        this.font = font;
     }
 
     public TextProcessingFactory getTextProcessingFactory() {
diff --git a/components/camel-pdf/src/test/java/org/apache/camel/component/pdf/PdfCreationTest.java b/components/camel-pdf/src/test/java/org/apache/camel/component/pdf/PdfCreationTest.java
index 31cea45..9bb9005 100644
--- a/components/camel-pdf/src/test/java/org/apache/camel/component/pdf/PdfCreationTest.java
+++ b/components/camel-pdf/src/test/java/org/apache/camel/component/pdf/PdfCreationTest.java
@@ -115,7 +115,7 @@ public class PdfCreationTest extends CamelTestSupport {
             @Override
             public void configure() throws Exception {
                 from("direct:start")
-                        .to("pdf:create")
+                        .to("pdf:create?font=Courier&pageSize=PAGE_SIZE_A1")
                         .to("mock:result");
             }
         };
diff --git a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/PdfEndpointBuilderFactory.java b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/PdfEndpointBuilderFactory.java
index 07ecaf1..f754512 100644
--- a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/PdfEndpointBuilderFactory.java
+++ b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/PdfEndpointBuilderFactory.java
@@ -41,21 +41,7 @@ public interface PdfEndpointBuilderFactory {
         /**
          * Font.
          * 
-         * The option is a: <code>org.apache.pdfbox.pdmodel.font.PDFont</code>
-         * type.
-         * 
-         * Default: Helvetica
-         * Group: producer
-         */
-        default PdfEndpointBuilder font(Object font) {
-            doSetProperty("font", font);
-            return this;
-        }
-        /**
-         * Font.
-         * 
-         * The option will be converted to a
-         * <code>org.apache.pdfbox.pdmodel.font.PDFont</code> type.
+         * The option is a: <code>java.lang.String</code> type.
          * 
          * Default: Helvetica
          * Group: producer
@@ -227,21 +213,7 @@ public interface PdfEndpointBuilderFactory {
         /**
          * Page size.
          * 
-         * The option is a:
-         * <code>org.apache.pdfbox.pdmodel.common.PDRectangle</code> type.
-         * 
-         * Default: A4
-         * Group: producer
-         */
-        default PdfEndpointBuilder pageSize(Object pageSize) {
-            doSetProperty("pageSize", pageSize);
-            return this;
-        }
-        /**
-         * Page size.
-         * 
-         * The option will be converted to a
-         * <code>org.apache.pdfbox.pdmodel.common.PDRectangle</code> type.
+         * The option is a: <code>java.lang.String</code> type.
          * 
          * Default: A4
          * Group: producer
diff --git a/docs/components/modules/ROOT/pages/pdf-component.adoc b/docs/components/modules/ROOT/pages/pdf-component.adoc
index 4e13560..75f0cf7 100644
--- a/docs/components/modules/ROOT/pages/pdf-component.adoc
+++ b/docs/components/modules/ROOT/pages/pdf-component.adoc
@@ -79,14 +79,14 @@ with the following path and query parameters:
 [width="100%",cols="2,5,^1,2",options="header"]
 |===
 | Name | Description | Default | Type
-| *font* (producer) | Font | Helvetica | PDFont
+| *font* (producer) | Font | Helvetica | String
 | *fontSize* (producer) | Font size in pixels | 14 | float
 | *lazyStartProducer* (producer) | Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and [...]
 | *marginBottom* (producer) | Margin bottom in pixels | 20 | int
 | *marginLeft* (producer) | Margin left in pixels | 20 | int
 | *marginRight* (producer) | Margin right in pixels | 40 | int
 | *marginTop* (producer) | Margin top in pixels | 20 | int
-| *pageSize* (producer) | Page size | A4 | PDRectangle
+| *pageSize* (producer) | Page size | A4 | String
 | *textProcessingFactory* (producer) | Text processing to use. autoFormatting: Text is getting sliced by words, then max amount of words that fits in the line will be written into pdf document. With this strategy all words that doesn't fit in the line will be moved to the new line. lineTermination: Builds set of classes for line-termination writing strategy. Text getting sliced by line termination symbol and then it will be written regardless it fits in the line or not. | lineTermination [...]
 | *basicPropertyBinding* (advanced) | Whether the endpoint should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities | false | boolean
 | *synchronous* (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean