Index: openacs-4/packages/contacts/bin/convert.sh
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/bin/Attic/convert.sh,v
diff -u -r1.6 -r1.7
--- openacs-4/packages/contacts/bin/convert.sh 8 Nov 2006 07:50:38 -0000 1.6
+++ openacs-4/packages/contacts/bin/convert.sh 13 Dec 2006 12:50:16 -0000 1.7
@@ -10,5 +10,5 @@
#/usr/bin/openoffice -writer -headless -pt pdfconv $1 -display lektor2:1.0
# If you are going to use jooconverter
-/usr/bin/java -jar /usr/bin/jooconverter/jooconverter-2.1rc2/jooconverter-2.1rc2.jar $1 $2
-#/etc/openoffice.org-2.0/program/soffice.bin -writer -headless -pt pdfconv $1 -display lektor:1.0
\ No newline at end of file
+#/usr/bin/java -jar /usr/bin/jooconverter/jooconverter-2.1rc2/jooconverter-2.1rc2.jar $1 $2
+/usr/lib/openoffice/program/soffice.bin -writer -headless -pt pdfconv $1 -display localhost:1.0
\ No newline at end of file
Index: openacs-4/packages/contacts/tcl/oo-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/tcl/oo-procs.tcl,v
diff -u -r1.6 -r1.7
--- openacs-4/packages/contacts/tcl/oo-procs.tcl 8 Nov 2006 18:32:25 -0000 1.6
+++ openacs-4/packages/contacts/tcl/oo-procs.tcl 13 Dec 2006 12:50:17 -0000 1.7
@@ -1176,4 +1176,117 @@
}
}
}
+
+
+#----------------------------------------------------------------------
+# This function does the same as contact::oo::import_oo_pdf_using_soffice (same API)
+# but it's using the Cognovis Remote Converter functions to convert into pdf.
+#----------------------------------------------------------------------
+# 2006/11/08 Developed/Created by Cognovis/NFL
+#----------------------------------------------------------------------
+ad_proc -public contact::oo::import_oo_pdf_using_remote_converter {
+ -oo_file:required
+ {-title ""}
+ {-item_id ""}
+ {-parent_id ""}
+ {-no_import:boolean}
+ {-return_pdf:boolean}
+ {-return_pdf_with_id:boolean}
+} {
+ Imports an OpenOffice file (.sxw / .odt) as a PDF file into the content repository. If item_id is specified a new revision of that item is created, else a new item is created.
+
+ This function does the same as contact::oo::import_oo_pdf_using_soffice (same API, that means same function call)
+ but it's using the Cognovis Remote Converter functions to convert into PDF.
+
+ The following parameters are not really used (and stay just here for compatibility reasons):
+ -printer_name
+
+ @param oo_file The full path to the OpenOffice file that contains the data to be exported as PDF.
+ @param printer_name (NOT USED here: The name of the printer that is assigned as the PDF converter. Defaults to "pdfconv".)
+ @param title Title which will be used for the resulting content item and file name if none was given in the item
+ @param item_id The item_id of the content item to which the content should be associated.
+ @param parent_id Needed to set the parent of this object
+ @param no_import If this flag is specified the location of the generated PDF will be returned, but the pdf will not be stored in the content repository
+ @param return_pdf If this flag is specified the location of the generated PDF will be returned and the PDF will be stored in the content repository (in contrast to "no_import"
+ @param return_pdf_with_id Same as return_pdf but it will return a list with three elements: file_item_id, file_mime_type and pdf_filename
+ @return item_id of the revision that contains the file
+ @return file location of the file if "no_import" has been specified.
+} {
+ set destination_file "[file rootname $oo_file].pdf"
+ set remote_server "http://cvs.cognovis.de:8080/contacts"
+
+ # Set the retrieve URL, making sure to trim the "/tmp/" part of it
+ set local_retrieve_url [export_vars -base "[ad_url][apm_package_url_from_key contacts]" -url {{filename "[string range $oo_file 5 end]"}}]
+ set page [lindex [ad_httpget -url [export_vars -base "${remote_server}/convert" -url {{url $local_retrieve_url}}]] 1]
+ set oo_file [ns_tmpnam]
+ set file [open "$oo_file" w]
+ puts $file $page
+ flush $file
+ close $file
+
+ # Test the PDF
+ if {[catch {exec -- /usr/bin/pdf2ps $destination_file /tmp/document.ps}]} {
+ ns_log Notice "PDF CONV:: Could not import using remoteconverter"
+ return 0
+ ad_script_abort
+ }
+
+
+ #--- the following code is identical to contact::oo::import_oo_pdf_using_soffice (on 2006/11/01+08) ---
+
+ # Strip the extension.
+ set pdf_filename $destination_file
+ set mime_type "application/pdf"
+ if {![file exists $pdf_filename]} {
+ ###############
+ # this is a fix to use the oo file if pdf file could not be generated
+ ###############
+ set pdf_filename $oo_file
+ set mime_type "application/odt"
+ } else {
+ ns_unlink $oo_file
+ }
+
+ if {$no_import_p} {
+ return [list $mime_type $pdf_filename]
+ }
+ set pdf_filesize [file size $pdf_filename]
+
+ set file_name [file tail $pdf_filename]
+ if {$title eq ""} {
+ set title $file_name
+ }
+
+ if {[exists_and_not_null $item_id]} {
+ set parent_id [get_parent -item_id $item_id]
+
+ set revision_id [cr_import_content \
+ -title $title \
+ -item_id $item_id \
+ $parent_id \
+ $pdf_filename \
+ $pdf_filesize \
+ $mime_type \
+ $file_name ]
+ } else {
+ set revision_id [cr_import_content \
+ -title $title \
+ $parent_id \
+ $pdf_filename \
+ $pdf_filesize \
+ $mime_type \
+ $file_name ]
+ }
+
+ content::item::set_live_revision -revision_id $revision_id
+ if {$return_pdf_p} {
+ return [list $mime_type $pdf_filename]
+ } elseif {$return_pdf_with_id_p} {
+ return [list [content::revision::item_id -revision_id $revision_id] $mime_type $pdf_filename]
+ } else {
+ ns_unlink $pdf_filename
+ return [content::revision::item_id -revision_id $revision_id]
+ }
+}
+
#----------------------------------------------------------------------
\ No newline at end of file
Index: openacs-4/packages/contacts/www/convert.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/convert.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/contacts/www/convert.tcl 13 Dec 2006 12:50:17 -0000 1.1
@@ -0,0 +1,90 @@
+ad_page_contract {
+ Download file, convert it to pdf and return it
+
+ @param url URL where to get the odt file from
+} {
+ url
+}
+
+set page [lindex [ad_httpget -url "$url"] 1]
+set oo_file [ns_tmpnam]
+set file [open "$oo_file" w]
+puts $file $page
+flush $file
+close $file
+
+set status [catch {exec -- /bin/sh [acs_package_root_dir contacts]/bin/convert.sh $oo_file } result]
+
+if { $status == 0 } {
+
+ # The command succeeded, and wrote nothing to stderr.
+ # $result contains what it wrote to stdout, unless you
+ # redirected it
+
+} elseif { [string equal $::errorCode NONE] } {
+
+ # The command exited with a normal status, but wrote something
+ # to stderr, which is included in $result.
+
+} else {
+
+ switch -exact -- [lindex $::errorCode 0] {
+
+ CHILDKILLED {
+ foreach { - pid sigName msg } $::errorCode break
+
+ # A child process, whose process ID was $pid,
+ # died on a signal named $sigName. A human-
+ # readable message appears in $msg.
+
+ }
+
+ CHILDSTATUS {
+
+ foreach { - pid code } $::errorCode break
+
+ # A child process, whose process ID was $pid,
+ # exited with a non-zero exit status, $code.
+
+ }
+
+ CHILDSUSP {
+
+ foreach { - pid sigName msg } $::errorCode break
+
+ # A child process, whose process ID was $pid,
+ # has been suspended because of a signal named
+ # $sigName. A human-readable description of the
+ # signal appears in $msg.
+
+ }
+
+ POSIX {
+
+ foreach { - errName msg } $::errorCode break
+
+ # One of the kernel calls to launch the command
+ # failed. The error code is in $errName, and a
+ # human-readable message is in $msg.
+
+ }
+
+ }
+}
+
+# Strip the extension.
+set pdf_filename "[file rootname $oo_file].pdf"
+set mime_type "application/pdf"
+
+if {![file exists $pdf_filename]} {
+ ###############
+ # this is a fix to use the oo file if pdf file could not be generated
+ ###############
+ set pdf_filename $oo_file
+ set mime_type "application/odt"
+}
+
+ns_returnfile 200 $mime_type $pdf_filename
+
+ns_unlink $oo_file
+ns_unlink $pdf_filename
\ No newline at end of file
Index: openacs-4/packages/contacts/www/retrieve.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/retrieve.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/contacts/www/retrieve.tcl 13 Dec 2006 12:50:17 -0000 1.1
@@ -0,0 +1,10 @@
+ad_page_contract {
+ Get a file from the /tmp directory
+} {
+ filename
+}
+
+# Protection if someone wants to move out of /tmp/ directory
+regsub -all {\.\.} $filename {} filename
+
+ns_returnfile 200 application/odt "/tmp/$filename"
\ No newline at end of file