You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2017/01/10 10:02:36 UTC

[2/2] syncope git commit: [SYNCOPE-989] Customized FopSerializer as Cocoon 3 is still bound to FOP 1.0

[SYNCOPE-989] Customized FopSerializer as Cocoon 3 is still bound to FOP 1.0


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/c6220090
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/c6220090
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/c6220090

Branch: refs/heads/master
Commit: c622009090b49336b2c4da4bbf6720163bbf5198
Parents: bbbd945
Author: Francesco Chicchiricc� <il...@apache.org>
Authored: Tue Jan 10 11:01:48 2017 +0100
Committer: Francesco Chicchiricc� <il...@apache.org>
Committed: Tue Jan 10 11:02:25 2017 +0100

----------------------------------------------------------------------
 core/logic/pom.xml                              |  8 --
 .../apache/syncope/core/logic/ReportLogic.java  |  2 +-
 .../core/logic/report/FopSerializer.java        | 83 ++++++++++++++++++++
 pom.xml                                         | 20 +----
 4 files changed, 85 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/c6220090/core/logic/pom.xml
----------------------------------------------------------------------
diff --git a/core/logic/pom.xml b/core/logic/pom.xml
index 1d6e81c..58d1f81 100644
--- a/core/logic/pom.xml
+++ b/core/logic/pom.xml
@@ -74,14 +74,6 @@ under the License.
       <groupId>org.apache.xmlgraphics</groupId>
       <artifactId>fop</artifactId>
     </dependency>
-    <dependency>
-      <groupId>org.apache.avalon.framework</groupId>
-      <artifactId>avalon-framework-api</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.avalon.framework</groupId>
-      <artifactId>avalon-framework-impl</artifactId>
-    </dependency>
 
     <dependency>
       <groupId>org.apache.logging.log4j</groupId>

http://git-wip-us.apache.org/repos/asf/syncope/blob/c6220090/core/logic/src/main/java/org/apache/syncope/core/logic/ReportLogic.java
----------------------------------------------------------------------
diff --git a/core/logic/src/main/java/org/apache/syncope/core/logic/ReportLogic.java b/core/logic/src/main/java/org/apache/syncope/core/logic/ReportLogic.java
index 3fd8ccf..033dfa3 100644
--- a/core/logic/src/main/java/org/apache/syncope/core/logic/ReportLogic.java
+++ b/core/logic/src/main/java/org/apache/syncope/core/logic/ReportLogic.java
@@ -28,7 +28,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.zip.ZipInputStream;
 import javax.xml.transform.stream.StreamSource;
-import org.apache.cocoon.optional.pipeline.components.sax.fop.FopSerializer;
 import org.apache.cocoon.pipeline.NonCachingPipeline;
 import org.apache.cocoon.pipeline.Pipeline;
 import org.apache.cocoon.sax.SAXPipelineComponent;
@@ -60,6 +59,7 @@ import org.apache.syncope.common.lib.to.JobTO;
 import org.apache.syncope.common.lib.types.JobAction;
 import org.apache.syncope.common.lib.types.JobType;
 import org.apache.syncope.common.lib.types.StandardEntitlement;
+import org.apache.syncope.core.logic.report.FopSerializer;
 import org.apache.syncope.core.logic.report.XSLTTransformer;
 import org.apache.syncope.core.persistence.api.dao.ConfDAO;
 import org.apache.syncope.core.persistence.api.dao.search.OrderByClause;

http://git-wip-us.apache.org/repos/asf/syncope/blob/c6220090/core/logic/src/main/java/org/apache/syncope/core/logic/report/FopSerializer.java
----------------------------------------------------------------------
diff --git a/core/logic/src/main/java/org/apache/syncope/core/logic/report/FopSerializer.java b/core/logic/src/main/java/org/apache/syncope/core/logic/report/FopSerializer.java
new file mode 100644
index 0000000..9b8b590
--- /dev/null
+++ b/core/logic/src/main/java/org/apache/syncope/core/logic/report/FopSerializer.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.syncope.core.logic.report;
+
+import java.io.File;
+import java.io.OutputStream;
+
+import org.apache.cocoon.pipeline.ProcessingException;
+import org.apache.cocoon.pipeline.caching.CacheKey;
+import org.apache.cocoon.pipeline.caching.SimpleCacheKey;
+import org.apache.cocoon.pipeline.component.CachingPipelineComponent;
+import org.apache.cocoon.pipeline.util.StringRepresentation;
+import org.apache.cocoon.sax.AbstractSAXSerializer;
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.Fop;
+import org.apache.fop.apps.FopFactory;
+import org.apache.fop.apps.FopFactoryBuilder;
+import org.apache.xmlgraphics.util.MimeConstants;
+import org.xml.sax.ContentHandler;
+
+public class FopSerializer extends AbstractSAXSerializer implements CachingPipelineComponent {
+
+    private static final FopFactory FOP_FACTORY = new FopFactoryBuilder(new File(".").toURI()).build();
+
+    private String outputFormat;
+
+    /**
+     * Create a new FOP serializer that produces a PDF in output
+     */
+    public FopSerializer() {
+        this(MimeConstants.MIME_PDF);
+    }
+
+    /**
+     * Create a new FOP serializer that produces the specified mime
+     *
+     * @param outputFormat the output's mime type
+     * @see {@link MimeConstants}
+     */
+    public FopSerializer(final String outputFormat) {
+        if (outputFormat == null) {
+            throw new IllegalArgumentException("The parameter 'outputFormat' mustn't be null.");
+        }
+
+        this.outputFormat = outputFormat;
+    }
+
+    @Override
+    public CacheKey constructCacheKey() {
+        return new SimpleCacheKey();
+    }
+
+    @Override
+    public void setOutputStream(final OutputStream outputStream) {
+        try {
+            Fop fop = FOP_FACTORY.newFop(this.outputFormat, outputStream);
+            ContentHandler fopContentHandler = fop.getDefaultHandler();
+
+            this.setContentHandler(fopContentHandler);
+        } catch (FOPException e) {
+            throw new ProcessingException("Impossible to initialize FOPSerializer", e);
+        }
+    }
+
+    @Override
+    public String toString() {
+        return StringRepresentation.buildString(this, "outputFormat=" + this.outputFormat);
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/c6220090/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 0f705f8..022aac9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -895,32 +895,14 @@ under the License.
       <dependency>
         <groupId>org.apache.xmlgraphics</groupId>
         <artifactId>fop</artifactId>
-        <version>1.1</version>
+        <version>2.1</version>
         <exclusions>
           <exclusion>
-            <groupId>org.apache.avalon.framework</groupId>
-            <artifactId>avalon-framework-api</artifactId>
-          </exclusion>
-          <exclusion>
-            <groupId>org.apache.avalon.framework</groupId>
-            <artifactId>avalon-framework-impl</artifactId>
-          </exclusion>
-          <exclusion>
             <groupId>xalan</groupId>
             <artifactId>xalan</artifactId>
           </exclusion>
         </exclusions>
       </dependency>
-      <dependency>
-        <groupId>org.apache.avalon.framework</groupId>
-        <artifactId>avalon-framework-api</artifactId>
-        <version>4.3.1</version>
-      </dependency>
-      <dependency>
-        <groupId>org.apache.avalon.framework</groupId>
-        <artifactId>avalon-framework-impl</artifactId>
-        <version>4.3.1</version>
-      </dependency>
             
       <!-- Activiti -->
       <dependency>