pietsch 2003/03/05 10:58:16
Modified: . Tag: fop-0_20_2-maintain build.xml
src/org/apache/fop/apps Tag: fop-0_20_2-maintain
CommandLineOptions.java
src/org/apache/fop/pdf Tag: fop-0_20_2-maintain
PDFDocument.java PDFXObject.java
src/org/apache/fop/render/pdf Tag: fop-0_20_2-maintain
PDFRenderer.java
Added: src/java-1.3/org/apache/fop/pdf Tag: fop-0_20_2-maintain
PDFEncryption.java
src/java-1.4/org/apache/fop/pdf Tag: fop-0_20_2-maintain
PDFEncryption.java
Log:
Added PDF encryption.
Submitted by: Patrick C. Lankswert <[EMAIL PROTECTED]>
Revision Changes Path
No revision
No revision
1.44.2.38 +10 -3 xml-fop/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/xml-fop/build.xml,v
retrieving revision 1.44.2.37
retrieving revision 1.44.2.38
diff -u -r1.44.2.37 -r1.44.2.38
--- build.xml 18 Feb 2003 12:27:34 -0000 1.44.2.37
+++ build.xml 5 Mar 2003 18:58:14 -0000 1.44.2.38
@@ -189,7 +189,7 @@
<tstamp/>
<property name="Name" value="Fop"/>
<property name="name" value="fop"/>
- <property name="version" value="0.20.5rc2"/>
+ <property name="version" value="0.20.5rc3"/>
<filter token="version" value="${version}"/>
<property name="year" value="1999-2003"/>
@@ -302,11 +302,17 @@
<target name="init-filters-jdk13" depends="init-avail" unless="jdk14.present">
<echo message="JDK 1.3 or earlier present."/>
<copy file="src/codegen/jdk13.filter" toFile="build/src/codegen/filter"/>
+ <copy todir="build/src">
+ <fileset dir="src/java-1.3"/>
+ </copy>
</target>
<target name="init-filters-jdk14" depends="init-avail" if="jdk14.present">
<echo message="JDK 1.4 present."/>
<copy file="src/codegen/jdk14.filter" toFile="build/src/codegen/filter"/>
+ <copy todir="build/src">
+ <fileset dir="src/java-1.4"/>
+ </copy>
</target>
@@ -371,8 +377,9 @@
<target name="prepare-src" depends="prepare, prepare-jimi, prepare-jai,
prepare-trax">
<!-- copy src files -->
<copy todir="${build.src}" filtering="yes">
- <fileset dir="${src.dir}"
-
excludes="**/${jimi},**/${jai},**/${tiff},**/${xsltransform},**/${trax},**/apps/TraxInputHandler.java"/>
+ <fileset dir="${src.dir}"
+ includes="**/*.java"
+
excludes="java-*/**,**/${jimi},**/${jai},**/${tiff},**/${xsltransform},**/${trax},**/apps/TraxInputHandler.java"/>
<filterset>
<filter token="XSLFO-STD" value="${xslfo.std}"/>
<filter token="XSLFO-STDID" value="${xslfo.std.id}"/>
No revision
No revision
1.1.2.1 +156 -0 xml-fop/src/java-1.3/org/apache/fop/pdf/Attic/PDFEncryption.java
No revision
No revision
1.1.2.1 +421 -0 xml-fop/src/java-1.4/org/apache/fop/pdf/Attic/PDFEncryption.java
No revision
No revision
1.14.2.10 +95 -30 xml-fop/src/org/apache/fop/apps/CommandLineOptions.java
Index: CommandLineOptions.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/apps/CommandLineOptions.java,v
retrieving revision 1.14.2.9
retrieving revision 1.14.2.10
diff -u -r1.14.2.9 -r1.14.2.10
--- CommandLineOptions.java 25 Feb 2003 10:18:31 -0000 1.14.2.9
+++ CommandLineOptions.java 5 Mar 2003 18:58:15 -0000 1.14.2.10
@@ -147,6 +147,26 @@
}
+ private boolean pdfEncryptionAvailable = false;
+ private boolean pdfEncryptionChecked = false;
+ private boolean encryptionAvailable() {
+ if (!pdfEncryptionChecked) {
+ try {
+ Class c = Class.forName("javax.crypto.Cipher");
+ pdfEncryptionAvailable
+ = org.apache.fop.pdf.PDFEncryption.encryptionAvailable();
+ }
+ catch(ClassNotFoundException e) {
+ pdfEncryptionAvailable = false;
+ }
+ pdfEncryptionChecked = true;
+ if (!pdfEncryptionAvailable) {
+ log.warn("PDF encryption not available.");
+ }
+ }
+ return pdfEncryptionAvailable;
+ }
+
/**
* parses the commandline arguments
* @return true if parse was successful and procesing can continue, false if
processing should stop
@@ -219,6 +239,44 @@
outfile = new File(args[i + 1]);
i++;
}
+ } else if (args[i].equals("-o")) {
+ if ((i + 1 == args.length) || (args[i + 1].charAt(0) == '-')) {
+ if (encryptionAvailable()) {
+ rendererOptions.put("ownerPassword", "");
+ }
+ } else {
+ if (encryptionAvailable()) {
+ rendererOptions.put("ownerPassword", args[i + 1]);
+ }
+ i++;
+ }
+ } else if (args[i].equals("-u")) {
+ if ((i + 1 == args.length) || (args[i + 1].charAt(0) == '-')) {
+ if (encryptionAvailable()) {
+ rendererOptions.put("userPassword", "");
+ }
+ } else {
+ if (encryptionAvailable()) {
+ rendererOptions.put("userPassword", args[i + 1]);
+ }
+ i++;
+ }
+ } else if (args[i].equals("-noprint")) {
+ if (encryptionAvailable()) {
+ rendererOptions.put("allowPrint", "FALSE");
+ }
+ } else if (args[i].equals("-nocopy")) {
+ if (encryptionAvailable()) {
+ rendererOptions.put("allowCopyContent", "FALSE");
+ }
+ } else if (args[i].equals("-noedit")) {
+ if (encryptionAvailable()) {
+ rendererOptions.put("allowEditContent", "FALSE");
+ }
+ } else if (args[i].equals("-noannotations")) {
+ if (encryptionAvailable()) {
+ rendererOptions.put("allowEditAnnotations", "FALSE");
+ }
} else if (args[i].equals("-mif")) {
setOutputMode(MIF_OUTPUT);
if ((i + 1 == args.length)
@@ -534,38 +592,45 @@
*/
public static void printUsage() {
System.err.println("\nUSAGE\nFop [options] [-fo|-xml] infile [-xsl file]
[-awt|-pdf|-mif|-pcl|-ps|-txt|-at|-print] <outfile>\n"
- + " [OPTIONS] \n"
- + " -d debug mode \n"
- + " -x dump configuration settings \n"
- + " -q quiet mode \n"
- + " -c cfg.xml use additional configuration file
cfg.xml\n"
- + " -l lang the language to use for user
information \n"
- + " -s for area tree XML, down to block
areas only\n\n"
- + " [INPUT] \n"
- + " infile xsl:fo input file (the same
as the next) \n"
- + " -fo infile xsl:fo input file \n"
- + " -xml infile xml input file, must be used
together with -xsl \n"
- + " -xsl stylesheet xslt stylesheet \n \n"
- + " [OUTPUT] \n"
- + " outfile input will be rendered as pdf
file into outfile \n"
- + " -pdf outfile input will be rendered as pdf
file (outfile req'd) \n"
- + " -awt input will be displayed on
screen \n"
+ + " [OPTIONS]\n"
+ + " -d debug mode\n"
+ + " -x dump configuration settings\n"
+ + " -q quiet mode\n"
+ + " -c cfg.xml use additional configuration
file cfg.xml\n"
+ + " -l lang the language to use for user
information\n"
+ + " -s (-at output) omit tree below
block areas\n"
+ + " -"+TXTRenderer.encodingOptionName+" (-txt
output encoding use the encoding for the output file.\n"
+ + " The encoding must be a valid
java encoding.\n"
+ + " -o [password] pdf file will be encrypted with
option owner password\n"
+ + " -u [password] pdf file will be encrypted with
option user password\n"
+ + " -noprint pdf file will be encrypted
without printing permission\n"
+ + " -nocopy pdf file will be encrypted
without copy content permission\n"
+ + " -noedit pdf file will be encrypted
without edit content permission\n"
+ + " -noannotations pdf file will be encrypted
without edit annotation permission\n"
+ + "\n [INPUT]\n"
+ + " infile xsl:fo input file (the same
as the next)\n"
+ + " -fo infile xsl:fo input file\n"
+ + " -xml infile xml input file, must be used
together with -xsl\n"
+ + " -xsl stylesheet xslt stylesheet\n"
+ + "\n [OUTPUT]\n"
+ + " outfile input will be rendered as pdf
file into outfile\n"
+ + " -pdf outfile input will be rendered as pdf
file (outfile req'd)\n"
+ + " -awt input will be displayed on
screen\n"
+ " -mif outfile input will be rendered as mif
file (outfile req'd)\n"
- + " -pcl outfile input will be rendered as pcl
file (outfile req'd) \n"
- + " -ps outfile input will be rendered as
PostScript file (outfile req'd) \n"
- + " -txt outfile input will be rendered as
text file (outfile req'd) \n"
- + " -"+TXTRenderer.encodingOptionName+" encoding
use the encoding for the output file.\n"
- + " the encoding must be a valid
java encoding.\n"
- + " -svg outfile input will be rendered as an
svg slides file (outfile req'd) \n"
- + " -at outfile representation of area tree
as XML (outfile req'd) \n"
- + " -print input file will be rendered
and sent to the printer \n"
- + " see options with \"-print
help\" \n\n"
- + " [Examples]\n" + " Fop foo.fo foo.pdf \n"
+ + " -pcl outfile input will be rendered as pcl
file (outfile req'd)\n"
+ + " -ps outfile input will be rendered as
PostScript file (outfile req'd)\n"
+ + " -txt outfile input will be rendered as
text file (outfile req'd)\n"
+ + " -svg outfile input will be rendered as an
svg slides file (outfile req'd)\n"
+ + " -at outfile representation of area tree
as XML (outfile req'd)\n"
+ + " -print input file will be rendered
and sent to the printer\n"
+ + " see print specific options
with \"-print help\"\n"
+ + "\n [Examples]\n"
+ + " Fop foo.fo foo.pdf\n"
+ " Fop -fo foo.fo -pdf foo.pdf (does the same as
the previous line)\n"
+ " Fop -xsl foo.xsl -xml foo.xml -pdf foo.pdf\n"
+ " Fop foo.fo -mif foo.mif\n"
- + " Fop foo.fo -print or Fop -print foo.fo \n"
- + " Fop foo.fo -awt \n");
+ + " Fop foo.fo -print or Fop -print foo.fo\n"
+ + " Fop foo.fo -awt\n");
}
/**
@@ -573,7 +638,7 @@
*/
public void printUsagePrintOutput() {
System.err.println("USAGE: -print [-Dstart=i] [-Dend=i] [-Dcopies=i]
[-Deven=true|false] "
- + " org.apache.fop.apps.Fop (..) -print \n"
+ + " org.apache.fop.apps.Fop (..) -print\n"
+ "Example:\n"
+ "java -Dstart=1 -Dend=2 org.apache.Fop.apps.Fop
infile.fo -print ");
}
No revision
No revision
1.30.2.8 +43 -1 xml-fop/src/org/apache/fop/pdf/PDFDocument.java
Index: PDFDocument.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFDocument.java,v
retrieving revision 1.30.2.7
retrieving revision 1.30.2.8
diff -u -r1.30.2.7 -r1.30.2.8
--- PDFDocument.java 25 Feb 2003 14:29:37 -0000 1.30.2.7
+++ PDFDocument.java 5 Mar 2003 18:58:15 -0000 1.30.2.8
@@ -160,6 +160,11 @@
protected IDReferences idReferences;
/**
+ * the documents encryption, if exists
+ */
+ protected PDFEncryption encryption;
+
+ /**
* the colorspace (0=RGB, 1=CMYK)
*/
// protected int colorspace = 0;
@@ -238,6 +243,30 @@
}
/**
+ * set the encryption object
+ *
+ * @param ownerPassword The owner password for the pdf file
+ * @param userPassword The user password for the pdf file
+ * @param allowPrint Indicates whether the printing permission will be set
+ * @param allowCopyContent Indicates whether the content extracting permission
will be set
+ * @param allowEditContent Indicates whether the edit content permission will
be set
+ * @param allowEditAnnotations Indicates whether the edit annotations
permission will be set
+ */
+ public void setEncryption(String ownerPassword, String userPassword,
+ boolean allowPrint, boolean allowCopyContent,
+ boolean allowEditContent, boolean
allowEditAnnotations) {
+ this.encryption = new PDFEncryption(++this.objectcount);
+ this.encryption.setOwnerPassword(ownerPassword);
+ this.encryption.setUserPassword(userPassword);
+ this.encryption.setAllowPrint(allowPrint);
+ this.encryption.setAllowCopyContent(allowCopyContent);
+ this.encryption.setAllowEditContent(allowEditContent);
+ this.encryption.setAllowEditAnnotation(allowEditAnnotations);
+ this.encryption.init();
+ addTrailerObject(this.encryption);
+ }
+
+ /**
* Make a /Catalog (Root) object. This object is written in
* the trailer.
*/
@@ -1170,6 +1199,9 @@
*/
PDFStream obj = new PDFStream(++this.objectcount);
obj.addDefaultFilters();
+ if (this.encryption != null) {
+ obj.addFilter(this.encryption.makeFilter(obj.number,obj.generation));
+ }
this.objects.add(obj);
return obj;
@@ -1317,6 +1349,15 @@
by the table's length */
this.position += outputXref(stream);
+ // Determine existance of encryption dictionary
+ String encryptEntry = "";
+
+ if (this.encryption != null) {
+ encryptEntry =
+ "/Encrypt " + this.encryption.number + " " + this.encryption.generation
+ " R\n"+
+
"/ID[<"+this.encryption.getFileID(1)+"><"+this.encryption.getFileID(2)+">]\n";
+ }
+
/* construct the trailer */
String pdf =
"trailer\n" +
@@ -1324,6 +1365,7 @@
"/Size " + (this.objectcount + 1) + "\n" +
"/Root " + this.root.number + " " + this.root.generation + " R\n" +
"/Info " + this.info.number + " " + this.info.generation + " R\n" +
+ encryptEntry +
">>\n" +
"startxref\n" +
this.xref + "\n" +
1.14.2.6 +10 -2 xml-fop/src/org/apache/fop/pdf/PDFXObject.java
Index: PDFXObject.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFXObject.java,v
retrieving revision 1.14.2.5
retrieving revision 1.14.2.6
diff -u -r1.14.2.5 -r1.14.2.6
--- PDFXObject.java 25 Feb 2003 14:29:38 -0000 1.14.2.5
+++ PDFXObject.java 5 Mar 2003 18:58:15 -0000 1.14.2.6
@@ -108,6 +108,9 @@
pdfICCStream = pdfDoc.makePDFICCStream();
pdfICCStream.setColorSpace(jpegimage.getColorSpace());
pdfICCStream.addDefaultFilters();
+ if (pdfDoc.encryption != null) {
+
pdfICCStream.addFilter(pdfDoc.encryption.makeFilter(pdfICCStream.number,
pdfICCStream.generation));
+ }
}
}
} catch (Exception e) {
@@ -185,6 +188,9 @@
imgStream.setData(imgData);
//imgStream.addFilter(new FlateFilter());
imgStream.addDefaultFilters();
+ if (pdfDoc.encryption != null) {
+
imgStream.addFilter(pdfDoc.encryption.makeFilter(this.number,this.generation));
+ }
String dictEntries = imgStream.applyFilters();
@@ -241,7 +247,9 @@
} else {
imgStream.addDefaultFilters();
}
-
+ if (pdfDoc.encryption != null) {
+
imgStream.addFilter(pdfDoc.encryption.makeFilter(this.number,this.generation));
+ }
String dictEntries = imgStream.applyFilters();
No revision
No revision
1.91.2.15 +46 -1 xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java
Index: PDFRenderer.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java,v
retrieving revision 1.91.2.14
retrieving revision 1.91.2.15
diff -u -r1.91.2.14 -r1.91.2.15
--- PDFRenderer.java 2 Mar 2003 16:55:17 -0000 1.91.2.14
+++ PDFRenderer.java 5 Mar 2003 18:58:16 -0000 1.91.2.15
@@ -170,6 +170,51 @@
*/
public void setOptions(java.util.Map options) {
this.options = options;
+
+ // Process encryption options, if any exist
+ boolean encrypt = false;
+ String oPassword = "";
+ String uPassword = "";
+ boolean allowPrint = true;
+ boolean allowCopyContent = true;
+ boolean allowEditContent = true;
+ boolean allowEditAnnotations = true;
+ String option;
+
+ option = (String) options.get("ownerPassword");
+ if (option != null) {
+ encrypt = true;
+ oPassword = option;
+ }
+ option = (String) options.get("userPassword");
+ if (option != null) {
+ encrypt = true;
+ uPassword = option;
+ }
+ option = (String) options.get("allowPrint");
+ if (option != null) {
+ encrypt = true;
+ allowPrint = option.equals("TRUE");
+ }
+ option = (String) options.get("allowCopyContent");
+ if (option != null) {
+ encrypt = true;
+ allowCopyContent = option.equals("TRUE");
+ }
+ option = (String) options.get("allowEditContent");
+ if (option != null) {
+ encrypt = true;
+ allowEditContent = option.equals("TRUE");
+ }
+ option = (String) options.get("allowEditAnnotations");
+ if (option != null) {
+ encrypt = true;
+ allowEditAnnotations = option.equals("TRUE");
+ }
+ if (encrypt) {
+
this.pdfDoc.setEncryption(oPassword,uPassword,allowPrint,allowCopyContent,
+ allowEditContent, allowEditAnnotations);
+ }
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]