From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- swext/Configuration_mediawiki.mk | 28 + swext/Extension_wiki-publisher.mk | 53 + swext/Jar_mediawiki.mk | 34 + swext/Makefile | 14 + swext/Module_swext.mk | 19 + swext/README.md | 3 + swext/mediawiki/dialogs/EditSetting.xdl | 38 + swext/mediawiki/dialogs/Module1.xba | 24 + swext/mediawiki/dialogs/SendToMediaWiki.xdl | 45 + swext/mediawiki/dialogs/Settings.xdl | 37 + swext/mediawiki/dialogs/dialog.xlb | 24 + swext/mediawiki/dialogs/script.xlb | 22 + swext/mediawiki/help/help.tree | 22 + swext/mediawiki/help/wiki.xhp | 106 ++ swext/mediawiki/help/wikiaccount.xhp | 46 + swext/mediawiki/help/wikiformats.xhp | 59 + swext/mediawiki/help/wikisend.xhp | 48 + swext/mediawiki/help/wikisettings.xhp | 43 + swext/mediawiki/src/META-INF/manifest.xml | 42 + swext/mediawiki/src/THIRDPARTYLICENSEREADME.html | 83 + .../src/com/sun/star/wiki/EditPageParser.java | 176 ++ swext/mediawiki/src/com/sun/star/wiki/Helper.java | 1057 ++++++++++ swext/mediawiki/src/com/sun/star/wiki/MANIFEST.MF | 1 + .../sun/star/wiki/MainThreadDialogExecutor.java | 158 ++ .../mediawiki/src/com/sun/star/wiki/Settings.java | 310 +++ .../src/com/sun/star/wiki/WikiArticle.java | 261 +++ .../src/com/sun/star/wiki/WikiCancelException.java | 24 + .../src/com/sun/star/wiki/WikiDialog.java | 283 +++ .../com/sun/star/wiki/WikiEditSettingDialog.java | 416 ++++ .../src/com/sun/star/wiki/WikiEditorImpl.java | 353 ++++ .../sun/star/wiki/WikiOptionsEventHandlerImpl.java | 279 +++ .../src/com/sun/star/wiki/WikiPropDialog.java | 372 ++++ .../sun/star/wiki/WikiProtocolSocketFactory.java | 333 ++++ swext/mediawiki/src/components.rdb | 19 + swext/mediawiki/src/description-en-US.txt | 1 + swext/mediawiki/src/description.xml | 34 + swext/mediawiki/src/filter/mediawiki.ott | Bin 0 -> 6304 bytes swext/mediawiki/src/filter/odt2mediawiki.xsl | 2012 ++++++++++++++++++++ .../registry/data/org/openoffice/Office/Addons.xcu | 58 + .../org/openoffice/Office/Custom/WikiExtension.xcu | 132 ++ .../data/org/openoffice/Office/OptionsDialog.xcu | 41 + .../registry/data/org/openoffice/Office/Paths.xcu | 27 + .../data/org/openoffice/Office/ProtocolHandler.xcu | 27 + .../data/org/openoffice/TypeDetection/Filter.xcu | 47 + .../data/org/openoffice/TypeDetection/Types.xcu | 35 + .../org/openoffice/Office/Custom/WikiExtension.xcs | 188 ++ 46 files changed, 7434 insertions(+) create mode 100644 swext/Configuration_mediawiki.mk create mode 100644 swext/Extension_wiki-publisher.mk create mode 100644 swext/Jar_mediawiki.mk create mode 100644 swext/Makefile create mode 100644 swext/Module_swext.mk create mode 100644 swext/README.md create mode 100644 swext/mediawiki/dialogs/EditSetting.xdl create mode 100644 swext/mediawiki/dialogs/Module1.xba create mode 100644 swext/mediawiki/dialogs/SendToMediaWiki.xdl create mode 100644 swext/mediawiki/dialogs/Settings.xdl create mode 100644 swext/mediawiki/dialogs/dialog.xlb create mode 100644 swext/mediawiki/dialogs/script.xlb create mode 100644 swext/mediawiki/help/help.tree create mode 100644 swext/mediawiki/help/wiki.xhp create mode 100644 swext/mediawiki/help/wikiaccount.xhp create mode 100644 swext/mediawiki/help/wikiformats.xhp create mode 100644 swext/mediawiki/help/wikisend.xhp create mode 100644 swext/mediawiki/help/wikisettings.xhp create mode 100644 swext/mediawiki/src/META-INF/manifest.xml create mode 100644 swext/mediawiki/src/THIRDPARTYLICENSEREADME.html create mode 100644 swext/mediawiki/src/com/sun/star/wiki/EditPageParser.java create mode 100644 swext/mediawiki/src/com/sun/star/wiki/Helper.java create mode 100644 swext/mediawiki/src/com/sun/star/wiki/MANIFEST.MF create mode 100644 swext/mediawiki/src/com/sun/star/wiki/MainThreadDialogExecutor.java create mode 100644 swext/mediawiki/src/com/sun/star/wiki/Settings.java create mode 100644 swext/mediawiki/src/com/sun/star/wiki/WikiArticle.java create mode 100644 swext/mediawiki/src/com/sun/star/wiki/WikiCancelException.java create mode 100644 swext/mediawiki/src/com/sun/star/wiki/WikiDialog.java create mode 100644 swext/mediawiki/src/com/sun/star/wiki/WikiEditSettingDialog.java create mode 100644 swext/mediawiki/src/com/sun/star/wiki/WikiEditorImpl.java create mode 100644 swext/mediawiki/src/com/sun/star/wiki/WikiOptionsEventHandlerImpl.java create mode 100644 swext/mediawiki/src/com/sun/star/wiki/WikiPropDialog.java create mode 100644 swext/mediawiki/src/com/sun/star/wiki/WikiProtocolSocketFactory.java create mode 100644 swext/mediawiki/src/components.rdb create mode 100644 swext/mediawiki/src/description-en-US.txt create mode 100644 swext/mediawiki/src/description.xml create mode 100644 swext/mediawiki/src/filter/mediawiki.ott create mode 100644 swext/mediawiki/src/filter/odt2mediawiki.xsl create mode 100644 swext/mediawiki/src/registry/data/org/openoffice/Office/Addons.xcu create mode 100644 swext/mediawiki/src/registry/data/org/openoffice/Office/Custom/WikiExtension.xcu create mode 100644 swext/mediawiki/src/registry/data/org/openoffice/Office/OptionsDialog.xcu create mode 100644 swext/mediawiki/src/registry/data/org/openoffice/Office/Paths.xcu create mode 100644 swext/mediawiki/src/registry/data/org/openoffice/Office/ProtocolHandler.xcu create mode 100644 swext/mediawiki/src/registry/data/org/openoffice/TypeDetection/Filter.xcu create mode 100644 swext/mediawiki/src/registry/data/org/openoffice/TypeDetection/Types.xcu create mode 100644 swext/mediawiki/src/registry/schema/org/openoffice/Office/Custom/WikiExtension.xcs (limited to 'swext') diff --git a/swext/Configuration_mediawiki.mk b/swext/Configuration_mediawiki.mk new file mode 100644 index 000000000..99c83e681 --- /dev/null +++ b/swext/Configuration_mediawiki.mk @@ -0,0 +1,28 @@ +# +# +# 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/. +# +# + +$(eval $(call gb_Configuration_Configuration,mediawiki,nodeliver)) + +$(eval $(call gb_Configuration_add_datas,mediawiki,swext/mediawiki/src/registry/data,\ + org/openoffice/Office/ProtocolHandler.xcu \ + org/openoffice/Office/Paths.xcu \ + org/openoffice/TypeDetection/Filter.xcu \ + org/openoffice/TypeDetection/Types.xcu \ +)) + +$(eval $(call gb_Configuration_add_localized_datas,mediawiki,swext/mediawiki/src/registry/data,\ + org/openoffice/Office/Addons.xcu \ + org/openoffice/Office/OptionsDialog.xcu \ + org/openoffice/Office/Custom/WikiExtension.xcu \ +)) + +$(eval $(call gb_Configuration_add_schemas,mediawiki,swext/mediawiki/src/registry/schema,\ + org/openoffice/Office/Custom/WikiExtension.xcs \ +)) diff --git a/swext/Extension_wiki-publisher.mk b/swext/Extension_wiki-publisher.mk new file mode 100644 index 000000000..ec31c9691 --- /dev/null +++ b/swext/Extension_wiki-publisher.mk @@ -0,0 +1,53 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# +# 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/. +# +# + +$(eval $(call gb_Extension_Extension,wiki-publisher,swext/mediawiki/src)) + +$(eval $(call gb_Extension_use_unpacked,wiki-publisher,xsltml)) + +$(eval $(call gb_Extension_use_default_description,wiki-publisher,swext/mediawiki/src/description-en-US.txt)) +$(eval $(call gb_Extension_use_default_license,wiki-publisher)) + +$(eval $(call gb_Extension_add_file,wiki-publisher,Addons.xcu,$(call gb_XcuFile_for_extension,swext/mediawiki/src/registry/data/org/openoffice/Office/Addons.xcu))) +$(eval $(call gb_Extension_add_file,wiki-publisher,Filter.xcu,$(SRCDIR)/swext/mediawiki/src/registry/data/org/openoffice/TypeDetection/Filter.xcu)) +$(eval $(call gb_Extension_add_file,wiki-publisher,OptionsDialog.xcu,$(call gb_XcuFile_for_extension,swext/mediawiki/src/registry/data/org/openoffice/Office/OptionsDialog.xcu))) +$(eval $(call gb_Extension_add_file,wiki-publisher,Paths.xcu,$(SRCDIR)/swext/mediawiki/src/registry/data/org/openoffice/Office/Paths.xcu)) +$(eval $(call gb_Extension_add_file,wiki-publisher,ProtocolHandler.xcu,$(SRCDIR)/swext/mediawiki/src/registry/data/org/openoffice/Office/ProtocolHandler.xcu)) +$(eval $(call gb_Extension_add_file,wiki-publisher,Types.xcu,$(SRCDIR)/swext/mediawiki/src/registry/data/org/openoffice/TypeDetection/Types.xcu)) +$(eval $(call gb_Extension_add_file,wiki-publisher,WikiExtension.xcs,$(SRCDIR)/swext/mediawiki/src/registry/schema/org/openoffice/Office/Custom/WikiExtension.xcs)) +$(eval $(call gb_Extension_add_file,wiki-publisher,WikiExtension.xcu,$(call gb_XcuFile_for_extension,swext/mediawiki/src/registry/data/org/openoffice/Office/Custom/WikiExtension.xcu))) +$(eval $(call gb_Extension_add_file,wiki-publisher,mediawiki.jar,$(call gb_Jar_get_target,mediawiki))) +$(eval $(call gb_Extension_add_file,wiki-publisher,components.rdb,$(SRCDIR)/swext/mediawiki/src/components.rdb)) +$(eval $(call gb_Extension_add_file,wiki-publisher,WikiEditor/EditSetting.xdl,$(SRCDIR)/swext/mediawiki/dialogs/EditSetting.xdl)) +$(eval $(call gb_Extension_add_file,wiki-publisher,WikiEditor/Settings.xdl,$(SRCDIR)/swext/mediawiki/dialogs/Settings.xdl)) +$(eval $(call gb_Extension_add_file,wiki-publisher,WikiEditor/Module1.xba,$(SRCDIR)/swext/mediawiki/dialogs/Module1.xba)) +$(eval $(call gb_Extension_add_file,wiki-publisher,WikiEditor/script.xlb,$(SRCDIR)/swext/mediawiki/dialogs/script.xlb)) +$(eval $(call gb_Extension_add_file,wiki-publisher,WikiEditor/dialog.xlb,$(SRCDIR)/swext/mediawiki/dialogs/dialog.xlb)) +$(eval $(call gb_Extension_add_file,wiki-publisher,WikiEditor/SendToMediaWiki.xdl,$(SRCDIR)/swext/mediawiki/dialogs/SendToMediaWiki.xdl)) +$(eval $(call gb_Extension_add_file,wiki-publisher,filter/math/cmarkup.xsl,$(call gb_UnpackedTarball_get_dir,xsltml)/cmarkup.xsl)) +$(eval $(call gb_Extension_add_file,wiki-publisher,filter/math/entities.xsl,$(call gb_UnpackedTarball_get_dir,xsltml)/entities.xsl)) +$(eval $(call gb_Extension_add_file,wiki-publisher,filter/math/glayout.xsl,$(call gb_UnpackedTarball_get_dir,xsltml)/glayout.xsl)) +$(eval $(call gb_Extension_add_file,wiki-publisher,filter/math/mmltex.xsl,$(call gb_UnpackedTarball_get_dir,xsltml)/mmltex.xsl)) +$(eval $(call gb_Extension_add_file,wiki-publisher,filter/math/scripts.xsl,$(call gb_UnpackedTarball_get_dir,xsltml)/scripts.xsl)) +$(eval $(call gb_Extension_add_file,wiki-publisher,filter/math/tables.xsl,$(call gb_UnpackedTarball_get_dir,xsltml)/tables.xsl)) +$(eval $(call gb_Extension_add_file,wiki-publisher,filter/math/tokens.xsl,$(call gb_UnpackedTarball_get_dir,xsltml)/tokens.xsl)) +$(eval $(call gb_Extension_add_file,wiki-publisher,filter/odt2mediawiki.xsl,$(SRCDIR)/swext/mediawiki/src/filter/odt2mediawiki.xsl)) +$(eval $(call gb_Extension_add_file,wiki-publisher,license/THIRDPARTYLICENSEREADME.html,$(SRCDIR)/swext/mediawiki/src/THIRDPARTYLICENSEREADME.html)) +$(eval $(call gb_Extension_add_file,wiki-publisher,templates/MediaWiki/mediawiki.ott,$(SRCDIR)/swext/mediawiki/src/filter/mediawiki.ott)) +$(eval $(call gb_Extension_add_helpfile,wiki-publisher,$(SRCDIR)/swext/mediawiki/help,com.sun.wiki-publisher/wikisend.xhp,wikisend.xhp)) +$(eval $(call gb_Extension_add_helpfile,wiki-publisher,$(SRCDIR)/swext/mediawiki/help,com.sun.wiki-publisher/wikiformats.xhp,wikiformats.xhp)) +$(eval $(call gb_Extension_add_helpfile,wiki-publisher,$(SRCDIR)/swext/mediawiki/help,com.sun.wiki-publisher/wikiaccount.xhp,wikiaccount.xhp)) +$(eval $(call gb_Extension_add_helpfile,wiki-publisher,$(SRCDIR)/swext/mediawiki/help,com.sun.wiki-publisher/wiki.xhp,wiki.xhp)) +$(eval $(call gb_Extension_add_helpfile,wiki-publisher,$(SRCDIR)/swext/mediawiki/help,com.sun.wiki-publisher/wikisettings.xhp,wikisettings.xhp)) + +$(eval $(call gb_Extension_add_helptreefile,wiki-publisher,$(SRCDIR)/swext/mediawiki/help,help.tree,help.tree,com.sun.wiki-publisher)) + +# vim: set noet sw=4 ts=4: diff --git a/swext/Jar_mediawiki.mk b/swext/Jar_mediawiki.mk new file mode 100644 index 000000000..25a2ce91b --- /dev/null +++ b/swext/Jar_mediawiki.mk @@ -0,0 +1,34 @@ +# +# +# 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/. +# +# + +$(eval $(call gb_Jar_Jar,mediawiki)) + +$(eval $(call gb_Jar_set_packageroot,mediawiki,com)) + +$(eval $(call gb_Jar_set_manifest,mediawiki,$(SRCDIR)/swext/mediawiki/src/com/sun/star/wiki/MANIFEST.MF)) + +$(eval $(call gb_Jar_use_jars,mediawiki,\ + libreoffice \ +)) + +$(eval $(call gb_Jar_add_sourcefiles,mediawiki,\ + swext/mediawiki/src/com/sun/star/wiki/EditPageParser \ + swext/mediawiki/src/com/sun/star/wiki/Helper \ + swext/mediawiki/src/com/sun/star/wiki/MainThreadDialogExecutor \ + swext/mediawiki/src/com/sun/star/wiki/Settings \ + swext/mediawiki/src/com/sun/star/wiki/WikiArticle \ + swext/mediawiki/src/com/sun/star/wiki/WikiCancelException \ + swext/mediawiki/src/com/sun/star/wiki/WikiDialog \ + swext/mediawiki/src/com/sun/star/wiki/WikiEditorImpl \ + swext/mediawiki/src/com/sun/star/wiki/WikiEditSettingDialog \ + swext/mediawiki/src/com/sun/star/wiki/WikiOptionsEventHandlerImpl \ + swext/mediawiki/src/com/sun/star/wiki/WikiPropDialog \ + swext/mediawiki/src/com/sun/star/wiki/WikiProtocolSocketFactory \ +)) diff --git a/swext/Makefile b/swext/Makefile new file mode 100644 index 000000000..0997e6284 --- /dev/null +++ b/swext/Makefile @@ -0,0 +1,14 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# 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/. +# + +module_directory:=$(dir $(realpath $(firstword $(MAKEFILE_LIST)))) + +include $(module_directory)/../solenv/gbuild/partial_build.mk + +# vim: set noet sw=4 ts=4: diff --git a/swext/Module_swext.mk b/swext/Module_swext.mk new file mode 100644 index 000000000..0a5462c18 --- /dev/null +++ b/swext/Module_swext.mk @@ -0,0 +1,19 @@ +# +# +# 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/. +# +# + +$(eval $(call gb_Module_Module,swext)) + +ifeq ($(ENABLE_MEDIAWIKI),TRUE) +$(eval $(call gb_Module_add_targets,swext,\ + Jar_mediawiki \ + Configuration_mediawiki \ + Extension_wiki-publisher \ +)) +endif diff --git a/swext/README.md b/swext/README.md new file mode 100644 index 000000000..6ddc53d11 --- /dev/null +++ b/swext/README.md @@ -0,0 +1,3 @@ +# Writer Extensions + +Currently only contains MediaWiki extension. diff --git a/swext/mediawiki/dialogs/EditSetting.xdl b/swext/mediawiki/dialogs/EditSetting.xdl new file mode 100644 index 000000000..95d78aa92 --- /dev/null +++ b/swext/mediawiki/dialogs/EditSetting.xdl @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/swext/mediawiki/dialogs/Module1.xba b/swext/mediawiki/dialogs/Module1.xba new file mode 100644 index 000000000..6808d3fcd --- /dev/null +++ b/swext/mediawiki/dialogs/Module1.xba @@ -0,0 +1,24 @@ + + + +REM ***** BASIC ***** + +Sub Main + +End Sub diff --git a/swext/mediawiki/dialogs/SendToMediaWiki.xdl b/swext/mediawiki/dialogs/SendToMediaWiki.xdl new file mode 100644 index 000000000..91d135005 --- /dev/null +++ b/swext/mediawiki/dialogs/SendToMediaWiki.xdl @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/swext/mediawiki/dialogs/Settings.xdl b/swext/mediawiki/dialogs/Settings.xdl new file mode 100644 index 000000000..f4495bb25 --- /dev/null +++ b/swext/mediawiki/dialogs/Settings.xdl @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/swext/mediawiki/dialogs/dialog.xlb b/swext/mediawiki/dialogs/dialog.xlb new file mode 100644 index 000000000..43c4d7501 --- /dev/null +++ b/swext/mediawiki/dialogs/dialog.xlb @@ -0,0 +1,24 @@ + + + + + + + + diff --git a/swext/mediawiki/dialogs/script.xlb b/swext/mediawiki/dialogs/script.xlb new file mode 100644 index 000000000..986225384 --- /dev/null +++ b/swext/mediawiki/dialogs/script.xlb @@ -0,0 +1,22 @@ + + + + + + diff --git a/swext/mediawiki/help/help.tree b/swext/mediawiki/help/help.tree new file mode 100644 index 000000000..ac223de66 --- /dev/null +++ b/swext/mediawiki/help/help.tree @@ -0,0 +1,22 @@ + + + + + + + + MediaWiki + Wiki Publisher + MediaWiki Formats + Send to MediaWiki + MediaWiki Options + + + diff --git a/swext/mediawiki/help/wiki.xhp b/swext/mediawiki/help/wiki.xhp new file mode 100644 index 000000000..23464c0be --- /dev/null +++ b/swext/mediawiki/help/wiki.xhp @@ -0,0 +1,106 @@ + + + + + +Wiki Publisher +/com.sun.wiki-publisher/wiki.xhp + + + + + + + +Wiki;Wiki Publisher +Wiki Publisher +extensions;MediaWiki + +Wiki Publisher +By using the Wiki Publisher you can upload your current Writer text document to a MediaWiki server. After uploading, all wiki users can read your document on the wiki. + +Choose File - Send - To MediaWiki to upload the current Writer document to a MediaWiki server. +System Requirements + + +Java Runtime Environment + + +A wiki account on a supported MediaWiki server + + +Installing Wiki Publisher +Before you use the Wiki Publisher, ensure that %PRODUCTNAME uses a Java Runtime Environment (JRE). To check the status of the JRE, choose Tools - Options - %PRODUCTNAME - Advanced. Ensure that “Use a Java runtime environment” is checked and that a Java runtime folder is selected in the big listbox. If no JRE was activated, then activate a JRE of version 1.4 or later and restart %PRODUCTNAME. +To Connect to a Wiki +Note: You can store your user name and password for all respective dialogs inside %PRODUCTNAME. The password will be stored in a secure way, where access is maintained by a master password. To enable the master password, choose Tools - Options - %PRODUCTNAME - Security. +Note: If you connect to the web using a proxy server, enter the proxy information to Tools - Options - Internet - Proxy, and restart the software. + + +Open a Writer document, and choose Tools - Options - Internet - MediaWiki. + + +In the Options dialog, click Add. + + +In the MediaWiki dialog, enter the account information for the wiki. + + + + + In the URL text box, enter the address of a wiki that you want to connect to. +You can copy the URL from a web browser and paste it into the textbox. + + + In the Username box, enter your user ID for your wiki account. +If the wiki allows anonymous write access, you can leave the Username and Password boxes empty. + + +In the Password box, enter the password for your wiki account, then click OK. + + +Optionally enable “Save password” to save the password between sessions. A master password is used to maintain access to all saved passwords. Choose Tools - Options - %PRODUCTNAME - Security to enable the master password. “Save password” is unavailable when the master password is not enabled. +To Create a New Wiki Page + + +Open a Writer document. + + +Write the content of the wiki page. You can use formatting such as text formats, headings, footnotes, and more. See the list of supported formats. + + +Choose File - Send - To MediaWiki. + + +In the Send to MediaWiki dialog, specify the settings for your entry. + + +MediaWiki server: Select the wiki. +Title: Type the title of your page. Type the title of an existing page to overwrite the page with your current text document. Type a new title to create a new page on the wiki. + +Summary: Enter an optional short summary of your page. + +This is a minor edit: Check this box to mark the uploaded page as a minor edit of the already existing page with the same title. +Show in web browser: Check this box to open your system web browser and show the uploaded wiki page. + + +Click Send. + + + + diff --git a/swext/mediawiki/help/wikiaccount.xhp b/swext/mediawiki/help/wikiaccount.xhp new file mode 100644 index 000000000..5cc49c674 --- /dev/null +++ b/swext/mediawiki/help/wikiaccount.xhp @@ -0,0 +1,46 @@ + + + + + + + MediaWiki + /com.sun.wiki-publisher/wikiaccount.xhp + + + + + + + +MediaWiki + Use the MediaWiki dialog to add or edit your MediaWiki account settings. + + Enter the URL of a MediaWiki server, starting with "https://". + + Enter your user name on the MediaWiki server. Leave empty for anonymous access. + + Enter your password on the MediaWiki server. Leave empty for anonymous access. + + Enable to store your password between sessions. The master password must be enabled; see Tools - Options - %PRODUCTNAME - Security. +Enter the Internet address of a wiki server in a format like “https://wiki.documentfoundation.org” or copy the URL from a web browser. + If the wiki allows anonymous access, you can leave the account text boxes empty. Else enter your user name and password. + If you have enabled the master password feature on the Security tab page of the Tools - Options - %PRODUCTNAME dialog, then the software can store your password and automatically insert the data where necessary. Enable the Save password checkbox to store your password. + + diff --git a/swext/mediawiki/help/wikiformats.xhp b/swext/mediawiki/help/wikiformats.xhp new file mode 100644 index 000000000..6e463778f --- /dev/null +++ b/swext/mediawiki/help/wikiformats.xhp @@ -0,0 +1,59 @@ + + + + + +MediaWiki Formats +/com.sun.wiki-publisher/wikiformats.xhp + + + + + + + +MediaWiki Formats +The following list gives an overview of the text formats that the Wiki Publisher can upload to the wiki server. +The OpenDocument format used by Writer and the MediaWiki format are quite different. Only a subset of all features can be transformed from one format to the other. +Headings +Apply a heading paragraph style to the headings in your Writer document. The wiki will show the heading styles of the same outline level, formatted as defined by the wiki engine. +Hyperlinks +Native OpenDocument hyperlinks are transformed into “external” wiki links. Therefore, the built-in linking facility of OpenDocument should only be used to create links that point to other sites outside the wiki web. For creating wiki links that point to other subjects of the same wiki domain, use wiki links. +Lists +Lists can be exported reliably when the whole list uses a consistent list style. Use the Numbering or Bullets icon to generate a list in Writer. If you need a list without numbering or bullets, use Format - Bullets and Numbering to define and apply the respective list style. +Paragraphs +Alignment +Explicit text alignment should not be used in wiki articles. Nevertheless, text alignment is supported for left, centered, and right alignment of text. +Pre-formatted text +A paragraph style with a fixed-width font is transformed as pre-formatted text. Pre-formatted text is shown on the wiki with a border around the text. +Character styles +Character styles modify the appearance of parts of a paragraph. The transformation supports bold, italics, bold/italics, subscript and superscript. All fixed-width fonts are transformed into the wiki typewriter style. +Images +Images cannot be exported by a transformation producing a single file of wiki text. However, if the image is already uploaded to the target wiki domain (e. g., Wikimedia Commons), then the transformation produces a valid image tag that includes the image. Image captions are also supported. +Tables +Simple tables are supported well. Table headers are translated into corresponding wiki-style table headers. However, custom formatting of table borders, column sizes and background colors is ignored. +Joined Cells +OpenDocument and especially LibreOffice represent tables that have joined cells that span rows as tables with nested tables. In contrast, the wiki model of table is to declare column and row spans for such joined cells. +If only columns of the same row are joined, the result of the transformation resembles the source document very well. +Borders +Irrespective of custom table styles for border and background, a table is always exported as “prettytable,” which renders in the wiki engine with simple borders and bold header. +Character set and special characters +The character set of the transformation result is fixed to UTF-8. Depending on your system, this might not be the default character set. This might cause “special characters” to look broken when viewed with default settings. However, you can switch your editor to UTF-8 encoding to fix this. If your editor does not support switching the encoding, you can display the result of the transformation in the Firefox browser and switch the encoding to UTF-8 there. Now, you can copy and paste the transformation result to your program of choice. + + diff --git a/swext/mediawiki/help/wikisend.xhp b/swext/mediawiki/help/wikisend.xhp new file mode 100644 index 000000000..f61f0367e --- /dev/null +++ b/swext/mediawiki/help/wikisend.xhp @@ -0,0 +1,48 @@ + + + + + + + Send to MediaWiki + /com.sun.wiki-publisher/wikisend.xhp + + + + + + + +Send to MediaWiki + In the Send to MediaWiki dialog, specify the settings for your current wiki upload. + + Select the MediaWiki server where you want to publish your document. Click Add to add a new server to the list. + + Enter the title of your wiki entry. This is the top heading of your wiki entry. For a new entry, the title must be unique on this wiki. If you enter an existing title, your upload will overwrite the existing wiki entry. + + Enter an optional short summary or comment. See https://meta.wikimedia.org/wiki/Help:Edit_summary. + + This is a minor edit: Check this box to mark the uploaded page as a minor edit of the already existing page with the same title. + + Show in web browser: Check this box to open your system web browser and show the uploaded wiki page. + + + + + diff --git a/swext/mediawiki/help/wikisettings.xhp b/swext/mediawiki/help/wikisettings.xhp new file mode 100644 index 000000000..7a5316270 --- /dev/null +++ b/swext/mediawiki/help/wikisettings.xhp @@ -0,0 +1,43 @@ + + + + + +MediaWiki Options +/com.sun.wiki-publisher/wikisettings.xhp + + + + + + + +MediaWiki Options +You can add, edit and remove MediaWiki servers. Open the options dialog by going to Tools - Options - Internet - MediaWiki.Listbox + +Click Add to add a new wiki server.
Select an entry and click Edit to edit the account settings.
Select an entry and click Remove to remove the entry from the list.
Add button + +Opens the MediaWiki dialog to add a new entry to the list.Edit button + +Opens the MediaWiki dialog to edit the selected entry.Remove button + +Removes the selected entry from the list. +When you click Add or Edit, the MediaWiki dialog opens. + +
diff --git a/swext/mediawiki/src/META-INF/manifest.xml b/swext/mediawiki/src/META-INF/manifest.xml new file mode 100644 index 000000000..ab4d1054c --- /dev/null +++ b/swext/mediawiki/src/META-INF/manifest.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + diff --git a/swext/mediawiki/src/THIRDPARTYLICENSEREADME.html b/swext/mediawiki/src/THIRDPARTYLICENSEREADME.html new file mode 100644 index 000000000..a9efb72a6 --- /dev/null +++ b/swext/mediawiki/src/THIRDPARTYLICENSEREADME.html @@ -0,0 +1,83 @@ + + + + + THIRDPARTYLICENSEREADME + + +DO NOT TRANSLATE OR LOCALIZE THIS DOCUMENT
+
+ +
+
The following software may be +included in this product: Tomcat 4.0 or higher; Use of any of this +software is governed by the terms of the license below:
+

The Apache Software +Foundation
+

+

Tomcat
+

+
+The Apache Software License, Version 1.1 +
+
+Copyright (c) 2001 The Apache Software Foundation. All rights +reserved. +
+Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +
+1. Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution.
+3. The end-user documentation included with the redistribution, if any, +must include the following acknowledgment: "This product includes +software developed by the Apache Software Foundation +(http://www.apache.org/)." Alternately, this acknowledgment may appear +in the software itself, if and wherever such third-party +acknowledgments normally appear.
+4. The names "XML-RPC" and "Apache Software Foundation" must not be +used to endorse or promote products derived from this software without +prior written permission. For written permission, please contact +apache@apache.org.
+5. Products derived from this software may not be called "Apache", nor +may "Apache" appear in their name, without prior written permission of +the Apache Software Foundation.
+THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR +ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +SUCH DAMAGE. +
+==================================================================== +
+This software consists of voluntary contributions made by many +individuals on behalf of the Apache Software Foundation. For more +information on the Apache Software Foundation, please see +. +
+
+
+ + diff --git a/swext/mediawiki/src/com/sun/star/wiki/EditPageParser.java b/swext/mediawiki/src/com/sun/star/wiki/EditPageParser.java new file mode 100644 index 000000000..114709fae --- /dev/null +++ b/swext/mediawiki/src/com/sun/star/wiki/EditPageParser.java @@ -0,0 +1,176 @@ +/* + * 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 . + */ + +package com.sun.star.wiki; + +import javax.swing.text.html.*; +import javax.swing.text.MutableAttributeSet; + +public class EditPageParser extends HTMLEditorKit.ParserCallback +{ + + protected String m_sEditTime = ""; + protected String m_sEditToken = ""; + protected String m_sLoginToken = ""; + protected String m_sMainURL = ""; + + private boolean m_bHTMLStartFound = false; + private boolean m_bInHead = false; + + protected int m_nWikiArticleStart = -1; + protected int m_nWikiArticleEnd = -1; + protected int m_nHTMLArticleStart = -1; + protected int m_nHTMLArticleEnd = -1; + protected int m_nNoArticleInd = -1; + protected int m_nErrorInd = -1; + + @Override + public void handleComment( char[] data,int pos ) + { + // insert code to handle comments + } + + @Override + public void handleEndTag( HTML.Tag t,int pos ) + { + if ( t == HTML.Tag.TEXTAREA ) + { + m_nWikiArticleEnd = pos; + } + else if ( t == HTML.Tag.DIV ) + { + if ( m_bHTMLStartFound ) + { + m_nHTMLArticleStart = pos+6; + m_bHTMLStartFound = false; + } + } + else if ( t == HTML.Tag.HEAD ) + { + m_bInHead = false; + } + } + + @Override + public void handleError( String errorMsg,int pos ) + { + } + + @Override + public void handleSimpleTag( HTML.Tag t, MutableAttributeSet a,int pos ) + { + // insert code to handle simple tags + + if ( t == HTML.Tag.INPUT ) + { + String sName = ( String ) a.getAttribute( HTML.Attribute.NAME ); + if ( sName != null ) + { + if ( sName.equalsIgnoreCase( "wpEdittime" ) ) + { + this.m_sEditTime = ( String ) a.getAttribute( HTML.Attribute.VALUE ); + } + else if ( sName.equalsIgnoreCase( "wpEditToken" ) ) + { + this.m_sEditToken = ( String ) a.getAttribute( HTML.Attribute.VALUE ); + } + else if ( sName.equalsIgnoreCase( "wpLoginToken" ) ) + { + this.m_sLoginToken = ( String ) a.getAttribute( HTML.Attribute.VALUE ); + } + } + + } + else if ( t == HTML.Tag.LINK ) + { + if ( m_bInHead ) + { + String sName = ( String ) a.getAttribute( HTML.Attribute.HREF ); + if ( sName != null ) + { + // get the main URL from the first header-link with load.php (which is used for stylesheet) + int nPhpFileStart = sName.indexOf( "load.php" ); + if (nPhpFileStart < 0) + // if not found, try header-link with opensearch_desc.php + nPhpFileStart = sName.indexOf( "opensearch_desc.php" ); + + if ( nPhpFileStart >= 0 + && m_sMainURL.length() == 0 ) + { + m_sMainURL = sName.substring( 0, nPhpFileStart ); + } + } + } + } + + } + + @Override + public void handleStartTag( HTML.Tag t, MutableAttributeSet a,int pos ) + { + // insert code to handle starting tags + String sClass; + + if ( t == HTML.Tag.HEAD ) + { + m_bInHead = true; + } + else if ( t == HTML.Tag.TEXTAREA ) + { + String sName = ( String ) a.getAttribute( HTML.Attribute.NAME ); + if ( sName != null && sName.equalsIgnoreCase( "wpTextbox1" ) ) + { + m_nWikiArticleStart = pos; + } + } + else if ( t == HTML.Tag.DIV ) + { + String sId = ( String ) a.getAttribute( HTML.Attribute.ID ); + sClass = ( String ) a.getAttribute( HTML.Attribute.CLASS ); + if ( sId != null && sId.equalsIgnoreCase( "contentSub" ) ) + { + m_bHTMLStartFound = true; + } + if ( sClass != null ) + { + if ( sClass.equalsIgnoreCase( "printfooter" ) ) + { + m_nHTMLArticleEnd = pos; + } + else if ( sClass.equalsIgnoreCase( "noarticletext" ) ) + { + m_nNoArticleInd = pos; + } + else if ( sClass.equalsIgnoreCase( "errorbox" ) ) + { + m_nErrorInd = pos; + } + } + } + else if ( t == HTML.Tag.P ) + { + sClass = ( String ) a.getAttribute( HTML.Attribute.CLASS ); + if ( sClass != null && sClass.equalsIgnoreCase( "error" ) ) + { + m_nErrorInd = pos; + } + } + } + + +} diff --git a/swext/mediawiki/src/com/sun/star/wiki/Helper.java b/swext/mediawiki/src/com/sun/star/wiki/Helper.java new file mode 100644 index 000000000..4a5ec943a --- /dev/null +++ b/swext/mediawiki/src/com/sun/star/wiki/Helper.java @@ -0,0 +1,1057 @@ +/* + * 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 . + */ + +package com.sun.star.wiki; + +import com.sun.star.awt.MessageBoxButtons; +import com.sun.star.awt.MessageBoxType; +import com.sun.star.awt.XControl; +import com.sun.star.awt.XDialog; +import com.sun.star.awt.XMessageBox; +import com.sun.star.awt.XMessageBoxFactory; +import com.sun.star.awt.XWindowPeer; +import com.sun.star.beans.NamedValue; +import com.sun.star.beans.PropertyValue; +import com.sun.star.beans.XPropertySet; +import com.sun.star.container.XContainerQuery; +import com.sun.star.container.XEnumeration; +import com.sun.star.container.XNameAccess; +import com.sun.star.container.XNameContainer; +import com.sun.star.document.XDocumentPropertiesSupplier; +import com.sun.star.document.XDocumentProperties; +import com.sun.star.frame.XModel; +import com.sun.star.frame.XModuleManager; +import com.sun.star.io.XInputStream; +import com.sun.star.io.XOutputStream; +import com.sun.star.lang.XMultiComponentFactory; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.lang.XComponent; +import com.sun.star.system.SystemShellExecuteFlags; +import com.sun.star.system.XSystemShellExecute; +import com.sun.star.task.UrlRecord; +import com.sun.star.task.XInteractionHandler; +import com.sun.star.task.XMasterPasswordHandling; +import com.sun.star.task.XPasswordContainer; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.util.XChangesBatch; +import java.net.*; +import java.io.*; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLException; +import javax.swing.text.html.HTMLEditorKit; + + +public class Helper +{ + public static final int GENERALSEND_ERROR = 0; + public static final int NOWIKIFILTER_ERROR = 1; + public static final int NOURLCONNECTION_ERROR = 2; + public static final int WRONGLOGIN_ERROR = 3; + public static final int INVALIDURL_ERROR = 4; + public static final int NOURL_ERROR = 5; + + public static final int DLG_SENDTITLE = 6; + public static final int DLG_WIKIARTICLE = 7; + + public static final int DLG_OK = 9; + + // 11 is reserved + public static final int DLG_ADDBUTTON = 12; + public static final int DLG_EDITBUTTON = 13; + public static final int DLG_SENDBUTTON = 14; + public static final int DLG_REMOVEBUTTON = 15; + + public static final int DLG_EDITSETTING_URLLABEL = 16; + public static final int DLG_EDITSETTING_USERNAMELABEL = 17; + public static final int DLG_EDITSETTING_PASSWORDLABEL = 18; + + public static final int DLG_SENDTOMEDIAWIKI_LABEL1 = 20; + public static final int DLG_SENDTOMEDIAWIKI_LABEL2 = 21; + public static final int DLG_SENDTOMEDIAWIKI_LABEL3 = 22; + public static final int DLG_SENDTOMEDIAWIKI_MINORCHECK = 23; + public static final int DLG_SENDTOMEDIAWIKI_BROWSERCHECK = 24; + public static final int UNKNOWNCERT_ERROR = 25; + public static final int DLG_MEDIAWIKI_TITLE = 26; + public static final int DLG_EDITSETTING_ACCOUNTLINE = 27; + public static final int DLG_EDITSETTING_WIKILINE = 28; + public static final int DLG_EDITSETTING_SAVEBOX = 29; + public static final int CANCELSENDING_ERROR = 30; + public static final int DLG_MEDIAWIKIEXTENSION_STRING = 31; + public static final int DLG_WIKIPAGEEXISTS_LABEL1 = 32; + + private static final int STRINGS_NUM = 33; + + private static final String[] m_pEntryNames = { "GeneralSendError", + "NoWikiFilter", + "NoConnectionToURL", + "WrongLogin", + "InvalidURL", + "NoURL", + "Dlg_SendTitle", + "Dlg_WikiArticle", + "Dlg_No", + "Dlg_OK", + "Dlg_Yes", + null, // reserved + "Dlg_AddButton", + "Dlg_EditButton", + "Dlg_SendButton", + "Dlg_RemoveButton", + "Dlg_EditSetting_UrlLabel", + "Dlg_EditSetting_UsernameLabel", + "Dlg_EditSetting_PasswordLabel", + "Dlg_NewWikiPage_Label1", + "Dlg_SendToMediaWiki_Label1", + "Dlg_SendToMediaWiki_Label2", + "Dlg_SendToMediaWiki_Label3", + "Dlg_SendToMediaWiki_MinorCheck", + "Dlg_SendToMediaWiki_BrowserCheck", + "UnknownCert", + "Dlg_MediaWiki_Title", + "Dlg_EditSetting_AccountLine", + "Dlg_EditSetting_WikiLine", + "Dlg_EditSetting_SaveBox", + "CancelSending", + "Dlg_MediaWiki_Extension_String", + "Dlg_WikiPageExists_Label1" }; + + private static String[] m_pConfigStrings; + + private static boolean m_bAllowConnection = true; + + private static Boolean m_bShowInBrowser = null; + + private static XPasswordContainer m_xPasswordContainer; + private static XInteractionHandler m_xInteractionHandler; + + synchronized protected static String GetLocalizedString( XComponentContext xContext, int nID ) + throws com.sun.star.uno.Exception + { + if ( nID >= STRINGS_NUM ) + throw new com.sun.star.uno.RuntimeException(); + + if ( m_pConfigStrings == null ) + { + XNameAccess xNameAccess = GetConfigNameAccess( xContext, "org.openoffice.Office.Custom.WikiExtension/Strings" ); + + String[] pStrings = new String[STRINGS_NUM]; + for ( int nInd = 0; nInd < STRINGS_NUM; nInd++ ) + if ( m_pEntryNames[nInd] != null ) + pStrings[nInd] = AnyConverter.toString( xNameAccess.getByName( m_pEntryNames[nInd] ) ); + else + pStrings[nInd] = ""; + + m_pConfigStrings = pStrings; + } + + return m_pConfigStrings[nID]; + } + + synchronized protected static void AllowConnection( boolean bAllow ) + { + m_bAllowConnection = bAllow; + // TODO: how to shut down any pending connections? + // hope it doesn't matter? + } + + synchronized protected static boolean IsConnectionAllowed() + { + return m_bAllowConnection; + } + + synchronized protected static boolean GetShowInBrowserByDefault( XComponentContext xContext ) + { + if ( m_bShowInBrowser == null ) + { + try + { + XNameAccess xAccess = Helper.GetConfigNameAccess( xContext, "org.openoffice.Office.Custom.WikiExtension/Settings" ); + m_bShowInBrowser = Boolean.valueOf( AnyConverter.toBoolean( xAccess.getByName( "PreselectShowBrowser" ) ) ); + } + catch( com.sun.star.uno.Exception e ) + { + e.printStackTrace(); + } + } + + return m_bShowInBrowser != null ? m_bShowInBrowser.booleanValue() : false; + } + + synchronized protected static void SetShowInBrowserByDefault( XComponentContext xContext, boolean bValue ) + { + try + { + m_bShowInBrowser = Boolean.valueOf( bValue ); + + XPropertySet xProps = Helper.GetConfigProps( xContext, "org.openoffice.Office.Custom.WikiExtension/Settings" ); + xProps.setPropertyValue( "PreselectShowBrowser", Boolean.valueOf( bValue ) ); + XChangesBatch xBatch = UnoRuntime.queryInterface( XChangesBatch.class, xProps ); + if ( xBatch != null ) + xBatch.commitChanges(); + } + catch( Exception e ) + { + e.printStackTrace(); + } + } + + synchronized protected static XPasswordContainer GetPasswordContainer( XComponentContext xContext ) + throws com.sun.star.uno.Exception + { + if ( m_xPasswordContainer == null && xContext != null ) + { + XMultiComponentFactory xFactory = xContext.getServiceManager(); + if ( xFactory != null ) + m_xPasswordContainer = UnoRuntime.queryInterface( + XPasswordContainer.class, + xFactory.createInstanceWithContext( "com.sun.star.task.PasswordContainer", xContext ) ); + } + + if ( m_xPasswordContainer == null ) + throw new com.sun.star.uno.RuntimeException(); + + return m_xPasswordContainer; + } + + synchronized protected static XInteractionHandler GetInteractionHandler( XComponentContext xContext ) + throws com.sun.star.uno.Exception + { + if ( m_xInteractionHandler == null && xContext != null ) + { + XMultiComponentFactory xFactory = xContext.getServiceManager(); + if ( xFactory != null ) + m_xInteractionHandler = UnoRuntime.queryInterface( + XInteractionHandler.class, + xFactory.createInstanceWithContext( "com.sun.star.task.InteractionHandler", xContext ) ); + } + + if ( m_xInteractionHandler == null ) + throw new com.sun.star.uno.RuntimeException(); + + return m_xInteractionHandler; + } + + protected static String GetMainURL( String sWebPage, String sVURL ) + { + String sResultURL = ""; + try + { + StringReader aReader = new StringReader( sWebPage ); + HTMLEditorKit.Parser aParser = GetHTMLParser(); + EditPageParser aCallback = new EditPageParser(); + + aParser.parse( aReader, aCallback, true ); + sResultURL = aCallback.m_sMainURL; + + if ( !sResultURL.startsWith( "http" ) ) + { + //if the url is only relative then complete it + URL aURL = new URL( sVURL ); + sResultURL = aURL.getProtocol() + "://" + aURL.getHost() + sResultURL; + } + } + catch( Exception e ) + { + e.printStackTrace(); + } + + if ( sResultURL.length() == 0 ) + { + // usually that should not happen + // workaround: try to get index.php from the provided URL + int nIndex = sVURL.indexOf( "index.php" ); + if ( nIndex >= 0 ) + sResultURL = sVURL.substring( 0, nIndex ); + } + + return sResultURL; + } + + protected static String GetRedirectURL( String sWebPage, String sURL ) + { + //scrape the HTML source and find the EditURL + // TODO/LATER: Use parser in future + + int nInd = sWebPage.indexOf( "http-equiv=\"refresh\"" ); + if ( nInd == -1 ) + return ""; + + String sResultURL = ""; + int nContent = sWebPage.indexOf( "content=", nInd ); + if ( nContent > 0 ) + { + int nURL = sWebPage.indexOf( "URL=", nContent ); + if ( nURL > 0 ) + { + int nEndURL = sWebPage.indexOf('"', nURL ); + if ( nEndURL > 0 ) + sResultURL = sWebPage.substring( nURL + 4, nEndURL ); + } + } + + try + { + URL aURL = new URL( sURL ); + if ( !sResultURL.startsWith( aURL.getProtocol() )) + { + //if the url is only relative then complete it + if ( sResultURL.startsWith( "/" ) ) + sResultURL = aURL.getProtocol() + "://" + aURL.getHost() + sResultURL; + else + sResultURL = aURL.getProtocol() + "://" + aURL.getHost() + aURL.getPath() + sResultURL; + } + } + catch ( MalformedURLException ex ) + { + ex.printStackTrace(); + } + + return sResultURL; + + } + + protected static String CreateTempFile( XComponentContext xContext ) + { + String sURL = ""; + try + { + Object oTempFile = xContext.getServiceManager().createInstanceWithContext( "com.sun.star.io.TempFile", xContext ); + XPropertySet xPropertySet = UnoRuntime.queryInterface( XPropertySet.class, oTempFile ); + xPropertySet.setPropertyValue( "RemoveFile", Boolean.FALSE ); + sURL = ( String ) xPropertySet.getPropertyValue( "Uri" ); + + XInputStream xInputStream = UnoRuntime.queryInterface( XInputStream.class, oTempFile ); + xInputStream.closeInput(); + XOutputStream xOutputStream = UnoRuntime.queryInterface( XOutputStream.class, oTempFile ); + xOutputStream.closeOutput(); + } catch ( com.sun.star.uno.Exception ex ) + { + ex.printStackTrace(); + } + return sURL; + } + + private static void close(BufferedReader c) { + if (c == null) return; + try { + c.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + protected static String EachLine( String sURL ) + { + String sText = ""; + BufferedReader aBufReader = null; + try + { + URL aURL = new URL( sURL ); + File aFile = new File( aURL.getFile() ); + InputStreamReader aInputReader = new InputStreamReader( new FileInputStream( aFile ), "UTF-8" ); + aBufReader = new BufferedReader( aInputReader ); + + StringBuffer aBuf = new StringBuffer(); + String sEachLine = aBufReader.readLine(); + + while( sEachLine != null ) + { + aBuf.append( sEachLine ); + aBuf.append( "\n" ); + + sEachLine = aBufReader.readLine(); + } + sText = aBuf.toString(); + + aBufReader.close(); + } catch ( Exception e ) { + e.printStackTrace(); + } + finally { + close(aBufReader); + } + return sText; + } + + protected static String GetDocTitle( XModel xDoc ) + { + XDocumentPropertiesSupplier xDocPropSup = + UnoRuntime.queryInterface(XDocumentPropertiesSupplier.class, xDoc); + XDocumentProperties xDocProps = xDocPropSup.getDocumentProperties(); + return xDocProps.getTitle(); + } + + protected static void SetDocTitle( XModel xDoc, String sTitle ) + { + XDocumentPropertiesSupplier xDocPropSup = + UnoRuntime.queryInterface(XDocumentPropertiesSupplier.class, xDoc); + XDocumentProperties xDocProps = xDocPropSup.getDocumentProperties(); + xDocProps.setTitle(sTitle); + } + + protected static String GetDocServiceName( XComponentContext xContext, XModel xModel ) + { + String aDocServiceName = ""; + if ( xModel != null && xContext != null ) + { + try + { + XMultiComponentFactory xFactory = xContext.getServiceManager(); + if ( xFactory == null ) + throw new com.sun.star.uno.RuntimeException(); + + Object oModuleManager = xFactory.createInstanceWithContext( "com.sun.star.frame.ModuleManager", xContext ); + XModuleManager xModuleManager = UnoRuntime.queryInterface( XModuleManager.class, oModuleManager ); + if ( xModuleManager != null ) + aDocServiceName = xModuleManager.identify( xModel ); + } + catch( java.lang.Exception e ) + { + e.printStackTrace(); + } + } + + return aDocServiceName; + } + + protected static String GetFilterName( XComponentContext xContext, String aTypeName, String aDocServiceName ) + { + if ( xContext == null || aTypeName == null || aTypeName.length() == 0 + || aDocServiceName == null || aDocServiceName.length() == 0 ) { + return ""; + } + String aFilterName = ""; + try + { + Object oFilterFactory = xContext.getServiceManager().createInstanceWithContext( "com.sun.star.document.FilterFactory", xContext ); + XContainerQuery xQuery = UnoRuntime.queryInterface( XContainerQuery.class, oFilterFactory ); + if ( xQuery != null ) + { + NamedValue[] aRequest = new NamedValue[2]; + aRequest[0] = new NamedValue( "Type", aTypeName ); + aRequest[1] = new NamedValue( "DocumentService", aDocServiceName ); + + XEnumeration xSet = xQuery.createSubSetEnumerationByProperties( aRequest ); + if ( xSet != null ) + { + boolean bAcceptable = false; + while ( xSet.hasMoreElements() && !bAcceptable ) + { + PropertyValue[] pFilterProps = ( PropertyValue[] )AnyConverter.toArray( xSet.nextElement() ); + if ( pFilterProps != null ) + { + int nLen = pFilterProps.length; + String aTmpFilter = null; + + for ( int nInd = 0; nInd < nLen; nInd++ ) + { + if ( pFilterProps[nInd].Name.equals( "Name" ) ) + aTmpFilter = AnyConverter.toString( pFilterProps[nInd].Value ); + else if ( pFilterProps[nInd].Name.equals( "Flags" ) ) + bAcceptable = ( ( AnyConverter.toInt( pFilterProps[nInd].Value ) & 2 ) == 2 ); // must allow export + } + + if ( bAcceptable ) + aFilterName = aTmpFilter; + } + } + } + } + } + catch( java.lang.Exception e ) + { + e.printStackTrace(); + } + + return aFilterName; + } + + private static XMultiServiceFactory GetConfigurationProvider( XComponentContext xContext ) + throws com.sun.star.uno.Exception + { + XMultiServiceFactory xConfigurationProvider = null; + if ( xContext != null ) + { + XMultiComponentFactory xFactory = xContext.getServiceManager(); + Object oConfigProvider = xFactory.createInstanceWithContext( "com.sun.star.configuration.ConfigurationProvider", xContext ); + xConfigurationProvider = UnoRuntime.queryInterface( XMultiServiceFactory.class, oConfigProvider ); + } + + if ( xConfigurationProvider == null ) + throw new com.sun.star.uno.RuntimeException(); + + return xConfigurationProvider; + } + + private static Object GetConfig( XComponentContext xContext, String sNodepath, boolean bWriteAccess ) + throws com.sun.star.uno.Exception + { + if ( xContext == null || sNodepath == null ) + throw new com.sun.star.uno.RuntimeException(); + + PropertyValue aVal = new PropertyValue(); + aVal.Name = "nodepath"; + aVal.Value = sNodepath; + Object[] aArgs = new Object[1]; + aArgs[0] = aVal; + + return GetConfigurationProvider( xContext ).createInstanceWithArguments( + ( bWriteAccess ? "com.sun.star.configuration.ConfigurationUpdateAccess" + : "com.sun.star.configuration.ConfigurationAccess" ), + aArgs ); + } + + private static XPropertySet GetConfigProps( XComponentContext xContext, String sNodepath ) + throws com.sun.star.uno.Exception + { + XPropertySet xProps = UnoRuntime.queryInterface( XPropertySet.class, GetConfig( xContext, sNodepath, true ) ); + if ( xProps == null ) + throw new com.sun.star.uno.RuntimeException(); + + return xProps; + } + + + protected static XNameContainer GetConfigNameContainer( XComponentContext xContext, String sNodepath ) + throws com.sun.star.uno.Exception + { + XNameContainer xContainer = UnoRuntime.queryInterface( XNameContainer.class, GetConfig( xContext, sNodepath, true ) ); + if ( xContainer == null ) + throw new com.sun.star.uno.RuntimeException(); + + return xContainer; + } + + protected static XNameAccess GetConfigNameAccess( XComponentContext xContext, String sNodepath ) + throws com.sun.star.uno.Exception + { + XNameAccess xNameAccess = UnoRuntime.queryInterface( XNameAccess.class, GetConfig( xContext, sNodepath, false ) ); + if ( xNameAccess == null ) + throw new com.sun.star.uno.RuntimeException(); + + return xNameAccess; + } + + private static Proxy GetConfigurationProxy(URI uri, XComponentContext xContext) + { + assert(uri != null); + assert(xContext != null); + + try + { + XNameAccess xNameAccess = GetConfigNameAccess( xContext, "org.openoffice.Inet/Settings" ); + + int nProxyType = AnyConverter.toInt( xNameAccess.getByName( "ooInetProxyType" ) ); + if ( nProxyType == 0 ) { + return Proxy.NO_PROXY; + } else { + if ( nProxyType == 1 ) + { + // system proxy + return null; + } + else if ( nProxyType == 2 ) + { + String aProxyNameProp = "ooInetHTTPProxyName"; + String aProxyPortProp = "ooInetHTTPProxyPort"; + + if (uri.getScheme().equals("https")) + { + aProxyNameProp = "ooInetHTTPSProxyName"; + aProxyPortProp = "ooInetHTTPSProxyPort"; + } + + String aProxyName = AnyConverter.toString( xNameAccess.getByName( aProxyNameProp ) ); + + int nProxyPort = 80; + + Object aPortNo = xNameAccess.getByName( aProxyPortProp ); + if ( !AnyConverter.isVoid( aPortNo ) ) + nProxyPort = AnyConverter.toInt( aPortNo ); + + if ( nProxyPort == -1 ) + nProxyPort = 80; + + // TODO: check whether the URL is in the NoProxy list + InetSocketAddress address = new InetSocketAddress(aProxyName, nProxyPort); + return new Proxy(Proxy.Type.HTTP, address); + } + } + } + catch( java.lang.Exception e ) + { + e.printStackTrace(); + } + return null; // invalid configuration value? + } + + protected static void ShowURLInBrowser( XComponentContext xContext, String sURL ) + { + if ( xContext != null && sURL != null && sURL.length() > 0 ) + { + try + { + Object oSystemShell = xContext.getServiceManager().createInstanceWithContext( "com.sun.star.system.SystemShellExecute", xContext ); + XSystemShellExecute xSystemShell = UnoRuntime.queryInterface( XSystemShellExecute.class, oSystemShell ); + if ( xSystemShell != null ) + xSystemShell.execute( sURL, "", SystemShellExecuteFlags.URIS_ONLY ); + } + catch( Exception e ) + { + e.printStackTrace(); + } + } + } + + protected static HttpURLConnection PrepareMethod(String method, URI uri, XComponentContext xContext) + throws WikiCancelException, IOException, SSLException + { + assert(method != null); + assert(uri != null); + assert(xContext != null); + + if (!IsConnectionAllowed()) { + throw new WikiCancelException(); + } + + if (java.net.CookieHandler.getDefault() == null) { + // set a cookie manager so cookies don't get lost + // apparently it's not possible to do that on a per-connection + // basis but only globally? + java.net.CookieHandler.setDefault(new java.net.CookieManager()); + } + + Proxy proxy = GetConfigurationProxy(uri, xContext); + HttpURLConnection conn = null; + if (proxy != null) { + conn = (HttpURLConnection) uri.toURL().openConnection(proxy); + } else { + conn = (HttpURLConnection) uri.toURL().openConnection(); + } + if (uri.getScheme().equals("https") && AllowUnknownCert(xContext, uri.getHost())) + { + // let unknown certificates be accepted + ((HttpsURLConnection) conn).setSSLSocketFactory(new WikiProtocolSocketFactory()); + } + +// enable this to help debug connections where TLS gets in the way +// ((HttpsURLConnection) conn).setSSLSocketFactory(new LoggingProtocolSocketFactory()); + + conn.setRequestMethod(method); + // TODO: is it possible to read the version from the extension metadata? + conn.setRequestProperty("User-Agent", "LibreOffice Wiki Publisher 1.2.0"); + // note: don't connect yet so that the caller can do some further setup + + return conn; + } + + protected static String ReadResponseBody(HttpURLConnection conn) + throws IOException + { + String ret = null; + InputStream stream = conn.getInputStream(); + try { + // there doesn't seem to be an easier way get the content encoding + String type = conn.getContentType(); + String charset = "ISO-8859-1"; // default in RFC2616 + for (String param : type.split(";")) { + if (param.trim().toLowerCase().startsWith("charset=")) { + charset = param.trim().substring("charset=".length()); + break; + } + } + BufferedReader br = + new BufferedReader(new InputStreamReader(stream, charset)); + StringBuilder buf = new StringBuilder(); + String line; + while ((line = br.readLine()) != null) { + buf.append(line); + } + ret = buf.toString(); + } finally { + stream.close(); + } + return ret; + } + + private static class HTMLParse extends HTMLEditorKit + { + + @Override + public HTMLEditorKit.Parser getParser() + { + return super.getParser(); + } + } + + protected static HTMLEditorKit.Parser GetHTMLParser() + { + return new HTMLParse().getParser(); + } + + private static boolean LoginReportsError( String sRespond ) + { + boolean bResult = true; + if ( sRespond != null ) + { + try + { + StringReader aReader = new StringReader( sRespond ); + HTMLEditorKit.Parser aParser = GetHTMLParser(); + EditPageParser aCallback = new EditPageParser(); + + aParser.parse( aReader, aCallback, true ); + bResult = ( aCallback.m_nErrorInd >= 0 ); + } + catch( Exception e ) + { + e.printStackTrace(); + } + } + + return bResult; + } + + private static String GetLoginToken( String sLoginPage ) + { + String sResult = ""; + if ( sLoginPage != null && sLoginPage.length() > 0 ) + { + try + { + StringReader aReader = new StringReader( sLoginPage ); + HTMLEditorKit.Parser aParser = Helper.GetHTMLParser(); + EditPageParser aCallbacks = new EditPageParser(); + + aParser.parse( aReader, aCallbacks, true ); + sResult = aCallbacks.m_sLoginToken; + } + catch( Exception e ) + { + e.printStackTrace(); + } + } + + return sResult; + } + + protected static boolean Login(URI aMainURL, String sWikiUser, String sWikiPass, XComponentContext xContext) + throws java.io.IOException, WikiCancelException, URISyntaxException + { + boolean success = false; + + if ( sWikiUser != null && sWikiPass != null && xContext != null ) + { + String sLoginPage = null; + URI aURI = new URI(aMainURL.toString() + "index.php?title=Special:Userlogin"); + HttpURLConnection connGet = PrepareMethod("GET", aURI, xContext); + connGet.setInstanceFollowRedirects(true); + + connGet.connect(); + int nResultCode = connGet.getResponseCode(); + if (nResultCode == 200) { + sLoginPage = ReadResponseBody(connGet); + } + + if ( sLoginPage != null ) + { + String sLoginToken = GetLoginToken( sLoginPage ); + + URI aPostURI = new URI(aMainURL.toString() + "index.php?title=Special:Userlogin&action=submitlogin"); + + HttpURLConnection connPost = PrepareMethod("POST", aPostURI, xContext); + connPost.setInstanceFollowRedirects(true); + connPost.setDoInput(true); + connPost.setDoOutput(true); + connPost.connect(); + + OutputStreamWriter post = new OutputStreamWriter(connPost.getOutputStream(), "UTF-8"); + try + { + post.write("wpName="); + post.write(URLEncoder.encode(sWikiUser, "UTF-8")); + post.write("&wpRemember=1"); + post.write("&wpPassword="); + post.write(URLEncoder.encode(sWikiPass, "UTF-8")); + + if (sLoginToken.length() > 0) { + post.write("&wpLoginToken="); + post.write(URLEncoder.encode(sLoginToken, "UTF-8")); + } + + String[][] pArgs = GetSpecialArgs( xContext, aMainURL.getHost() ); + if ( pArgs != null ) + for ( int nArgInd = 0; nArgInd < pArgs.length; nArgInd++ ) + if ( pArgs[nArgInd].length == 2 && pArgs[nArgInd][0] != null && pArgs[nArgInd][1] != null ) + { + post.write("&"); + post.write(URLEncoder.encode(pArgs[nArgInd][0], "UTF-8")); + post.write("="); + post.write(URLEncoder.encode(pArgs[nArgInd][0], "UTF-8")); + } + + post.flush(); + } + finally + { + post.close(); + } + + nResultCode = connPost.getResponseCode(); + + if ( nResultCode == 200 ) + { + String sResult = ReadResponseBody(connPost); + if ( !LoginReportsError( sResult ) ) + success = true; + } + } + } + + return success; + } + + protected static String[] GetPasswordsForURLAndUser( XComponentContext xContext, String sURL, String sUserName ) + { + String[] aResult = null; + + try + { + if ( xContext != null && sURL != null && sURL.length() > 0 && sUserName != null && sUserName.length() > 0 ) + { + UrlRecord aRec = GetPasswordContainer( xContext ).findForName( sURL, sUserName, GetInteractionHandler( xContext ) ); + if ( aRec != null && aRec.UserList != null && aRec.UserList.length > 0 + && aRec.UserList[0].UserName.equals( sUserName ) ) + aResult = aRec.UserList[0].Passwords; + } + } + catch( Exception e ) + { + e.printStackTrace(); + } + + return aResult; + } + + protected static boolean PasswordStoringIsAllowed( XComponentContext xContext ) + { + boolean bResult = false; + try + { + XMasterPasswordHandling xMasterHdl = UnoRuntime.queryInterface( XMasterPasswordHandling.class, GetPasswordContainer( xContext ) ); + if ( xMasterHdl != null ) + bResult = xMasterHdl.isPersistentStoringAllowed(); + } + catch( Exception e ) + { + e.printStackTrace(); + } + + return bResult; + } + + protected static void ShowError( XComponentContext xContext, XDialog xDialog, int nTitleID, int nErrorID, String sArg, boolean bQuery ) + { + XWindowPeer xPeer = null; + XControl xControl = UnoRuntime.queryInterface( XControl.class, xDialog ); + if ( xControl != null ) + xPeer = xControl.getPeer(); + ShowError( xContext, xPeer, nTitleID, nErrorID, sArg, bQuery ); + } + + protected static boolean ShowError( XComponentContext xContext, XWindowPeer xParentPeer, int nTitleID, int nErrorID, String sArg, boolean bQuery ) + { + boolean bResult = false; + + if ( xContext != null && nErrorID >= 0 && nErrorID < STRINGS_NUM ) + { + String sError = null; + String sTitle = ""; + + try + { + sError = GetLocalizedString( xContext, nErrorID ); + if ( sError != null && sArg != null ) + sError = sError.replaceAll( "\\$ARG1", sArg ); + + sTitle = GetLocalizedString( xContext, nTitleID ); + } + catch( Exception e ) + { + e.printStackTrace(); + } + + if ( sError == null ) + sError = "Error: " + nErrorID; + + if ( xParentPeer != null ) + { + XMessageBoxFactory xMBFactory = null; + XMessageBox xMB = null; + try + { + XMultiComponentFactory xFactory = xContext.getServiceManager(); + if ( xFactory != null ) + xMBFactory = UnoRuntime.queryInterface( + XMessageBoxFactory.class, + xFactory.createInstanceWithContext( "com.sun.star.awt.Toolkit", xContext ) ); + + if ( xMBFactory != null ) + { + if ( bQuery ) + { + xMB = xMBFactory.createMessageBox( + xParentPeer, + MessageBoxType.QUERYBOX, + MessageBoxButtons.BUTTONS_YES_NO | MessageBoxButtons.DEFAULT_BUTTON_NO, + sTitle, + sError ); + } + else + { + xMB = xMBFactory.createMessageBox( + xParentPeer, + MessageBoxType.ERRORBOX, + MessageBoxButtons.BUTTONS_OK, + sTitle, + sError ); + } + if ( xMB != null ) + { + bResult = MainThreadDialogExecutor.Execute( xContext, xMB ); + } + } + } + catch( Exception e ) + { + e.printStackTrace(); + } + finally + { + if ( xMB != null ) + Dispose( xMB ); + } + } + } + + return bResult; + } + + private static boolean AllowUnknownCert( XComponentContext xContext, String aURL ) + { + try + { + XNameAccess xNameAccess = GetConfigNameAccess( xContext, "org.openoffice.Office.Custom.WikiExtension/SpecialData" ); + if ( xNameAccess.hasByName( aURL ) ) + { + XNameAccess xEntry = UnoRuntime.queryInterface( XNameAccess.class, xNameAccess.getByName( aURL ) ); + if ( xEntry != null && xEntry.hasByName( "AllowUnknownCertificate" ) ) + return AnyConverter.toBoolean( xEntry.getByName( "AllowUnknownCertificate" ) ); + } + } + catch( Exception e ) + { + e.printStackTrace(); + } + + return false; + } + + private static String[][] GetSpecialArgs( XComponentContext xContext, String aURL ) + { + try + { + XNameAccess xNameAccess = GetConfigNameAccess( xContext, "org.openoffice.Office.Custom.WikiExtension/SpecialData" ); + if ( xNameAccess.hasByName( aURL ) ) + { + XNameAccess xEntry = UnoRuntime.queryInterface( XNameAccess.class, xNameAccess.getByName( aURL ) ); + if ( xEntry != null ) + { + XNameAccess xArgs = UnoRuntime.queryInterface( XNameAccess.class, xEntry.getByName( "AdditionalLoginArguments" ) ); + if ( xArgs != null ) + { + String[] pNames = xArgs.getElementNames(); + if ( pNames != null && pNames.length > 0 ) + { + String[][] pResult = new String[pNames.length][2]; + for ( int nInd = 0; nInd < pNames.length; nInd++ ) + { + XNameAccess xArgument = UnoRuntime.queryInterface( XNameAccess.class, xArgs.getByName( pNames[nInd] ) ); + if ( xArgument == null ) + throw new com.sun.star.uno.RuntimeException(); + + pResult[nInd][0] = pNames[nInd]; + pResult[nInd][1] = AnyConverter.toString( xArgument.getByName( "Value" ) ); + } + + return pResult; + } + } + } + } + } + catch( Exception e ) + { + e.printStackTrace(); + } + + return null; + } + + protected static boolean AllowThreadUsage( XComponentContext xContext ) + { + if ( xContext != null ) + { + try + { + XMultiComponentFactory xFactory = xContext.getServiceManager(); + if ( xFactory == null ) + throw new com.sun.star.uno.RuntimeException(); + + Object oCheckCallback = xFactory.createInstanceWithContext( "com.sun.star.awt.AsyncCallback", xContext ); + return ( oCheckCallback != null ); + } + catch( Exception e ) + { + e.printStackTrace(); + } + } + + return false; + } + + public static void Dispose( Object oObject ) + { + if ( oObject != null ) + { + try + { + XComponent xComp = UnoRuntime.queryInterface( XComponent.class, oObject ); + if ( xComp != null ) + xComp.dispose(); + } + catch( Exception e ) + { + e.printStackTrace(); + } + } + } +} + diff --git a/swext/mediawiki/src/com/sun/star/wiki/MANIFEST.MF b/swext/mediawiki/src/com/sun/star/wiki/MANIFEST.MF new file mode 100644 index 000000000..6f900e21f --- /dev/null +++ b/swext/mediawiki/src/com/sun/star/wiki/MANIFEST.MF @@ -0,0 +1 @@ +RegistrationClassName: com.sun.star.wiki.WikiEditorImpl diff --git a/swext/mediawiki/src/com/sun/star/wiki/MainThreadDialogExecutor.java b/swext/mediawiki/src/com/sun/star/wiki/MainThreadDialogExecutor.java new file mode 100644 index 000000000..a6ee07fc8 --- /dev/null +++ b/swext/mediawiki/src/com/sun/star/wiki/MainThreadDialogExecutor.java @@ -0,0 +1,158 @@ +/* + * 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 . + */ + +package com.sun.star.wiki; + +import com.sun.star.uno.Any; +import com.sun.star.awt.XDialog; +import com.sun.star.awt.XCallback; +import com.sun.star.awt.XMessageBox; +import com.sun.star.awt.XRequestCallback; +import com.sun.star.lang.XMultiComponentFactory; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; + +public class MainThreadDialogExecutor implements XCallback +{ + private WikiDialog m_aWikiDialog; + private XDialog m_xDialog; + private XMessageBox m_xMessageBox; + private boolean m_bResult = false; + private boolean m_bCalled = false; + private boolean m_bClose = false; + + public static boolean Show( XComponentContext xContext, WikiDialog aWikiDialog ) + { + MainThreadDialogExecutor aExecutor = new MainThreadDialogExecutor( aWikiDialog ); + return GetCallback( xContext, aExecutor ); + } + + + + public static boolean Execute( XComponentContext xContext, XMessageBox xMessageBox ) + { + MainThreadDialogExecutor aExecutor = new MainThreadDialogExecutor( xMessageBox ); + return GetCallback( xContext, aExecutor ); + } + + public static boolean Close( XComponentContext xContext, XDialog xDialog ) + { + MainThreadDialogExecutor aExecutor = new MainThreadDialogExecutor( xDialog ); + aExecutor.m_bClose = true; + aExecutor.m_bCalled = true; // no yielding, asynchronous closing + return GetCallback( xContext, aExecutor ); + } + + private static boolean GetCallback( XComponentContext xContext, MainThreadDialogExecutor aExecutor ) + { + if (aExecutor == null) + return false; + + try + { + String aThreadName = null; + Thread aCurThread = Thread.currentThread(); + if ( aCurThread != null ) + aThreadName = aCurThread.getName(); + + if ( aThreadName != null && aThreadName.equals( "com.sun.star.thread.WikiEditorSendingThread" ) ) + { + // the main thread should be accessed asynchronously + XMultiComponentFactory xFactory = xContext.getServiceManager(); + if ( xFactory == null ) + throw new com.sun.star.uno.RuntimeException(); + + XRequestCallback xRequest = UnoRuntime.queryInterface( + XRequestCallback.class, + xFactory.createInstanceWithContext( "com.sun.star.awt.AsyncCallback", xContext ) ); + if ( xRequest != null ) + { + xRequest.addCallback( aExecutor, Any.VOID ); + do + { + Thread.yield(); + } + while( !aExecutor.m_bCalled ); + } + } + else + { + // handle it as a main thread + aExecutor.notify( Any.VOID ); + } + } + catch( Exception e ) + { + e.printStackTrace(); + } + + return aExecutor.GetResult(); + } + + private MainThreadDialogExecutor( WikiDialog aWikiDialog ) + { + m_aWikiDialog = aWikiDialog; + } + + private MainThreadDialogExecutor( XDialog xDialog ) + { + m_xDialog = xDialog; + } + + private MainThreadDialogExecutor( XMessageBox xMessageBox ) + { + m_xMessageBox = xMessageBox; + } + + private boolean GetResult() + { + return m_bResult; + } + + public void notify( Object aData ) + { + if ( m_aWikiDialog != null ) + m_bResult = m_aWikiDialog.show(); + else if ( m_xDialog != null ) + { + if ( !m_bClose ) + m_bResult = ( m_xDialog.execute() == 1 ); + else + { + try + { + m_xDialog.endExecute(); + } + catch( Exception e ) + { + e.printStackTrace(); + } + m_bResult = true; + } + } + else if ( m_xMessageBox != null ) + { + int nRes = m_xMessageBox.execute(); + m_bResult = ( nRes == com.sun.star.awt.MessageBoxResults.OK + || nRes == com.sun.star.awt.MessageBoxResults.YES ); + } + + m_bCalled = true; + } +} + diff --git a/swext/mediawiki/src/com/sun/star/wiki/Settings.java b/swext/mediawiki/src/com/sun/star/wiki/Settings.java new file mode 100644 index 000000000..34e11e13e --- /dev/null +++ b/swext/mediawiki/src/com/sun/star/wiki/Settings.java @@ -0,0 +1,310 @@ +/* + * 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 . + */ + +package com.sun.star.wiki; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.sun.star.beans.XPropertySet; +import com.sun.star.container.XNameAccess; +import com.sun.star.container.XNameContainer; +import com.sun.star.container.XNameReplace; +import com.sun.star.lang.XSingleServiceFactory; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.util.XChangesBatch; + +public class Settings +{ + + /* Singleton */ + private static Settings m_instance; + + + private final XComponentContext m_xContext; + private final List> m_WikiConnections = new ArrayList>(); + private final List> m_aWikiDocs = new ArrayList>(); + + private Settings( XComponentContext ctx ) + { + m_xContext=ctx; + loadConfiguration(); + } + + + public static synchronized Settings getSettings( XComponentContext ctx ) + { + if ( m_instance == null ) + m_instance = new Settings( ctx ); + return m_instance; + } + + + public void addWikiCon ( Map wikiCon ) + { + m_WikiConnections.add( wikiCon ); + } + + + private String getWikiConUrlByNumber( int num ) + { + String url = ""; + if ( num >=0 && num < m_WikiConnections.size() ) + { + Map ht = m_WikiConnections.get( num ); + url = ht.get( "Url" ); + } + return url; + } + + + public void addWikiDoc ( Map aWikiDoc ) + { + String sURL = ( String ) aWikiDoc.get( "CompleteUrl" ); + Map aEntry = getDocByCompleteUrl( sURL ); + + if ( aEntry != null ) + { + // add doc to the end, even if it has been added before + m_aWikiDocs.remove( aEntry ); + } + else if ( m_aWikiDocs.size() > 10 ) + { + // if the number of elements has reached maximum the oldest element should be removed + m_aWikiDocs.remove( 0 ); + } + + m_aWikiDocs.add( aWikiDoc ); + } + + + public Object[] getWikiDocList( int serverid ) + { + String wikiserverurl = getWikiConUrlByNumber( serverid ); + List theDocs = new ArrayList(); + String [] docs = new String[0]; + for ( int i=0; i ht = m_aWikiDocs.get( i ); + String docurl = ( String ) ht.get( "Url" ); + if ( docurl.equals( wikiserverurl ) ) + { + theDocs.add( (String ) ht.get( "Doc" ) ); + } + } + return theDocs.toArray( docs ); + } + + public String[] getWikiURLs() + { + String [] WikiList = new String [m_WikiConnections.size()]; + for ( int i=0; i ht = m_WikiConnections.get( i ); + WikiList[i] = ht.get( "Url" ); + } + return WikiList; + } + + + public Map getSettingByUrl( String sUrl ) + { + Map ht = null; + for( int i=0;i h1 = m_WikiConnections.get( i ); + String u1 = h1.get( "Url" ); + if ( u1.equals( sUrl ) ) + { + ht = h1; + try + { + String sUserName = ht.get( "Username" ); + String aPassword = ht.get( "Password" ); + if ( sUserName != null && sUserName.length() > 0 && ( aPassword == null || aPassword.length() == 0 ) ) + { + String[] pPasswords = Helper.GetPasswordsForURLAndUser( m_xContext, sUrl, sUserName ); + if ( pPasswords != null && pPasswords.length > 0 ) + ht.put( "Password", pPasswords[0] ); + } + } + catch( Exception e ) + { + e.printStackTrace(); + } + + break; + } + } + return ht; + } + + private Map getDocByCompleteUrl( String curl ) + { + Map ht = null; + for( int i=0;i h1 = m_aWikiDocs.get( i ); + String u1 = ( String ) h1.get( "CompleteUrl" ); + if ( u1.equals( curl ) ) + { + ht = h1; + } + } + return ht; + } + + + public void removeSettingByUrl( String sUrl ) + { + for( int i=0;i h1 = m_WikiConnections.get( i ); + String u1 = h1.get( "Url" ); + if ( u1.equals( sUrl ) ) + { + m_WikiConnections.remove( i ); + } + } + } + + + public void storeConfiguration() + { + try + { + { + // remove stored connection information + XNameContainer xContainer = Helper.GetConfigNameContainer(m_xContext, "org.openoffice.Office.Custom.WikiExtension/ConnectionList"); + String[] pNames = xContainer.getElementNames(); + for (String pName : pNames) + { + xContainer.removeByName(pName); + } + // store all connections + XSingleServiceFactory xConnectionFactory = UnoRuntime.queryInterface(XSingleServiceFactory.class, xContainer); + for (Map ht : m_WikiConnections) + { + Object oNewConnection = xConnectionFactory.createInstance(); + XNameReplace xNewConn = UnoRuntime.queryInterface(XNameReplace.class, oNewConnection); + if (xNewConn != null) + { + xNewConn.replaceByName("UserName", ht.get("Username")); + } + xContainer.insertByName(ht.get("Url"), xNewConn); + } + // commit changes + XChangesBatch xBatch = UnoRuntime.queryInterface(XChangesBatch.class, xContainer); + xBatch.commitChanges(); + } + + { + // remove stored connection information + XNameContainer xContainer = Helper.GetConfigNameContainer(m_xContext, "org.openoffice.Office.Custom.WikiExtension/RecentDocs"); + String[] pNames = xContainer.getElementNames(); + for (String pName : pNames) + { + xContainer.removeByName(pName); + } + // store all Docs + XSingleServiceFactory xDocListFactory = UnoRuntime.queryInterface(XSingleServiceFactory.class, xContainer); + int i = 0; + for (Map ht : m_aWikiDocs) + { + Object oNewDoc = xDocListFactory.createInstance(); + XNameReplace xNewDoc = UnoRuntime.queryInterface(XNameReplace.class, oNewDoc); + for (Map.Entry entry : ht.entrySet()) + { + xNewDoc.replaceByName(entry.getKey(), entry.getValue()); + } + xContainer.insertByName("d" + i++, xNewDoc); + } + // commit changes + XChangesBatch xBatch = UnoRuntime.queryInterface(XChangesBatch.class, xContainer); + xBatch.commitChanges(); + } + + } + catch ( Exception ex ) + { + ex.printStackTrace(); + } + } + + public void loadConfiguration() + { + m_WikiConnections.clear(); + try + { + // get configuration service + // connect to configmanager + XNameAccess xAccess = Helper.GetConfigNameAccess( m_xContext, "org.openoffice.Office.Custom.WikiExtension" ); + + if ( xAccess != null ) + { + Object oList = xAccess.getByName( "ConnectionList" ); + XNameAccess xConnectionList = UnoRuntime.queryInterface( XNameAccess.class, oList ); + String [] allCons = xConnectionList.getElementNames(); + for (String aConnection : allCons) + { + Map ht = new HashMap(); + ht.put("Url", aConnection); + ht.put( "Username", "" ); + ht.put( "Password", "" ); + try + { + XPropertySet xProps = UnoRuntime.queryInterface(XPropertySet.class, xConnectionList.getByName(aConnection)); + if ( xProps != null ) + { + String aUsername = AnyConverter.toString( xProps.getPropertyValue( "UserName" ) ); + if ( aUsername != null && aUsername.length() > 0 ) + ht.put( "Username", aUsername ); + } + } + catch( Exception e ) + { + e.printStackTrace(); + } + addWikiCon( ht ); + } + + Object oDocs = xAccess.getByName( "RecentDocs" ); + XNameAccess xRecentDocs = UnoRuntime.queryInterface( XNameAccess.class, oDocs ); + String [] allDocs = xRecentDocs.getElementNames(); + for (String aDocument : allDocs) + { + Object oDoc = xRecentDocs.getByName(aDocument); + XNameAccess xDoc = UnoRuntime.queryInterface( XNameAccess.class, oDoc ); + Map ht = new HashMap(); + ht.put( "Url", xDoc.getByName( "Url" ) ); + ht.put( "CompleteUrl", xDoc.getByName( "CompleteUrl" ) ); + ht.put( "Doc", xDoc.getByName( "Doc" ) ); + addWikiDoc( ht ); + } + } + } + catch ( Exception ex ) + { + ex.printStackTrace(); + } + } +} diff --git a/swext/mediawiki/src/com/sun/star/wiki/WikiArticle.java b/swext/mediawiki/src/com/sun/star/wiki/WikiArticle.java new file mode 100644 index 000000000..5c22afa2a --- /dev/null +++ b/swext/mediawiki/src/com/sun/star/wiki/WikiArticle.java @@ -0,0 +1,261 @@ +/* + * 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 . + */ + +package com.sun.star.wiki; + +import java.io.StringReader; +import java.io.OutputStreamWriter; +import java.util.Map; +import java.net.URLEncoder; +import java.net.URI; +import java.net.HttpURLConnection; + +import javax.swing.text.html.HTMLEditorKit; + +import com.sun.star.uno.XComponentContext; + + +public class WikiArticle +{ + private final XComponentContext m_xContext; + + private String m_sEditTime = ""; + private String m_sEditToken = ""; + + private String m_sHTMLCode; + private boolean m_bNoArticle = true; + + private String m_sWikiUser; + private String m_sWikiPass; + + private final String m_sTitle; + + private final URI m_aMainURI; + private boolean m_isLoggedIn = false; + + /** Creates a new instance of WikiArticle */ + public WikiArticle( XComponentContext xContext, String sTitle, Map wikiSettings, boolean bLogin, WikiPropDialog aPropDialog ) + throws java.net.URISyntaxException, java.io.IOException, WikiCancelException + { + m_xContext = xContext; + + String sMainUrl = wikiSettings.get("Url"); + m_sWikiUser = wikiSettings.get("Username"); + m_sWikiPass = wikiSettings.get("Password"); + m_sTitle = sTitle; + + m_aMainURI = new URI(sMainUrl); + + if ( bLogin ) + { + WikiEditSettingDialog aDialog = new WikiEditSettingDialog(m_xContext, "vnd.sun.star.script:WikiEditor.EditSetting?location=application", wikiSettings, false ); + try + { + while( !Login() ) + { + if ( aPropDialog != null ) + aPropDialog.SetThrobberActive( false ); + + if ( MainThreadDialogExecutor.Show( xContext, aDialog ) ) + { + m_sWikiUser = wikiSettings.get("Username"); + m_sWikiPass = wikiSettings.get("Password"); + } + else + throw new WikiCancelException(); + + if ( aPropDialog != null ) + { + aPropDialog.SetThrobberActive( true ); + Thread.yield(); + } + } + } + finally + { + aDialog.DisposeDialog(); + } + } + + // in case of loading the html contents are used + // in case of saving the contents should be checked whether they are empty + InitArticleHTML(); + } + + public String GetMainURL() + { + return m_aMainURI.toString(); + } + + public String GetTitle() + { + return m_sTitle; + } + + + + private String getArticleWiki() + throws java.net.URISyntaxException, java.io.IOException, WikiCancelException + { + String sWikiCode = null; + + if (m_isLoggedIn) + { + URI aURI = new URI(m_aMainURI.toString() + "index.php?title=" + m_sTitle + "&action=edit"); + HttpURLConnection connGet = Helper.PrepareMethod("GET", aURI, m_xContext); + connGet.connect(); + + int nResultCode = connGet.getResponseCode(); + String sWebPage = null; + if (nResultCode == 200) { + sWebPage = Helper.ReadResponseBody(connGet); + } + + if ( sWebPage != null ) + { + StringReader r = new StringReader(sWebPage); + HTMLEditorKit.Parser parse = Helper.GetHTMLParser(); + EditPageParser callback = new EditPageParser(); + + parse.parse(r,callback,true); + m_sEditTime = callback.m_sEditTime; + m_sEditToken = callback.m_sEditToken; + + int iPosStart = callback.m_nWikiArticleStart; + int iPosEnd = callback.m_nWikiArticleEnd; + + if ( iPosStart >= 0 && iPosEnd > 0 ) + { + String sArticle = sWebPage.substring(iPosStart, iPosEnd); + iPosStart = sArticle.indexOf('>') + 1; + sWikiCode = sArticle.substring( iPosStart, sArticle.length() ); + } + } + } + + return sWikiCode; + } + + private void InitArticleHTML() + throws java.net.URISyntaxException, java.io.IOException, WikiCancelException + { + if (m_isLoggedIn) + { + URI uri = new URI(m_aMainURI.toString() + "index.php?title=" + m_sTitle); + HttpURLConnection connGet = Helper.PrepareMethod("GET", uri, m_xContext); + connGet.connect(); + + int nResultCode = connGet.getResponseCode(); + String sWebPage = null; + if (nResultCode == 200) { + sWebPage = Helper.ReadResponseBody(connGet); + } + + if ( sWebPage != null ) + { + StringReader r = new StringReader(sWebPage); + HTMLEditorKit.Parser parse = Helper.GetHTMLParser(); + EditPageParser callback = new EditPageParser(); + + parse.parse(r,callback,true); + + int iPosStart = callback.m_nHTMLArticleStart; + int iPosEnd = callback.m_nHTMLArticleEnd; + int nPosNoArt = callback.m_nNoArticleInd; + + if ( iPosStart >= 0 && iPosEnd > 0 ) + { + m_sHTMLCode = sWebPage.substring(iPosStart, iPosEnd); + m_bNoArticle = ( nPosNoArt >= 0 && nPosNoArt >= iPosStart && nPosNoArt <= iPosEnd ); + } + } + } + } + + protected boolean setArticle( String sWikiCode, String sWikiComment, boolean bMinorEdit ) + throws java.net.URISyntaxException, java.io.IOException, WikiCancelException + { + boolean bResult = false; + + if (m_isLoggedIn && sWikiCode != null && sWikiComment != null) + { + // get the edit time and token + getArticleWiki(); + + URI uri = new URI(m_aMainURI.toString() + "index.php?title=" + m_sTitle + "&action=submit"); + + HttpURLConnection connPost = Helper.PrepareMethod("POST", uri, m_xContext); + connPost.setDoInput(true); + connPost.setDoOutput(true); + connPost.connect(); + + OutputStreamWriter post = new OutputStreamWriter(connPost.getOutputStream(), "UTF-8"); + try + { + post.write("wpTextbox1="); + post.write(URLEncoder.encode(sWikiCode, "UTF-8")); + post.write("&wpSummary="); + post.write(URLEncoder.encode(sWikiComment, "UTF-8")); + post.write("&wpSection="); + post.write("&wpEdittime="); + post.write(URLEncoder.encode(m_sEditTime, "UTF-8")); + post.write("&wpSave=Save%20page"); + post.write("&wpEditToken="); + post.write(URLEncoder.encode(m_sEditToken, "UTF-8")); + + if (bMinorEdit) { + post.write("&wpMinoredit=1"); + } + + post.flush(); + } + finally + { + post.close(); + } + + int nResultCode = connPost.getResponseCode(); + if ( nResultCode < 400 ) + bResult = true; + + String aResult = Helper.ReadResponseBody(connPost); + + // TODO: remove the debug printing, try to detect the error + System.out.print( "nSubmitCode = " + nResultCode + "\n===\n" + aResult ); + } + + return bResult; + } + + private boolean Login() + throws java.net.URISyntaxException, java.io.IOException, WikiCancelException + { + m_isLoggedIn = Helper.Login( m_aMainURI, m_sWikiUser, m_sWikiPass, m_xContext ); + return m_isLoggedIn; + } + + protected boolean NotExist() + { + boolean bResult = true; + if ( m_sHTMLCode != null ) + bResult = m_bNoArticle; + + return bResult; + } + +} diff --git a/swext/mediawiki/src/com/sun/star/wiki/WikiCancelException.java b/swext/mediawiki/src/com/sun/star/wiki/WikiCancelException.java new file mode 100644 index 000000000..0a6c81ebe --- /dev/null +++ b/swext/mediawiki/src/com/sun/star/wiki/WikiCancelException.java @@ -0,0 +1,24 @@ +/* + * 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 . + */ + +package com.sun.star.wiki; + +class WikiCancelException extends java.lang.Exception +{ +} + diff --git a/swext/mediawiki/src/com/sun/star/wiki/WikiDialog.java b/swext/mediawiki/src/com/sun/star/wiki/WikiDialog.java new file mode 100644 index 000000000..66bef678e --- /dev/null +++ b/swext/mediawiki/src/com/sun/star/wiki/WikiDialog.java @@ -0,0 +1,283 @@ +/* + * 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 . + */ + +package com.sun.star.wiki; + +import com.sun.star.awt.XControl; +import com.sun.star.awt.XControlContainer; +import com.sun.star.awt.XControlModel; +import com.sun.star.awt.XDialog; +import com.sun.star.awt.XDialogEventHandler; +import com.sun.star.awt.XDialogProvider2; +import com.sun.star.awt.XAnimation; +import com.sun.star.beans.XPropertySet; +import com.sun.star.lang.XMultiComponentFactory; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.awt.XTopWindow; +import com.sun.star.awt.XTopWindowListener; +import com.sun.star.awt.XWindow; +import com.sun.star.container.XNameContainer; +import com.sun.star.lang.EventObject; +import com.sun.star.lang.XMultiServiceFactory; + +public class WikiDialog implements XDialogEventHandler, XTopWindowListener +{ + protected XComponentContext m_xContext; + private XControlContainer m_xControlContainer; + protected XDialog m_xDialog; + private String[] m_aMethods; + protected boolean m_bAction = false; + protected Settings m_aSettings; + protected Thread m_aThread; + protected boolean m_bThreadFinished = false; + + + /** Creates a new instance of WikiDialog */ + public WikiDialog(XComponentContext c, String DialogURL) + { + this.m_xContext = c; + XMultiComponentFactory xMCF = m_xContext.getServiceManager(); + m_aSettings = Settings.getSettings(m_xContext); + try + { + Object obj; + obj = xMCF.createInstanceWithContext("com.sun.star.awt.DialogProvider2", m_xContext ); + XDialogProvider2 xDialogProvider = UnoRuntime.queryInterface( XDialogProvider2.class, obj ); + + m_xDialog = xDialogProvider.createDialogWithHandler( DialogURL, this ); + m_xControlContainer = UnoRuntime.queryInterface( XControlContainer.class, m_xDialog ); + XTopWindow xTopWindow = UnoRuntime.queryInterface( XTopWindow.class, m_xDialog ); + if ( xTopWindow != null ) + xTopWindow.addTopWindowListener( this ); + } + catch (com.sun.star.uno.Exception ex) + { + ex.printStackTrace(); + } + } + + public synchronized void ThreadStop( boolean bSelf ) + { + if ( bSelf || m_aThread != null && !m_bThreadFinished ) + { + try + { + Helper.AllowConnection( bSelf ); + } + catch( Exception ex ) + { + ex.printStackTrace(); + } + } + + m_aThread = null; + m_bThreadFinished = true; + } + + protected void setMethods (String [] Methods) + { + this.m_aMethods = Methods; + } + + + public boolean show( ) + { + m_bThreadFinished = false; + + if( m_xDialog != null ) m_xDialog.execute(); + return m_bAction; + } + + + public String[] getSupportedMethodNames() + { + return m_aMethods; + } + + + public boolean callHandlerMethod( XDialog xDialog, Object EventObject, String MethodName ) + { + return true; + } + + public void SetTitle( String sTitle ) + throws Exception + { + SetTitle( m_xDialog, sTitle ); + } + + private static void SetTitle( XDialog xDialog, String sTitle ) + throws Exception + { + if ( xDialog == null || sTitle == null ) { + return; + } + XControl xDialogControl = UnoRuntime.queryInterface( XControl.class, xDialog ); + if ( xDialogControl != null ) + { + XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, xDialogControl.getModel() ); + if ( xPropSet != null ) + xPropSet.setPropertyValue( "Title", sTitle ); + } + } + + protected XPropertySet GetPropSet(String sControl) + { + return GetPropSet( m_xControlContainer, sControl ); + } + + private static XPropertySet GetPropSet( XControlContainer xControlContainer, String sControl ) + { + XPropertySet xPS = null; + + if ( xControlContainer != null && sControl != null ) + { + XControl xControl = xControlContainer.getControl(sControl); + xPS = UnoRuntime.queryInterface(XPropertySet.class, xControl.getModel() ); + } + + if ( xPS == null ) + throw new com.sun.star.uno.RuntimeException(); + + return xPS; + } + + + + protected void InsertThrobber( int X, int Y, int Width, int Height ) + { + try + { + XControl xDialogControl = UnoRuntime.queryInterface( XControl.class, m_xDialog ); + XControlModel xDialogModel = null; + if ( xDialogControl != null ) + xDialogModel = xDialogControl.getModel(); + + XMultiServiceFactory xDialogFactory = UnoRuntime.queryInterface( XMultiServiceFactory.class, xDialogModel ); + if ( xDialogFactory != null ) + { + XControlModel xThrobberModel = UnoRuntime.queryInterface( XControlModel.class, xDialogFactory.createInstance( "com.sun.star.awt.SpinningProgressControlModel" ) ); + XPropertySet xThrobberProps = UnoRuntime.queryInterface( XPropertySet.class, xThrobberModel ); + if ( xThrobberProps != null ) + { + xThrobberProps.setPropertyValue( "Name", "WikiThrobber" ); + xThrobberProps.setPropertyValue( "PositionX", Integer.valueOf( X ) ); + xThrobberProps.setPropertyValue( "PositionY", Integer.valueOf( Y ) ); + xThrobberProps.setPropertyValue( "Width", Integer.valueOf( Width ) ); + xThrobberProps.setPropertyValue( "Height", Integer.valueOf( Height ) ); + + XNameContainer xDialogContainer = UnoRuntime.queryInterface( XNameContainer.class, xDialogModel ); + xDialogContainer.insertByName( "WikiThrobber", xThrobberModel ); + } + } + } + catch( Exception e ) + { + e.printStackTrace(); + } + + SetThrobberVisible( false ); + } + + public void SetThrobberActive( boolean bActive ) + { + if ( m_xControlContainer != null ) + { + try + { + XAnimation xThrobber = UnoRuntime.queryInterface( XAnimation.class, m_xControlContainer.getControl( "WikiThrobber" ) ); + if ( xThrobber != null ) + { + if ( bActive ) + xThrobber.startAnimation(); + else + xThrobber.stopAnimation(); + } + } + catch( Exception e ) + { + e.printStackTrace(); + } + } + } + + public void SetThrobberVisible( boolean bVisible ) + { + if ( m_xControlContainer != null ) + { + try + { + XWindow xWindow = UnoRuntime.queryInterface( XWindow.class, m_xControlContainer.getControl( "WikiThrobber" ) ); + if ( xWindow != null ) + xWindow.setVisible( bVisible ); + } + catch ( Exception e ) + { + e.printStackTrace(); + } + } + } + + public void SetFocusTo( String aControl ) + { + if ( m_xControlContainer != null ) + { + try + { + XWindow xWindow = UnoRuntime.queryInterface( XWindow.class, m_xControlContainer.getControl( aControl ) ); + if ( xWindow != null ) + xWindow.setFocus(); + } + catch ( Exception e ) + { + e.printStackTrace(); + } + } + } + + public void DisposeDialog() + { + Helper.Dispose( m_xDialog ); + } + + public void windowOpened( EventObject e ) + {} + + public void windowClosing( EventObject e ) + {} + + public void windowClosed( EventObject e ) + {} + + public void windowMinimized( EventObject e ) + {} + + public void windowNormalized( EventObject e ) + {} + + public void windowActivated( EventObject e ) + {} + + public void windowDeactivated( EventObject e ) + {} + + public void disposing( EventObject e ) + {} +} + diff --git a/swext/mediawiki/src/com/sun/star/wiki/WikiEditSettingDialog.java b/swext/mediawiki/src/com/sun/star/wiki/WikiEditSettingDialog.java new file mode 100644 index 000000000..e1f1aac35 --- /dev/null +++ b/swext/mediawiki/src/com/sun/star/wiki/WikiEditSettingDialog.java @@ -0,0 +1,416 @@ +/* + * 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 . + */ + +package com.sun.star.wiki; + +import java.util.HashMap; +import java.util.Map; + +import java.net.URI; +import java.net.HttpURLConnection; +import javax.net.ssl.SSLException; + +import com.sun.star.awt.XDialog; +import com.sun.star.beans.XPropertySet; +import com.sun.star.lang.EventObject; +import com.sun.star.uno.XComponentContext; + +public class WikiEditSettingDialog extends WikiDialog +{ + + private static final String sOKMethod = "OK"; + + private final String[] Methods = {sOKMethod }; + private final Map setting; + private final boolean addMode; + private boolean m_bAllowURLChange = true; + + public WikiEditSettingDialog( XComponentContext xContext, String DialogURL ) + { + super( xContext, DialogURL ); + super.setMethods( Methods ); + setting = new HashMap(); + addMode = true; + + InsertThrobber( 184, 20, 10, 10 ); + InitStrings( xContext ); + InitSaveCheckbox( xContext, false ); + } + + public WikiEditSettingDialog( XComponentContext xContext, String DialogURL, Map ht, boolean bAllowURLChange ) + { + super( xContext, DialogURL ); + super.setMethods( Methods ); + setting = ht; + + boolean bInitSaveCheckBox = false; + + try + { + XPropertySet xUrlField = GetPropSet( "UrlField" ); + + xUrlField.setPropertyValue( "Text", ht.get( "Url" ) ); + + GetPropSet( "UsernameField" ).setPropertyValue( "Text", ht.get( "Username" ) ); + + if ( Helper.PasswordStoringIsAllowed( m_xContext ) ) + { + String[] pPasswords = Helper.GetPasswordsForURLAndUser( m_xContext, ht.get( "Url" ), ht.get( "Username" ) ); + bInitSaveCheckBox = ( pPasswords != null && pPasswords.length > 0 && pPasswords[0].equals( ht.get( "Password" ) ) ); + } + + // the password should be entered by the user or the Cancel should be pressed + // GetPropSet( "PasswordField" ).setPropertyValue( "Text", ht.get( "Password" )); + } + catch ( Exception ex ) + { + ex.printStackTrace(); + } + + addMode = false; + m_bAllowURLChange = bAllowURLChange; + + InsertThrobber( 184, 20, 10, 10 ); + InitStrings( xContext ); + InitSaveCheckbox( xContext, bInitSaveCheckBox ); + } + + @Override + public boolean show( ) + { + SetThrobberVisible( false ); + EnableControls( true ); + boolean bResult = super.show(); + + try + { + if ( bResult && Helper.PasswordStoringIsAllowed( m_xContext ) + && ( (Short)( GetPropSet( "SaveBox" ).getPropertyValue("State") ) ).shortValue() != (short)0 ) + { + String sURL = setting.get( "Url" ); + String sUserName = setting.get( "Username" ); + String sPassword = setting.get( "Password" ); + + if ( sURL != null && sURL.length() > 0 && sUserName != null && sUserName.length() > 0 && sPassword != null && sPassword.length() > 0 ) + { + String[] pPasswords = { sPassword }; + Helper.GetPasswordContainer( m_xContext ).addPersistent( sURL, sUserName, pPasswords, Helper.GetInteractionHandler( m_xContext ) ); + } + } + } + catch( Exception e ) + { + e.printStackTrace(); + } + + return bResult; + } + + private void EnableControls( boolean bEnable ) + { + if ( !bEnable ) + SetFocusTo( "CancelButton" ); + + try + { + GetPropSet( "UsernameField" ).setPropertyValue( "Enabled", Boolean.valueOf( bEnable ) ); + GetPropSet( "PasswordField" ).setPropertyValue( "Enabled", Boolean.valueOf( bEnable ) ); + GetPropSet( "OkButton" ).setPropertyValue( "Enabled", Boolean.valueOf( bEnable ) ); + GetPropSet( "HelpButton" ).setPropertyValue( "Enabled", Boolean.valueOf( bEnable ) ); + + if ( bEnable ) + { + GetPropSet( "UrlField" ).setPropertyValue( "Enabled", Boolean.valueOf( m_bAllowURLChange ) ); + GetPropSet( "SaveBox" ).setPropertyValue( "Enabled", Boolean.valueOf( Helper.PasswordStoringIsAllowed( m_xContext ) ) ); + if ( m_bAllowURLChange ) + SetFocusTo( "UrlField" ); + else + SetFocusTo( "UsernameField" ); + } + else + { + GetPropSet( "UrlField" ).setPropertyValue( "Enabled", Boolean.FALSE ); + GetPropSet( "SaveBox" ).setPropertyValue( "Enabled", Boolean.FALSE ); + } + } + catch ( Exception ex ) + { + ex.printStackTrace(); + } + } + + private void InitStrings( XComponentContext xContext ) + { + try + { + SetTitle( Helper.GetLocalizedString( xContext, Helper.DLG_MEDIAWIKI_TITLE ) ); + GetPropSet( "UrlLabel" ).setPropertyValue( "Label", Helper.GetLocalizedString( xContext, Helper.DLG_EDITSETTING_URLLABEL ) ); + GetPropSet( "UsernameLabel" ).setPropertyValue( "Label", Helper.GetLocalizedString( xContext, Helper.DLG_EDITSETTING_USERNAMELABEL ) ); + GetPropSet( "PasswordLabel" ).setPropertyValue( "Label", Helper.GetLocalizedString( xContext, Helper.DLG_EDITSETTING_PASSWORDLABEL ) ); + GetPropSet( "AccountLine" ).setPropertyValue( "Label", Helper.GetLocalizedString( xContext, Helper.DLG_EDITSETTING_ACCOUNTLINE ) ); + GetPropSet( "WikiLine" ).setPropertyValue( "Label", Helper.GetLocalizedString( xContext, Helper.DLG_EDITSETTING_WIKILINE ) ); + GetPropSet( "SaveBox" ).setPropertyValue( "Label", Helper.GetLocalizedString( xContext, Helper.DLG_EDITSETTING_SAVEBOX ) ); + GetPropSet( "OkButton" ).setPropertyValue( "Label", Helper.GetLocalizedString( xContext, Helper.DLG_OK ) ); + } + catch( Exception e ) + { + e.printStackTrace(); + } + } + + private void InitSaveCheckbox( XComponentContext xContext, boolean bInitSaveCheckBox ) + { + XPropertySet xSaveCheck = GetPropSet( "SaveBox" ); + try + { + xSaveCheck.setPropertyValue( "State", Short.valueOf( bInitSaveCheckBox ? (short)1 : (short)0 ) ); + xSaveCheck.setPropertyValue( "Enabled", Boolean.valueOf( Helper.PasswordStoringIsAllowed( xContext ) ) ); + } + catch( Exception e ) + { + e.printStackTrace(); + } + } + + private void DoLogin() + { + String sRedirectURL = ""; + String sURL = ""; + try + { + sURL = ( String ) GetPropSet( "UrlField" ).getPropertyValue( "Text" ); + String sUserName = ( String ) GetPropSet( "UsernameField" ).getPropertyValue( "Text" ); + String sPassword = ( String ) GetPropSet( "PasswordField" ).getPropertyValue( "Text" ); + + boolean bAllowIndex = true; + + do + { + if ( sRedirectURL.length() > 0 ) + { + sURL = sRedirectURL; + sRedirectURL = ""; + } + + if ( sURL.length() > 0 ) + { + URI aURI = new URI(sURL); + HttpURLConnection connGet = Helper.PrepareMethod("GET", aURI, m_xContext); + connGet.setInstanceFollowRedirects(false); + connGet.connect(); + + int nResultCode = connGet.getResponseCode(); + String sWebPage = null; + if ( nResultCode == 200 ) + sWebPage = Helper.ReadResponseBody(connGet); + else if ( nResultCode >= 301 && nResultCode <= 303 || nResultCode == 307 ) + sRedirectURL = connGet.getHeaderField("Location"); + + if ( sWebPage != null && sWebPage.length() > 0 ) + { + //the URL is valid + String sMainURL = Helper.GetMainURL( sWebPage, sURL ); + + if ( sMainURL.length() == 0 ) + { + // TODO: + // it's not a Wiki Page, check first whether a redirect is requested + // happens usually in case of https + sRedirectURL = Helper.GetRedirectURL( sWebPage, sURL ); + if ( sRedirectURL.length() == 0 ) + { + // show error + Helper.ShowError( m_xContext, + m_xDialog, + Helper.DLG_MEDIAWIKI_TITLE, + Helper.NOURLCONNECTION_ERROR, + sURL, + false ); + } + } + else + { + URI aMainURI = new URI(sMainURL); + + if ( ( sUserName.length() > 0 || sPassword.length() > 0 ) + && !Helper.Login(aMainURI, sUserName, sPassword, m_xContext)) + { + // a wrong login information is provided + // show error + Helper.ShowError( m_xContext, + m_xDialog, + Helper.DLG_MEDIAWIKI_TITLE, + Helper.WRONGLOGIN_ERROR, + null, + false ); + } + else + { + setting.put( "Url", aMainURI.toASCIIString() ); + setting.put( "Username", sUserName ); + setting.put( "Password", sPassword ); + if ( addMode ) + { + // no cleaning of the settings is necessary + Settings.getSettings( m_xContext ).addWikiCon( setting ); + Settings.getSettings( m_xContext ).storeConfiguration(); + } + + m_bAction = true; + } + } + } + else if ( sRedirectURL == null || sRedirectURL.length() == 0 ) + { + if ( sURL.length() > 0 && !sURL.endsWith( "index.php" ) && bAllowIndex ) + { + // the used MainURL is not always directly accessible + // add the suffix as workaround, but only once + sRedirectURL = sURL + "/index.php"; + bAllowIndex = false; + } + else + { + // URL invalid + // show error + Helper.ShowError( m_xContext, + m_xDialog, + Helper.DLG_MEDIAWIKI_TITLE, + Helper.INVALIDURL_ERROR, + null, + false ); + } + } + } + else + { + // URL field empty + // show error + Helper.ShowError( m_xContext, + m_xDialog, + Helper.DLG_MEDIAWIKI_TITLE, + Helper.NOURL_ERROR, + null, + false ); + } + } while (sRedirectURL != null && sRedirectURL.length() > 0); + } + catch ( WikiCancelException ce ) + { + } + catch ( SSLException essl ) + { + if ( Helper.IsConnectionAllowed() ) + { + Helper.ShowError( m_xContext, + m_xDialog, + Helper.DLG_MEDIAWIKI_TITLE, + Helper.UNKNOWNCERT_ERROR, + null, + false ); + } + essl.printStackTrace(); + } + catch ( Exception ex ) + { + if ( Helper.IsConnectionAllowed() ) + { + Helper.ShowError( m_xContext, + m_xDialog, + Helper.DLG_MEDIAWIKI_TITLE, + Helper.NOURLCONNECTION_ERROR, + sURL, + false ); + } + ex.printStackTrace(); + } + } + + @Override + public boolean callHandlerMethod( XDialog xDialog, Object EventObject, String MethodName ) + { + if ( MethodName.equals( sOKMethod ) ) + { + EnableControls( false ); + SetThrobberVisible( true ); + SetThrobberActive( true ); + + if ( Helper.AllowThreadUsage( m_xContext ) ) + { + final XDialog xDialogForThread = xDialog; + final XComponentContext xContext = m_xContext; + + // the thread name is used to allow the error dialogs + m_bThreadFinished = false; + m_aThread = new Thread( "com.sun.star.thread.WikiEditorSendingThread" ) + { + @Override + public void run() + { + try + { + Thread.yield(); + } catch( java.lang.Exception e ){} + + DoLogin(); + WikiEditSettingDialog.this.EnableControls( true ); + WikiEditSettingDialog.this.SetThrobberActive( false ); + WikiEditSettingDialog.this.SetThrobberVisible( false ); + + ThreadStop( true ); + + if ( m_bAction ) + MainThreadDialogExecutor.Close( xContext, xDialogForThread ); + } + }; + + m_aThread.start(); + } + else + { + try + { + DoLogin(); + } catch( java.lang.Exception e ) + {} + finally + { + EnableControls( true ); + SetThrobberActive( false ); + SetThrobberVisible( false ); + + if ( m_bAction ) + xDialog.endExecute(); + + Helper.AllowConnection( true ); + } + } + + return true; + } + + return false; + } + + @Override + public void windowClosed( EventObject e ) + { + ThreadStop( false ); + } +} + diff --git a/swext/mediawiki/src/com/sun/star/wiki/WikiEditorImpl.java b/swext/mediawiki/src/com/sun/star/wiki/WikiEditorImpl.java new file mode 100644 index 000000000..3d1bee21e --- /dev/null +++ b/swext/mediawiki/src/com/sun/star/wiki/WikiEditorImpl.java @@ -0,0 +1,353 @@ +/* + * 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 . + */ + +package com.sun.star.wiki; + +import java.io.File; +import java.net.URI; +import java.util.HashMap; +import java.util.Map; + +import javax.net.ssl.SSLException; + +import com.sun.star.awt.XWindowPeer; +import com.sun.star.beans.PropertyValue; +import com.sun.star.frame.DispatchDescriptor; +import com.sun.star.frame.XController; +import com.sun.star.frame.XDispatch; +import com.sun.star.frame.XDispatchProvider; +import com.sun.star.frame.XFrame; +import com.sun.star.frame.XModel; +import com.sun.star.frame.XStorable; +import com.sun.star.lang.XInitialization; +import com.sun.star.lang.XSingleComponentFactory; +import com.sun.star.lib.uno.helper.Factory; +import com.sun.star.lib.uno.helper.WeakBase; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; + + +public final class WikiEditorImpl extends WeakBase + implements com.sun.star.lang.XServiceInfo, XDispatchProvider, XDispatch, XInitialization +{ + + private static final String m_implementationName = WikiEditorImpl.class.getName(); + private static final String[] m_serviceNames = {"com.sun.star.wiki.WikiEditor" }; + + + + // protocol name that this protocol handler handles + private static final String protocolName = "vnd.com.sun.star.wiki:"; + + private final XComponentContext m_xContext; + private XFrame m_xFrame; + private XModel m_xModel; + private final Settings m_aSettings; + private String m_aFilterName; + + public WikiEditorImpl( XComponentContext xContext ) + { + // Helper.trustAllSSL(); + m_xContext = xContext; + m_aSettings = Settings.getSettings( m_xContext ); + } + + public static XSingleComponentFactory __getComponentFactory( String sImplementationName ) + { + XSingleComponentFactory xFactory = null; + + if ( sImplementationName.equals( m_implementationName ) ) + xFactory = Factory.createComponentFactory( WikiEditorImpl.class, m_serviceNames ); + else if ( sImplementationName.equals( WikiOptionsEventHandlerImpl.m_sImplementationName ) ) + xFactory = Factory.createComponentFactory( WikiOptionsEventHandlerImpl.class, + WikiOptionsEventHandlerImpl.m_pServiceNames ); + + return xFactory; + } + + // com.sun.star.lang.XServiceInfo: + public String getImplementationName() + { + return m_implementationName; + } + + public boolean supportsService( String sService ) + { + int len = m_serviceNames.length; + + for( int i=0; i < len; i++ ) + { + if ( sService.equals( m_serviceNames[i] )) + return true; + } + return false; + } + + public String[] getSupportedServiceNames() + { + return m_serviceNames; + } + + + public synchronized void initialize( Object[] args ) throws com.sun.star.uno.Exception + { + if ( args.length > 0 ) + { + m_xFrame = UnoRuntime.queryInterface( XFrame.class, args[0] ); + } + } + + + + public void dispatch( + final com.sun.star.util.URL aURL, + com.sun.star.beans.PropertyValue[] propertyValue ) + { + final com.sun.star.util.URL myURL = aURL; + if ( aURL.Protocol.equals(protocolName) ) + { + try + { + if ( myURL.Path.equals("send") ) + { + sendArticle(); + } + } catch( java.lang.Throwable t ) + { + } + } + } + + + public com.sun.star.frame.XDispatch queryDispatch( + com.sun.star.util.URL aURL, + String str, + int param ) + { + if ( aURL.Protocol.equals( protocolName )) + { + + // by default, we are responsible + return this; + } else + { + return null; + } + } + + public XDispatch[] queryDispatches( DispatchDescriptor[] seqDescripts ) + { + int nCount = seqDescripts.length; + XDispatch[] lDispatcher = new XDispatch[nCount]; + + for( int i=0; i aWikiSetting ) + { + boolean bResult = false; + + if ( aSendDialog != null ) + { + String sTemp2Url = null; + + try + { + // TODO: stop progress spinning + WikiArticle aArticle = new WikiArticle( m_xContext, aSendDialog.GetWikiTitle(), aWikiSetting, true, aSendDialog ); + + boolean bAllowSending = true; + if ( !aArticle.NotExist() ) + { + // ask whether creation of a new page is allowed + aSendDialog.SetThrobberActive( false ); + bAllowSending = Helper.ShowError( + m_xContext, + UnoRuntime.queryInterface( XWindowPeer.class, m_xFrame.getContainerWindow() ), + Helper.DLG_SENDTITLE, + Helper.DLG_WIKIPAGEEXISTS_LABEL1, + aSendDialog.GetWikiTitle(), + true ); + aSendDialog.SetThrobberActive( true ); + } + + if ( bAllowSending ) + { + PropertyValue[] lProperties = new PropertyValue[2]; + lProperties[0] = new PropertyValue(); + lProperties[0].Name = "FilterName"; + lProperties[0].Value = m_aFilterName; + lProperties[1] = new PropertyValue(); + lProperties[1].Name = "Overwrite"; + lProperties[1].Value = Boolean.TRUE; + + sTemp2Url = Helper.CreateTempFile( m_xContext ); + + XStorable xStore = UnoRuntime.queryInterface ( XStorable.class, m_xModel ); + if ( xStore == null ) + throw new com.sun.star.uno.RuntimeException(); + + xStore.storeToURL( sTemp2Url, lProperties ); + String sWikiCode = Helper.EachLine( sTemp2Url ); + + if ( aArticle.setArticle( sWikiCode, aSendDialog.m_sWikiComment, aSendDialog.m_bWikiMinorEdit ) ) + { + bResult = true; + Helper.SetDocTitle( m_xModel, aArticle.GetTitle() ); + Map aDocInfo = new HashMap(); + aDocInfo.put( "Doc", aArticle.GetTitle() ); + aDocInfo.put( "Url", aArticle.GetMainURL() ); + aDocInfo.put( "CompleteUrl", aArticle.GetMainURL() + aArticle.GetTitle() ); + m_aSettings.addWikiDoc( aDocInfo ); + m_aSettings.storeConfiguration(); + } + else + { + Helper.ShowError( m_xContext, + UnoRuntime.queryInterface( XWindowPeer.class, m_xFrame.getContainerWindow() ), + Helper.DLG_SENDTITLE, + Helper.GENERALSEND_ERROR, + null, + false ); + } + } + } + catch( WikiCancelException ec ) + { + // nothing to do, the sending was cancelled + } + catch( SSLException essl ) + { + if ( Helper.IsConnectionAllowed() ) + { + // report the error only if sending was not cancelled + Helper.ShowError( m_xContext, + UnoRuntime.queryInterface( XWindowPeer.class, m_xFrame.getContainerWindow() ), + Helper.DLG_SENDTITLE, + Helper.UNKNOWNCERT_ERROR, + null, + false ); + } + } + catch( Exception e ) + { + if ( Helper.IsConnectionAllowed() ) + { + // report the error only if sending was not cancelled + Helper.ShowError( m_xContext, + UnoRuntime.queryInterface( XWindowPeer.class, m_xFrame.getContainerWindow() ), + Helper.DLG_SENDTITLE, + Helper.GENERALSEND_ERROR, + null, + false ); + } + e.printStackTrace(); + } + + if ( sTemp2Url != null ) + { + try + { + // remove the temporary file + File aFile = new File( new URI( sTemp2Url ) ); + if (!aFile.delete()) { + throw new java.lang.Exception("could not remove" + sTemp2Url); + } + } + catch ( java.lang.Exception e ) + { + e.printStackTrace(); + } + } + } + + return bResult; + } + +} diff --git a/swext/mediawiki/src/com/sun/star/wiki/WikiOptionsEventHandlerImpl.java b/swext/mediawiki/src/com/sun/star/wiki/WikiOptionsEventHandlerImpl.java new file mode 100644 index 000000000..c35246be4 --- /dev/null +++ b/swext/mediawiki/src/com/sun/star/wiki/WikiOptionsEventHandlerImpl.java @@ -0,0 +1,279 @@ +/* + * 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 . + */ + +package com.sun.star.wiki; + +import com.sun.star.awt.XContainerWindowEventHandler; +import com.sun.star.awt.XControl; +import com.sun.star.awt.XControlContainer; +import com.sun.star.awt.XDialog; +import com.sun.star.awt.XDialogEventHandler; +import com.sun.star.awt.XWindow; +import com.sun.star.beans.XPropertySet; +import com.sun.star.lang.WrappedTargetException; +import com.sun.star.lang.XServiceInfo; +import com.sun.star.lib.uno.helper.WeakBase; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import java.util.Map; + +public final class WikiOptionsEventHandlerImpl extends WeakBase + implements XServiceInfo, XContainerWindowEventHandler, XDialogEventHandler +{ + static final String[] m_pServiceNames = { "com.sun.star.wiki.WikiOptionsEventHandler" }; + static final String m_sImplementationName = WikiOptionsEventHandlerImpl.class.getName(); + + private static final String sExternalEvent = "external_event"; + private static final String sAdd = "Add"; + private static final String sEdit = "Edit"; + private static final String sRemove = "Remove"; + private static final String sListStatus = "ListStatus"; + private static final String sListEdit = "ListEdit"; + private static final String sInitialize = "initialize"; + private static final String sOk = "ok"; + private static final String sBack = "back"; + + private final XComponentContext m_xContext; + private XDialog m_xDialog; + private XControlContainer m_xControlContainer; + + private Settings m_aSettings; + + public WikiOptionsEventHandlerImpl( XComponentContext xContext ) + { + m_xContext = xContext; + } + + private XPropertySet GetPropSet( String sControl ) + { + if ( m_xControlContainer != null ) + { + XControl xControl = m_xControlContainer.getControl(sControl); + XPropertySet xListProps = UnoRuntime.queryInterface(XPropertySet.class, xControl.getModel() ); + return xListProps; + } + + return null; + } + + private void RefreshView() + { + if ( m_aSettings != null ) + { + String[] pWikiList = m_aSettings.getWikiURLs(); + XPropertySet xListProps = GetPropSet( "WikiList" ); + if ( xListProps != null ) + { + try + { + xListProps.setPropertyValue( "StringItemList", pWikiList ); + } + catch ( Exception ex ) + { + ex.printStackTrace(); + } + } + } + } + + private void CheckButtonState() + { + XPropertySet xListProps = GetPropSet( "WikiList" ); + if ( xListProps != null ) + { + try + { + short [] pSel = (short []) xListProps.getPropertyValue( "SelectedItems" ); + XPropertySet xEditProps = GetPropSet( "EditButton" ); + XPropertySet xRemoveProps = GetPropSet( "RemoveButton" ); + Boolean bState = Boolean.valueOf( pSel.length != 0 ); + + xEditProps.setPropertyValue( "Enabled", bState ); + xRemoveProps.setPropertyValue( "Enabled", bState ); + } + catch ( Exception ex ) + { + ex.printStackTrace(); + } + } + } + + private void AddSetting() + { + WikiEditSettingDialog aSettingDialog = new WikiEditSettingDialog( m_xContext, "vnd.sun.star.script:WikiEditor.EditSetting?location=application" ); + if ( aSettingDialog.show() ) + RefreshView(); + + aSettingDialog.DisposeDialog(); + } + + private void EditSetting() + { + XPropertySet xListProps = GetPropSet( "WikiList" ); + if ( xListProps != null ) + { + Map ht = null; + try + { + short[] pSel = (short []) xListProps.getPropertyValue( "SelectedItems" ); + String[] pItems = (String []) xListProps.getPropertyValue("StringItemList"); + if ( pSel.length > 0 && pItems.length > pSel[0] ) + { + String selName = pItems[pSel[0]]; + ht = m_aSettings.getSettingByUrl( selName ); + } + } + catch ( Exception ex ) + { + ex.printStackTrace(); + } + + WikiEditSettingDialog aSettingDialog = new WikiEditSettingDialog(m_xContext, "vnd.sun.star.script:WikiEditor.EditSetting?location=application", ht, true ); + if ( aSettingDialog.show() ) + RefreshView(); + + aSettingDialog.DisposeDialog(); + } + } + + private void RemoveSetting() + { + XPropertySet xListProps = GetPropSet("WikiList"); + if ( xListProps != null ) + { + try + { + short[] pSel = (short []) xListProps.getPropertyValue("SelectedItems"); + String[] pItems = (String []) GetPropSet("WikiList").getPropertyValue("StringItemList"); + if ( pSel.length > 0 && pItems.length > pSel[0] ) + { + m_aSettings.removeSettingByUrl( pItems[pSel[0]] ); + RefreshView(); + } + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + } + + private void InitStrings() + { + try + { + GetPropSet( "FixedLine1" ).setPropertyValue( "Label", Helper.GetLocalizedString( m_xContext, Helper.DLG_MEDIAWIKIEXTENSION_STRING ) ); + GetPropSet( "AddButton" ).setPropertyValue( "Label", Helper.GetLocalizedString( m_xContext, Helper.DLG_ADDBUTTON ) ); + GetPropSet( "EditButton" ).setPropertyValue( "Label", Helper.GetLocalizedString( m_xContext, Helper.DLG_EDITBUTTON ) ); + GetPropSet( "RemoveButton" ).setPropertyValue( "Label", Helper.GetLocalizedString( m_xContext, Helper.DLG_REMOVEBUTTON ) ); + } + catch( Exception e ) + { + e.printStackTrace(); + } + } + + // com.sun.star.lang.XServiceInfo: + public String getImplementationName() + { + return m_sImplementationName; + } + + public boolean supportsService( String sService ) + { + int len = m_pServiceNames.length; + + for( int i=0; i < len; i++ ) + { + if ( sService.equals( m_pServiceNames[i] )) + return true; + } + return false; + } + + public String[] getSupportedServiceNames() + { + return m_pServiceNames; + } + + // XContainerWindowEventHandler + public boolean callHandlerMethod( XWindow xWindow, Object aEventObject, String sMethod ) + throws WrappedTargetException, com.sun.star.uno.RuntimeException + { + if ( sMethod.equals( sExternalEvent ) ) + { + String sEvent = AnyConverter.toString( aEventObject ); + if ( sEvent != null ) + { + if ( sEvent.equals( sOk ) ) + { + if ( m_aSettings != null ) + m_aSettings.storeConfiguration(); + } + else if ( sEvent.equals( sInitialize ) || sEvent.equals( sBack ) ) + { + if ( sEvent.equals( sInitialize ) ) + { + m_xDialog = UnoRuntime.queryInterface( XDialog.class, xWindow ); + m_xControlContainer = UnoRuntime.queryInterface( XControlContainer.class, m_xDialog ); + m_aSettings = Settings.getSettings( m_xContext ); + m_aSettings.loadConfiguration(); // throw away all the noncommitted changes + InitStrings(); + } + else if ( m_aSettings != null ) + m_aSettings.loadConfiguration(); // throw away all the noncommitted changes + + RefreshView(); + CheckButtonState(); + } + } + } + else if ( sMethod.equals( sAdd ) ) + { + AddSetting(); + } + else if ( sMethod.equals( sEdit ) || sMethod.equals( sListEdit ) ) + { + EditSetting(); + } + else if ( sMethod.equals( sRemove ) ) + { + RemoveSetting(); + CheckButtonState(); + } + else if ( sMethod.equals( sListStatus ) ) + { + CheckButtonState(); + } + + return true; + } + + public boolean callHandlerMethod( XDialog xDialog, Object aEventObject, String sMethod ) + throws WrappedTargetException, com.sun.star.uno.RuntimeException + { + return true; + } + + public String[] getSupportedMethodNames() + { + return new String[] { sExternalEvent, sAdd, sEdit, sRemove }; + } +} + diff --git a/swext/mediawiki/src/com/sun/star/wiki/WikiPropDialog.java b/swext/mediawiki/src/com/sun/star/wiki/WikiPropDialog.java new file mode 100644 index 000000000..9ac41d4d3 --- /dev/null +++ b/swext/mediawiki/src/com/sun/star/wiki/WikiPropDialog.java @@ -0,0 +1,372 @@ +/* + * 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 . + */ + +package com.sun.star.wiki; + +import java.util.Map; + +import com.sun.star.awt.XDialog; +import com.sun.star.beans.XPropertySet; +import com.sun.star.lang.EventObject; +import com.sun.star.uno.XComponentContext; + +public class WikiPropDialog extends WikiDialog{ + + private WikiEditorImpl m_aWikiEditor; + + private static final String sSendMethod = "Send"; + private static final String sWikiListMethod = "WikiListChange"; + private static final String sArticleTextMethod = "ArticleTextChange"; + private static final String sAddWikiMethod = "AddWiki"; + + private final String[] m_pMethods = {sSendMethod, sWikiListMethod, sArticleTextMethod, sAddWikiMethod}; + + private String m_sWikiTitle = ""; + private String m_sWikiEngineURL = ""; + protected String m_sWikiComment = ""; + protected boolean m_bWikiMinorEdit = false; + + /** Creates a new instance of WikiPropDialog */ + public WikiPropDialog(XComponentContext xContext, String DialogURL, WikiEditorImpl aWikiEditorForThrobber ) + { + super(xContext, DialogURL); + super.setMethods(m_pMethods); + + if ( aWikiEditorForThrobber != null ) + { + InsertThrobber( 224, 122, 10, 10 ); + m_aWikiEditor = aWikiEditorForThrobber; + } + + InitStrings( xContext ); + InitShowBrowser(); + InitControls(); + } + + private void InitControls() + { + try + { + GetPropSet( "CommentText" ).setPropertyValue( "AutoVScroll", Boolean.TRUE ); + } + catch( Exception e ) + { + e.printStackTrace(); + } + } + + private void InitStrings( XComponentContext xContext ) + { + try + { + SetTitle( Helper.GetLocalizedString( xContext, Helper.DLG_SENDTITLE ) ); + GetPropSet( "Label1" ).setPropertyValue( "Label", Helper.GetLocalizedString( xContext, Helper.DLG_SENDTOMEDIAWIKI_LABEL1 ) ); + GetPropSet( "FixedLine2" ).setPropertyValue( "Label", Helper.GetLocalizedString( xContext, Helper.DLG_WIKIARTICLE ) ); + GetPropSet( "Label2" ).setPropertyValue( "Label", Helper.GetLocalizedString( xContext, Helper.DLG_SENDTOMEDIAWIKI_LABEL2 ) ); + GetPropSet( "Label3" ).setPropertyValue( "Label", Helper.GetLocalizedString( xContext, Helper.DLG_SENDTOMEDIAWIKI_LABEL3 ) ); + GetPropSet( "MinorCheck" ).setPropertyValue( "Label", Helper.GetLocalizedString( xContext, Helper.DLG_SENDTOMEDIAWIKI_MINORCHECK ) ); + GetPropSet( "BrowserCheck" ).setPropertyValue( "Label", Helper.GetLocalizedString( xContext, Helper.DLG_SENDTOMEDIAWIKI_BROWSERCHECK ) ); + GetPropSet( "AddButton" ).setPropertyValue( "Label", Helper.GetLocalizedString( xContext, Helper.DLG_ADDBUTTON ) ); + GetPropSet( "SendButton" ).setPropertyValue( "Label", Helper.GetLocalizedString( xContext, Helper.DLG_SENDBUTTON ) ); + } + catch( Exception e ) + { + e.printStackTrace(); + } + } + + private void InitShowBrowser() + { + try + { + GetPropSet( "BrowserCheck" ).setPropertyValue( "State", Short.valueOf( Helper.GetShowInBrowserByDefault( m_xContext ) ? (short)1 : (short)0 ) ); + } + catch( Exception e ) + { + e.printStackTrace(); + } + } + + @Override + public boolean show() + { + EnableControls( true ); + boolean bResult = super.show(); + + if ( bResult && Helper.GetShowInBrowserByDefault( m_xContext ) ) + Helper.ShowURLInBrowser( m_xContext, m_sWikiEngineURL + "index.php?title=" + m_sWikiTitle ); + + return bResult; + } + + @Override + public synchronized void ThreadStop( boolean bSelf ) + { + boolean bShowError = ( !bSelf && m_aThread != null && !m_bThreadFinished ); + + super.ThreadStop( bSelf ); + + if ( bShowError ) + Helper.ShowError( m_xContext, + m_xDialog, + Helper.DLG_SENDTITLE, + Helper.CANCELSENDING_ERROR, + null, + false ); + } + + public void fillWikiList() + { + String [] WikiList = m_aSettings.getWikiURLs(); + + try + { + XPropertySet xPS = GetPropSet("WikiList"); + xPS.setPropertyValue("StringItemList", WikiList); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + + private void fillDocList() + { + XPropertySet xPS = GetPropSet("ArticleText"); + try + { + short [] sel = (short[]) GetPropSet("WikiList").getPropertyValue("SelectedItems"); + xPS.setPropertyValue("StringItemList", m_aSettings.getWikiDocList(sel[0])); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + + + public String GetWikiTitle() + { + return m_sWikiTitle; + } + + public void SetWikiTitle(String sArticle) + { + m_sWikiTitle = sArticle; + try + { + XPropertySet xPS = GetPropSet("ArticleText"); + xPS.setPropertyValue("Text", sArticle); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + + + private void switchSendButtonIfNecessary() + { + XPropertySet xSendButton = GetPropSet( "SendButton" ); + if ( xSendButton != null ) + { + XPropertySet xWikiListProps = GetPropSet( "WikiList" ); + XPropertySet xArticleProps = GetPropSet( "ArticleText" ); + if ( xWikiListProps != null && xArticleProps != null ) + { + try + { + short [] pSel = (short[]) GetPropSet("WikiList").getPropertyValue("SelectedItems"); + String sArticle = (String)xArticleProps.getPropertyValue( "Text" ); + if ( pSel != null && pSel.length > 0 && sArticle != null && sArticle.length() != 0 ) + xSendButton.setPropertyValue( "Enabled", Boolean.TRUE ); + else + xSendButton.setPropertyValue( "Enabled", Boolean.FALSE ); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + } + } + + private void EnableControls( boolean bEnable ) + { + try + { + String[] pControls = { "WikiList", + "ArticleText", + "CommentText", + "MinorCheck", + "BrowserCheck", + "HelpButton", + "AddButton" }; + + for ( int nInd = 0; nInd < pControls.length; nInd++ ) + GetPropSet( pControls[nInd] ).setPropertyValue( "Enabled", Boolean.valueOf( bEnable ) ); + + if ( bEnable ) + { + SetFocusTo( "WikiList" ); + switchSendButtonIfNecessary(); + } + else + { + GetPropSet( "SendButton" ).setPropertyValue( "Enabled", Boolean.valueOf( bEnable ) ); + SetFocusTo( "CancelButton" ); + } + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + + @Override + public boolean callHandlerMethod( XDialog xDialog, Object EventObject, String MethodName ) + { + if ( MethodName.equals( sSendMethod ) ) + { + try + { + XPropertySet aWikiListProps = GetPropSet( "WikiList" ); + XPropertySet aArticleTextProps = GetPropSet( "ArticleText" ); + XPropertySet aCommentTextProps = GetPropSet( "CommentText" ); + XPropertySet aMinorCheckProps = GetPropSet( "MinorCheck" ); + XPropertySet aBrowserCheckProps = GetPropSet( "BrowserCheck" ); + + short [] sel = (short[]) aWikiListProps.getPropertyValue("SelectedItems"); + String [] items = (String []) aWikiListProps.getPropertyValue("StringItemList"); + m_sWikiEngineURL = items[sel[0]]; + m_sWikiTitle = (String) aArticleTextProps.getPropertyValue("Text"); + m_sWikiComment = (String) aCommentTextProps.getPropertyValue("Text"); + + short minorState = ((Short) aMinorCheckProps.getPropertyValue("State")).shortValue(); + if (minorState != 0) + m_bWikiMinorEdit = true; + else + m_bWikiMinorEdit = false; + + short nBrowserState = ((Short) aBrowserCheckProps.getPropertyValue("State")).shortValue(); + Helper.SetShowInBrowserByDefault( m_xContext, nBrowserState != 0 ); + + // allow to disable other buttons + EnableControls( false ); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + + final XDialog xDialogToClose = xDialog; + final XComponentContext xContext = m_xContext; + + // start spinning + SetThrobberVisible( true ); + SetThrobberActive( true ); + + // the following method might show a dialog, should be used in main thread + final Map aWikiSettings = m_aSettings.getSettingByUrl( m_sWikiEngineURL ); + if ( Helper.AllowThreadUsage( m_xContext ) ) + { + m_aThread = new Thread( "com.sun.star.thread.WikiEditorSendingThread" ) + { + @Override + public void run() + { + try + { + if ( m_aWikiEditor != null ) + { + Thread.yield(); + m_bAction = m_aWikiEditor.SendArticleImpl( + WikiPropDialog.this, aWikiSettings); + } + } + finally + { + EnableControls( true ); + SetThrobberActive( false ); + SetThrobberVisible( false ); + + ThreadStop( true ); + if ( m_bAction ) + MainThreadDialogExecutor.Close( xContext, xDialogToClose ); + } + } + }; + + m_aThread.start(); + } + else + { + try + { + if (m_aWikiEditor != null && aWikiSettings != null) + { + m_bAction = m_aWikiEditor.SendArticleImpl( + WikiPropDialog.this, aWikiSettings); + } + } catch( java.lang.Exception e ) + {} + finally + { + EnableControls( true ); + SetThrobberActive( false ); + SetThrobberVisible( false ); + + if ( m_bAction ) + xDialogToClose.endExecute(); + } + } + + return true; + } + else if ( MethodName.equals( sWikiListMethod ) ) + { + fillDocList(); + switchSendButtonIfNecessary(); + return true; + } + else if ( MethodName.equals( sArticleTextMethod ) ) + { + switchSendButtonIfNecessary(); + return true; + } + else if ( MethodName.equals( sAddWikiMethod ) ) + { + WikiEditSettingDialog xAddDialog = new WikiEditSettingDialog(m_xContext, "vnd.sun.star.script:WikiEditor.EditSetting?location=application"); + if ( xAddDialog.show() ) + fillWikiList(); + + xAddDialog.DisposeDialog(); + + return true; + } + + return false; + } + + @Override + public void windowClosed( EventObject e ) + { + ThreadStop( false ); + } +} + diff --git a/swext/mediawiki/src/com/sun/star/wiki/WikiProtocolSocketFactory.java b/swext/mediawiki/src/com/sun/star/wiki/WikiProtocolSocketFactory.java new file mode 100644 index 000000000..7ca94390d --- /dev/null +++ b/swext/mediawiki/src/com/sun/star/wiki/WikiProtocolSocketFactory.java @@ -0,0 +1,333 @@ +/* + * 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 . + */ + +package com.sun.star.wiki; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.Socket; +import java.net.UnknownHostException; +import java.security.KeyStore; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSocket; +import javax.net.ssl.SSLSocketFactory; +import javax.net.ssl.TrustManager; +import javax.net.ssl.TrustManagerFactory; +import javax.net.ssl.X509TrustManager; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; + +class WikiProtocolSocketFactory extends SSLSocketFactory +{ + private SSLContext m_aSSLContext; + + private synchronized SSLContext GetNotSoSecureSSLContext() + { + if ( m_aSSLContext != null ) { + return m_aSSLContext; + } + TrustManager[] pTrustUnknownCerts = new TrustManager[] + { + new X509TrustManager() { + private X509TrustManager m_aOrgTrustManager; + + private X509TrustManager GetOrgTrustManager() + { + if ( m_aOrgTrustManager == null ) + { + try + { + TrustManagerFactory aFactory = TrustManagerFactory.getInstance( TrustManagerFactory.getDefaultAlgorithm() ); + aFactory.init( (KeyStore)null ); + TrustManager[] pTrustmanagers = aFactory.getTrustManagers(); + if ( pTrustmanagers.length != 0 && pTrustmanagers[0] != null ) + m_aOrgTrustManager = (X509TrustManager)pTrustmanagers[0]; + } + catch( Exception e ) + { + throw new RuntimeException( "No access to the default trust manager!", e ); + } + } + + if (m_aOrgTrustManager == null) + throw new RuntimeException("No access to the default trust manager!"); + + return m_aOrgTrustManager; + } + + public X509Certificate[] getAcceptedIssuers() + { + return GetOrgTrustManager().getAcceptedIssuers(); + } + + public void checkClientTrusted(X509Certificate[] certs, String authType) throws CertificateException + { + GetOrgTrustManager().checkClientTrusted( certs, authType ); + } + + public void checkServerTrusted(X509Certificate[] certs, String authType) throws CertificateException + { + if ( certs == null || certs.length == 0 ) + GetOrgTrustManager().checkServerTrusted( certs, authType ); + else + for ( int nInd = 0; nInd < certs.length; nInd++ ) + certs[nInd].checkValidity(); + } + } + }; + + try + { + SSLContext aContext = SSLContext.getInstance("TLSv1.2"); + if ( aContext != null ) + { + aContext.init( null, pTrustUnknownCerts, null ); + m_aSSLContext = aContext; + } + } + catch ( Exception e ) + { + } + + if ( m_aSSLContext == null ) + throw new RuntimeException("failed to create SSLContext"); + + return m_aSSLContext; + } + + @Override + public Socket createSocket(InetAddress address, int port) + throws IOException + { + return GetNotSoSecureSSLContext().getSocketFactory().createSocket(address, port); + } + + @Override + public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) + throws IOException + { + return GetNotSoSecureSSLContext().getSocketFactory().createSocket(address, port, localAddress, localPort); + } + + @Override + public Socket createSocket( String sHost, int nPort, InetAddress clientHost, int clientPort ) + throws IOException, UnknownHostException + { + return GetNotSoSecureSSLContext().getSocketFactory().createSocket( sHost, nPort, clientHost, clientPort ); + } + + @Override + public Socket createSocket( String sHost, int nPort ) + throws IOException, UnknownHostException + { + return GetNotSoSecureSSLContext().getSocketFactory().createSocket( sHost, nPort ); + } + + @Override + public Socket createSocket( Socket aSocket, String sHost, int nPort, boolean bAutoClose ) + throws IOException + { + return GetNotSoSecureSSLContext().getSocketFactory().createSocket( aSocket, sHost, nPort, bAutoClose ); + } + + @Override + public String[] getDefaultCipherSuites() + { + return GetNotSoSecureSSLContext().getSocketFactory().getDefaultCipherSuites(); + } + + @Override + public String[] getSupportedCipherSuites() + { + return GetNotSoSecureSSLContext().getSocketFactory().getSupportedCipherSuites(); + } + + @Override + public boolean equals(Object obj) + { + return (obj != null) && (obj instanceof WikiProtocolSocketFactory); + } + + @Override + public int hashCode() + { + return WikiProtocolSocketFactory.class.hashCode(); + } +} + +// A factory that creates streams that log everything that's written +// to stderr - useful for debugging encrypted TLS connections +class LoggingProtocolSocketFactory extends SSLSocketFactory +{ + private static class LogSocket extends SSLSocket + { + private final SSLSocket m_Socket; + + public LogSocket(SSLSocket socket) + { + m_Socket = socket; + } + + private static class LogStream extends java.io.FilterOutputStream + { + public LogStream(java.io.OutputStream stream) + { + super(stream); + } + + @Override + public void write(byte[] buf, int offset, int len) + throws IOException + { + System.err.println("LogStream.write: \"" + new String(buf, offset, len, "UTF-8") + "\""); + out.write(buf, offset, len); + } + } + + @Override + public java.io.OutputStream getOutputStream() throws IOException + { + return new LogStream(m_Socket.getOutputStream()); + } + + @Override public void addHandshakeCompletedListener(javax.net.ssl.HandshakeCompletedListener listener) { m_Socket.addHandshakeCompletedListener(listener); } + @Override public String[] getEnabledCipherSuites() { return m_Socket.getEnabledCipherSuites(); } + @Override public String[] getEnabledProtocols() { return m_Socket.getEnabledProtocols(); } + @Override public boolean getEnableSessionCreation() { return m_Socket.getEnableSessionCreation(); } + @Override public boolean getNeedClientAuth() { return m_Socket.getNeedClientAuth(); } + @Override public javax.net.ssl.SSLSession getSession() { return m_Socket.getSession(); } + @Override public javax.net.ssl.SSLParameters getSSLParameters() { return m_Socket.getSSLParameters(); } + @Override public String[] getSupportedCipherSuites() { return m_Socket.getSupportedCipherSuites(); } + @Override public String[] getSupportedProtocols() { return m_Socket.getSupportedProtocols(); } + @Override public boolean getUseClientMode() { return m_Socket.getUseClientMode(); } + @Override public boolean getWantClientAuth() { return m_Socket.getWantClientAuth(); } + @Override public void removeHandshakeCompletedListener(javax.net.ssl.HandshakeCompletedListener listener) { m_Socket.removeHandshakeCompletedListener(listener); } + @Override public void setEnabledCipherSuites(String[] suites) { m_Socket.setEnabledCipherSuites(suites); } + @Override public void setEnabledProtocols(String[] protocols) { m_Socket.setEnabledProtocols(protocols); } + @Override public void setEnableSessionCreation(boolean flag) { m_Socket.setEnableSessionCreation(flag); } + @Override public void setNeedClientAuth(boolean need) { m_Socket.setNeedClientAuth(need); } + @Override public void setSSLParameters(javax.net.ssl.SSLParameters params) { m_Socket.setSSLParameters(params); } + @Override public void setUseClientMode(boolean mode) { m_Socket.setUseClientMode(mode); } + @Override public void setWantClientAuth(boolean want) { m_Socket.setWantClientAuth(want); } + @Override public void startHandshake() throws IOException { m_Socket.startHandshake(); } + + @Override public void bind(java.net.SocketAddress bindpoint) throws IOException { m_Socket.bind(bindpoint); } + @Override public void close() throws IOException { m_Socket.close(); } + @Override public void connect(java.net.SocketAddress endpoint) throws IOException { m_Socket.connect(endpoint); } + @Override public void connect(java.net.SocketAddress endpoint, int timeout) throws IOException { m_Socket.connect(endpoint, timeout); } + @Override public java.nio.channels.SocketChannel getChannel() { return m_Socket.getChannel(); } + @Override public InetAddress getInetAddress() { return m_Socket.getInetAddress(); } + @Override public java.io.InputStream getInputStream() throws IOException { return m_Socket.getInputStream(); } + @Override public boolean getKeepAlive() throws java.net.SocketException { return m_Socket.getKeepAlive(); } + @Override public InetAddress getLocalAddress() { return m_Socket.getLocalAddress(); } + @Override public int getLocalPort() { return m_Socket.getLocalPort(); } + @Override public java.net.SocketAddress getLocalSocketAddress() { return m_Socket.getLocalSocketAddress(); } + @Override public boolean getOOBInline() throws java.net.SocketException { return m_Socket.getOOBInline(); } + @Override public int getPort() { return m_Socket.getPort(); } + @Override public int getReceiveBufferSize() throws java.net.SocketException { return m_Socket.getReceiveBufferSize(); } + @Override public java.net.SocketAddress getRemoteSocketAddress() { return m_Socket.getRemoteSocketAddress(); } + @Override public boolean getReuseAddress() throws java.net.SocketException { return m_Socket.getReuseAddress(); } + @Override public int getSendBufferSize() throws java.net.SocketException { return m_Socket.getSendBufferSize(); } + @Override public int getSoLinger() throws java.net.SocketException { return m_Socket.getSoLinger(); } + @Override public int getSoTimeout() throws java.net.SocketException { return m_Socket.getSoTimeout(); } + @Override public boolean getTcpNoDelay() throws java.net.SocketException { return m_Socket.getTcpNoDelay(); } + @Override public int getTrafficClass() throws java.net.SocketException { return m_Socket.getTrafficClass(); } + @Override public boolean isBound() { return m_Socket.isBound(); } + @Override public boolean isClosed() { return m_Socket.isClosed(); } + @Override public boolean isConnected() { return m_Socket.isConnected(); } + @Override public boolean isInputShutdown() { return m_Socket.isInputShutdown(); } + @Override public boolean isOutputShutdown() { return m_Socket.isOutputShutdown(); } + @Override public void sendUrgentData(int data) throws IOException { m_Socket.sendUrgentData(data); } + @Override public void setKeepAlive(boolean on) throws java.net.SocketException { m_Socket.setKeepAlive(on); } + @Override public void setOOBInline(boolean on) throws java.net.SocketException { m_Socket.setOOBInline(on); } + @Override public void setPerformancePreferences(int connectionTime, int latency, int bandwidth) { m_Socket.setPerformancePreferences(connectionTime, latency, bandwidth); } + @Override public void setReceiveBufferSize(int size) throws java.net.SocketException { m_Socket.setReceiveBufferSize(size); } + @Override public void setReuseAddress(boolean on) throws java.net.SocketException { m_Socket.setReuseAddress(on); } + @Override public void setSendBufferSize(int size) throws java.net.SocketException { m_Socket.setSendBufferSize(size); } + @Override public void setSoLinger(boolean on, int linger) throws java.net.SocketException { m_Socket.setSoLinger(on, linger); } + @Override public void setSoTimeout(int timeout) throws java.net.SocketException{ m_Socket.setSoTimeout(timeout); } + @Override public void setTcpNoDelay(boolean on) throws java.net.SocketException{ m_Socket.setTcpNoDelay(on); } + @Override public void setTrafficClass(int tc) throws java.net.SocketException { m_Socket.setTrafficClass(tc); } + @Override public void shutdownInput() throws IOException { m_Socket.shutdownInput(); } + @Override public void shutdownOutput() throws IOException { m_Socket.shutdownOutput(); } + @Override public String toString() { return m_Socket.toString(); } + + } + + @Override + public Socket createSocket(InetAddress address, int port) + throws IOException + { + return new LogSocket((SSLSocket) SSLSocketFactory.getDefault().createSocket(address, port)); + } + + @Override + public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) + throws IOException + { + return new LogSocket((SSLSocket) SSLSocketFactory.getDefault().createSocket(address, port, localAddress, localPort)); + } + + @Override + public Socket createSocket( String sHost, int nPort, InetAddress clientHost, int clientPort ) + throws IOException, UnknownHostException + { + return new LogSocket((SSLSocket) SSLSocketFactory.getDefault().createSocket(sHost, nPort, clientHost, clientPort)); + } + + @Override + public Socket createSocket( String sHost, int nPort ) + throws IOException, UnknownHostException + { + return new LogSocket((SSLSocket) SSLSocketFactory.getDefault().createSocket(sHost, nPort)); + } + + @Override + public Socket createSocket( Socket aSocket, String sHost, int nPort, boolean bAutoClose ) + throws IOException + { + return new LogSocket((SSLSocket) ((SSLSocketFactory) SSLSocketFactory.getDefault()).createSocket(aSocket, sHost, nPort, bAutoClose)); + } + + @Override + public String[] getDefaultCipherSuites() + { + // have to implement abstract method, just use the default + return ((SSLSocketFactory) SSLSocketFactory.getDefault()).getDefaultCipherSuites(); + } + + @Override + public String[] getSupportedCipherSuites() + { + // have to implement abstract method, just use the default + return ((SSLSocketFactory) SSLSocketFactory.getDefault()).getSupportedCipherSuites(); + } + + @Override + public boolean equals(Object obj) + { + return (obj != null) && (obj instanceof LoggingProtocolSocketFactory); + } + + @Override + public int hashCode() + { + return LoggingProtocolSocketFactory.class.hashCode(); + } +} + diff --git a/swext/mediawiki/src/components.rdb b/swext/mediawiki/src/components.rdb new file mode 100644 index 000000000..7cee92900 --- /dev/null +++ b/swext/mediawiki/src/components.rdb @@ -0,0 +1,19 @@ + + + + + + + + + + + + diff --git a/swext/mediawiki/src/description-en-US.txt b/swext/mediawiki/src/description-en-US.txt new file mode 100644 index 000000000..d993ce105 --- /dev/null +++ b/swext/mediawiki/src/description-en-US.txt @@ -0,0 +1 @@ +The Wiki Publisher enables you to create Wiki articles on MediaWiki servers without having to know the syntax of the MediaWiki markup language. Publish your new and existing documents transparently with the Writer to a wiki page. diff --git a/swext/mediawiki/src/description.xml b/swext/mediawiki/src/description.xml new file mode 100644 index 000000000..e83d4f308 --- /dev/null +++ b/swext/mediawiki/src/description.xml @@ -0,0 +1,34 @@ + + + + + + + Wiki Publisher + + + + + + The Document Foundation + + + + + diff --git a/swext/mediawiki/src/filter/mediawiki.ott b/swext/mediawiki/src/filter/mediawiki.ott new file mode 100644 index 000000000..eb94e9607 Binary files /dev/null and b/swext/mediawiki/src/filter/mediawiki.ott differ diff --git a/swext/mediawiki/src/filter/odt2mediawiki.xsl b/swext/mediawiki/src/filter/odt2mediawiki.xsl new file mode 100644 index 000000000..435f0f498 --- /dev/null +++ b/swext/mediawiki/src/filter/odt2mediawiki.xsl @@ -0,0 +1,2012 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/swext/mediawiki/src/registry/data/org/openoffice/Office/Addons.xcu b/swext/mediawiki/src/registry/data/org/openoffice/Office/Addons.xcu new file mode 100644 index 000000000..854c7b94c --- /dev/null +++ b/swext/mediawiki/src/registry/data/org/openoffice/Office/Addons.xcu @@ -0,0 +1,58 @@ + + + + + + + + + .uno:PickList\.uno:SendToMenu\.uno:SendMailDocAsPDF + + + AddAfter + + + AddLast + + + com.sun.star.text.TextDocument,com.sun.star.text.WebDocument + + + + + private:separator + + + + + To Media~Wiki... + + + vnd.com.sun.star.wiki:send + + + _self + + + + + + + + diff --git a/swext/mediawiki/src/registry/data/org/openoffice/Office/Custom/WikiExtension.xcu b/swext/mediawiki/src/registry/data/org/openoffice/Office/Custom/WikiExtension.xcu new file mode 100644 index 000000000..729f80b56 --- /dev/null +++ b/swext/mediawiki/src/registry/data/org/openoffice/Office/Custom/WikiExtension.xcu @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + true + + + + + The operation 'Send to MediaWiki' could not be completed successfully. + + + The MediaWiki export filter cannot be found. Choose 'Tools-XML Filter Settings' to install the filter, or use the setup to install the component. + + + A connection to the MediaWiki system at '$ARG1' could not be created. + + + User name or password is incorrect. Please try again, or leave the fields blank for an anonymous connection. + + + A connection could not be created because the URL is invalid. + + + Specify a MediaWiki server by providing a URL. + + + The transfer has been interrupted. Please check the integrity of the wiki article. + + + U~RL + + + ~Username + + + ~Password + + + Send to MediaWiki + + + Wiki article + + + No + + + OK + + + Yes + + + ~Add... + + + ~Edit... + + + ~Send + + + ~Remove + + + A wiki article with the title '$ARG1' does not exist yet. Do you want to create a new article with that name? + + + Media~Wiki Server + + + ~Title + + + S~ummary + + + This is a ~minor edit + + + Show in web ~browser + + + The certificate of the selected site is unknown. + + + MediaWiki + + + Account + + + MediaWiki Server + + + ~Save password + + + Wiki Publisher + + + A wiki article with the title '$ARG1' already exists. Do you want to replace the current article with your article? + + + diff --git a/swext/mediawiki/src/registry/data/org/openoffice/Office/OptionsDialog.xcu b/swext/mediawiki/src/registry/data/org/openoffice/Office/OptionsDialog.xcu new file mode 100644 index 000000000..2b35ced08 --- /dev/null +++ b/swext/mediawiki/src/registry/data/org/openoffice/Office/OptionsDialog.xcu @@ -0,0 +1,41 @@ + + + + + + + + + com.sun.wiki-publisher + + + MediaWiki + + + %origin%/WikiEditor/Settings.xdl + + + com.sun.star.wiki.WikiOptionsEventHandlerImpl + + + + + + + diff --git a/swext/mediawiki/src/registry/data/org/openoffice/Office/Paths.xcu b/swext/mediawiki/src/registry/data/org/openoffice/Office/Paths.xcu new file mode 100644 index 000000000..01763bfd6 --- /dev/null +++ b/swext/mediawiki/src/registry/data/org/openoffice/Office/Paths.xcu @@ -0,0 +1,27 @@ + + + + + + + + + + + diff --git a/swext/mediawiki/src/registry/data/org/openoffice/Office/ProtocolHandler.xcu b/swext/mediawiki/src/registry/data/org/openoffice/Office/ProtocolHandler.xcu new file mode 100644 index 000000000..8337a2abc --- /dev/null +++ b/swext/mediawiki/src/registry/data/org/openoffice/Office/ProtocolHandler.xcu @@ -0,0 +1,27 @@ + + + + + + + vnd.com.sun.star.wiki:* + + + + diff --git a/swext/mediawiki/src/registry/data/org/openoffice/TypeDetection/Filter.xcu b/swext/mediawiki/src/registry/data/org/openoffice/TypeDetection/Filter.xcu new file mode 100644 index 000000000..3309b5038 --- /dev/null +++ b/swext/mediawiki/src/registry/data/org/openoffice/TypeDetection/Filter.xcu @@ -0,0 +1,47 @@ + + + + + + + 0 + MediaWiki + com.sun.star.text.TextDocument + + com.sun.star.documentconversion.XSLTFilter,,,com.sun.star.comp.Writer.XMLOasisExporter,,%origin%/filter/odt2mediawiki.xsl + com.sun.star.comp.Writer.XmlFilterAdaptor + + MediaWiki + + EXPORT ALIEN 3RDPARTYFILTER + + + 0 + MediaWiki + com.sun.star.text.WebDocument + + com.sun.star.documentconversion.XSLTFilter,,,com.sun.star.comp.Writer.XMLOasisExporter,,%origin%/filter/odt2mediawiki.xsl + com.sun.star.comp.Writer.XmlFilterAdaptor + + MediaWiki + + EXPORT ALIEN 3RDPARTYFILTER + + + diff --git a/swext/mediawiki/src/registry/data/org/openoffice/TypeDetection/Types.xcu b/swext/mediawiki/src/registry/data/org/openoffice/TypeDetection/Types.xcu new file mode 100644 index 000000000..15e4f8500 --- /dev/null +++ b/swext/mediawiki/src/registry/data/org/openoffice/TypeDetection/Types.xcu @@ -0,0 +1,35 @@ + + + + + + + com.sun.star.comp.filters.XMLFilterDetect + + txt + + false + + + MediaWiki + + + + + diff --git a/swext/mediawiki/src/registry/schema/org/openoffice/Office/Custom/WikiExtension.xcs b/swext/mediawiki/src/registry/schema/org/openoffice/Office/Custom/WikiExtension.xcs new file mode 100644 index 000000000..c0147ae7b --- /dev/null +++ b/swext/mediawiki/src/registry/schema/org/openoffice/Office/Custom/WikiExtension.xcs @@ -0,0 +1,188 @@ + + + + + Configuration parameters for the accounts. + + + + + An argument for a request. + + The value of the argument. + + + + + The smart configuration for the MediaWikiServer. + + The value of the argument. + + + The additional arguments that can be used on login. The name of an entry is the argument name. + + + + + The name of the entry is a connection URL of a wiki server. + + The UserName that is used to access the URL. + + + + + Wiki Document + + Main URL for this Wiki + + + The Document name + + + Identifier + + + + + + + The set of smart configurations for MediaWiki Servers. + + + The list of the MediaWiki servers. + + + The recently stored documents. + + + The addon related settings. + + Specifies whether "Show in webbrowser" checkbox should be preselected. + + + + + Contains the strings that should be localized + + + The general error shown in case the document could not be sent to the wiki server. + + + The error is shown in case wiki filter is not evailable. + + + The error is shown in case no wiki system was found on specified URL. + + + The error is shown in case user name or password is incorrect. + + + The error is shown in case the provided URL has invalid syntax. + + + The error is shown in case no wiki server was specified. + + + The error is shown in case transfer was interrupted by user. The user is notified that the integrity of the wiki article should be checked. + + + The title of the send dialog. + + + The dialog string used to border the wiki article related information. + + + "No" button in dialog. + + + "Ok" button in dialog. + + + "Yes" button in dialog. + + + "Add..." button text. + + + "Edit..." button text. + + + "Send" button text. + + + "Remove" button text. + + + "URL" label. + + + "Username" label. + + + "Password" label. + + + The text asking whether a new wiki page should be created. + + + The label referring to the MediaWiki server selection. + + + The label referring to the input of wiki article title. + + + The label referring to the comments input. + + + Text for checkbox specifying whether it is a minor input. + + + Text for checkbox specifying whether the article should be shown in browser after editing. + + + The error is shown in case a wiki site is accessed using https and has an unknown certificate. + + + "MediaWiki" string that is used as title in some dialogs. + + + The text bordering the account information in the dialog. + + + The text bordering wiki server information in the dialog. + + + The checkbox specifying whether the password should be stored using the password container. + + + The string containing the name of the extension. + + + The text asking whether an existing wiki page should be overwritten. + + + + + -- cgit v1.2.3