[PATCH] Init: Added new Exporter classes.
Javier Fernandez (via Code Review)
gerrit at gerrit.libreoffice.org
Mon Mar 25 03:46:48 PDT 2013
Hi,
I have submitted a patch for review:
https://gerrit.libreoffice.org/3009
To pull it, you can do:
git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/09/3009/1
Init: Added new Exporter classes.
Change-Id: I45a0c3a4665581dcd0709d1ae72fbbbf404d7182
---
A wizards/com/sun/star/wizards/web/export/AbstractExporter.py
A wizards/com/sun/star/wizards/web/export/CopyExporter.py
A wizards/com/sun/star/wizards/web/export/Exporter.py
A wizards/com/sun/star/wizards/web/export/__init__.py
4 files changed, 199 insertions(+), 0 deletions(-)
diff --git a/wizards/com/sun/star/wizards/web/export/AbstractExporter.py b/wizards/com/sun/star/wizards/web/export/AbstractExporter.py
new file mode 100644
index 0000000..2dd45c2
--- /dev/null
+++ b/wizards/com/sun/star/wizards/web/export/AbstractExporter.py
@@ -0,0 +1,106 @@
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This file incorporates work covered by the following license notice:
+#
+# 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 .
+#
+import traceback
+import uno
+
+from .Exporter import Exporter
+from ..TypeDetection import *
+from ...common.Desktop import Desktop
+from ...common.Properties import Properties
+from ...common.FileAccess import FileAccess
+from ...document.OfficeDocument import OfficeDocument
+from ...text.TextDocument import TextDocument
+
+from com.sun.star.lang import IllegalArgumentException
+from com.sun.star.document.MacroExecMode import NEVER_EXECUTE
+from com.sun.star.document.UpdateDocMode import NO_UPDATE
+
+class AbstractExporter(Exporter):
+
+ exporter = None
+ fileAccess = None
+
+ def __init__(self, exporter_):
+ print ("DEBUG !!! AbstractExporter.init - exporter: ", exporter_)
+ self.exporter = exporter_
+
+ def storeToURL(self, officeDocument, props, targetUrl, filterName, filterData):
+ props = Properties()
+ props["FilterName"] = filterName
+ if (len(filterData) > 0):
+ props["FilterData"] = filterData
+ o = props.getProperties1()
+ officeDocument.storeToURL(targetUrl, tuple(o))
+
+ def storeToURL1(self, officeDocument, targetUrl, filterName, filterData):
+ self.storeToURL(officeDocument, Properties(), targetUrl, filterName, filterData)
+
+ def storeToURL2(self, officeDocument, targetUrl, filterName):
+ self.storeToURL(officeDocument, Properties(), targetUrl, filterName, [])
+
+ def getArgument(self, name, p):
+ return p.cp_Arguments.getElement(name).cp_Value
+
+ def openDocument(self, doc, xmsf):
+ document = None
+ # open the document.
+ try:
+ desktop = Desktop.getDesktop(xmsf)
+ props = list(range(3))
+ props[0] = Properties.createProperty("Hidden", True)
+ props[1] = Properties.createProperty("MacroExecutionMode", NEVER_EXECUTE)
+ props[2] = Properties.createProperty("UpdateDocMode", NO_UPDATE)
+ print ("DEBUG !!! openDocument -- URL: ", doc.cp_URL)
+ document = desktop.loadComponentFromURL(doc.cp_URL, "_blank", 0, tuple(props))
+ except IllegalArgumentException:
+ traceback.print_exc()
+ # try to get the number of pages in the document
+ try:
+ self.pageCount(doc, document)
+ except Exception:
+ traceback.print_exc()
+ # Here i do nothing since pages is not *so* important.
+ return document
+
+ def closeDocument(self, doc, xmsf):
+ try:
+ doc.close(False)
+ except Exception:
+ traceback.print_exc()
+
+ def pageCount(self, doc, document):
+ if (doc.appType == WRITER_DOC):
+ doc.pages = TextDocument.getPageCount(document)
+ elif (doc.appType == IMPRESS_DOC):
+ doc.pages = OfficeDocument.getSlideCount(document)
+ elif (doc.appType == DRAW_DOC):
+ doc.pages = OfficeDocument.getSlideCount(document)
+
+ def getFileAccess(self, xmsf):
+ if (self.fileAccess == None):
+ try:
+ self.fileAccess = FileAccess(xmsf)
+ except Exception:
+ traceback.print_exc()
+ return self.fileAccess
+
+ def calcFileSize(self, doc, url, xmsf):
+ # if the exporter exports to a
+ # binary format, get the size of the destination.
+ if (self.exporter.cp_Binary):
+ doc.sizeBytes = self.getFileAccess(xmsf).getSize(url)
diff --git a/wizards/com/sun/star/wizards/web/export/CopyExporter.py b/wizards/com/sun/star/wizards/web/export/CopyExporter.py
new file mode 100644
index 0000000..862c045
--- /dev/null
+++ b/wizards/com/sun/star/wizards/web/export/CopyExporter.py
@@ -0,0 +1,52 @@
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This file incorporates work covered by the following license notice:
+#
+# 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 .
+#
+import traceback
+
+from .AbstractExporter import AbstractExporter
+from ...common.FileAccess import FileAccess
+
+class CopyExporter(AbstractExporter):
+
+ # @see com.sun.star.wizards.web.export.Exporter#export(java.lang.Object, java.io.File, com.sun.star.wizards.web.data.CGSettings, com.sun.star.lang.XMultiServiceFactory)
+ def export(self, source, target, xmsf, task):
+ try:
+ task.advance(True)
+
+ # this will open the document, and calculate the pages/slides number
+ # in it.
+ if (self.exporter.cp_PageType > 0):
+ self.closeDocument(self.openDocument(source, xmsf), xmsf)
+
+ task.advance(True)
+
+ print ("WARNING !!! CopyExporter (creating newtarget) - source.urlFilename: ", source.urlFilename)
+
+ newTarget = FileAccess.connectURLs(
+ FileAccess.getParentDir(target), source.urlFilename)
+
+ print ("WARNING !!! CopyExporter (export) - source, target: ", source.cp_URL, newTarget)
+ b = self.getFileAccess(xmsf).copy(source.cp_URL, newTarget)
+
+ task.advance(True)
+
+ self.calcFileSize(source, newTarget, xmsf)
+
+ return b
+ except Exception:
+ traceback.print_exc()
+ return False
diff --git a/wizards/com/sun/star/wizards/web/export/Exporter.py b/wizards/com/sun/star/wizards/web/export/Exporter.py
new file mode 100644
index 0000000..5f5c7ec
--- /dev/null
+++ b/wizards/com/sun/star/wizards/web/export/Exporter.py
@@ -0,0 +1,40 @@
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This file incorporates work covered by the following license notice:
+#
+# 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 .
+#
+from ..abc import abstractmethod
+
+class Exporter:
+
+ # This method exports a document with a specified filter.<br/>
+ # The method is responsible for exporting the given source document
+ # to the given target directory.
+ # The exporter *must* also set the given CGDocument sizeBytes field to the
+ # size of the converted document, *if* the target document is
+ # of a binary format.
+ # always use source.urlFilename as destination filename.
+ # @param source is a CGDocument object.
+ # @param targetDirectory contains the URL of a directory to which the file should be exported to.
+ # @param xmsf this is a basic multiServiceFactory.
+ # @param task - a task monitoring object. This should advance
+ # (call task.advance(true) ) 3 times, while exporting.
+ @abstractmethod
+ def export(self, source, targetDirectory, xmsf, task):
+ pass
+
+ @abstractmethod
+ def init(self, exporter):
+ pass
diff --git a/wizards/com/sun/star/wizards/web/export/__init__.py b/wizards/com/sun/star/wizards/web/export/__init__.py
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/wizards/com/sun/star/wizards/web/export/__init__.py
@@ -0,0 +1 @@
+
--
To view, visit https://gerrit.libreoffice.org/3009
To unsubscribe, visit https://gerrit.libreoffice.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I45a0c3a4665581dcd0709d1ae72fbbbf404d7182
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: Javier Fernandez <javier.fgb at gmail.com>
More information about the LibreOffice
mailing list