diff options
Diffstat (limited to 'filter/source/xsltdialog')
40 files changed, 8526 insertions, 0 deletions
diff --git a/filter/source/xsltdialog/exports.dxp b/filter/source/xsltdialog/exports.dxp new file mode 100644 index 000000000000..f0e1c69934bc --- /dev/null +++ b/filter/source/xsltdialog/exports.dxp @@ -0,0 +1,2 @@ +component_getImplementationEnvironment +component_getFactory diff --git a/filter/source/xsltdialog/hidother.src b/filter/source/xsltdialog/hidother.src new file mode 100644 index 000000000000..efac7d4451be --- /dev/null +++ b/filter/source/xsltdialog/hidother.src @@ -0,0 +1,78 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "xmlfilterhelpids.hrc" + +hidspecial HID_XML_SOURCE_FILE_DIALOG { HelpId = HID_XML_SOURCE_FILE_DIALOG; }; +hidspecial HID_XML_SOURCE_FILE_VALIDATE { HelpId = HID_XML_SOURCE_FILE_VALIDATE; }; +hidspecial HID_XML_FILTER_SETTINGS_DIALOG { HelpId = HID_XML_FILTER_SETTINGS_DIALOG; }; +hidspecial HID_XML_FILTER_LIST { HelpId = HID_XML_FILTER_LIST; }; +hidspecial HID_XML_FILTER_NEW { HelpId = HID_XML_FILTER_NEW; }; +hidspecial HID_XML_FILTER_EDIT { HelpId = HID_XML_FILTER_EDIT; }; +hidspecial HID_XML_FILTER_TEST { HelpId = HID_XML_FILTER_TEST; }; +hidspecial HID_XML_FILTER_DELETE { HelpId = HID_XML_FILTER_DELETE; }; +hidspecial HID_XML_FILTER_SAVE { HelpId = HID_XML_FILTER_SAVE; }; +hidspecial HID_XML_FILTER_OPEN { HelpId = HID_XML_FILTER_OPEN; }; +hidspecial HID_XML_FILTER_CLOSE { HelpId = HID_XML_FILTER_CLOSE; }; + +hidspecial HID_XML_FILTER_TABDIALOG { HelpId = HID_XML_FILTER_TABDIALOG; }; +hidspecial HID_XML_FILTER_TABPAGE_BASIC { HelpId = HID_XML_FILTER_TABPAGE_BASIC; }; +hidspecial HID_XML_FILTER_TABPAGE_XSLT { HelpId = HID_XML_FILTER_TABPAGE_XSLT; }; +hidspecial HID_XML_FILTER_NAME { HelpId = HID_XML_FILTER_NAME; }; +hidspecial HID_XML_FILTER_APPLICATION { HelpId = HID_XML_FILTER_APPLICATION; }; +hidspecial HID_XML_FILTER_INTERFACE_NAME { HelpId = HID_XML_FILTER_INTERFACE_NAME; }; +hidspecial HID_XML_FILTER_EXTENSION { HelpId = HID_XML_FILTER_EXTENSION; }; +hidspecial HID_XML_FILTER_DESCRIPTION { HelpId = HID_XML_FILTER_DESCRIPTION; }; +hidspecial HID_XML_FILTER_DOCTYPE { HelpId = HID_XML_FILTER_DOCTYPE; }; +hidspecial HID_XML_FILTER_DTD { HelpId = HID_XML_FILTER_DTD; }; +hidspecial HID_XML_FILTER_DTD_BROWSE { HelpId = HID_XML_FILTER_DTD_BROWSE; }; +hidspecial HID_XML_FILTER_EXPORT_XSLT { HelpId = HID_XML_FILTER_EXPORT_XSLT; }; +hidspecial HID_XML_FILTER_EXPORT_XSLT_BROWSE { HelpId = HID_XML_FILTER_EXPORT_XSLT_BROWSE; }; +hidspecial HID_XML_FILTER_IMPORT_XSLT { HelpId = HID_XML_FILTER_IMPORT_XSLT; }; +hidspecial HID_XML_FILTER_IMPORT_XSLT_BROWSE { HelpId = HID_XML_FILTER_IMPORT_XSLT_BROWSE; }; +hidspecial HID_XML_FILTER_IMPORT_TEMPLATE { HelpId = HID_XML_FILTER_IMPORT_TEMPLATE; }; +hidspecial HID_XML_FILTER_IMPORT_TEMPLATE_BROWSE { HelpId = HID_XML_FILTER_IMPORT_TEMPLATE_BROWSE; }; + +hidspecial HID_XML_FILTER_TEST_DIALOG { HelpId = HID_XML_FILTER_TEST_DIALOG; }; + +hidspecial HID_XML_FILTER_TEST_EXPORT_BROWSE { HelpId = HID_XML_FILTER_TEST_EXPORT_BROWSE; }; +hidspecial HID_XML_FILTER_TEST_EXPORT_CURRENT { HelpId = HID_XML_FILTER_TEST_EXPORT_CURRENT; }; +hidspecial HID_XML_FILTER_TEST_EXPORT_CURRENT_FILE { HelpId = HID_XML_FILTER_TEST_EXPORT_CURRENT_FILE; }; + +hidspecial HID_XML_FILTER_TEST_IMPORT_XSLT_FILE { HelpId = HID_XML_FILTER_TEST_IMPORT_XSLT_FILE; }; +hidspecial HID_XML_FILTER_TEST_IMPORT_TEMPLATE_FILE { HelpId = HID_XML_FILTER_TEST_IMPORT_TEMPLATE_FILE; }; +hidspecial HID_XML_FILTER_TEST_IMPORT_DISPLAY_SOURCE { HelpId = HID_XML_FILTER_TEST_IMPORT_DISPLAY_SOURCE; }; +hidspecial HID_XML_FILTER_TEST_IMPORT_BROWSE { HelpId = HID_XML_FILTER_TEST_IMPORT_BROWSE; }; +hidspecial HID_XML_FILTER_TEST_IMPORT_RECENT { HelpId = HID_XML_FILTER_TEST_IMPORT_RECENT; }; +hidspecial HID_XML_FILTER_TEST_IMPORT_RECENT_FILE { HelpId = HID_XML_FILTER_TEST_IMPORT_RECENT_FILE; }; +hidspecial HID_XML_FILTER_TEST_CLOSE { HelpId = HID_XML_FILTER_TEST_CLOSE; }; + +hidspecial HID_XML_FILTER_TEST_VALIDATE_OUPUT { HelpId = HID_XML_FILTER_TEST_VALIDATE_OUPUT; }; +hidspecial HID_XML_FILTER_OUTPUT_WINDOW { HelpId = HID_XML_FILTER_OUTPUT_WINDOW; }; + +hidspecial HID_XML_FILTER_TEST_EXPORT_XSLT_FILE { HelpId = HID_XML_FILTER_TEST_EXPORT_XSLT_FILE; }; +hidspecial HID_XML_FILTER_TABPAGE_CTRL { HelpId = HID_XML_FILTER_TABPAGE_CTRL; }; diff --git a/filter/source/xsltdialog/makefile.mk b/filter/source/xsltdialog/makefile.mk new file mode 100644 index 000000000000..c8b95594df4f --- /dev/null +++ b/filter/source/xsltdialog/makefile.mk @@ -0,0 +1,102 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. +PRJNAME=filter +TARGET=xsltdlg + +ENABLE_EXCEPTIONS=TRUE +USE_DEFFILE=TRUE +#GEN_HID=TRUE +GEN_HID_OTHER=TRUE + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +# --- Files ------------------------------------- + +SRS1NAME=$(TARGET) +SRC1FILES = xmlfiltersettingsdialog.src \ + xmlfiltertabdialog.src \ + xmlfiltertabpagebasic.src \ + xmlfiltertabpagexslt.src \ + xmlfiltertestdialog.src \ + xmlfileview.src \ + xmlfilterdialogstrings.src + +SLOFILES= $(SLO)$/typedetectionimport.obj \ + $(SLO)$/typedetectionexport.obj \ + $(SLO)$/xmlfilterjar.obj \ + $(SLO)$/xmlfilterdialogcomponent.obj \ + $(SLO)$/xmlfiltersettingsdialog.obj \ + $(SLO)$/xmlfiltertabdialog.obj \ + $(SLO)$/xmlfiltertabpagebasic.obj \ + $(SLO)$/xmlfiltertabpagexslt.obj \ + $(SLO)$/xmlfiltertestdialog.obj \ + $(SLO)$/xmlfileview.obj + +# --- Library ----------------------------------- + +RESLIB1NAME=$(TARGET) +RESLIB1SRSFILES= $(SRS)$/$(TARGET).srs + +SHL1TARGET=$(TARGET)$(DLLPOSTFIX) + +SHL1STDLIBS=\ + $(SFX2LIB) \ + $(SVTOOLLIB) \ + $(SVLLIB) \ + $(TKLIB) \ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(COMPHELPERLIB) \ + $(SALLIB) \ + $(TOOLSLIB) \ + $(VCLLIB) \ + $(UNOTOOLSLIB) \ + $(ONELIB) + +SHL1DEPN= +SHL1IMPLIB= i$(SHL1TARGET) +SHL1LIBS= $(SLB)$/$(TARGET).lib +SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME=$(SHL1TARGET) +DEF1EXPORTFILE=exports.dxp + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + +ALLTAR : $(MISC)/xsltdlg.component + +$(MISC)/xsltdlg.component .ERRREMOVE : $(SOLARENV)/bin/createcomponent.xslt \ + xsltdlg.component + $(XSLTPROC) --nonet --stringparam uri \ + '$(COMPONENTPREFIX_BASIS_NATIVE)$(SHL1TARGETN:f)' -o $@ \ + $(SOLARENV)/bin/createcomponent.xslt xsltdlg.component diff --git a/filter/source/xsltdialog/typedetectionexport.cxx b/filter/source/xsltdialog/typedetectionexport.cxx new file mode 100644 index 000000000000..e3cccd8dd6c1 --- /dev/null +++ b/filter/source/xsltdialog/typedetectionexport.cxx @@ -0,0 +1,298 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_filter.hxx" + +#ifndef _COM_SUN_STAR_XML_SAX_XATTRIBUTELIST_HXX +#include <com/sun/star/xml/sax/XAttributeList.hpp> +#endif +#ifndef _COM_SUN_STAR_XML_BEANS_PROPERTYVALUE_HPP +#include <com/sun/star/beans/PropertyValue.hpp> +#endif +#include <com/sun/star/io/XActiveDataSource.hpp> +#include <tools/urlobj.hxx> + +#include "typedetectionexport.hxx" +#include "xmlfiltersettingsdialog.hxx" + +#include <comphelper/attributelist.hxx> + +using namespace rtl; +using namespace com::sun::star::beans; +using namespace com::sun::star::uno; +using namespace com::sun::star::io; +using namespace com::sun::star::lang; +using namespace com::sun::star::xml::sax; + +TypeDetectionExporter::TypeDetectionExporter( Reference< XMultiServiceFactory >& xMSF ) +: mxMSF( xMSF ) +{ +} + +static OUString createRelativeURL( const OUString& rFilterName, const OUString& rURL ) +{ + if( rURL.getLength() && + (rURL.compareToAscii( RTL_CONSTASCII_STRINGPARAM("http:") ) != 0) && + (rURL.compareToAscii( RTL_CONSTASCII_STRINGPARAM("shttp:") ) != 0) && + (rURL.compareToAscii( RTL_CONSTASCII_STRINGPARAM("jar:") ) != 0) && + (rURL.compareToAscii( RTL_CONSTASCII_STRINGPARAM("ftp:") ) != 0)) + { + INetURLObject aURL( rURL ); + OUString aName( aURL.GetName() ); + if( aName.getLength() == 0 ) + { + sal_Int32 nPos = rURL.lastIndexOf( sal_Unicode( '/' ) ); + if( nPos == -1 ) + { + aName = rURL; + } + else + { + aName = rURL.copy( nPos + 1 ); + } + } + + OUString aRelURL( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.Package:" ) ); + aRelURL += rFilterName; + aRelURL += OUString( sal_Unicode( '/' ) ); + aRelURL += aName; + return aRelURL; + } + else + { + return rURL; + } +} + +void TypeDetectionExporter::doExport( Reference< XOutputStream > xOS, const XMLFilterVector& rFilters ) +{ + try + { + const OUString sComponentData ( RTL_CONSTASCII_USTRINGPARAM ( "oor:component-data" ) ); + const OUString sNode ( RTL_CONSTASCII_USTRINGPARAM ( "node" ) ); + const OUString sName ( RTL_CONSTASCII_USTRINGPARAM ( "oor:name" ) ); + const OUString sWhiteSpace ( RTL_CONSTASCII_USTRINGPARAM ( " " ) ); + const OUString sUIName ( RTL_CONSTASCII_USTRINGPARAM ( "UIName" ) ); + const OUString sComma ( RTL_CONSTASCII_USTRINGPARAM ( "," ) ); + const OUString sDelim ( RTL_CONSTASCII_USTRINGPARAM ( ";" ) ); + const OUString sData ( RTL_CONSTASCII_USTRINGPARAM ( "Data" ) ); + const OUString sDocTypePrefix ( RTL_CONSTASCII_USTRINGPARAM ( "doctype:" ) ); + const OUString sFilterAdaptorService( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.Writer.XmlFilterAdaptor" ) ); + const OUString sXSLTFilterService ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.documentconversion.XSLTFilter" ) ); + const OUString sCdataAttribute ( RTL_CONSTASCII_USTRINGPARAM( "CDATA" ) ); + + + // set up sax writer and connect to given output stream + Reference< XDocumentHandler > xHandler( mxMSF->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.sax.Writer" ) ) ), UNO_QUERY ); + Reference< XActiveDataSource > xDocSrc( xHandler, UNO_QUERY ); + xDocSrc->setOutputStream( xOS ); + + ::comphelper::AttributeList * pAttrList = new ::comphelper::AttributeList; + pAttrList->AddAttribute ( OUString::createFromAscii( "xmlns:oor" ), sCdataAttribute, OUString::createFromAscii( "http://openoffice.org/2001/registry" ) ); + pAttrList->AddAttribute ( OUString::createFromAscii( "xmlns:xs" ), sCdataAttribute, OUString::createFromAscii( "http://www.w3.org/2001/XMLSchema" ) ); + pAttrList->AddAttribute ( sName, sCdataAttribute, OUString::createFromAscii( "TypeDetection" ) ); + pAttrList->AddAttribute ( OUString::createFromAscii( "oor:package" ), sCdataAttribute, OUString::createFromAscii( "org.openoffice.Office" ) ); + Reference < XAttributeList > xAttrList (pAttrList); + + xHandler->startDocument(); + xHandler->ignorableWhitespace ( sWhiteSpace ); + xHandler->startElement( sComponentData, xAttrList ); + + // export types + { + xAttrList = pAttrList = new ::comphelper::AttributeList; + pAttrList->AddAttribute ( sName, sCdataAttribute, OUString::createFromAscii( "Types" ) ); + xHandler->ignorableWhitespace ( sWhiteSpace ); + xHandler->startElement( sNode, xAttrList ); + + XMLFilterVector::const_iterator aIter( rFilters.begin() ); + while( aIter != rFilters.end() ) + { + const filter_info_impl* pFilter = (*aIter); + + xAttrList = pAttrList = new ::comphelper::AttributeList; + pAttrList->AddAttribute( sName, sCdataAttribute, pFilter->maType ); + xHandler->ignorableWhitespace ( sWhiteSpace ); + xHandler->startElement( sNode, xAttrList ); + OUString sValue( sal_Unicode('0') ); + sValue += sComma; + sValue += sComma; + if( pFilter->maDocType.getLength() ) + { + sValue += sDocTypePrefix; + sValue += pFilter->maDocType; + } + sValue += sComma; + sValue += sComma; + sValue += pFilter->maExtension; + sValue += sComma; + sValue += OUString::valueOf( pFilter->mnDocumentIconID ); + sValue += sComma; + + addProperty( xHandler, sData, sValue ); + addLocaleProperty( xHandler, sUIName, pFilter->maInterfaceName ); + xHandler->ignorableWhitespace ( sWhiteSpace ); + xHandler->endElement( sNode ); + + aIter++; + } + + xHandler->ignorableWhitespace ( sWhiteSpace ); + xHandler->endElement( sNode ); + } + + // export filters + { + xAttrList = pAttrList = new ::comphelper::AttributeList; + pAttrList->AddAttribute ( sName, sCdataAttribute, OUString::createFromAscii( "Filters" ) ); + xHandler->ignorableWhitespace ( sWhiteSpace ); + xHandler->startElement( sNode, xAttrList ); + + XMLFilterVector::const_iterator aIter( rFilters.begin() ); + while( aIter != rFilters.end() ) + { + const filter_info_impl* pFilter = (*aIter); + + xAttrList = pAttrList = new ::comphelper::AttributeList; + pAttrList->AddAttribute( sName, sCdataAttribute, pFilter->maFilterName ); + xHandler->ignorableWhitespace ( sWhiteSpace ); + xHandler->startElement( sNode, xAttrList ); + addLocaleProperty( xHandler, sUIName, pFilter->maInterfaceName ); + + OUString sValue( sal_Unicode('0') ); + sValue += sComma; + sValue += pFilter->maType; + sValue += sComma, + sValue += pFilter->maDocumentService; + sValue += sComma, + sValue += sFilterAdaptorService; + sValue += sComma, + sValue += OUString::valueOf( pFilter->maFlags ); + sValue += sComma; + sValue += sXSLTFilterService; + sValue += sDelim; + sValue += sDelim; + + const application_info_impl* pAppInfo = getApplicationInfo( pFilter->maExportService ); + sValue += pAppInfo->maXMLImporter; + sValue += sDelim; + sValue += pAppInfo->maXMLExporter; + sValue += sDelim; + + sValue += createRelativeURL( pFilter->maFilterName, pFilter->maImportXSLT ); + sValue += sDelim; + sValue += createRelativeURL( pFilter->maFilterName, pFilter->maExportXSLT ); + sValue += sDelim; + sValue += createRelativeURL( pFilter->maFilterName, pFilter->maDTD ); + sValue += sDelim; + sValue += pFilter->maComment; + sValue += sComma; + sValue += OUString( sal_Unicode('0') ); + sValue += sComma; + sValue += createRelativeURL( pFilter->maFilterName, pFilter->maImportTemplate ); + addProperty( xHandler, sData, sValue ); + xHandler->ignorableWhitespace ( sWhiteSpace ); + xHandler->endElement( sNode ); + aIter++; + } + + xHandler->endElement( sNode ); + } + + // finish + xHandler->ignorableWhitespace ( sWhiteSpace ); + xHandler->endElement( sComponentData ); + xHandler->endDocument(); + } + catch( Exception& ) + { + DBG_ERROR( "TypeDetectionExporter::doExport exception catched!" ); + } +} + +void TypeDetectionExporter::addProperty( Reference< XDocumentHandler > xHandler, const OUString& rName, const OUString& rValue ) +{ + try + { + const OUString sCdataAttribute( RTL_CONSTASCII_USTRINGPARAM( "CDATA" ) ); + const OUString sProp( RTL_CONSTASCII_USTRINGPARAM( "prop" ) ); + const OUString sValue( RTL_CONSTASCII_USTRINGPARAM( "value" ) ); + const OUString sWhiteSpace ( RTL_CONSTASCII_USTRINGPARAM ( " " ) ); + + ::comphelper::AttributeList * pAttrList = new ::comphelper::AttributeList; + pAttrList->AddAttribute ( OUString::createFromAscii( "oor:name" ), sCdataAttribute, rName ); + pAttrList->AddAttribute ( OUString::createFromAscii( "oor:type" ), sCdataAttribute, OUString::createFromAscii( "xs:string" ) ); + Reference < XAttributeList > xAttrList (pAttrList); + + xHandler->ignorableWhitespace ( sWhiteSpace ); + xHandler->startElement( sProp, xAttrList ); + xAttrList = NULL; + xHandler->ignorableWhitespace ( sWhiteSpace ); + xHandler->startElement( sValue,xAttrList ); + xHandler->characters( rValue ); + xHandler->endElement( sValue ); + xHandler->ignorableWhitespace ( sWhiteSpace ); + xHandler->endElement( sProp ); + } + catch( Exception& ) + { + DBG_ERROR( "TypeDetectionExporter::addProperty exception catched!" ); + } +} + +void TypeDetectionExporter::addLocaleProperty( Reference< XDocumentHandler > xHandler, const OUString& rName, const OUString& rValue ) +{ + try + { + const OUString sCdataAttribute( RTL_CONSTASCII_USTRINGPARAM( "CDATA" ) ); + const OUString sProp( RTL_CONSTASCII_USTRINGPARAM( "prop" ) ); + const OUString sValue( RTL_CONSTASCII_USTRINGPARAM( "value" ) ); + const OUString sWhiteSpace ( RTL_CONSTASCII_USTRINGPARAM ( " " ) ); + + ::comphelper::AttributeList * pAttrList = new ::comphelper::AttributeList; + pAttrList->AddAttribute ( OUString::createFromAscii( "oor:name" ), sCdataAttribute, rName ); + pAttrList->AddAttribute ( OUString::createFromAscii( "oor:type" ), sCdataAttribute, OUString::createFromAscii( "xs:string" ) ); + Reference < XAttributeList > xAttrList (pAttrList); + + xHandler->ignorableWhitespace ( sWhiteSpace ); + xHandler->startElement( sProp, xAttrList ); + xAttrList = pAttrList = new ::comphelper::AttributeList; + pAttrList->AddAttribute ( OUString::createFromAscii( "xml:lang" ), sCdataAttribute, OUString::createFromAscii( "en-US" ) ); + xHandler->ignorableWhitespace ( sWhiteSpace ); + xHandler->startElement( sValue, xAttrList ); + xHandler->characters( rValue ); + xHandler->endElement( sValue ); + xHandler->ignorableWhitespace ( sWhiteSpace ); + xHandler->endElement( sProp ); + } + catch( Exception& ) + { + DBG_ERROR( "TypeDetectionExporter::addLocaleProperty exception catched!" ); + } +} + diff --git a/filter/source/xsltdialog/typedetectionexport.hxx b/filter/source/xsltdialog/typedetectionexport.hxx new file mode 100644 index 000000000000..09dfb5d12d4d --- /dev/null +++ b/filter/source/xsltdialog/typedetectionexport.hxx @@ -0,0 +1,53 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _TYPEDETECTION_EXPORT_HXX +#define _TYPEDETECTION_EXPORT_HXX + +#ifndef _COM_SUN_STAR_XML_SAX_XDOCUMENTHANDLER_HXX +#include <com/sun/star/xml/sax/XDocumentHandler.hpp> +#endif +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/io/XOutputStream.hpp> + +#include "xmlfilterjar.hxx" + +class TypeDetectionExporter +{ +public: + TypeDetectionExporter( com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& xMSF ); + + void doExport(com::sun::star::uno::Reference < com::sun::star::io::XOutputStream > xOS, const XMLFilterVector& rFilters ); + +private: + void addProperty( com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler > xWriter, const rtl::OUString& rName, const rtl::OUString& rValue ); + void addLocaleProperty( com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler > xWriter, const rtl::OUString& rName, const rtl::OUString& rValue ); + + com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > mxMSF; +}; + +#endif diff --git a/filter/source/xsltdialog/typedetectionimport.cxx b/filter/source/xsltdialog/typedetectionimport.cxx new file mode 100644 index 000000000000..392e034ceae3 --- /dev/null +++ b/filter/source/xsltdialog/typedetectionimport.cxx @@ -0,0 +1,362 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_filter.hxx" +#include <com/sun/star/xml/sax/InputSource.hpp> +#include <com/sun/star/xml/sax/XParser.hpp> +#include <com/sun/star/xml/sax/XAttributeList.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <tools/debug.hxx> + +#include "typedetectionimport.hxx" +#include "xmlfiltersettingsdialog.hxx" + +using namespace com::sun::star::lang; +using namespace com::sun::star::uno; +using namespace com::sun::star::io; +using namespace com::sun::star::beans; +using namespace com::sun::star::xml::sax; +using namespace com::sun::star; +using namespace rtl; +using namespace std; + +TypeDetectionImporter::TypeDetectionImporter( Reference< XMultiServiceFactory >& xMSF ) +: mxMSF(xMSF), + sRootNode( RTL_CONSTASCII_USTRINGPARAM( "oor:component-data" ) ), + sNode( RTL_CONSTASCII_USTRINGPARAM( "node" ) ), + sName( RTL_CONSTASCII_USTRINGPARAM( "oor:name" ) ), + sProp( RTL_CONSTASCII_USTRINGPARAM( "prop" ) ), + sValue( RTL_CONSTASCII_USTRINGPARAM( "value" ) ), + sUIName( RTL_CONSTASCII_USTRINGPARAM( "UIName" ) ), + sData( RTL_CONSTASCII_USTRINGPARAM( "Data" ) ), + sFilters( RTL_CONSTASCII_USTRINGPARAM( "Filters" ) ), + sTypes( RTL_CONSTASCII_USTRINGPARAM( "Types" ) ), + sFilterAdaptorService( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.Writer.XmlFilterAdaptor" ) ), + sXSLTFilterService( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.documentconversion.XSLTFilter" ) ), + sCdataAttribute( RTL_CONSTASCII_USTRINGPARAM( "CDATA" ) ), + sWhiteSpace( RTL_CONSTASCII_USTRINGPARAM( " " ) ) +{ +} + +TypeDetectionImporter::~TypeDetectionImporter (void ) +{ +} + +void TypeDetectionImporter::doImport( Reference< XMultiServiceFactory >& xMSF, Reference< XInputStream > xIS, XMLFilterVector& rFilters ) +{ + try + { + Reference< XParser > xParser( xMSF->createInstance(OUString::createFromAscii( "com.sun.star.xml.sax.Parser" ) ), UNO_QUERY ); + if( xParser.is() ) + { + TypeDetectionImporter* pImporter = new TypeDetectionImporter( xMSF ); + Reference < XDocumentHandler > xDocHandler( pImporter ); + xParser->setDocumentHandler( xDocHandler ); + + InputSource source; + source.aInputStream = xIS; + + // start parsing + xParser->parseStream( source ); + + pImporter->fillFilterVector( rFilters ); + } + } + catch( Exception& /* e */ ) + { + DBG_ERROR( "TypeDetectionImporter::doImport exception catched!" ); + } +} + +void TypeDetectionImporter::fillFilterVector( XMLFilterVector& rFilters ) +{ + // create filter infos from imported filter nodes + NodeVector::iterator aIter = maFilterNodes.begin(); + while( aIter != maFilterNodes.end() ) + { + filter_info_impl* pFilter = createFilterForNode( (*aIter) ); + if( pFilter ) + rFilters.push_back( pFilter ); + + delete (*aIter++); + } + + // now delete type nodes + aIter = maTypeNodes.begin(); + while( aIter != maTypeNodes.end() ) + delete (*aIter++); +} + +static OUString getSubdata( int index, sal_Unicode delimeter, const OUString& rData ) +{ + sal_Int32 nLastIndex = 0; + + sal_Int32 nNextIndex = rData.indexOf( delimeter ); + + OUString aSubdata; + + while( index ) + { + nLastIndex = nNextIndex + 1; + nNextIndex = rData.indexOf( delimeter, nLastIndex ); + + index--; + + if( (index > 0) && (nLastIndex == 0) ) + return aSubdata; + } + + if( nNextIndex == -1 ) + { + aSubdata = rData.copy( nLastIndex ); + } + else + { + aSubdata = rData.copy( nLastIndex, nNextIndex - nLastIndex ); + } + + return aSubdata; +} + +Node* TypeDetectionImporter::findTypeNode( const OUString& rType ) +{ + // now delete type nodes + NodeVector::iterator aIter = maTypeNodes.begin(); + while( aIter != maTypeNodes.end() ) + { + if( (*aIter)->maName == rType ) + return (*aIter); + + aIter++; + } + + return NULL; +} + +filter_info_impl* TypeDetectionImporter::createFilterForNode( Node * pNode ) +{ + filter_info_impl* pFilter = new filter_info_impl; + + pFilter->maFilterName = pNode->maName; + pFilter->maInterfaceName = pNode->maPropertyMap[sUIName]; + + OUString aData = pNode->maPropertyMap[sData]; + + sal_Unicode aComma(','); + + pFilter->maType = getSubdata( 1, aComma, aData ); + pFilter->maDocumentService = getSubdata( 2, aComma, aData ); + + OUString aFilterService( getSubdata( 3, aComma, aData ) ); + pFilter->maFlags = getSubdata( 4, aComma, aData ).toInt32(); + + // parse filter user data + sal_Unicode aDelim(';'); + OUString aFilterUserData( getSubdata( 5, aComma, aData ) ); + + OUString aAdapterService( getSubdata( 0, aDelim, aFilterUserData ) ); + //Import/ExportService + pFilter->maImportService = getSubdata( 2, aDelim, aFilterUserData ); + pFilter->maExportService = getSubdata( 3, aDelim, aFilterUserData ); + pFilter->maImportXSLT = getSubdata( 4, aDelim, aFilterUserData ); + pFilter->maExportXSLT = getSubdata( 5, aDelim, aFilterUserData ); + pFilter->maDTD = getSubdata( 6, aDelim, aFilterUserData ); + pFilter->maComment = getSubdata( 7, aDelim, aFilterUserData ); + + + pFilter->maImportTemplate = getSubdata( 7, aComma, aData ); + + Node* pTypeNode = findTypeNode( pFilter->maType ); + if( pTypeNode ) + { + OUString aTypeUserData( pTypeNode->maPropertyMap[sData] ); + + pFilter->maDocType = getSubdata( 2, aComma, aTypeUserData ); + pFilter->maExtension = getSubdata( 4, aComma, aTypeUserData ); + pFilter->mnDocumentIconID = getSubdata( 5, aComma, aTypeUserData ).toInt32(); + } + + bool bOk = true; + + if( pTypeNode == NULL ) + bOk = false; + + if( pFilter->maFilterName.getLength() == 0 ) + bOk = false; + + if( pFilter->maInterfaceName.getLength() == 0 ) + bOk = false; + + if( pFilter->maType.getLength() == 0 ) + bOk = false; + + if( pFilter->maFlags == 0 ) + bOk = false; + + if( aFilterService != sFilterAdaptorService ) + bOk = false; + + if( aAdapterService != sXSLTFilterService ) + bOk = false; + + if( pFilter->maExtension.getLength() == 0 ) + bOk = false; + + if( !bOk ) + { + delete pFilter; + pFilter = NULL; + } + + return pFilter; +} + +void SAL_CALL TypeDetectionImporter::startDocument( ) + throw(xml::sax::SAXException, uno::RuntimeException) +{ +} + +void SAL_CALL TypeDetectionImporter::endDocument( ) + throw(xml::sax::SAXException, uno::RuntimeException) +{ +} + +void SAL_CALL TypeDetectionImporter::startElement( const OUString& aName, const uno::Reference< xml::sax::XAttributeList >& xAttribs ) + throw(xml::sax::SAXException, uno::RuntimeException) +{ + ImportState eNewState = e_Unknown; + + if( maStack.empty() ) + { + // #109668# support legacy name as well on import + if( aName == sRootNode || aName.equalsAscii("oor:node") ) + { + eNewState = e_Root; + } + } + else if( maStack.top() == e_Root ) + { + if( aName == sNode ) + { + OUString aNodeName( xAttribs->getValueByName( sName ) ); + + if( aNodeName == sFilters ) + { + eNewState = e_Filters; + } + else if( aNodeName == sTypes ) + { + eNewState = e_Types; + } + } + } + else if( (maStack.top() == e_Filters) || (maStack.top() == e_Types) ) + { + if( aName == sNode ) + { + maNodeName = xAttribs->getValueByName( sName ); + + eNewState = (maStack.top() == e_Filters) ? e_Filter : e_Type; + } + } + else if( (maStack.top() == e_Filter) || (maStack.top() == e_Type)) + { + if( aName == sProp ) + { + maPropertyName = xAttribs->getValueByName( sName ); + eNewState = e_Property; + } + } + else if( maStack.top() == e_Property ) + { + if( aName == sValue ) + { + eNewState = e_Value; + maValue = OUString(); + } + } + + maStack.push( eNewState ); +} +void SAL_CALL TypeDetectionImporter::endElement( const OUString& /* aName */ ) + throw(xml::sax::SAXException, uno::RuntimeException) +{ + if( !maStack.empty() ) + { + ImportState eCurrentState = maStack.top(); + switch( eCurrentState ) + { + case e_Filter: + case e_Type: + { + Node* pNode = new Node; + pNode->maName = maNodeName; + pNode->maPropertyMap = maPropertyMap; + maPropertyMap.clear(); + + if( eCurrentState == e_Filter ) + { + maFilterNodes.push_back( pNode ); + } + else + { + maTypeNodes.push_back( pNode ); + } + } + break; + + case e_Property: + maPropertyMap[ maPropertyName ] = maValue; + break; + default: break; + } + + maStack.pop(); + } +} +void SAL_CALL TypeDetectionImporter::characters( const OUString& aChars ) + throw(xml::sax::SAXException, uno::RuntimeException) +{ + if( !maStack.empty() && maStack.top() == e_Value ) + { + maValue += aChars; + } +} +void SAL_CALL TypeDetectionImporter::ignorableWhitespace( const OUString& /* aWhitespaces */ ) + throw(xml::sax::SAXException, uno::RuntimeException) +{ +} +void SAL_CALL TypeDetectionImporter::processingInstruction( const OUString& /* aTarget */, const OUString& /* aData */ ) + throw(xml::sax::SAXException, uno::RuntimeException) +{ +} +void SAL_CALL TypeDetectionImporter::setDocumentLocator( const uno::Reference< xml::sax::XLocator >& /* xLocator */ ) + throw(xml::sax::SAXException, uno::RuntimeException) +{ +} + diff --git a/filter/source/xsltdialog/typedetectionimport.hxx b/filter/source/xsltdialog/typedetectionimport.hxx new file mode 100644 index 000000000000..b4c13ff44a9c --- /dev/null +++ b/filter/source/xsltdialog/typedetectionimport.hxx @@ -0,0 +1,129 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _TYPEDETECTION_IMPORT_HXX +#define _TYPEDETECTION_IMPORT_HXX + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <cppuhelper/implbase1.hxx> // helper for implementations +#ifndef _COM_SUN_STAR_XML_SAX_XDUCUMENTHANDLER_HPP_ +#include <com/sun/star/xml/sax/XDocumentHandler.hpp> +#endif +#include <comphelper/stl_types.hxx> + +#include "xmlfilterjar.hxx" + +#include <vector> +#include <stack> + +namespace com { namespace sun { namespace star { + namespace xml { namespace sax { class XAttributeList; } } + namespace beans { struct PropertyValue; } +} } } + +enum ImportState +{ + e_Root, + e_Filters, + e_Types, + e_Filter, + e_Type, + e_Property, + e_Value, + e_Unknown +}; + +DECLARE_STL_USTRINGACCESS_MAP( ::rtl::OUString, PropertyMap ); + +struct Node +{ + ::rtl::OUString maName; + PropertyMap maPropertyMap; +}; + +typedef std::vector< Node* > NodeVector; + +class TypeDetectionImporter : public cppu::WeakImplHelper1 < com::sun::star::xml::sax::XDocumentHandler > +{ +public: + TypeDetectionImporter( com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& xMSF ); + virtual ~TypeDetectionImporter( void ); + + static void doImport( com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& xMSF, com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xOS, XMLFilterVector& rFilters ); + + virtual void SAL_CALL startDocument( ) + throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL endDocument( ) + throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL startElement( const ::rtl::OUString& aName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttribs ) + throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL endElement( const ::rtl::OUString& aName ) + throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL characters( const ::rtl::OUString& aChars ) + throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL ignorableWhitespace( const ::rtl::OUString& aWhitespaces ) + throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL processingInstruction( const ::rtl::OUString& aTarget, const ::rtl::OUString& aData ) + throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setDocumentLocator( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >& xLocator ) + throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + +private: + void fillFilterVector( XMLFilterVector& rFilters ); + filter_info_impl* createFilterForNode( Node * pNode ); + Node* findTypeNode( const ::rtl::OUString& rType ); + + com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > mxMSF; + + std::stack< ImportState > maStack; + PropertyMap maPropertyMap; + + NodeVector maFilterNodes; + NodeVector maTypeNodes; + + ::rtl::OUString maValue; + ::rtl::OUString maNodeName; + ::rtl::OUString maPropertyName; + + const ::rtl::OUString sRootNode; + const ::rtl::OUString sNode; + const ::rtl::OUString sName; + const ::rtl::OUString sProp; + const ::rtl::OUString sValue; + const ::rtl::OUString sUIName; + const ::rtl::OUString sData; + const ::rtl::OUString sFilters; + const ::rtl::OUString sTypes; + const ::rtl::OUString sFilterAdaptorService; + const ::rtl::OUString sXSLTFilterService; + + const ::rtl::OUString sCdataAttribute; + const ::rtl::OUString sWhiteSpace; + +}; +#endif diff --git a/filter/source/xsltdialog/xmlfileview.cxx b/filter/source/xsltdialog/xmlfileview.cxx new file mode 100644 index 000000000000..a9cb18bed8d2 --- /dev/null +++ b/filter/source/xsltdialog/xmlfileview.cxx @@ -0,0 +1,990 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_filter.hxx" +#include <com/sun/star/xml/sax/XDocumentHandler.hpp> +#include <com/sun/star/xml/sax/XErrorHandler.hpp> +#include <com/sun/star/xml/sax/SAXParseException.hpp> +#include <com/sun/star/xml/XImportFilter.hpp> +#include <com/sun/star/io/XActiveDataSource.hpp> +#include <comphelper/oslfile2streamwrap.hxx> + +#include <rtl/tencinfo.h> +#include <vcl/svapp.hxx> +#include <vos/mutex.hxx> +#include <svtools/textview.hxx> +#ifndef _SCRBAR_HXX //autogen +#include <vcl/scrbar.hxx> +#endif +#include <tools/stream.hxx> +#include <tools/time.hxx> +#include <osl/file.hxx> +#include <vcl/msgbox.hxx> +#include <svtools/colorcfg.hxx> +#include <svtools/htmltokn.h> +#include <svtools/txtattr.hxx> + +#include "xmlfilterdialogstrings.hrc" +#include "xmlfiltersettingsdialog.hxx" +#include "xmlfileview.hxx" +#include "xmlfileview.hrc" +#include "xmlfilterhelpids.hrc" + +using namespace rtl; +using namespace osl; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::uno; +using namespace com::sun::star::io; +using namespace com::sun::star::xml; +using namespace com::sun::star::xml::sax; + + +#define MAX_SYNTAX_HIGHLIGHT 20 +#define MAX_HIGHLIGHTTIME 200 +#define SYNTAX_HIGHLIGHT_TIMEOUT 200 + + +struct SwTextPortion +{ + USHORT nLine; + USHORT nStart, nEnd; + svtools::ColorConfigEntry eType; +}; + +SV_DECL_VARARR(SwTextPortions, SwTextPortion,16,16) +SV_IMPL_VARARR(SwTextPortions, SwTextPortion); + +class XMLErrorHandler : public ::cppu::WeakImplHelper1< XErrorHandler > +{ +public: + XMLErrorHandler( XMLSourceFileDialog* pParent, ListBox& rListBox ); + + // Methods + virtual void SAL_CALL error( const Any& aSAXParseException ) throw (SAXException, RuntimeException); + virtual void SAL_CALL fatalError( const Any& aSAXParseException ) throw (SAXException, RuntimeException); + virtual void SAL_CALL warning( const Any& aSAXParseException ) throw (SAXException, RuntimeException); + +private: + XMLSourceFileDialog* mpParent; + ListBox& mrListBox; +}; + +XMLErrorHandler::XMLErrorHandler( XMLSourceFileDialog* pParent, ListBox& rListBox ) +: mpParent( pParent ), + mrListBox( rListBox ) +{ +} + +// XMLErrorHandler +void SAL_CALL XMLErrorHandler::error( const Any& aSAXParseException ) throw (SAXException, RuntimeException) +{ + vos::OGuard aGuard( Application::GetSolarMutex() ); + + SAXParseException e; + if( aSAXParseException >>= e ) + { + String sErr( String::CreateFromInt32( e.LineNumber ) ); + sErr += String( RTL_CONSTASCII_USTRINGPARAM( " : " ) ); + sErr += String( e.Message ); + USHORT nEntry = mrListBox.InsertEntry( sErr ); + mrListBox.SetEntryData( nEntry, (void*)e.LineNumber ); + } +} + +void SAL_CALL XMLErrorHandler::fatalError( const Any& aSAXParseException ) throw (SAXException, RuntimeException) +{ + vos::OGuard aGuard( Application::GetSolarMutex() ); + + SAXParseException e; + if( aSAXParseException >>= e ) + { + String sErr( String::CreateFromInt32( e.LineNumber ) ); + sErr += String( RTL_CONSTASCII_USTRINGPARAM( " : " ) ); + sErr += String( e.Message ); + USHORT nEntry = mrListBox.InsertEntry( sErr ); + mrListBox.SetEntryData( nEntry, (void*)e.LineNumber ); + } +} + +void SAL_CALL XMLErrorHandler::warning( const Any& /* aSAXParseException */ ) throw (SAXException, RuntimeException) +{ +/* + SAXParseException e; + if( aSAXParseException >>= e ) + { + String sErr( String::CreateFromInt32( e.LineNumber ) ); + sErr += String( RTL_CONSTASCII_USTRINGPARAM( " : " ) ); + sErr += String( e.Message ); + USHORT nEntry = mrListBox.InsertEntry( sErr ); + mrListBox.SetEntryData( nEntry, (void*)e.LineNumber ); + } +*/ +} + + +XMLFileWindow::XMLFileWindow( Window* pParent ) : + Window( pParent, WB_BORDER|WB_CLIPCHILDREN ), + pTextEngine(0), + pOutWin(0), + pHScrollbar(0), + pVScrollbar(0), + nCurTextWidth(0), + nStartLine(USHRT_MAX), + eSourceEncoding(gsl_getSystemTextEncoding()), + bHighlighting(false) +{ + CreateTextEngine(); +} + +XMLFileWindow::~XMLFileWindow() +{ + if ( pTextEngine ) + { + EndListening( *pTextEngine ); + pTextEngine->RemoveView( pTextView ); + + delete pHScrollbar; + delete pVScrollbar; + + delete pTextView; + delete pTextEngine; + } + delete pOutWin; +} + +void XMLFileWindow::DataChanged( const DataChangedEvent& rDCEvt ) +{ + Window::DataChanged( rDCEvt ); + + switch ( rDCEvt.GetType() ) + { + case DATACHANGED_SETTINGS: + // ScrollBars neu anordnen bzw. Resize ausloesen, da sich + // ScrollBar-Groesse geaendert haben kann. Dazu muss dann im + // Resize-Handler aber auch die Groesse der ScrollBars aus + // den Settings abgefragt werden. + if( rDCEvt.GetFlags() & SETTINGS_STYLE ) + Resize(); + break; + } +} + +void XMLFileWindow::Resize() +{ + // ScrollBars, etc. passiert in Adjust... + if ( pTextView ) + { + long nVisY = pTextView->GetStartDocPos().Y(); + pTextView->ShowCursor(); + Size aOutSz( GetOutputSizePixel() ); + long nMaxVisAreaStart = pTextView->GetTextEngine()->GetTextHeight() - aOutSz.Height(); + if ( nMaxVisAreaStart < 0 ) + nMaxVisAreaStart = 0; + if ( pTextView->GetStartDocPos().Y() > nMaxVisAreaStart ) + { + Point aStartDocPos( pTextView->GetStartDocPos() ); + aStartDocPos.Y() = nMaxVisAreaStart; + pTextView->SetStartDocPos( aStartDocPos ); + pTextView->ShowCursor(); + } + long nScrollStd = GetSettings().GetStyleSettings().GetScrollBarSize(); + Size aScrollSz(aOutSz.Width() - nScrollStd, nScrollStd ); + Point aScrollPos(0, aOutSz.Height() - nScrollStd); + + pHScrollbar->SetPosSizePixel( aScrollPos, aScrollSz); + + aScrollSz.Width() = aScrollSz.Height(); + aScrollSz.Height() = aOutSz.Height() - aScrollSz.Height(); + aScrollPos = Point(aOutSz.Width() - nScrollStd, 0); + + pVScrollbar->SetPosSizePixel( aScrollPos, aScrollSz); + aOutSz.Width() -= nScrollStd; + aOutSz.Height() -= nScrollStd; + pOutWin->SetOutputSizePixel(aOutSz); + InitScrollBars(); + + // Zeile im ersten Resize setzen + if(USHRT_MAX != nStartLine) + { + if(nStartLine < pTextEngine->GetParagraphCount()) + { + TextSelection aSel(TextPaM( nStartLine, 0 ), TextPaM( nStartLine, 0x0 )); + pTextView->SetSelection(aSel); + pTextView->ShowCursor(); + } + nStartLine = USHRT_MAX; + } + + if ( nVisY != pTextView->GetStartDocPos().Y() ) + InvalidateWindow(); + } + +} + +void TextViewOutWin::DataChanged( const DataChangedEvent& rDCEvt ) +{ + Window::DataChanged( rDCEvt ); + + switch( rDCEvt.GetType() ) + { + case DATACHANGED_SETTINGS: + // den Settings abgefragt werden. + if( rDCEvt.GetFlags() & SETTINGS_STYLE ) + { + const Color &rCol = GetSettings().GetStyleSettings().GetWindowColor(); + SetBackground( rCol ); + Font aFont( pTextView->GetTextEngine()->GetFont() ); + aFont.SetFillColor( rCol ); + pTextView->GetTextEngine()->SetFont( aFont ); + } + break; + } +} + +void TextViewOutWin::MouseMove( const MouseEvent &rEvt ) +{ + if ( pTextView ) + pTextView->MouseMove( rEvt ); +} + +void TextViewOutWin::MouseButtonUp( const MouseEvent &rEvt ) +{ + if ( pTextView ) + pTextView->MouseButtonUp( rEvt ); +} + +void TextViewOutWin::MouseButtonDown( const MouseEvent &rEvt ) +{ + GrabFocus(); + if ( pTextView ) + pTextView->MouseButtonDown( rEvt ); +} + +void TextViewOutWin::Command( const CommandEvent& rCEvt ) +{ + switch(rCEvt.GetCommand()) + { + case COMMAND_CONTEXTMENU: + break; + case COMMAND_WHEEL: + case COMMAND_STARTAUTOSCROLL: + case COMMAND_AUTOSCROLL: + { + const CommandWheelData* pWData = rCEvt.GetWheelData(); + if( !pWData || COMMAND_WHEEL_ZOOM != pWData->GetMode() ) + { + ((XMLFileWindow*)GetParent())->HandleWheelCommand( rCEvt ); + } + } + break; + + default: + if ( pTextView ) + pTextView->Command( rCEvt ); + else + Window::Command(rCEvt); + } +} + +void TextViewOutWin::KeyInput( const KeyEvent& rKEvt ) +{ + if(!TextEngine::DoesKeyChangeText( rKEvt )) + pTextView->KeyInput( rKEvt ); +} + +void TextViewOutWin::Paint( const Rectangle& rRect ) +{ + pTextView->Paint( rRect ); +} + +void XMLFileWindow::CreateTextEngine() +{ + const Color &rCol = GetSettings().GetStyleSettings().GetWindowColor(); + pOutWin = new TextViewOutWin(this, 0); + pOutWin->SetBackground(Wallpaper(rCol)); + pOutWin->SetPointer(Pointer(POINTER_TEXT)); + pOutWin->Show(); + + //Scrollbars anlegen + pHScrollbar = new ScrollBar(this, WB_3DLOOK |WB_HSCROLL|WB_DRAG); + pHScrollbar->SetScrollHdl(LINK(this, XMLFileWindow, ScrollHdl)); + pHScrollbar->Show(); + + pVScrollbar = new ScrollBar(this, WB_3DLOOK |WB_VSCROLL|WB_DRAG); + pVScrollbar->SetScrollHdl(LINK(this, XMLFileWindow, ScrollHdl)); + pHScrollbar->EnableDrag(); + pVScrollbar->Show(); + + pTextEngine = new TextEngine; + pTextView = new TextView( pTextEngine, pOutWin ); + pTextView->SetAutoIndentMode(TRUE); + pOutWin->SetTextView(pTextView); + + pTextEngine->SetUpdateMode( FALSE ); + pTextEngine->InsertView( pTextView ); + + Font aFont; + aFont.SetTransparent( FALSE ); + aFont.SetFillColor( rCol ); + SetPointFont( aFont ); + aFont = GetFont(); + aFont.SetFillColor( rCol ); + pOutWin->SetFont( aFont ); + pTextEngine->SetFont( aFont ); + + aSyntaxIdleTimer.SetTimeout( SYNTAX_HIGHLIGHT_TIMEOUT ); + aSyntaxIdleTimer.SetTimeoutHdl( LINK( this, XMLFileWindow, SyntaxTimerHdl ) ); + + pTextEngine->EnableUndo( FALSE ); + pTextEngine->SetUpdateMode( TRUE ); + +// pTextView->ShowCursor( TRUE, TRUE ); + pTextView->HideCursor(); + + InitScrollBars(); + StartListening( *pTextEngine ); +} + +void XMLFileWindow::SetScrollBarRanges() +{ + pHScrollbar->SetRange( Range( 0, nCurTextWidth-1 ) ); + pVScrollbar->SetRange( Range(0, pTextEngine->GetTextHeight()-1) ); +} + +void XMLFileWindow::InitScrollBars() +{ + SetScrollBarRanges(); + + Size aOutSz( pOutWin->GetOutputSizePixel() ); + pVScrollbar->SetVisibleSize( aOutSz.Height() ); + pVScrollbar->SetPageSize( aOutSz.Height() * 8 / 10 ); + pVScrollbar->SetLineSize( pOutWin->GetTextHeight() ); + pVScrollbar->SetThumbPos( pTextView->GetStartDocPos().Y() ); + pHScrollbar->SetVisibleSize( aOutSz.Width() ); + pHScrollbar->SetPageSize( aOutSz.Width() * 8 / 10 ); + pHScrollbar->SetLineSize( pOutWin->GetTextWidth( 'x' ) ); + pHScrollbar->SetThumbPos( pTextView->GetStartDocPos().X() ); + +} + +IMPL_LINK(XMLFileWindow, ScrollHdl, ScrollBar*, pScroll) +{ + if(pScroll == pVScrollbar) + { + long nDiff = pTextView->GetStartDocPos().Y() - pScroll->GetThumbPos(); + GetTextView()->Scroll( 0, nDiff ); + pTextView->ShowCursor( FALSE, TRUE ); + pScroll->SetThumbPos( pTextView->GetStartDocPos().Y() ); + } + else + { + long nDiff = pTextView->GetStartDocPos().X() - pScroll->GetThumbPos(); + GetTextView()->Scroll( nDiff, 0 ); + pTextView->ShowCursor( FALSE, TRUE ); + pScroll->SetThumbPos( pTextView->GetStartDocPos().X() ); + } + return 0; +} + +void XMLFileWindow::Notify( SfxBroadcaster& /* rBC */, const SfxHint& rHint ) +{ + if ( rHint.ISA( TextHint ) ) + { + const TextHint& rTextHint = (const TextHint&)rHint; + if( rTextHint.GetId() == TEXT_HINT_VIEWSCROLLED ) + { + pHScrollbar->SetThumbPos( pTextView->GetStartDocPos().X() ); + pVScrollbar->SetThumbPos( pTextView->GetStartDocPos().Y() ); + } + else if( rTextHint.GetId() == TEXT_HINT_TEXTHEIGHTCHANGED ) + { + if ( (long)pTextEngine->GetTextHeight() < pOutWin->GetOutputSizePixel().Height() ) + pTextView->Scroll( 0, pTextView->GetStartDocPos().Y() ); + pVScrollbar->SetThumbPos( pTextView->GetStartDocPos().Y() ); + SetScrollBarRanges(); + } + else if( rTextHint.GetId() == TEXT_HINT_FORMATPARA ) + { + DoDelayedSyntaxHighlight( (USHORT)rTextHint.GetValue() ); + } + } +} + +void XMLFileWindow::InvalidateWindow() +{ + pOutWin->Invalidate(); + Window::Invalidate(); + +} + +void XMLFileWindow::Command( const CommandEvent& rCEvt ) +{ + switch(rCEvt.GetCommand()) + { + case COMMAND_WHEEL: + case COMMAND_STARTAUTOSCROLL: + case COMMAND_AUTOSCROLL: + { + const CommandWheelData* pWData = rCEvt.GetWheelData(); + if( !pWData || COMMAND_WHEEL_ZOOM != pWData->GetMode() ) + HandleScrollCommand( rCEvt, pHScrollbar, pVScrollbar ); + } + break; + default: + Window::Command(rCEvt); + } +} + +void XMLFileWindow::HandleWheelCommand( const CommandEvent& rCEvt ) +{ + pTextView->Command(rCEvt); + HandleScrollCommand( rCEvt, pHScrollbar, pVScrollbar ); +} + +void XMLFileWindow::GetFocus() +{ + pOutWin->GrabFocus(); +} + +void XMLFileWindow::ShowWindow( const rtl::OUString& rFileName ) +{ + String aFileName( rFileName ); + SvFileStream aStream( aFileName, STREAM_READ ); + + // since the xml files we load are utf-8 encoded, we need to set + // this encoding at the SvFileStream, else the TextEngine will + // use its default encoding which is not UTF8 + const sal_Char *pCharSet = rtl_getBestMimeCharsetFromTextEncoding( RTL_TEXTENCODING_UTF8 ); + rtl_TextEncoding eDestEnc = rtl_getTextEncodingFromMimeCharset( pCharSet ); + aStream.SetStreamCharSet( eDestEnc ); + + if( Read( aStream ) ) + { + long nPrevTextWidth = nCurTextWidth; + nCurTextWidth = pTextEngine->CalcTextWidth() + 25; // kleine Toleranz + if ( nCurTextWidth != nPrevTextWidth ) + SetScrollBarRanges(); + + TextPaM aPaM( pTextView->CursorStartOfDoc() ); + TextSelection aSelection( aPaM, aPaM ); + pTextView->SetSelection( aSelection, true ); + + Window::Show(); + } +} + +void XMLFileWindow::showLine( sal_Int32 nLine ) +{ + TextPaM aPaM( pTextView->CursorStartOfDoc() ); + while( nLine-- ) + aPaM = pTextView->CursorDown( aPaM ); + + TextSelection aSelection( pTextView->CursorEndOfLine( aPaM ), aPaM ); + pTextView->SetSelection( aSelection, true ); +} + + +XMLSourceFileDialog::XMLSourceFileDialog( Window* pParent, ResMgr& rResMgr, const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rxMSF ) +: WorkWindow( pParent, ResId( DLG_XML_SOURCE_FILE_DIALOG, rResMgr ) ), + mnOutputHeight( LogicToPixel( Size( 80, 80 ), MAP_APPFONT ).Height() ), + mxMSF( rxMSF ), + mrResMgr( rResMgr ), + maLBOutput( this ), + maPBValidate( this, ResId( PB_VALIDATE, rResMgr ) ) +{ + + FreeResource(); + + maPBValidate.SetClickHdl(LINK( this, XMLSourceFileDialog, ClickHdl_Impl ) ); + maLBOutput.SetSelectHdl(LINK(this, XMLSourceFileDialog, SelectHdl_Impl ) ); + mpTextWindow = new XMLFileWindow( this ); + mpTextWindow->SetHelpId( HID_XML_FILTER_OUTPUT_WINDOW ); + maLBOutput.SetHelpId( HID_XML_FILTER_TEST_VALIDATE_OUPUT ); + + Resize(); +} + +XMLSourceFileDialog::~XMLSourceFileDialog() +{ + if( maFileURL.getLength() ) + osl::File::remove( maFileURL ); + + delete mpTextWindow; +} + +void XMLSourceFileDialog::ShowWindow( const rtl::OUString& rFileName, const filter_info_impl* pFilterInfo ) +{ + EnterWait(); + if( maFileURL.getLength() ) + { + osl::File::remove( maFileURL ); + delete mpTextWindow; + mpTextWindow = new XMLFileWindow( this ); + maLBOutput.Hide(); + maLBOutput.Clear(); + maPBValidate.Enable(TRUE); + Resize(); + } + + mpFilterInfo = pFilterInfo; + maFileURL = rFileName; + mpTextWindow->ShowWindow( rFileName ); + WorkWindow::Show(); + LeaveWait(); +} + +void XMLSourceFileDialog::Resize() +{ + bool bOutputVisible = maLBOutput.IsVisible() != 0; + + Point aSpacing( LogicToPixel( Point( 6, 6 ), MAP_APPFONT ) ); + Size aButton( maPBValidate.GetSizePixel() ); + + Size aDialogSize( GetOutputSizePixel() ); + +// Point aButtonPos( aSpacing.X(), aSpacing.Y() ); +// maPBValidate.SetPosSizePixel( aButtonPos, aButton ); + + Size aOutputSize( aDialogSize.Width(), bOutputVisible ? mnOutputHeight : 0 ); + + Point aTextWindowPos( 0, 2* aSpacing.Y() + aButton.Height() ); + Size aTextWindowSize( aDialogSize.Width(), aDialogSize.Height() - aTextWindowPos.Y() - aOutputSize.Height() ); + + mpTextWindow->SetPosSizePixel( aTextWindowPos, aTextWindowSize ); + + if( bOutputVisible ) + { + Point aOutputPos( 0, aTextWindowPos.Y() + aTextWindowSize.Height() ); + maLBOutput.SetPosSizePixel( aOutputPos, aOutputSize ); + } +} + + +IMPL_LINK(XMLSourceFileDialog, SelectHdl_Impl, ListBox *, pListBox ) +{ + USHORT nEntry = pListBox->GetSelectEntryPos(); + if( LISTBOX_ENTRY_NOTFOUND != nEntry ) + { + int nLine = (int)(sal_IntPtr)pListBox->GetEntryData(nEntry); + if( -1 != nLine ) + { + if( nLine > 0 ) + nLine--; + + showLine( nLine ); + } + } + return 0; +} + +IMPL_LINK(XMLSourceFileDialog, ClickHdl_Impl, PushButton *, /* pButton */ ) +{ + onValidate(); + return 0; +} + +void XMLSourceFileDialog::onValidate() +{ + EnterWait(); + + maLBOutput.Show(); + maPBValidate.Enable(FALSE); + Resize(); + + try + { + Reference< XImportFilter > xImporter( mxMSF->createInstance( OUString::createFromAscii( "com.sun.star.documentconversion.XSLTValidate" ) ), UNO_QUERY ); + if( xImporter.is() ) + { + osl::File aInputFile( maFileURL ); + /* osl::File::RC rc = */ aInputFile.open( OpenFlag_Read ); + + Reference< XInputStream > xIS( new comphelper::OSLInputStreamWrapper( aInputFile ) ); + + Sequence< PropertyValue > aSourceData(3); + aSourceData[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "InputStream" ) ); + aSourceData[0].Value <<= xIS; + + aSourceData[1].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "FileName" ) ); + aSourceData[1].Value <<= maFileURL; + + aSourceData[2].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "ErrorHandler" ) ); + Reference< XErrorHandler > xHandle( new XMLErrorHandler( this, maLBOutput ) ); + aSourceData[2].Value <<= xHandle; + + Reference< XDocumentHandler > xWriter( mxMSF->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.sax.Writer" ) ) ), UNO_QUERY ); + Reference< XOutputStream > xOS( mxMSF->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.Pipe" ) ) ), UNO_QUERY ); + Reference< XActiveDataSource > xDocSrc( xWriter, UNO_QUERY ); + xDocSrc->setOutputStream( xOS ); + + Sequence< OUString > aFilterUserData( mpFilterInfo->getFilterUserData() ); + xImporter->importer( aSourceData, xWriter, aFilterUserData ); + } + } + catch(Exception& e) + { + String sErr( e.Message ); + USHORT nEntry = maLBOutput.InsertEntry( sErr ); + maLBOutput.SetEntryData( nEntry, (void*)-1 ); + } + + if( 0 == maLBOutput.GetEntryCount() ) + { + String sErr( RESID( STR_NO_ERRORS_FOUND ) ); + USHORT nEntry = maLBOutput.InsertEntry( sErr ); + maLBOutput.SetEntryData( nEntry, (void*)-1 ); + } + + LeaveWait(); +} + +void XMLSourceFileDialog::showLine( sal_Int32 nLine ) +{ + mpTextWindow->showLine( nLine ); +} + + +/////////////////////////////////////////////////////////////////////// + +void lcl_Highlight(const String& rSource, SwTextPortions& aPortionList) +{ + const sal_Unicode cOpenBracket = '<'; + const sal_Unicode cCloseBracket= '>'; + const sal_Unicode cSlash = '/'; + const sal_Unicode cExclamation = '!'; +// const sal_Unicode cQuote = '"'; +// const sal_Unicode cSQuote = '\''; + const sal_Unicode cMinus = '-'; + const sal_Unicode cSpace = ' '; + const sal_Unicode cTab = 0x09; + const sal_Unicode cLF = 0x0a; + const sal_Unicode cCR = 0x0d; + + + const USHORT nStrLen = rSource.Len(); + USHORT nInsert = 0; // Anzahl der eingefuegten Portions + USHORT nActPos = 0; //Position, an der '<' gefunden wurde + USHORT nOffset = 0; //Offset von nActPos zur '<' + USHORT nPortStart = USHRT_MAX; // fuer die TextPortion + USHORT nPortEnd = 0; // + SwTextPortion aText; + while(nActPos < nStrLen) + { + svtools::ColorConfigEntry eFoundType = svtools::HTMLUNKNOWN; + if(rSource.GetChar(nActPos) == cOpenBracket && nActPos < nStrLen - 2 ) + { + // 'leere' Portion einfuegen + if(nPortEnd < nActPos - 1 ) + { + aText.nLine = 0; + // am Anfang nicht verschieben + aText.nStart = nPortEnd; + if(nInsert) + aText.nStart += 1; + aText.nEnd = nActPos - 1; + aText.eType = svtools::HTMLUNKNOWN; + aPortionList.Insert(aText, nInsert++); + } + sal_Unicode cFollowFirst = rSource.GetChar((xub_StrLen)(nActPos + 1)); + sal_Unicode cFollowNext = rSource.GetChar((xub_StrLen)(nActPos + 2)); + if(cExclamation == cFollowFirst) + { + // "<!" SGML oder Kommentar + if(cMinus == cFollowNext && + nActPos < nStrLen - 3 && cMinus == rSource.GetChar((xub_StrLen)(nActPos + 3))) + { + eFoundType = svtools::HTMLCOMMENT; + } + else + eFoundType = svtools::HTMLSGML; + nPortStart = nActPos; + nPortEnd = nActPos + 1; + } + else if(cSlash == cFollowFirst) + { + // "</" Slash ignorieren + nPortStart = nActPos; + nActPos++; + nOffset++; + } + if(svtools::HTMLUNKNOWN == eFoundType) + { + //jetzt koennte hier ein keyword folgen + USHORT nSrchPos = nActPos; + while(++nSrchPos < nStrLen - 1) + { + sal_Unicode cNext = rSource.GetChar(nSrchPos); + if( cNext == cSpace || + cNext == cTab || + cNext == cLF || + cNext == cCR) + break; + else if(cNext == cCloseBracket) + { + break; + } + } + if(nSrchPos > nActPos + 1) + { + //irgend ein String wurde gefunden + String sToken = rSource.Copy(nActPos + 1, nSrchPos - nActPos - 1 ); + sToken.ToUpperAscii(); +// int nToken = ::GetHTMLToken(sToken); +// if(nToken) + { + //Token gefunden + eFoundType = svtools::HTMLKEYWORD; + nPortEnd = nSrchPos; + nPortStart = nActPos; + } +/* + else + { + //was war das denn? +#ifdef DEBUG + DBG_ERROR("Token nicht erkannt!") + DBG_ERROR(ByteString(sToken, gsl_getSystemTextEncoding()).GetBuffer()) +#endif + } +*/ + + } + } + // jetzt muss noch '>' gesucht werden + if(svtools::HTMLUNKNOWN != eFoundType) + { + BOOL bFound = FALSE; + for(USHORT i = nPortEnd; i < nStrLen; i++) + if(cCloseBracket == rSource.GetChar(i)) + { + bFound = TRUE; + nPortEnd = i; + break; + } + if(!bFound && (eFoundType == svtools::HTMLCOMMENT)) + { + // Kommentar ohne Ende in dieser Zeile + bFound = TRUE; + nPortEnd = nStrLen - 1; + } + + if(bFound ||(eFoundType == svtools::HTMLCOMMENT)) + { + SwTextPortion aText2; + aText2.nLine = 0; + aText2.nStart = nPortStart + 1; + aText2.nEnd = nPortEnd; + aText2.eType = eFoundType; + aPortionList.Insert(aText2, nInsert++); + eFoundType = svtools::HTMLUNKNOWN; + } + + } + } + nActPos++; + } + if(nInsert && nPortEnd < nActPos - 1) + { + aText.nLine = 0; + aText.nStart = nPortEnd + 1; + aText.nEnd = nActPos - 1; + aText.eType = svtools::HTMLUNKNOWN; + aPortionList.Insert(aText, nInsert++); + } +} + +void XMLFileWindow::DoDelayedSyntaxHighlight( USHORT nPara ) +{ + if ( !bHighlighting ) + { + aSyntaxLineTable.Insert( nPara, (void*)(USHORT)1 ); + aSyntaxIdleTimer.Start(); + } +} + +void XMLFileWindow::ImpDoHighlight( const String& rSource, USHORT nLineOff ) +{ + SwTextPortions aPortionList; + lcl_Highlight(rSource, aPortionList); + + USHORT nCount = aPortionList.Count(); + if ( !nCount ) + return; + + SwTextPortion& rLast = aPortionList[nCount-1]; + if ( rLast.nStart > rLast.nEnd ) // Nur bis Bug von MD behoeben + { + nCount--; + aPortionList.Remove( nCount); + if ( !nCount ) + return; + } + + // Evtl. Optimieren: + // Wenn haufig gleiche Farbe, dazwischen Blank ohne Farbe, + // ggf. zusammenfassen, oder zumindest das Blank, + // damit weniger Attribute + BOOL bOptimizeHighlight = TRUE; // war in der BasicIDE static + if ( bOptimizeHighlight ) + { + // Es muessen nur die Blanks und Tabs mit attributiert werden. + // Wenn zwei gleiche Attribute hintereinander eingestellt werden, + // optimiert das die TextEngine. + USHORT nLastEnd = 0; + for ( USHORT i = 0; i < nCount; i++ ) + { + SwTextPortion& r = aPortionList[i]; + DBG_ASSERT( r.nLine == aPortionList[0].nLine, "doch mehrere Zeilen ?" ); + if ( r.nStart > r.nEnd ) // Nur bis Bug von MD behoeben + continue; + + if ( r.nStart > nLastEnd ) + { + // Kann ich mich drauf verlassen, dass alle ausser + // Blank und Tab gehighlightet wird ?! + r.nStart = nLastEnd; + } + nLastEnd = r.nEnd+1; + if ( ( i == (nCount-1) ) && ( r.nEnd < rSource.Len() ) ) + r.nEnd = rSource.Len(); + } + } + + svtools::ColorConfig aConfig; + for ( USHORT i = 0; i < aPortionList.Count(); i++ ) + { + SwTextPortion& r = aPortionList[i]; + if ( r.nStart > r.nEnd ) // Nur bis Bug von MD behoeben + continue; +// USHORT nCol = r.eType; + if(r.eType != svtools::HTMLSGML && + r.eType != svtools::HTMLCOMMENT && + r.eType != svtools::HTMLKEYWORD && + r.eType != svtools::HTMLUNKNOWN) + r.eType = (svtools::ColorConfigEntry)svtools::HTMLUNKNOWN; + Color aColor((ColorData)aConfig.GetColorValue((svtools::ColorConfigEntry)r.eType).nColor); + USHORT nLine = nLineOff+r.nLine; // + pTextEngine->SetAttrib( TextAttribFontColor( aColor ), nLine, r.nStart, r.nEnd+1 ); + } +} + +IMPL_LINK( XMLFileWindow, SyntaxTimerHdl, Timer *, pTimer ) +{ + Time aSyntaxCheckStart; + DBG_ASSERT( pTextView, "Noch keine View, aber Syntax-Highlight ?!" ); + pTextEngine->SetUpdateMode( FALSE ); + + bHighlighting = TRUE; + USHORT nLine; + USHORT nCount = 0; + // zuerst wird der Bereich um dem Cursor bearbeitet + TextSelection aSel = pTextView->GetSelection(); + USHORT nCur = (USHORT)aSel.GetStart().GetPara(); + if(nCur > 40) + nCur -= 40; + else + nCur = 0; + if(aSyntaxLineTable.Count()) + for(USHORT i = 0; i < 80 && nCount < 40; i++, nCur++) + { + void * p = aSyntaxLineTable.Get(nCur); + if(p) + { + DoSyntaxHighlight( nCur ); + aSyntaxLineTable.Remove( nCur ); + nCount++; + if(!aSyntaxLineTable.Count()) + break; + if((Time().GetTime() - aSyntaxCheckStart.GetTime()) > MAX_HIGHLIGHTTIME ) + { + pTimer->SetTimeout( 2 * SYNTAX_HIGHLIGHT_TIMEOUT ); + break; + } + } + } + + // wenn dann noch etwas frei ist, wird von Beginn an weitergearbeitet + void* p = aSyntaxLineTable.First(); + while ( p && nCount < MAX_SYNTAX_HIGHLIGHT) + { + nLine = (USHORT)aSyntaxLineTable.GetCurKey(); + DoSyntaxHighlight( nLine ); + USHORT nC = (USHORT)aSyntaxLineTable.GetCurKey(); + p = aSyntaxLineTable.Next(); + aSyntaxLineTable.Remove(nC); + nCount ++; + if(Time().GetTime() - aSyntaxCheckStart.GetTime() > MAX_HIGHLIGHTTIME) + { + pTimer->SetTimeout( 2 * SYNTAX_HIGHLIGHT_TIMEOUT ); + break; + } + } + // os: #43050# hier wird ein TextView-Problem umpopelt: + // waehrend des Highlightings funktionierte das Scrolling nicht + TextView* pTmp = pTextEngine->GetActiveView(); + pTextEngine->SetActiveView(0); + pTextEngine->SetUpdateMode( TRUE ); + pTextEngine->SetActiveView(pTmp); + pTextView->ShowCursor(FALSE, FALSE); + + if(aSyntaxLineTable.Count() && !pTimer->IsActive()) + pTimer->Start(); + // SyntaxTimerHdl wird gerufen, wenn Text-Aenderung + // => gute Gelegenheit, Textbreite zu ermitteln! + long nPrevTextWidth = nCurTextWidth; + nCurTextWidth = pTextEngine->CalcTextWidth() + 25; // kleine Toleranz + if ( nCurTextWidth != nPrevTextWidth ) + SetScrollBarRanges(); + bHighlighting = FALSE; + + return 0; +} + +void XMLFileWindow::DoSyntaxHighlight( USHORT nPara ) +{ + // Durch das DelayedSyntaxHighlight kann es passieren, + // dass die Zeile nicht mehr existiert! + if ( nPara < pTextEngine->GetParagraphCount() ) + { + pTextEngine->RemoveAttribs( nPara ); + String aSource( pTextEngine->GetText( nPara ) ); + pTextEngine->SetUpdateMode( FALSE ); + ImpDoHighlight( aSource, nPara ); + // os: #43050# hier wird ein TextView-Problem umpopelt: + // waehrend des Highlightings funktionierte das Scrolling nicht + TextView* pTmp = pTextEngine->GetActiveView(); + pTmp->SetAutoScroll(FALSE); + pTextEngine->SetActiveView(0); + pTextEngine->SetUpdateMode( TRUE ); + pTextEngine->SetActiveView(pTmp); + // Bug 72887 show the cursor + pTmp->SetAutoScroll(TRUE); + pTmp->ShowCursor( FALSE/*pTmp->IsAutoScroll()*/ ); + } +} diff --git a/filter/source/xsltdialog/xmlfileview.hrc b/filter/source/xsltdialog/xmlfileview.hrc new file mode 100644 index 000000000000..7d4216fa9d27 --- /dev/null +++ b/filter/source/xsltdialog/xmlfileview.hrc @@ -0,0 +1,36 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLFILEVIEWDIALOG_HRC_ +#define _XMLFILEVIEWDIALOG_HRC_ + +#include "xmlfiltercommon.hrc" + +#define CTRL_SOURCE_VIEW 1 +#define PB_VALIDATE 2 + +#endif diff --git a/filter/source/xsltdialog/xmlfileview.hxx b/filter/source/xsltdialog/xmlfileview.hxx new file mode 100644 index 000000000000..190c52254374 --- /dev/null +++ b/filter/source/xsltdialog/xmlfileview.hxx @@ -0,0 +1,177 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _XMLFILEVIEW_HXX +#define _XMLFILEVIEW_HXX + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <svl/lstner.hxx> +#include <vcl/timer.hxx> + +#ifndef _TABLE_HXX //autogen +#include <tools/table.hxx> +#endif +#include <svtools/xtextedt.hxx> +#include <vcl/timer.hxx> +#ifndef _TABLE_HXX //autogen +#include <tools/table.hxx> +#endif +#include <vcl/wrkwin.hxx> +#include <vcl/ctrl.hxx> +#ifndef _SV_BUTTON_HXX +#include <vcl/button.hxx> +#endif +#include <vcl/lstbox.hxx> + +class ScrollBar; +class XMLFileWindow; +class TextEngine; +class TextView; +class DataChangedEvent; +class filter_info_impl; + +class TextViewOutWin : public Window +{ + TextView* pTextView; + +protected: + virtual void Paint( const Rectangle& ); + virtual void KeyInput( const KeyEvent& rKeyEvt ); + virtual void MouseMove( const MouseEvent& rMEvt ); + virtual void MouseButtonDown( const MouseEvent& rMEvt ); + virtual void MouseButtonUp( const MouseEvent& rMEvt ); + virtual void Command( const CommandEvent& rCEvt ); + virtual void DataChanged( const DataChangedEvent& ); + +public: + TextViewOutWin(Window* pParent, WinBits nBits) : + Window(pParent, nBits), pTextView(0){} + + void SetTextView( TextView* pView ) {pTextView = pView;} + +}; + +//------------------------------------------------------------ + +class XMLFileWindow : public Window, public SfxListener +{ + using Window::Notify; + +private: + TextView* pTextView; + TextEngine* pTextEngine; + + TextViewOutWin* pOutWin; + ScrollBar *pHScrollbar, + *pVScrollbar; + + long nCurTextWidth; + USHORT nStartLine; + rtl_TextEncoding eSourceEncoding; + + Timer aSyntaxIdleTimer; + Table aSyntaxLineTable; + + bool bHighlighting; +protected: + DECL_LINK( SyntaxTimerHdl, Timer * ); + void ImpDoHighlight( const String& rSource, USHORT nLineOff ); + + virtual void Resize(); + virtual void DataChanged( const DataChangedEvent& ); + virtual void GetFocus(); + + void CreateTextEngine(); + + virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ); + + DECL_LINK(ScrollHdl, ScrollBar*); + + void DoDelayedSyntaxHighlight( USHORT nPara ); + + void DoSyntaxHighlight( USHORT nPara ); + +public: + XMLFileWindow( Window* pParent ); + ~XMLFileWindow(); + + void SetScrollBarRanges(); + void InitScrollBars(); + ULONG Read( SvStream& rInput) { return pTextEngine->Read(rInput); } + + void ShowWindow( const rtl::OUString& rFileName ); + + TextView* GetTextView() { return pTextView; } + TextEngine* GetTextEngine() { return pTextEngine; } + + TextViewOutWin* GetOutWin() { return pOutWin; } + void InvalidateWindow(); + + void CreateScrollbars(); + + void SetStartLine(USHORT nLine) {nStartLine = nLine;} + + virtual void Command( const CommandEvent& rCEvt ); + void HandleWheelCommand( const CommandEvent& rCEvt ); + + TextView* getTextView() { return pTextView; } + + void showLine( sal_Int32 nLine ); +}; + +class XMLSourceFileDialog : public WorkWindow +{ + +public: + XMLSourceFileDialog( Window* pParent, ResMgr& rResMgr, const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rxMSF ); + virtual ~XMLSourceFileDialog(); + + void ShowWindow( const rtl::OUString& rFileName, const filter_info_impl* pFilterInfo ); + + virtual void Resize(); + + DECL_LINK(ClickHdl_Impl, PushButton * ); + DECL_LINK(SelectHdl_Impl, ListBox * ); + + void showLine( sal_Int32 nLine ); + + sal_Int32 mnOutputHeight; +private: + void onValidate(); + + const filter_info_impl* mpFilterInfo; + rtl::OUString maFileURL; + + com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > mxMSF; + ResMgr& mrResMgr; + + XMLFileWindow* mpTextWindow; + ListBox maLBOutput; +// Control maCtrlSourceView; + PushButton maPBValidate; +}; + +#endif diff --git a/filter/source/xsltdialog/xmlfileview.src b/filter/source/xsltdialog/xmlfileview.src new file mode 100644 index 000000000000..588c3dd47883 --- /dev/null +++ b/filter/source/xsltdialog/xmlfileview.src @@ -0,0 +1,64 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "xmlfileview.hrc" +#include "xmlfilterhelpids.hrc" + +#define DIALOG_WIDTH 500 +#define DIALOG_HEIGHT 400 + +WorkWindow DLG_XML_SOURCE_FILE_DIALOG +{ + Size = MAP_APPFONT( DIALOG_WIDTH, DIALOG_HEIGHT ); + HelpId = HID_XML_SOURCE_FILE_DIALOG; + OutputSize = TRUE ; + SVLook = TRUE ; + Sizeable = TRUE ; + Minable = TRUE ; + Maxable = TRUE ; + Moveable = TRUE ; + Closeable = TRUE ; + Text [ en-US ] = "XML Filter output" ; + + PushButton PB_VALIDATE + { + Pos = MAP_APPFONT ( 6 , 6 ) ; + Size = MAP_APPFONT ( 60 , 14 ) ; + TabStop = TRUE ; + HelpId = HID_XML_SOURCE_FILE_VALIDATE; + Text [ en-US ] = "~Validate"; + }; +}; + + + + + + + + + diff --git a/filter/source/xsltdialog/xmlfiltercommon.hrc b/filter/source/xsltdialog/xmlfiltercommon.hrc new file mode 100644 index 000000000000..e3e51bf250dd --- /dev/null +++ b/filter/source/xsltdialog/xmlfiltercommon.hrc @@ -0,0 +1,41 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _XMLFILTERCOMMON_HRC_ +#define _XMLFILTERCOMMON_HRC_ + +#ifndef _FILTER_HRC +#include "filter.hrc" +#endif + +#define DLG_XML_SOURCE_FILE_DIALOG (RID_XSLT_DIALOG_START+0) +#define DLG_XML_FILTER_SETTINGS_DIALOG (RID_XSLT_DIALOG_START+1) +#define DLG_XML_FILTER_TABDIALOG (RID_XSLT_DIALOG_START+2) +#define RID_XML_FILTER_TABPAGE_BASIC (RID_XSLT_DIALOG_START+3) +#define RID_XML_FILTER_TABPAGE_XSLT (RID_XSLT_DIALOG_START+4) +#define DLG_XML_FILTER_TEST_DIALOG (RID_XSLT_DIALOG_START+5) + +#endif diff --git a/filter/source/xsltdialog/xmlfiltercommon.hxx b/filter/source/xsltdialog/xmlfiltercommon.hxx new file mode 100644 index 000000000000..91e11bdad79a --- /dev/null +++ b/filter/source/xsltdialog/xmlfiltercommon.hxx @@ -0,0 +1,107 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _XMLFILTERCOMMON_HXX_ +#define _XMLFILTERCOMMON_HXX_ + +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/container/XHierarchicalName.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/io/XOutputStream.hpp> + +#include <vector> + +// -------------------------------------------------------------------- + +extern ::rtl::OUString string_encode( const ::rtl::OUString & rText ); +extern ::rtl::OUString string_decode( const ::rtl::OUString & rText ); + +// -------------------------------------------------------------------- + +extern bool isFileURL( const ::rtl::OUString & rURL ); + +// -------------------------------------------------------------------- + +bool copyStreams( ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > xIS, ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > xOS ); +bool createDirectory( ::rtl::OUString& rURL ); + +// -------------------------------------------------------------------- + +class filter_info_impl +{ +public: + rtl::OUString maFilterName; + rtl::OUString maType; + rtl::OUString maDocumentService; + rtl::OUString maFilterService; + rtl::OUString maInterfaceName; + rtl::OUString maComment; + rtl::OUString maExtension; + rtl::OUString maDTD; + rtl::OUString maExportXSLT; + rtl::OUString maImportXSLT; + rtl::OUString maImportTemplate; + rtl::OUString maDocType; + rtl::OUString maImportService; + rtl::OUString maExportService; + + sal_Int32 maFlags; + sal_Int32 maFileFormatVersion; + sal_Int32 mnDocumentIconID; + + sal_Bool mbReadonly; + filter_info_impl(); + filter_info_impl( const filter_info_impl& rInfo ); + int operator==( const filter_info_impl& ) const; + + com::sun::star::uno::Sequence< rtl::OUString > getFilterUserData() const; +}; + +// -------------------------------------------------------------------- + +struct application_info_impl +{ + rtl::OUString maDocumentService; + rtl::OUString maDocumentUIName; + rtl::OUString maXMLImporter; + rtl::OUString maXMLExporter; + + application_info_impl( const sal_Char * pDocumentService, ResId& rUINameRes, const sal_Char * mpXMLImporter, const sal_Char * mpXMLExporter ); +}; + +// -------------------------------------------------------------------- + +extern std::vector< application_info_impl* >& getApplicationInfos(); +extern rtl::OUString getApplicationUIName( const rtl::OUString& rServiceName ); +extern const application_info_impl* getApplicationInfo( const rtl::OUString& rServiceName ); + +extern ResMgr* getXSLTDialogResMgr(); + +#define RESID(x) ResId(x, *getXSLTDialogResMgr() ) + +#endif diff --git a/filter/source/xsltdialog/xmlfilterdialogcomponent.cxx b/filter/source/xsltdialog/xmlfilterdialogcomponent.cxx new file mode 100644 index 000000000000..e22ac2790955 --- /dev/null +++ b/filter/source/xsltdialog/xmlfilterdialogcomponent.cxx @@ -0,0 +1,436 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_filter.hxx" +#include <osl/mutex.hxx> +#include <vos/mutex.hxx> +#include <toolkit/awt/vclxwindow.hxx> + +#include <osl/thread.h> +#include <cppuhelper/factory.hxx> +#include <cppuhelper/typeprovider.hxx> +#include <cppuhelper/component.hxx> +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#include <com/sun/star/frame/XDesktop.hpp> +#include <com/sun/star/frame/XTerminateListener.hpp> +#include <cppuhelper/implbase4.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/awt/XWindow.hpp> +#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <toolkit/awt/vclxwindow.hxx> +#include <tools/resmgr.hxx> +#include <vcl/svapp.hxx> + +#include <svl/solar.hrc> + +#include "xmlfiltersettingsdialog.hxx" + +//using namespace ::comphelper; +using namespace ::rtl; +using namespace ::cppu; +using namespace ::osl; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::registry; +using namespace ::com::sun::star::frame; + + +class XMLFilterDialogComponentBase +{ +protected: + ::osl::Mutex maMutex; +}; + + +class XMLFilterDialogComponent : public XMLFilterDialogComponentBase, + public OComponentHelper, + public ::com::sun::star::ui::dialogs::XExecutableDialog, + public XServiceInfo, + public XInitialization, + public XTerminateListener +{ +public: + XMLFilterDialogComponent( const Reference< XMultiServiceFactory >& rxMSF ); + virtual ~XMLFilterDialogComponent(); + +protected: + // XInterface + virtual Any SAL_CALL queryInterface( const Type& aType ) throw (RuntimeException); + virtual Any SAL_CALL queryAggregation( Type const & rType ) throw (RuntimeException); + virtual void SAL_CALL acquire() throw (); + virtual void SAL_CALL release() throw (); + + // XTypeProvider + virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() throw(RuntimeException); + virtual Sequence< Type > SAL_CALL getTypes() throw (RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName() throw(com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService(const ::rtl::OUString& ServiceName) throw(RuntimeException); + virtual Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (RuntimeException); + + // XExecutableDialog + virtual void SAL_CALL setTitle( const ::rtl::OUString& aTitle ) throw(RuntimeException); + virtual sal_Int16 SAL_CALL execute( ) throw(RuntimeException); + + // XInitialization + virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) throw(Exception, RuntimeException); + + // XTerminateListener + virtual void SAL_CALL queryTermination( const EventObject& Event ) throw (TerminationVetoException, RuntimeException); + virtual void SAL_CALL notifyTermination( const EventObject& Event ) throw (RuntimeException); + virtual void SAL_CALL disposing( const EventObject& Source ) throw (RuntimeException); + + /** Called in dispose method after the listeners were notified. + */ + virtual void SAL_CALL disposing(); + +private: + com::sun::star::uno::Reference<com::sun::star::awt::XWindow> mxParent; /// parent window + com::sun::star::uno::Reference< XMultiServiceFactory > mxMSF; + + static ResMgr* mpResMgr; + XMLFilterSettingsDialog* mpDialog; +}; + +//------------------------------------------------------------------------- + +ResMgr* XMLFilterDialogComponent::mpResMgr = NULL; + +XMLFilterDialogComponent::XMLFilterDialogComponent( const com::sun::star::uno::Reference< XMultiServiceFactory >& rxMSF ) : + OComponentHelper( maMutex ), + mxMSF( rxMSF ), + mpDialog( NULL ) +{ + Reference< XDesktop > xDesktop( mxMSF->createInstance( OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ), UNO_QUERY ); + if( xDesktop.is() ) + { + Reference< XTerminateListener > xListener( this ); + xDesktop->addTerminateListener( xListener ); + } +} + +//------------------------------------------------------------------------- + +XMLFilterDialogComponent::~XMLFilterDialogComponent() +{ +} + +//------------------------------------------------------------------------- + +// XInterface +Any SAL_CALL XMLFilterDialogComponent::queryInterface( const Type& aType ) throw (RuntimeException) +{ + return OComponentHelper::queryInterface( aType ); +} + +//------------------------------------------------------------------------- + +Any SAL_CALL XMLFilterDialogComponent::queryAggregation( Type const & rType ) throw (RuntimeException) +{ + if (rType == ::getCppuType( (Reference< ::com::sun::star::ui::dialogs::XExecutableDialog > const *)0 )) + { + void * p = static_cast< ::com::sun::star::ui::dialogs::XExecutableDialog * >( this ); + return Any( &p, rType ); + } + else if (rType == ::getCppuType( (Reference< XServiceInfo > const *)0 )) + { + void * p = static_cast< XServiceInfo * >( this ); + return Any( &p, rType ); + } + else if (rType == ::getCppuType( (Reference< XInitialization > const *)0 )) + { + void * p = static_cast< XInitialization * >( this ); + return Any( &p, rType ); + } + else if (rType == ::getCppuType( (Reference< XTerminateListener > const *)0 )) + { + void * p = static_cast< XTerminateListener * >( this ); + return Any( &p, rType ); + } + return OComponentHelper::queryAggregation( rType ); +} + +//------------------------------------------------------------------------- + +void SAL_CALL XMLFilterDialogComponent::acquire() throw () +{ + OComponentHelper::acquire(); +} + +//------------------------------------------------------------------------- + +void SAL_CALL XMLFilterDialogComponent::release() throw () +{ + OComponentHelper::release(); +} + +//------------------------------------------------------------------------- + +OUString XMLFilterDialogComponent_getImplementationName() throw ( RuntimeException ) +{ + return OUString( RTL_CONSTASCII_USTRINGPARAM( "XMLFilterDialogComponent" ) ); +} + +//------------------------------------------------------------------------- + +Sequence< OUString > SAL_CALL XMLFilterDialogComponent_getSupportedServiceNames() throw ( RuntimeException ) +{ + OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.ui.XSLTFilterDialog" ) ); + Sequence< ::rtl::OUString > aSupported( &aServiceName, 1 ); + return aSupported; +} + +//------------------------------------------------------------------------- + +sal_Bool SAL_CALL XMLFilterDialogComponent_supportsService( const OUString& ServiceName ) throw ( RuntimeException ) +{ + Sequence< ::rtl::OUString > aSupported(XMLFilterDialogComponent_getSupportedServiceNames()); + const ::rtl::OUString* pArray = aSupported.getConstArray(); + for (sal_Int32 i = 0; i < aSupported.getLength(); ++i, ++pArray) + if (pArray->equals(ServiceName)) + return sal_True; + return sal_False; +} + +//------------------------------------------------------------------------- + +Reference< XInterface > SAL_CALL XMLFilterDialogComponent_createInstance( const Reference< XMultiServiceFactory > & rSMgr) throw ( Exception ) +{ + return (OWeakObject*)new XMLFilterDialogComponent( rSMgr ); +} + +//------------------------------------------------------------------------- +::rtl::OUString SAL_CALL XMLFilterDialogComponent::getImplementationName() throw(com::sun::star::uno::RuntimeException) +{ + return XMLFilterDialogComponent_getImplementationName(); +} + +//------------------------------------------------------------------------- + +Sequence< sal_Int8 > SAL_CALL XMLFilterDialogComponent::getImplementationId( void ) throw( RuntimeException ) +{ + static OImplementationId* pId = 0; + if( !pId ) + { + MutexGuard aGuard( Mutex::getGlobalMutex() ); + if( !pId) + { + static OImplementationId aId; + pId = &aId; + } + } + return pId->getImplementationId(); +} + +//------------------------------------------------------------------------- + +Sequence< Type > XMLFilterDialogComponent::getTypes() throw (RuntimeException) +{ + static OTypeCollection * s_pTypes = 0; + if (! s_pTypes) + { + MutexGuard aGuard( Mutex::getGlobalMutex() ); + if (! s_pTypes) + { + static OTypeCollection s_aTypes( + ::getCppuType( (const Reference< XComponent > *)0 ), + ::getCppuType( (const Reference< XTypeProvider > *)0 ), + ::getCppuType( (const Reference< XAggregation > *)0 ), + ::getCppuType( (const Reference< XWeak > *)0 ), + ::getCppuType( (const Reference< XServiceInfo > *)0 ), + ::getCppuType( (const Reference< XInitialization > *)0 ), + ::getCppuType( (const Reference< XTerminateListener > *)0 ), + ::getCppuType( (const Reference< ::com::sun::star::ui::dialogs::XExecutableDialog > *)0 )); + s_pTypes = &s_aTypes; + } + } + return s_pTypes->getTypes(); +} + +//------------------------------------------------------------------------- + +Sequence< ::rtl::OUString > SAL_CALL XMLFilterDialogComponent::getSupportedServiceNames() throw(com::sun::star::uno::RuntimeException) +{ + return XMLFilterDialogComponent_getSupportedServiceNames(); +} + +//------------------------------------------------------------------------- +sal_Bool SAL_CALL XMLFilterDialogComponent::supportsService(const ::rtl::OUString& ServiceName) throw(RuntimeException) +{ + return XMLFilterDialogComponent_supportsService( ServiceName ); +} + +//------------------------------------------------------------------------- + +/** Called in dispose method after the listeners were notified. +*/ +void SAL_CALL XMLFilterDialogComponent::disposing() +{ + vos::OGuard aGuard( Application::GetSolarMutex() ); + + if( mpDialog ) + { + delete mpDialog; + mpDialog = NULL; + } + + if( mpResMgr ) + { + delete mpResMgr; + mpResMgr = NULL; + } +} + +//------------------------------------------------------------------------- + +// XTerminateListener +void SAL_CALL XMLFilterDialogComponent::queryTermination( const EventObject& /* Event */ ) throw (TerminationVetoException, RuntimeException) +{ + vos::OGuard aGuard( Application::GetSolarMutex() ); + + // we will never give a veto here + if( mpDialog && !mpDialog->isClosable() ) + { + mpDialog->ToTop(); + throw TerminationVetoException(); + } +} + +//------------------------------------------------------------------------- + +void SAL_CALL XMLFilterDialogComponent::notifyTermination( const EventObject& /* Event */ ) throw (RuntimeException) +{ + // we are going down, so dispose us! + dispose(); +} + +void SAL_CALL XMLFilterDialogComponent::disposing( const EventObject& /* Source */ ) throw (RuntimeException) +{ +} + +//------------------------------------------------------------------------- +void SAL_CALL XMLFilterDialogComponent::setTitle( const ::rtl::OUString& /* _rTitle */ ) throw(RuntimeException) +{ +} + +//------------------------------------------------------------------------- +sal_Int16 SAL_CALL XMLFilterDialogComponent::execute( ) throw(RuntimeException) +{ + vos::OGuard aGuard( Application::GetSolarMutex() ); + + if( NULL == mpResMgr ) + { + ByteString aResMgrName( "xsltdlg" ); + + mpResMgr = ResMgr::CreateResMgr( aResMgrName.GetBuffer(), Application::GetSettings().GetUILocale() ); + } + + if( NULL == mpDialog ) + { + Window* pParent = NULL; + if( mxParent.is() ) + { + VCLXWindow* pImplementation = VCLXWindow::GetImplementation(mxParent); + if (pImplementation) + pParent = pImplementation->GetWindow(); + } + + Reference< XComponent > xComp( this ); + mpDialog = new XMLFilterSettingsDialog( pParent, *mpResMgr, mxMSF ); + mpDialog->ShowWindow(); + } + else if( !mpDialog->IsVisible() ) + { + mpDialog->ShowWindow(); + } + mpDialog->ToTop(); + + return 0; +} + +//------------------------------------------------------------------------- +void SAL_CALL XMLFilterDialogComponent::initialize( const Sequence< Any >& aArguments ) throw(Exception, RuntimeException) +{ + const Any* pArguments = aArguments.getConstArray(); + for(sal_Int32 i=0; i<aArguments.getLength(); ++i, ++pArguments) + { + PropertyValue aProperty; + if(*pArguments >>= aProperty) + { + if( aProperty.Name.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "ParentWindow" ) ) == 0 ) + { + aProperty.Value >>= mxParent; + } + } + } +} + + +extern "C" +{ +//================================================================================================== +void SAL_CALL component_getImplementationEnvironment( + const sal_Char ** ppEnvTypeName, uno_Environment ** /* ppEnv */ ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +//================================================================================================== +void * SAL_CALL component_getFactory( + const sal_Char * pImplName, void * pServiceManager, void * /* pRegistryKey */ ) +{ + void * pRet = 0; + + if( pServiceManager ) + { + Reference< XSingleServiceFactory > xFactory; + + OUString implName = OUString::createFromAscii( pImplName ); + if ( implName.equals(XMLFilterDialogComponent_getImplementationName()) ) + { + xFactory = createOneInstanceFactory( + reinterpret_cast< XMultiServiceFactory * >( pServiceManager ), + OUString::createFromAscii( pImplName ), + XMLFilterDialogComponent_createInstance, XMLFilterDialogComponent_getSupportedServiceNames() ); + + } + + if (xFactory.is()) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + } + + return pRet; +} +} diff --git a/filter/source/xsltdialog/xmlfilterdialogstrings.hrc b/filter/source/xsltdialog/xmlfilterdialogstrings.hrc new file mode 100644 index 000000000000..a70b5d503df5 --- /dev/null +++ b/filter/source/xsltdialog/xmlfilterdialogstrings.hrc @@ -0,0 +1,72 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLFILTERDIALOGSTRINGS_HRC_ +#define _XMLFILTERDIALOGSTRINGS_HRC_ + +#include "xmlfiltercommon.hrc" + +#define STR_COLUMN_HEADER_NAME (RID_XSLT_DIALOG_START + 0) +#define STR_COLUMN_HEADER_TYPE (RID_XSLT_DIALOG_START + 1) +#define STR_UNKNOWN_APPLICATION (RID_XSLT_DIALOG_START + 2) +#define STR_IMPORT_ONLY (RID_XSLT_DIALOG_START + 3) +#define STR_IMPORT_EXPORT (RID_XSLT_DIALOG_START + 4) +#define STR_EXPORT_ONLY (RID_XSLT_DIALOG_START + 5) + +#define STR_WARN_DELETE (RID_XSLT_DIALOG_START + 10) +#define STR_NO_ERRORS_FOUND (RID_XSLT_DIALOG_START + 11) +#define STR_NOT_SPECIFIED (RID_XSLT_DIALOG_START + 12) + +#define STR_DEFAULT_FILTER_NAME (RID_XSLT_DIALOG_START + 13) +#define STR_DEFAULT_EXTENSION (RID_XSLT_DIALOG_START + 14) + +#define STR_ERROR_FILTER_NAME_EXISTS (RID_XSLT_DIALOG_START + 15) +#define STR_ERROR_TYPE_NAME_EXISTS (RID_XSLT_DIALOG_START + 16) +#define STR_ERROR_DTD_NOT_FOUND (RID_XSLT_DIALOG_START + 17) +#define STR_ERROR_EXPORT_XSLT_NOT_FOUND (RID_XSLT_DIALOG_START + 18) +#define STR_ERROR_IMPORT_XSLT_NOT_FOUND (RID_XSLT_DIALOG_START + 19) +#define STR_ERROR_IMPORT_TEMPLATE_NOT_FOUND (RID_XSLT_DIALOG_START + 20) +#define STR_DEFAULT_UI_NAME (RID_XSLT_DIALOG_START + 21) +#define STR_UNDEFINED_FILTER (RID_XSLT_DIALOG_START + 22) + +#define STR_FILTER_HAS_BEEN_SAVED (RID_XSLT_DIALOG_START + 23) +#define STR_FILTERS_HAVE_BEEN_SAVED (RID_XSLT_DIALOG_START + 24) +#define STR_FILTER_PACKAGE (RID_XSLT_DIALOG_START + 25) +#define STR_FILTER_INSTALLED (RID_XSLT_DIALOG_START + 26) +#define STR_FILTERS_INSTALLED (RID_XSLT_DIALOG_START + 27) +#define STR_NO_FILTERS_FOUND (RID_XSLT_DIALOG_START + 28) + +#define STR_APPL_NAME_WRITER (RID_XSLT_DIALOG_START + 30) +#define STR_APPL_NAME_CALC (RID_XSLT_DIALOG_START + 31) +#define STR_APPL_NAME_IMPRESS (RID_XSLT_DIALOG_START + 32) +#define STR_APPL_NAME_DRAW (RID_XSLT_DIALOG_START + 33) +#define STR_APPL_NAME_OASIS_WRITER (RID_XSLT_DIALOG_START + 34) +#define STR_APPL_NAME_OASIS_CALC (RID_XSLT_DIALOG_START + 35) +#define STR_APPL_NAME_OASIS_IMPRESS (RID_XSLT_DIALOG_START + 36) +#define STR_APPL_NAME_OASIS_DRAW (RID_XSLT_DIALOG_START + 37) + +#endif diff --git a/filter/source/xsltdialog/xmlfilterdialogstrings.src b/filter/source/xsltdialog/xmlfilterdialogstrings.src new file mode 100644 index 000000000000..ee47ea279db6 --- /dev/null +++ b/filter/source/xsltdialog/xmlfilterdialogstrings.src @@ -0,0 +1,203 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "xmlfilterdialogstrings.hrc" + + +String STR_COLUMN_HEADER_NAME +{ + Text [ en-US ] = "Name"; +}; + +String STR_COLUMN_HEADER_TYPE +{ + Text [ en-US ] = "Type"; +}; + +String STR_UNKNOWN_APPLICATION +{ + Text [ en-US ] = "Unknown"; +}; + +String STR_IMPORT_ONLY +{ + Text [ en-US ] = "import filter"; +}; + +String STR_IMPORT_EXPORT +{ + Text [ en-US ] = "import/export filter"; +}; + +String STR_EXPORT_ONLY +{ + Text [ en-US ] = "export filter"; +}; + +String STR_APPL_NAME_WRITER +{ + Text = "%PRODUCTNAME Writer (.sxw)"; +}; + +String STR_APPL_NAME_CALC +{ + Text = "%PRODUCTNAME Calc (.sxc)"; +}; + +String STR_APPL_NAME_IMPRESS +{ + Text = "%PRODUCTNAME Impress (.sxi)"; +}; + +String STR_APPL_NAME_DRAW +{ + Text = "%PRODUCTNAME Draw (.sxd)"; +}; + +String STR_APPL_NAME_OASIS_WRITER +{ + Text = "%PRODUCTNAME Writer (.odt)"; +}; + +String STR_APPL_NAME_OASIS_CALC +{ + Text = "%PRODUCTNAME Calc (.ods)"; +}; + +String STR_APPL_NAME_OASIS_IMPRESS +{ + Text = "%PRODUCTNAME Impress (.odp)"; +}; + +String STR_APPL_NAME_OASIS_DRAW +{ + Text = "%PRODUCTNAME Draw (.odg)"; +}; + +String STR_WARN_DELETE +{ + Text [ en-US ] = "Do you really want to delete the XML Filter '%s'? This action cannot be undone."; +}; + +String STR_ERROR_FILTER_NAME_EXISTS +{ + Text [ en-US ] = "An XML filter with the name '%s' already exists. Please enter a different name."; +}; + +String STR_ERROR_TYPE_NAME_EXISTS +{ + Text [ en-US ] = "The name for the user interface '%s1' is already used by the XML filter '%s2'. Please enter a different name."; +}; + +String STR_ERROR_DTD_NOT_FOUND +{ + Text [ en-US ] = "The DTD could not be found. Please enter a valid path."; +}; + +String STR_ERROR_EXPORT_XSLT_NOT_FOUND +{ + Text [ en-US ] = "The XSLT for export cannot be found. Please enter a valid path."; +}; + +String STR_ERROR_IMPORT_XSLT_NOT_FOUND +{ + Text [ en-US ] = "The XSLT for import cannot be found. Please enter a valid path."; +}; + +String STR_ERROR_IMPORT_TEMPLATE_NOT_FOUND +{ + Text [ en-US ] = "The given import template cannot be found. Please enter a valid path."; +}; + +String STR_NOT_SPECIFIED +{ + Text [ en-US ] = "Not specified"; +}; + +String STR_NO_ERRORS_FOUND +{ + Text = "No errors found."; +}; + +String STR_DEFAULT_FILTER_NAME +{ + Text [ en-US ] = "New Filter"; +}; + +String STR_DEFAULT_UI_NAME +{ + Text [ en-US ] = "Untitled"; +}; + +String STR_DEFAULT_EXTENSION +{ + Text = "xml"; +}; + +String STR_UNDEFINED_FILTER +{ + Text [ en-US ] = "undefined filter"; +}; + +String STR_FILTER_HAS_BEEN_SAVED +{ + Text [ en-US ] = "The XML filter '%s' has been saved as package '%s'. "; +}; + +String STR_FILTERS_HAVE_BEEN_SAVED +{ + Text [ en-US ] = "%s XML filters have been saved in the package '%s'."; +}; + +String STR_FILTER_PACKAGE +{ + Text [ en-US ] = "XSLT filter package"; +}; + +String STR_FILTER_INSTALLED +{ + Text [ en-US ] = "The XML filter '%s' has been installed successfully."; +}; + +String STR_FILTERS_INSTALLED +{ + Text [ en-US ] = "%s XML filters have been installed successfully."; +}; + +String STR_NO_FILTERS_FOUND +{ + Text [ en-US ] = "No XML filter could be installed because the package '%s' does not contain any XML filters."; +}; + + + + + + + + + diff --git a/filter/source/xsltdialog/xmlfilterhelpids.hrc b/filter/source/xsltdialog/xmlfilterhelpids.hrc new file mode 100644 index 000000000000..9c49d0537723 --- /dev/null +++ b/filter/source/xsltdialog/xmlfilterhelpids.hrc @@ -0,0 +1,88 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _XMLFILTERHELPIDS_HRC_ +#define _XMLFILTERHELPIDS_HRC_ + +#ifndef _FILTER_HRC +#include "filter.hrc" +#endif + +#define HID_XML_SOURCE_FILE_DIALOG (HID_FILTER_XSLT_START + 0) +#define HID_XML_SOURCE_FILE_VALIDATE (HID_FILTER_XSLT_START + 1) +#define HID_XML_FILTER_SETTINGS_DIALOG (HID_FILTER_XSLT_START + 2) +#define HID_XML_FILTER_LIST (HID_FILTER_XSLT_START + 3) +#define HID_XML_FILTER_NEW (HID_FILTER_XSLT_START + 4) +#define HID_XML_FILTER_EDIT (HID_FILTER_XSLT_START + 5) +#define HID_XML_FILTER_TEST (HID_FILTER_XSLT_START + 6) +#define HID_XML_FILTER_DELETE (HID_FILTER_XSLT_START + 7) +#define HID_XML_FILTER_SAVE (HID_FILTER_XSLT_START + 8) +#define HID_XML_FILTER_OPEN (HID_FILTER_XSLT_START + 9) +#define HID_XML_FILTER_CLOSE (HID_FILTER_XSLT_START + 10) + +#define HID_XML_FILTER_TABDIALOG (HID_FILTER_XSLT_START + 11) +#define HID_XML_FILTER_TABPAGE_BASIC (HID_FILTER_XSLT_START + 12) +#define HID_XML_FILTER_TABPAGE_XSLT (HID_FILTER_XSLT_START + 13) +#define HID_XML_FILTER_NAME (HID_FILTER_XSLT_START + 14) +#define HID_XML_FILTER_APPLICATION (HID_FILTER_XSLT_START + 15) +#define HID_XML_FILTER_INTERFACE_NAME (HID_FILTER_XSLT_START + 16) +#define HID_XML_FILTER_EXTENSION (HID_FILTER_XSLT_START + 17) +#define HID_XML_FILTER_DESCRIPTION (HID_FILTER_XSLT_START + 18) +#define HID_XML_FILTER_DOCTYPE (HID_FILTER_XSLT_START + 19) +#define HID_XML_FILTER_DTD (HID_FILTER_XSLT_START + 20) +#define HID_XML_FILTER_DTD_BROWSE (HID_FILTER_XSLT_START + 21) +#define HID_XML_FILTER_EXPORT_XSLT (HID_FILTER_XSLT_START + 22) +#define HID_XML_FILTER_EXPORT_XSLT_BROWSE (HID_FILTER_XSLT_START + 23) +#define HID_XML_FILTER_IMPORT_XSLT (HID_FILTER_XSLT_START + 24) +#define HID_XML_FILTER_IMPORT_XSLT_BROWSE (HID_FILTER_XSLT_START + 25) +#define HID_XML_FILTER_IMPORT_TEMPLATE (HID_FILTER_XSLT_START + 26) +#define HID_XML_FILTER_TEST_DIALOG (HID_FILTER_XSLT_START + 27) + +#define HID_XML_FILTER_TEST_EXPORT_BROWSE (HID_FILTER_XSLT_START + 28) +#define HID_XML_FILTER_TEST_EXPORT_CURRENT (HID_FILTER_XSLT_START + 29) +#define HID_XML_FILTER_TEST_EXPORT_CURRENT_FILE (HID_FILTER_XSLT_START + 30) + +#define HID_XML_FILTER_TEST_IMPORT_XSLT_FILE (HID_FILTER_XSLT_START + 31) +#define HID_XML_FILTER_TEST_IMPORT_TEMPLATE_FILE (HID_FILTER_XSLT_START + 32) +#define HID_XML_FILTER_TEST_IMPORT_DISPLAY_SOURCE (HID_FILTER_XSLT_START + 33) +#define HID_XML_FILTER_TEST_IMPORT_BROWSE (HID_FILTER_XSLT_START + 34) +#define HID_XML_FILTER_TEST_IMPORT_RECENT (HID_FILTER_XSLT_START + 35) +#define HID_XML_FILTER_TEST_IMPORT_RECENT_FILE (HID_FILTER_XSLT_START + 36) +#define HID_XML_FILTER_TEST_CLOSE (HID_FILTER_XSLT_START + 37) + +#define HID_XML_FILTER_IMPORT_TEMPLATE_BROWSE (HID_FILTER_XSLT_START + 38) + +#define HID_XML_FILTER_TEST_VALIDATE_OUPUT (HID_FILTER_XSLT_START + 39) +#define HID_XML_FILTER_OUTPUT_WINDOW (HID_FILTER_XSLT_START + 40) + +#define HID_XML_FILTER_TEST_EXPORT_XSLT_FILE (HID_FILTER_XSLT_START + 41) + +#define HID_XML_FILTER_TABPAGE_CTRL (HID_FILTER_XSLT_START + 42) + +// last help id is HID_FILTER_XSLT_END ! +// #define HID_FILTER_XSLT_END (HID_FILTER_START + 99) + +#endif diff --git a/filter/source/xsltdialog/xmlfilterjar.cxx b/filter/source/xsltdialog/xmlfilterjar.cxx new file mode 100644 index 000000000000..0a01310b3b40 --- /dev/null +++ b/filter/source/xsltdialog/xmlfilterjar.cxx @@ -0,0 +1,405 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_filter.hxx" +#include <com/sun/star/io/XActiveDataControl.hpp> +#include <com/sun/star/io/XActiveDataSource.hpp> +#include <com/sun/star/frame/XConfigManager.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/io/XActiveDataSink.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/NamedValue.hpp> +#include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/container/XChild.hpp> +#include <com/sun/star/util/XChangesBatch.hpp> + + +#include <comphelper/oslfile2streamwrap.hxx> +#include <comphelper/storagehelper.hxx> +#include <unotools/streamwrap.hxx> +#include <tools/stream.hxx> +#include <tools/urlobj.hxx> +#include <unotools/tempfile.hxx> +#include <svl/urihelper.hxx> +#include <osl/file.hxx> + +#include <rtl/uri.hxx> + +#include "xmlfilterjar.hxx" +#include "xmlfilterdialogstrings.hrc" +#include "xmlfiltersettingsdialog.hxx" +#include "typedetectionexport.hxx" +#include "typedetectionimport.hxx" + +using namespace rtl; +using namespace osl; +using namespace comphelper; +using namespace com::sun::star; +using namespace com::sun::star::lang; +using namespace com::sun::star::frame; +using namespace com::sun::star::uno; +using namespace com::sun::star::util; +using namespace com::sun::star::container; +using namespace com::sun::star::beans; +using namespace com::sun::star::io; + +XMLFilterJarHelper::XMLFilterJarHelper( Reference< XMultiServiceFactory >& xMSF ) +: mxMSF( xMSF ), + sVndSunStarPackage( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.Package:" ) ), + sXSLTPath( RTL_CONSTASCII_USTRINGPARAM( "$(user)/xslt/" ) ), + sDTDPath( RTL_CONSTASCII_USTRINGPARAM( "$(user)/dtd/" ) ), + sTemplatePath( RTL_CONSTASCII_USTRINGPARAM( "$(user)/template/") ), + sSpecialConfigManager( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.config.SpecialConfigManager" ) ), + sPump( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.Pump" ) ), + sProgPath( RTL_CONSTASCII_USTRINGPARAM( "$(prog)/" ) ) +{ + try + { + Reference< XConfigManager > xCfgMgr( xMSF->createInstance(OUString::createFromAscii("com.sun.star.config.SpecialConfigManager")), UNO_QUERY ); + if( xCfgMgr.is() ) + { + sProgPath = xCfgMgr->substituteVariables( sProgPath ); + sXSLTPath = xCfgMgr->substituteVariables( sXSLTPath ); + sDTDPath = xCfgMgr->substituteVariables( sDTDPath ); + sTemplatePath = xCfgMgr->substituteVariables( sTemplatePath ); + } + } + catch(Exception&) + { + } +} + +static OUString encodeZipUri( const OUString& rURI ) +{ + return Uri::encode( rURI, rtl_UriCharClassUric, rtl_UriEncodeCheckEscapes, RTL_TEXTENCODING_UTF8 ); +} + +static Reference< XInterface > addFolder( Reference< XInterface >& xRootFolder, Reference< XSingleServiceFactory >& xFactory, const OUString& rName ) throw( Exception ) +{ + if ( rName.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( ".." ) ) ) + || rName.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( "." ) ) ) ) + throw lang::IllegalArgumentException(); + + Sequence< Any > aArgs(1); + aArgs[0] <<= (sal_Bool)sal_True; + + Reference< XInterface > xFolder( xFactory->createInstanceWithArguments(aArgs) ); + Reference< XNamed > xNamed( xFolder, UNO_QUERY ); + Reference< XChild > xChild( xFolder, UNO_QUERY ); + + if( xNamed.is() && xChild.is() ) + { + OUString aName( encodeZipUri( rName ) ); + xNamed->setName( aName ); + xChild->setParent( xRootFolder ); + } + + return xFolder; +} + +static void _addFile( Reference< XInterface >& xRootFolder, Reference< XSingleServiceFactory >& xFactory, Reference< XInputStream >& xInput, OUString aName ) throw( Exception ) +{ + + Reference< XActiveDataSink > xSink( xFactory->createInstance(), UNO_QUERY ); + Reference< XUnoTunnel > xTunnel( xSink, UNO_QUERY ); + if( xSink.is() && xTunnel.is()) + { + Reference< XNameContainer > xNameContainer(xRootFolder, UNO_QUERY ); + xNameContainer->insertByName(aName = encodeZipUri( aName ), makeAny(xTunnel)); + xSink->setInputStream( xInput ); + } +} + +/* +static void addFile( Reference< XInterface > xRootFolder, Reference< XSingleServiceFactory > xFactory, const OUString& rSourceFile, const OUString& rName ) throw( Exception ) +{ + Reference< XInputStream > xInput( new utl::OSeekableInputStreamWrapper( new SvFileStream(rSourceFile, STREAM_READ ), true ) ); + _addFile( xRootFolder, xFactory, xInput, rName ); +} +*/ + +void XMLFilterJarHelper::addFile( Reference< XInterface > xRootFolder, Reference< XSingleServiceFactory > xFactory, const OUString& rSourceFile ) throw( Exception ) +{ + if( rSourceFile.getLength() && + (rSourceFile.compareToAscii( RTL_CONSTASCII_STRINGPARAM("http:") ) != 0) && + (rSourceFile.compareToAscii( RTL_CONSTASCII_STRINGPARAM("shttp:") ) != 0) && + (rSourceFile.compareToAscii( RTL_CONSTASCII_STRINGPARAM("jar:") ) != 0) && + (rSourceFile.compareToAscii( RTL_CONSTASCII_STRINGPARAM("ftp:") ) != 0)) + { + OUString aFileURL( rSourceFile ); + + if( !aFileURL.matchIgnoreAsciiCase( OUString( RTL_CONSTASCII_USTRINGPARAM("file://") ) ) ) + { + aFileURL = URIHelper::SmartRel2Abs( sProgPath, aFileURL, Link(), false ); + } + + INetURLObject aURL( aFileURL ); + OUString aName( aURL.getName() ); + + SvFileStream* pStream = new SvFileStream(aFileURL, STREAM_READ ); + Reference< XInputStream > xInput( new utl::OSeekableInputStreamWrapper( pStream, true ) ); + _addFile( xRootFolder, xFactory, xInput, aName ); + } +} + +bool XMLFilterJarHelper::savePackage( const OUString& rPackageURL, const XMLFilterVector& rFilters ) +{ + try + { + osl::File::remove( rPackageURL ); + + // create the package jar file + + Sequence< Any > aArguments( 2 ); + aArguments[ 0 ] <<= rPackageURL; + + // let ZipPackage be used ( no manifest.xml is required ) + beans::NamedValue aArg; + aArg.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StorageFormat" ) ); + aArg.Value <<= ZIP_STORAGE_FORMAT_STRING; + aArguments[ 1 ] <<= aArg; + + Reference< XHierarchicalNameAccess > xIfc( + mxMSF->createInstanceWithArguments( + rtl::OUString::createFromAscii( + "com.sun.star.packages.comp.ZipPackage" ), + aArguments ), UNO_QUERY ); + + if( xIfc.is() ) + { + Reference< XSingleServiceFactory > xFactory( xIfc, UNO_QUERY ); + + // get root zip folder + Reference< XInterface > xRootFolder; + OUString szRootFolder( RTL_CONSTASCII_USTRINGPARAM("/") ); + xIfc->getByHierarchicalName( szRootFolder ) >>= xRootFolder; + + // export filters files + XMLFilterVector::const_iterator aIter( rFilters.begin() ); + while( aIter != rFilters.end() ) + { + const filter_info_impl* pFilter = (*aIter); + + Reference< XInterface > xFilterRoot( addFolder( xRootFolder, xFactory, pFilter->maFilterName ) ); + + if( xFilterRoot.is() ) + { + if( pFilter->maDTD.getLength() ) + addFile( xFilterRoot, xFactory, pFilter->maDTD ); + + if( pFilter->maExportXSLT.getLength() ) + addFile( xFilterRoot, xFactory, pFilter->maExportXSLT ); + try + { + if( pFilter->maImportXSLT.getLength() ) + addFile( xFilterRoot, xFactory, pFilter->maImportXSLT ); + } + catch( com::sun::star::container::ElementExistException&) + { + // in case of same named import / export XSLT the latter + // is ignored + DBG_ERROR( "XMLFilterJarHelper::same named xslt filter exception!" ); + } + + if( pFilter->maImportTemplate.getLength() ) + addFile( xFilterRoot, xFactory, pFilter->maImportTemplate ); + } + + aIter++; + } + + // create TypeDetection.xcu + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + OUString aTempFileURL( aTempFile.GetURL() ); + + { + osl::File aOutputFile( aTempFileURL ); + /* osl::File::RC rc = */ aOutputFile.open( OpenFlag_Write ); + Reference< XOutputStream > xOS( new OSLOutputStreamWrapper( aOutputFile ) ); + + TypeDetectionExporter aExporter( mxMSF ); + aExporter.doExport(xOS,rFilters); + } + + Reference< XInputStream > XIS( new utl::OSeekableInputStreamWrapper( new SvFileStream(aTempFileURL, STREAM_READ ), true ) ); + OUString szTypeDetection( RTL_CONSTASCII_USTRINGPARAM( "TypeDetection.xcu" ) ); + _addFile( xRootFolder, xFactory, XIS, szTypeDetection ); + + Reference< XChangesBatch > xBatch( xIfc, UNO_QUERY ); + if( xBatch.is() ) + xBatch->commitChanges(); + + return true; + } + } + catch( Exception& ) + { + DBG_ERROR( "XMLFilterJarHelper::savePackage exception catched!" ); + } + + osl::File::remove( rPackageURL ); + + return false; +} + + + +// + +void XMLFilterJarHelper::openPackage( const OUString& rPackageURL, XMLFilterVector& rFilters ) +{ + try + { + // create the package jar file + + Sequence< Any > aArguments( 2 ); + aArguments[ 0 ] <<= rPackageURL; + + // let ZipPackage be used ( no manifest.xml is required ) + beans::NamedValue aArg; + aArg.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StorageFormat" ) ); + aArg.Value <<= ZIP_STORAGE_FORMAT_STRING; + aArguments[ 1 ] <<= aArg; + + Reference< XHierarchicalNameAccess > xIfc( + mxMSF->createInstanceWithArguments( + rtl::OUString::createFromAscii( + "com.sun.star.packages.comp.ZipPackage" ), + aArguments ), UNO_QUERY ); + + if( xIfc.is() ) + { + Reference< XSingleServiceFactory > xFactory( xIfc, UNO_QUERY ); + + // get root zip folder + Reference< XInterface > xRootFolder; + OUString szRootFolder( RTL_CONSTASCII_USTRINGPARAM("/") ); + xIfc->getByHierarchicalName( szRootFolder ) >>= xRootFolder; + + OUString szTypeDetection( RTL_CONSTASCII_USTRINGPARAM("TypeDetection.xcu") ); + if( xIfc->hasByHierarchicalName( szTypeDetection ) ) + { + Reference< XActiveDataSink > xTypeDetection; + xIfc->getByHierarchicalName( szTypeDetection ) >>= xTypeDetection; + + if( xTypeDetection.is() ) + { + Reference< XInputStream > xIS( xTypeDetection->getInputStream() ); + + XMLFilterVector aFilters; + TypeDetectionImporter::doImport( mxMSF, xIS, aFilters ); + + // copy all files used by the filters imported from the + // typedetection to office/user/xslt + XMLFilterVector::iterator aIter( aFilters.begin() ); + while( aIter != aFilters.end() ) + { + if( copyFiles( xIfc, (*aIter) ) ) + { + rFilters.push_back( (*aIter) ); + } + else + { + // failed to copy all files + delete (*aIter); + } + aIter++; + } + } + } + } + } + catch( Exception& ) + { + DBG_ERROR( "XMLFilterJarHelper::savePackage exception catched!" ); + } +} + +bool XMLFilterJarHelper::copyFiles( Reference< XHierarchicalNameAccess > xIfc, filter_info_impl* pFilter ) +{ + bool bOk = copyFile( xIfc, pFilter->maDTD, sDTDPath ); + + if( bOk ) + bOk = copyFile( xIfc, pFilter->maExportXSLT, sXSLTPath ); + + if( bOk ) + bOk = copyFile( xIfc, pFilter->maImportXSLT, sXSLTPath ); + + if( bOk ) + bOk = copyFile( xIfc, pFilter->maImportTemplate, sTemplatePath ); + + return bOk; +} + +bool XMLFilterJarHelper::copyFile( Reference< XHierarchicalNameAccess > xIfc, OUString& rURL, const OUString& rTargetURL ) +{ + if( !rURL.matchIgnoreAsciiCase( sVndSunStarPackage ) ) + return true; + + try + { + OUString szPackagePath( encodeZipUri( rURL.copy( sVndSunStarPackage.getLength() ) ) ); + + if ( ::comphelper::OStorageHelper::PathHasSegment( szPackagePath, OUString( RTL_CONSTASCII_USTRINGPARAM( ".." ) ) ) + || ::comphelper::OStorageHelper::PathHasSegment( szPackagePath, OUString( RTL_CONSTASCII_USTRINGPARAM( "." ) ) ) ) + throw lang::IllegalArgumentException(); + + if( xIfc->hasByHierarchicalName( szPackagePath ) ) + { + Reference< XActiveDataSink > xFileEntry; + xIfc->getByHierarchicalName( szPackagePath ) >>= xFileEntry; + + if( xFileEntry.is() ) + { + Reference< XInputStream > xIS( xFileEntry->getInputStream() ); + + INetURLObject aBaseURL( rTargetURL ); + + rURL = URIHelper::SmartRel2Abs( aBaseURL, szPackagePath, Link(), false ); + + if( rURL.getLength() ) + { + // create output directory if needed + if( !createDirectory( rURL ) ) + return false; + + SvFileStream aOutputStream(rURL, STREAM_WRITE ); + Reference< XOutputStream > xOS( new utl::OOutputStreamWrapper( aOutputStream ) ); + + return copyStreams( xIS, xOS ); + } + } + } + } + catch( Exception& ) + { + DBG_ERROR( "XMLFilterJarHelper::copyFile exception catched" ); + } + return false; +} diff --git a/filter/source/xsltdialog/xmlfilterjar.hxx b/filter/source/xsltdialog/xmlfilterjar.hxx new file mode 100644 index 000000000000..a196905edabf --- /dev/null +++ b/filter/source/xsltdialog/xmlfilterjar.hxx @@ -0,0 +1,65 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _XMLFILTERJAR_HXX_ +#define _XMLFILTERJAR_HXX_ + +#include <com/sun/star/container/XHierarchicalNameAccess.hpp> +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> + +#include <vector> + +class filter_info_impl; + +typedef std::vector< filter_info_impl* > XMLFilterVector; + +class XMLFilterJarHelper +{ +public: + XMLFilterJarHelper( com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& xMSF ); + + bool savePackage( const rtl::OUString& rPackageURL, const XMLFilterVector& rFilters ); + void openPackage( const rtl::OUString& rPackageURL, XMLFilterVector& rFilters ); + +private: + void addFile( com::sun::star::uno::Reference< com::sun::star::uno::XInterface > xRootFolder, com::sun::star::uno::Reference< com::sun::star::lang::XSingleServiceFactory > xFactory, const ::rtl::OUString& rSourceFile ) throw( com::sun::star::uno::Exception ); + + bool copyFile( com::sun::star::uno::Reference< com::sun::star::container::XHierarchicalNameAccess > xIfc, ::rtl::OUString& rURL, const ::rtl::OUString& rTargetURL ); + bool copyFiles( com::sun::star::uno::Reference< com::sun::star::container::XHierarchicalNameAccess > xIfc, filter_info_impl* pFilter ); + + com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > mxMSF; + + ::rtl::OUString sVndSunStarPackage; + ::rtl::OUString sXSLTPath; + ::rtl::OUString sDTDPath; + ::rtl::OUString sTemplatePath; + ::rtl::OUString sSpecialConfigManager; + ::rtl::OUString sPump; + ::rtl::OUString sProgPath; +}; + +#endif diff --git a/filter/source/xsltdialog/xmlfiltersettingsdialog.cxx b/filter/source/xsltdialog/xmlfiltersettingsdialog.cxx new file mode 100644 index 000000000000..46cab18f6c77 --- /dev/null +++ b/filter/source/xsltdialog/xmlfiltersettingsdialog.cxx @@ -0,0 +1,1799 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_filter.hxx" +#include <com/sun/star/frame/XConfigManager.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/util/XFlushable.hpp> + +#ifndef _COM_SUN_STAR_BEANS_NAMEDVALUE_HPP_ +#include <com/sun/star/beans/PropertyValue.hpp> +#endif + +#include "com/sun/star/ui/dialogs/TemplateDescription.hpp" +#include <tools/urlobj.hxx> +#include <svtools/headbar.hxx> +#include <unotools/streamwrap.hxx> +#include <osl/file.hxx> +#include <vcl/msgbox.hxx> +#include <sfx2/filedlghelper.hxx> + +#include <rtl/uri.hxx> + +#include <algorithm> + +#include "xmlfilterdialogstrings.hrc" +#include "xmlfiltersettingsdialog.hxx" +#include "xmlfiltersettingsdialog.hrc" +#include "xmlfiltertabdialog.hxx" +#include "xmlfiltertestdialog.hxx" +#include "xmlfilterjar.hxx" +#include "xmlfilterhelpids.hrc" + +using namespace rtl; +using namespace osl; +using namespace com::sun::star::lang; +using namespace com::sun::star::uno; +using namespace com::sun::star::io; +using namespace com::sun::star::frame; +using namespace com::sun::star::container; +using namespace com::sun::star::beans; +using namespace com::sun::star::util; + +ResMgr* XMLFilterSettingsDialog::mpResMgr = NULL; + +XMLFilterSettingsDialog::XMLFilterSettingsDialog( Window* pParent, ResMgr& rResMgr, const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rxMSF ) : + WorkWindow( pParent, ResId( DLG_XML_FILTER_SETTINGS_DIALOG, rResMgr ) ), + mxMSF( rxMSF ), + maCtrlFilterList( this, ResId( CTRL_XML_FILTER_LIST, rResMgr ) ), + maPBNew( this, ResId( PB_XML_FILTER_NEW, rResMgr ) ), + maPBEdit( this, ResId( PB_XML_FILTER_EDIT, rResMgr ) ), + maPBTest( this, ResId( PB_XML_FILTER_TEST, rResMgr ) ), + maPBDelete( this, ResId( PB_XML_FILTER_DELETE, rResMgr ) ), + maPBSave( this, ResId( PB_XML_FILTER_SAVE, rResMgr ) ), + maPBOpen( this, ResId( PB_XML_FILTER_OPEN, rResMgr ) ), + maPBHelp( this, ResId( BTN_XML_FILTER_HELP, rResMgr ) ), + maPBClose( this, ResId( PB_XML_FILTER_CLOSE, rResMgr ) ), + mbIsClosable(true), + sTemplatePath( RTL_CONSTASCII_USTRINGPARAM( "$(user)/template/") ), + sDocTypePrefix( RTL_CONSTASCII_USTRINGPARAM( "doctype:") ) +{ + FreeResource(); + + mpResMgr = &rResMgr; + + mpFilterListBox = new XMLFilterListBox( &maCtrlFilterList ); + mpFilterListBox->SetSelectHdl( LINK( this, XMLFilterSettingsDialog, SelectionChangedHdl_Impl ) ); + mpFilterListBox->SetDeselectHdl( LINK( this, XMLFilterSettingsDialog, SelectionChangedHdl_Impl ) ); + mpFilterListBox->SetDoubleClickHdl( LINK( this, XMLFilterSettingsDialog, DoubleClickHdl_Impl ) ); + mpFilterListBox->SetHelpId( HID_XML_FILTER_LIST ); + + maPBNew.SetClickHdl(LINK( this, XMLFilterSettingsDialog, ClickHdl_Impl ) ); + maPBEdit.SetClickHdl(LINK( this, XMLFilterSettingsDialog, ClickHdl_Impl ) ); + maPBTest.SetClickHdl(LINK( this, XMLFilterSettingsDialog, ClickHdl_Impl ) ); + maPBDelete.SetClickHdl(LINK( this, XMLFilterSettingsDialog, ClickHdl_Impl ) ); + maPBSave.SetClickHdl(LINK( this, XMLFilterSettingsDialog, ClickHdl_Impl ) ); + maPBOpen.SetClickHdl(LINK( this, XMLFilterSettingsDialog, ClickHdl_Impl ) ); + maPBClose.SetClickHdl(LINK( this, XMLFilterSettingsDialog, ClickHdl_Impl ) ); + + try + { + mxFilterContainer = Reference< XNameContainer >::query( rxMSF->createInstance( OUString::createFromAscii("com.sun.star.document.FilterFactory" ) ) ); + mxTypeDetection = Reference< XNameContainer >::query( rxMSF->createInstance( OUString::createFromAscii("com.sun.star.document.TypeDetection" ) )); + mxExtendedTypeDetection = Reference< XNameContainer >::query( rxMSF->createInstance( OUString::createFromAscii("com.sun.star.document.ExtendedTypeDetectionFactory" ) ) ); + + Reference< XConfigManager > xCfgMgr( mxMSF->createInstance(OUString::createFromAscii("com.sun.star.config.SpecialConfigManager") ), UNO_QUERY ); + if( xCfgMgr.is() ) + { + sTemplatePath = xCfgMgr->substituteVariables( sTemplatePath ); + } + } + catch(Exception&) + { + DBG_ERROR( "XMLFilterSettingsDialog::XMLFilterSettingsDialog exception catched!" ); + } +} + +// ----------------------------------------------------------------------- + +XMLFilterSettingsDialog::~XMLFilterSettingsDialog() +{ + delete mpFilterListBox; +} + +// ----------------------------------------------------------------------- + +IMPL_LINK(XMLFilterSettingsDialog, ClickHdl_Impl, PushButton *, pButton ) +{ + mbIsClosable = false; + + if( &maPBNew == pButton ) + { + onNew(); + } + else if( &maPBEdit == pButton ) + { + onEdit(); + } + else if( &maPBTest == pButton ) + { + onTest(); + } + else if( &maPBDelete == pButton ) + { + onDelete(); + } + else if( &maPBSave == pButton ) + { + onSave(); + } + else if( &maPBOpen == pButton ) + { + onOpen(); + } + else if( &maPBClose == pButton ) + { + onClose(); + } + + mbIsClosable = true; + return 0; +} + +// ----------------------------------------------------------------------- + +IMPL_LINK(XMLFilterSettingsDialog, SelectionChangedHdl_Impl, void *, EMPTYARG ) +{ + updateStates(); + return 0; +} + +// ----------------------------------------------------------------------- + +IMPL_LINK(XMLFilterSettingsDialog, DoubleClickHdl_Impl, void *, EMPTYARG ) +{ + onEdit(); + return 0; +} + +bool XMLFilterSettingsDialog::isClosable() +{ + return mbIsClosable; +} + +// ----------------------------------------------------------------------- + +void XMLFilterSettingsDialog::ShowWindow() +{ + maCtrlFilterList.GrabFocus(); + disposeFilterList(); + mpFilterListBox->Clear(); + initFilterList(); + updateStates(); + mpFilterListBox->Reset(); + + WorkWindow::Show( TRUE ); +} + +// ----------------------------------------------------------------------- + +void XMLFilterSettingsDialog::updateStates() +{ + SvLBoxEntry* pSelectedEntry = mpFilterListBox->FirstSelected(); + + bool bHasSelection = pSelectedEntry != NULL; + + bool bMultiSelection = bHasSelection && (mpFilterListBox->NextSelected( pSelectedEntry ) != NULL ); + bool bIsReadonly = false; + bool bIsDefault = false; + if(pSelectedEntry) + { + filter_info_impl* pInfo = (filter_info_impl*)pSelectedEntry->GetUserData(); + bIsReadonly = 0 != pInfo->mbReadonly; + + sal_Int32 nFact = SvtModuleOptions::E_WRITER; + while(nFact <= SvtModuleOptions::E_BASIC) + { + ::rtl::OUString sDefault = maModuleOpt.GetFactoryDefaultFilter((SvtModuleOptions::EFactory)nFact); + if( sDefault == pInfo->maFilterName ) + { + bIsDefault = true; + break; + } + ++nFact; + } + } + maPBEdit.Enable( bHasSelection && !bMultiSelection && !bIsReadonly); + maPBTest.Enable( bHasSelection && !bMultiSelection ); + maPBDelete.Enable( bHasSelection && !bMultiSelection && !bIsReadonly && !bIsDefault); + maPBSave.Enable( bHasSelection ); +} + +// ----------------------------------------------------------------------- + +/** is called when the user clicks on the "New" button */ +void XMLFilterSettingsDialog::onNew() +{ + filter_info_impl aTempInfo; + + // create a unique filter name + aTempInfo.maFilterName = createUniqueFilterName( String( RESID( STR_DEFAULT_FILTER_NAME ) ) ); + + // init default extension + String aDefaultExtension( RESID( STR_DEFAULT_EXTENSION ) ); + aTempInfo.maExtension = aDefaultExtension; + + // set default ui name + aTempInfo.maInterfaceName = createUniqueInterfaceName( String( RESID( STR_DEFAULT_UI_NAME ) ) ); + + // set default application + aTempInfo.maDocumentService = OUString::createFromAscii("com.sun.star.text.TextDocument"); + + // execute XML Filter Dialog + XMLFilterTabDialog aDlg( this, *mpResMgr, mxMSF, &aTempInfo ); + if ( aDlg.Execute() == RET_OK ) + { + // insert the new filter + insertOrEdit( aDlg.getNewFilterInfo() ); + } +} + +// ----------------------------------------------------------------------- + +/** is called when the user clicks on the "Edit" Button */ +void XMLFilterSettingsDialog::onEdit() +{ + // get selected filter entry + SvLBoxEntry* pEntry = mpFilterListBox->FirstSelected(); + if( pEntry ) + { + // get its filter info + filter_info_impl* pOldInfo = (filter_info_impl*)pEntry->GetUserData(); + + // execute XML Filter Dialog + XMLFilterTabDialog aDlg( this, *mpResMgr, mxMSF, pOldInfo ); + if ( aDlg.Execute() == RET_OK ) + { + filter_info_impl* pNewInfo = aDlg.getNewFilterInfo(); + + if( !(*pOldInfo == *pNewInfo) ) + { + // change filter + insertOrEdit( pNewInfo, pOldInfo ); + } + } + } +} + +// ----------------------------------------------------------------------- + +/** helper to create a sequence of strings from an extensions strings + "ext1;ext2;ext3" will become { "ext1", "ext2", "ext3" } */ +static Sequence< OUString > createExtensionsSequence( const rtl::OUString& rExtensions ) +{ + // first count how many extensions we have inside the string + int nExtensions = 0; + + int nLength = rExtensions.getLength(); + if( nLength ) + { + // a non empty string has at least one extension + nExtensions++; + + // now count the delimeters ';' + const sal_Unicode * pString = rExtensions.getStr(); + int i; + for( i = 0; i < nLength; i++, pString++ ) + { + if( *pString == sal_Unicode( ';' ) ) + nExtensions++; + } + } + + Sequence< OUString > aExtensions( nExtensions ); + + // extract the extensions from the source string and fill the sequence + + int nLastIndex = 0; + int nCurrentIndex = 0; + int i; + + for( i = 0; i < nExtensions; i++ ) + { + nLastIndex = rExtensions.indexOf( sal_Unicode( ';' ), nLastIndex ); + + if( nLastIndex == -1 ) + { + aExtensions[i] = rExtensions.copy( nCurrentIndex ); + break; + } + else + { + aExtensions[i] = rExtensions.copy( nCurrentIndex, nLastIndex - nCurrentIndex ); + nCurrentIndex = nLastIndex + 1; + nLastIndex = nCurrentIndex; + } + } + + return aExtensions; +} + +// ----------------------------------------------------------------------- + +/** checks if the given name is unique inside the filter factory. If not, + numbers are added until the returned name is unique */ +OUString XMLFilterSettingsDialog::createUniqueFilterName( const OUString& rFilterName ) +{ + OUString aFilterName( rFilterName ); + OUString aSpace( sal_Unicode( ' ' ) ); + + sal_Int32 nId = 2; + + while( mxFilterContainer->hasByName( aFilterName ) ) + { + aFilterName = rFilterName; + aFilterName += aSpace; + aFilterName += OUString::valueOf( nId++ ); + } + + return aFilterName; +} + +// ----------------------------------------------------------------------- + +/** checks if the given name is unique inside the type detection. If not, + numbers are added until the returned name is unique */ +OUString XMLFilterSettingsDialog::createUniqueTypeName( const OUString& rTypeName ) +{ + OUString aTypeName( rTypeName ); + OUString aSpace( sal_Unicode( ' ' ) ); + + sal_Int32 nId = 2; + + while( mxFilterContainer->hasByName( aTypeName ) ) + { + aTypeName = rTypeName; + aTypeName += aSpace; + aTypeName += OUString::valueOf( nId++ ); + } + + return aTypeName; +} + +/** checks if the given name is a unique ui name inside the filter factory. If not, + numbers are added until the returned name is unique */ +OUString XMLFilterSettingsDialog::createUniqueInterfaceName( const OUString& rInterfaceName ) +{ + sal_Int32 nDefaultNumber = 0; + + try + { + Sequence< OUString > aFilterNames( mxFilterContainer->getElementNames() ); + OUString* pFilterName = aFilterNames.getArray(); + + const sal_Int32 nCount = aFilterNames.getLength(); + sal_Int32 nFilter; + + Sequence< PropertyValue > aValues; + for( nFilter = 0; (nFilter < nCount); nFilter++, pFilterName++ ) + { + Any aAny( mxFilterContainer->getByName( *pFilterName ) ); + if( !(aAny >>= aValues) ) + continue; + + const sal_Int32 nValueCount( aValues.getLength() ); + PropertyValue* pValues = aValues.getArray(); + sal_Int32 nValue; + + for( nValue = 0; nValue < nValueCount; nValue++, pValues++ ) + { + if( pValues->Name.equalsAscii( "UIName" ) ) + { + OUString aInterfaceName; + pValues->Value >>= aInterfaceName; + + + // see if this filter matches our default filter name + if( aInterfaceName.match( rInterfaceName ) ) + { + // if yes, make sure we generate a unique name with a higher number + // this is dump but fast + sal_Int32 nNumber = aInterfaceName.copy( rInterfaceName.getLength() ).toInt32(); + if( nNumber >= nDefaultNumber ) + nDefaultNumber = nNumber + 1; + } + } + } + } + } + catch( Exception& ) + { + DBG_ERROR( "XMLFilterSettingsDialog::createUniqueInterfaceName exception catched!" ); + } + + OUString aInterfaceName( rInterfaceName ); + if( nDefaultNumber ) + { + aInterfaceName += OUString( sal_Unicode( ' ' ) ); + aInterfaceName += String::CreateFromInt32( nDefaultNumber ); + } + + return aInterfaceName; +} + +// ----------------------------------------------------------------------- + +/** inserts a new filter into the ui and configuration if pOldInfo is NULL. + If pOldInfo is not null, the old filter will be replaced with the new settings */ +bool XMLFilterSettingsDialog::insertOrEdit( filter_info_impl* pNewInfo, const filter_info_impl* pOldInfo ) +{ + bool bOk = true; + + if( pOldInfo ) + { + // see if we need to update the type name + if( pOldInfo->maFilterName != pNewInfo->maFilterName ) + { + if( pOldInfo->maType == pOldInfo->maFilterName ) + { + pNewInfo->maType = OUString(); + } + } + + // see if we need to clean up old stuff first + try + { + // if filter name changed, we need to remove the old filter first + if( pOldInfo->maFilterName != pNewInfo->maFilterName ) + mxFilterContainer->removeByName( pOldInfo->maFilterName ); + + // if type name changed, we need to remove the old type first + if( pOldInfo->maType != pNewInfo->maType ) + mxTypeDetection->removeByName( pOldInfo->maType ); + } + catch( Exception& ) + { + DBG_ERROR( "XMLFilterSettingsDialog::insertOrEdit exception catched!" ); + bOk = false; + } + } + + filter_info_impl* pFilterEntry( NULL ); + + if( bOk ) + { + // create or copy filter info + if( pOldInfo ) + { + // change existing filter entry in filter list box + pFilterEntry = const_cast<filter_info_impl*>(pOldInfo); + *pFilterEntry = *pNewInfo; + } + else + { + // add new entry to filter list box + pFilterEntry = new filter_info_impl( *pNewInfo ); + } + } + + // check if we need to copy the template + if( pFilterEntry->maImportTemplate.getLength() ) + { + if( !pFilterEntry->maImportTemplate.matchIgnoreAsciiCase( sTemplatePath ) ) + { + INetURLObject aSourceURL( pFilterEntry->maImportTemplate ); + if( aSourceURL.GetName().getLength() != 0 ) + { + OUString aDestURL( sTemplatePath ); + aDestURL += pFilterEntry->maFilterName; + aDestURL += OUString( sal_Unicode('/') ); + if( createDirectory( aDestURL ) ) + { + aDestURL += aSourceURL.GetName(); + + SvFileStream aInputStream(pFilterEntry->maImportTemplate, STREAM_READ ); + Reference< XInputStream > xIS( new utl::OInputStreamWrapper( aInputStream ) ); + SvFileStream aOutputStream(aDestURL, STREAM_WRITE ); + Reference< XOutputStream > xOS( new utl::OOutputStreamWrapper( aOutputStream ) ); + + if( copyStreams( xIS, xOS ) ) + pFilterEntry->maImportTemplate = aDestURL; + } + } + } + } + + if( bOk ) + { + if( pFilterEntry->maType.getLength() == 0 ) + { + pFilterEntry->maType = createUniqueTypeName( pNewInfo->maFilterName ); + } + + // update import/export flags + if( pFilterEntry->maImportXSLT.getLength() ) + { + pFilterEntry->maFlags |= 1; + } + else + { + pFilterEntry->maFlags &= ~1; + } + + if( pFilterEntry->maExportXSLT.getLength() ) + { + pFilterEntry->maFlags |= 2; + } + else + { + pFilterEntry->maFlags &= ~2; + } + pFilterEntry->maFlags |= 0x80040; + + // 2. create user data for filter entry + Sequence< OUString > aUserData( pFilterEntry->getFilterUserData()); + + // 3. create property values for filter entry + Sequence< PropertyValue > aFilterData( 8 ); + + aFilterData[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "Type" ) ); + aFilterData[0].Value <<= pFilterEntry->maType; + + aFilterData[1].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "UIName" ) ); + aFilterData[1].Value <<= pFilterEntry->maInterfaceName; + + aFilterData[2].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "DocumentService" ) ); + aFilterData[2].Value <<= pFilterEntry->maDocumentService; + + aFilterData[3].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterService" ) ); + aFilterData[3].Value <<= OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Writer.XmlFilterAdaptor" ) ); + + aFilterData[4].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "Flags" ) ); + aFilterData[4].Value <<= pFilterEntry->maFlags; + + aFilterData[5].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "UserData" ) ); + aFilterData[5].Value <<= aUserData; + + aFilterData[6].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "FileFormatVersion" ) ); + aFilterData[6].Value <<= pFilterEntry->maFileFormatVersion; + + aFilterData[7].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "TemplateName" ) ); + aFilterData[7].Value <<= pFilterEntry->maImportTemplate; + + // 4. insert new or replace existing filter + try + { + Any aAny( makeAny( aFilterData ) ); + if( mxFilterContainer->hasByName( pFilterEntry->maFilterName ) ) + { + mxFilterContainer->replaceByName( pFilterEntry->maFilterName, aAny ); + } + else + { + mxFilterContainer->insertByName( pFilterEntry->maFilterName, aAny ); + } + } + catch( Exception& ) + { + DBG_ERROR( "XMLFilterSettingsDialog::insertOrEdit exception catched!" ); + bOk = false; + } + } + + // 5. prepare type information + if( bOk ) + { + Sequence< PropertyValue > aValues(4); + + aValues[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "UIName" ) ); + aValues[0].Value <<= pFilterEntry->maInterfaceName; +/* + aValues[i ].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ); + aValues[i++].Value <<= pFilterEntry->maDocType; +*/ + aValues[1].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "ClipboardFormat" ) ); + OUString aDocType; + if( !pFilterEntry->maDocType.match( sDocTypePrefix ) ) + { + aDocType = sDocTypePrefix; + aDocType += pFilterEntry->maDocType; + } + else + { + aDocType = pFilterEntry->maDocType; + } + if (aDocType == sDocTypePrefix) + aValues[1].Value <<= OUString(); + else + aValues[1].Value <<= aDocType; + + aValues[2].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "DocumentIconID" ) ); + aValues[2].Value <<= pFilterEntry->mnDocumentIconID; + + aValues[3].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "Extensions" ) ); + aValues[3].Value <<= createExtensionsSequence( pFilterEntry->maExtension ); + + // the detect service will only be registered, if a doctype/search token was specified + if (aDocType.getLength() > sDocTypePrefix.getLength()) + { + aValues.realloc(5); + aValues[4].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "DetectService" ) ); + aValues[4].Value <<= OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.filters.XMLFilterDetect" ) ); + } + + // 6. insert new or replace existing type information + if( mxTypeDetection.is() ) + { + try + { + Any aAny( makeAny( aValues ) ); + if( mxTypeDetection->hasByName( pFilterEntry->maType ) ) + { + mxTypeDetection->replaceByName( pFilterEntry->maType, aAny ); + } + else + { + mxTypeDetection->insertByName( pFilterEntry->maType, aAny ); + } + } + catch( Exception& ) + { + DBG_ERROR( "XMLFilterSettingsDialog::insertOrEdit exception catched!" ); + bOk = false; + } + } + + if( bOk ) + { + try + { + Reference< XFlushable > xFlushable = Reference< XFlushable >::query( mxTypeDetection ); + if( xFlushable.is() ) + xFlushable->flush(); + } + catch( Exception& ) + { + DBG_ERROR( "XMLFilterSettingsDialog::insertOrEdit exception catched!" ); + bOk = false; + } + } + + if( !bOk ) + { + // we failed to add the type, so lets remove the filter + try + { + mxFilterContainer->removeByName( pFilterEntry->maFilterName ); + } + catch( Exception& ) + { + DBG_ERROR( "XMLFilterSettingsDialog::insertOrEdit exception catched!" ); + bOk = false; + } + } + else + { + if( bOk ) + { + try + { + Reference< XFlushable > xFlushable( mxFilterContainer, UNO_QUERY ); + if( xFlushable.is() ) + xFlushable->flush(); + } + catch( Exception& ) + { + DBG_ERROR( "XMLFilterSettingsDialog::insertOrEdit exception catched!" ); + bOk = false; + } + + if( !bOk ) + { + // we failed to add the filter, so lets remove the type + try + { + mxTypeDetection->removeByName( pFilterEntry->maType ); + } + catch( Exception& ) + { + DBG_ERROR( "XMLFilterSettingsDialog::insertOrEdit exception catched!" ); + } + } + + } + } + } + + if( bOk ) + { + if( mxExtendedTypeDetection.is() ) + { + OUString sFilterDetectService( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.filters.XMLFilterDetect") ); + if( mxExtendedTypeDetection->hasByName( sFilterDetectService ) ) + { + Sequence< PropertyValue > aSequence; + if( mxExtendedTypeDetection->getByName( sFilterDetectService ) >>= aSequence ) + { + sal_Int32 nCount = aSequence.getLength(); + sal_Int32 nIndex; + for( nIndex = 0; nIndex < nCount; nIndex++ ) + { + OUString aName( aSequence[nIndex].Name ); + if( aSequence[nIndex].Name.equalsAscii( "Types" ) ) + { + Sequence< OUString > aTypes; + if( aSequence[nIndex].Value >>= aTypes ) + { + sal_Int32 nStrCount = aTypes.getLength(); + sal_Int32 nStr; + for( nStr = 0; nStr < nStrCount; nStr++ ) + { + OUString aType( aTypes[nStr] ); + if( aTypes[nStr] == pFilterEntry->maType ) + break; + } + + if( nStr == nStrCount ) + { + aTypes.realloc( nStrCount + 1 ); + aTypes[nStrCount] = pFilterEntry->maType; + + aSequence[nIndex].Value <<= aTypes; + + mxExtendedTypeDetection->replaceByName( sFilterDetectService, makeAny( aSequence ) ); + + Reference< XFlushable > xFlushable( mxExtendedTypeDetection, UNO_QUERY ); + if( xFlushable.is() ) + xFlushable->flush(); + } + } + + break; + } + } + } + } + } + } + + // update ui + if( bOk ) + { + if( pOldInfo ) + { + mpFilterListBox->changeEntry( pFilterEntry ); + } + else + { + mpFilterListBox->addFilterEntry( pFilterEntry ); + maFilterVector.push_back( pFilterEntry ); + } + } + + return bOk; +} + +// ----------------------------------------------------------------------- + +/** is called when the user clicks the "Test" button */ +void XMLFilterSettingsDialog::onTest() +{ + // get the first selected filter + SvLBoxEntry* pEntry = mpFilterListBox->FirstSelected(); + if( pEntry ) + { + filter_info_impl* pInfo = (filter_info_impl*)pEntry->GetUserData(); + + XMLFilterTestDialog aDlg( this, *mpResMgr, mxMSF ); + aDlg.test( *pInfo ); + } +} + +// ----------------------------------------------------------------------- + +void XMLFilterSettingsDialog::onDelete() +{ + SvLBoxEntry* pEntry = mpFilterListBox->FirstSelected(); + if( pEntry ) + { + filter_info_impl* pInfo = (filter_info_impl*)pEntry->GetUserData(); + + String aPlaceHolder( RTL_CONSTASCII_USTRINGPARAM("%s") ); + String aMessage(RESID(STR_WARN_DELETE)); + aMessage.SearchAndReplace( aPlaceHolder, pInfo->maFilterName ); + + WarningBox aWarnBox(this, (WinBits)(WB_YES_NO | WB_DEF_YES), aMessage ); + if( aWarnBox.Execute() == RET_YES ) + { + try + { + if( mxFilterContainer->hasByName( pInfo->maFilterName ) ) + { + mxFilterContainer->removeByName( pInfo->maFilterName ); + + bool bTypeStillUsed = false; + + // now loop over all filter and see if someone else uses the same type + Sequence< OUString > aFilterNames( mxFilterContainer->getElementNames() ); + OUString* pFilterName = aFilterNames.getArray(); + + const sal_Int32 nCount = aFilterNames.getLength(); + sal_Int32 nFilter; + Sequence< PropertyValue > aValues; + + for( nFilter = 0; (nFilter < nCount) && !bTypeStillUsed; nFilter++, pFilterName++ ) + { + Any aAny( mxFilterContainer->getByName( *pFilterName ) ); + if( !(aAny >>= aValues) ) + continue; + + const sal_Int32 nValueCount( aValues.getLength() ); + PropertyValue* pValues = aValues.getArray(); + sal_Int32 nValue; + + for( nValue = 0; (nValue < nValueCount) && !bTypeStillUsed; nValue++, pValues++ ) + { + if( pValues->Name.equalsAscii( "Type" ) ) + { + OUString aType; + pValues->Value >>= aType; + if( aType == pInfo->maType ) + bTypeStillUsed = true; + + break; + } + } + } + + // if the type is not used anymore, remove it also + if( !bTypeStillUsed ) + { + if( mxTypeDetection->hasByName( pInfo->maType ) ) + { + mxTypeDetection->removeByName( pInfo->maType ); + } + } + + Reference< XFlushable > xFlushable( mxFilterContainer, UNO_QUERY ); + if( xFlushable.is() ) + xFlushable->flush(); + + xFlushable = Reference< XFlushable >::query( mxTypeDetection ); + if( xFlushable.is() ) + xFlushable->flush(); + + // now remove entry from ui + mpFilterListBox->RemoveSelection(); + + // and delete the filter entry + maFilterVector.erase(std::find( maFilterVector.begin(), maFilterVector.end(), pInfo )); + + delete pInfo; + } + } + catch( Exception& ) + { + DBG_ERROR( "XMLFilterSettingsDialog::onDelete exception catched!" ); + } + } + } + + updateStates(); +} + +// ----------------------------------------------------------------------- + +void XMLFilterSettingsDialog::onSave() +{ + XMLFilterVector aFilters; + + int nFilters = 0; + + SvLBoxEntry* pEntry = mpFilterListBox->FirstSelected(); + while( pEntry ) + { + filter_info_impl* pInfo = (filter_info_impl*)pEntry->GetUserData(); + aFilters.push_back( pInfo ); + pEntry = mpFilterListBox->NextSelected( pEntry ); + nFilters++; + } + + // Open Fileopen-Dialog + ::sfx2::FileDialogHelper aDlg( + com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION, + 0 ); + + String aExtensions( RTL_CONSTASCII_USTRINGPARAM("*.jar") ); + String aFilterName( RESID( STR_FILTER_PACKAGE ) ); + aFilterName += String( RTL_CONSTASCII_USTRINGPARAM(" (") ); + aFilterName += aExtensions; + aFilterName += sal_Unicode(')'); + + aDlg.AddFilter( aFilterName, aExtensions ); + + if ( aDlg.Execute() == ERRCODE_NONE ) + { + XMLFilterJarHelper aJarHelper( mxMSF ); + aJarHelper.savePackage( aDlg.GetPath(), aFilters ); + + INetURLObject aURL( aDlg.GetPath() ); + + String sPlaceholder( RTL_CONSTASCII_USTRINGPARAM( "%s" ) ); + + String aMsg; + if( nFilters > 0 ) + { + aMsg = String( RESID( STR_FILTERS_HAVE_BEEN_SAVED ) ); + aMsg.SearchAndReplace( sPlaceholder, String::CreateFromInt32(nFilters) ); + aMsg.SearchAndReplace( sPlaceholder, aURL.GetName() ); + } + else + { + aMsg = String( RESID( STR_FILTER_HAS_BEEN_SAVED ) ); + aMsg.SearchAndReplace( sPlaceholder, (*aFilters.begin())->maFilterName ); + aMsg.SearchAndReplace( sPlaceholder, aURL.GetName() ); + } + + InfoBox aBox(this, aMsg ); + aBox.Execute(); + } +} + +// ----------------------------------------------------------------------- + +void XMLFilterSettingsDialog::onOpen() +{ + XMLFilterVector aFilters; + + // Open Fileopen-Dialog + ::sfx2::FileDialogHelper aDlg( + com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 ); + + String aExtensions( RTL_CONSTASCII_USTRINGPARAM("*.jar") ); + String aFilterName( RESID( STR_FILTER_PACKAGE ) ); + aFilterName += String( RTL_CONSTASCII_USTRINGPARAM(" (") ); + aFilterName += aExtensions; + aFilterName += sal_Unicode(')'); + + aDlg.AddFilter( aFilterName, aExtensions ); + + if ( aDlg.Execute() == ERRCODE_NONE ) + { + OUString aURL( aDlg.GetPath() ); + + XMLFilterJarHelper aJarHelper( mxMSF ); + aJarHelper.openPackage( aURL, aFilters ); + + int nFilters = 0; + XMLFilterVector::iterator aIter( aFilters.begin() ); + while( aIter != aFilters.end() ) + { + filter_info_impl* pInfo = (*aIter++); + + if( insertOrEdit( pInfo ) ) + { + aFilterName = pInfo->maFilterName; + nFilters++; + } + + delete pInfo; + } + + disposeFilterList(); + initFilterList(); + + String sPlaceholder( RTL_CONSTASCII_USTRINGPARAM( "%s" ) ); + String aMsg; + if( nFilters == 0 ) + { + INetURLObject aURLObj( aURL ); + aMsg = String( RESID( STR_NO_FILTERS_FOUND ) ); + aMsg.SearchAndReplace( sPlaceholder, aURLObj.GetName() ); + } + else if( nFilters == 1 ) + { + aMsg = String( RESID( STR_FILTER_INSTALLED ) ); + aMsg.SearchAndReplace( sPlaceholder, aFilterName ); + + } + else + { + aMsg = String( RESID( STR_FILTERS_INSTALLED ) ); + aMsg.SearchAndReplace( sPlaceholder, String::CreateFromInt32(nFilters) ); + } + + InfoBox aBox(this, aMsg ); + aBox.Execute(); + } +} + +// ----------------------------------------------------------------------- + +void XMLFilterSettingsDialog::onClose() +{ + Close(); +} + +long XMLFilterSettingsDialog::Notify( NotifyEvent& rNEvt ) +{ + // Zuerst Basisklasse rufen wegen TabSteuerung + long nRet = WorkWindow::Notify( rNEvt ); + if ( !nRet ) + { + if ( rNEvt.GetType() == EVENT_KEYINPUT ) + { + const KeyEvent* pKEvt = rNEvt.GetKeyEvent(); + KeyCode aKeyCode = pKEvt->GetKeyCode(); + USHORT nKeyCode = aKeyCode.GetCode(); + + if( nKeyCode == KEY_ESCAPE ) + { + Close(); + return TRUE; + } + } + } + + return nRet; +} + +// ----------------------------------------------------------------------- + +void XMLFilterSettingsDialog::disposeFilterList() +{ + std::vector< filter_info_impl* >::iterator aIter( maFilterVector.begin() ); + while( aIter != maFilterVector.end() ) + { + delete (*aIter++); + } + maFilterVector.clear(); + + mpFilterListBox->Clear(); +} + +// ----------------------------------------------------------------------- + +void XMLFilterSettingsDialog::initFilterList() +{ + if( mxFilterContainer.is() ) + { + Sequence< OUString > aFilterNames( mxFilterContainer->getElementNames() ); + OUString* pFilterName = aFilterNames.getArray(); + + const sal_Int32 nCount = aFilterNames.getLength(); + sal_Int32 nFilter; + + Sequence< PropertyValue > aValues; + + filter_info_impl* pTempFilter = new filter_info_impl; + Sequence< OUString > aUserData; + + for( nFilter = 0; nFilter < nCount; nFilter++, pFilterName++ ) + { + aUserData.realloc(0); + + try + { + Any aAny( mxFilterContainer->getByName( *pFilterName ) ); + if( !(aAny >>= aValues) ) + continue; + + OUString aFilterService; + pTempFilter->maFilterName = *pFilterName; + + const sal_Int32 nValueCount( aValues.getLength() ); + PropertyValue* pValues = aValues.getArray(); + sal_Int32 nValue; + + for( nValue = 0; nValue < nValueCount; nValue++, pValues++ ) + { + if( pValues->Name.equalsAscii( "Type" ) ) + { + pValues->Value >>= pTempFilter->maType; + } + else if( pValues->Name.equalsAscii( "UIName" ) ) + { + pValues->Value >>= pTempFilter->maInterfaceName; + } + else if( pValues->Name.equalsAscii( "DocumentService" ) ) + { + pValues->Value >>= pTempFilter->maDocumentService; + } + else if( pValues->Name.equalsAscii( "FilterService" ) ) + { + pValues->Value >>= aFilterService; + } + else if( pValues->Name.equalsAscii( "Flags" ) ) + { + pValues->Value >>= pTempFilter->maFlags; + } + else if( pValues->Name.equalsAscii( "UserData" ) ) + { + pValues->Value >>= aUserData; + } + else if( pValues->Name.equalsAscii( "FileFormatVersion" ) ) + { + pValues->Value >>= pTempFilter->maFileFormatVersion; + } + else if( pValues->Name.equalsAscii( "TemplateName" ) ) + { + pValues->Value >>= pTempFilter->maImportTemplate; + } + else if(pValues->Name.equalsAscii( "Finalized" )) + { + pValues->Value >>= pTempFilter->mbReadonly; + } + } + + // if this is not a XmlFilterAdaptor entry, skip it + if( !aFilterService.equalsAscii( "com.sun.star.comp.Writer.XmlFilterAdaptor" ) ) + continue; + + + // if we don't have the needed user data, skip it + if( aUserData.getLength() < 6 ) + continue; + + // if this is not an XSLTFilter entry, skip it + if( !aUserData[0].equalsAscii( "com.sun.star.documentconversion.XSLTFilter" ) ) + continue; + + // get filter information from userdata + pTempFilter->maImportService = aUserData[2]; + pTempFilter->maExportService = aUserData[3]; + pTempFilter->maImportXSLT = aUserData[4]; + pTempFilter->maExportXSLT = aUserData[5]; + if( aUserData.getLength() >= 7 ) + pTempFilter->maDTD = aUserData[6]; + if( aUserData.getLength() >= 8 ) + pTempFilter->maComment = aUserData[7]; + + // get type information + if( mxTypeDetection.is() ) + { + try + { + aAny = mxTypeDetection->getByName( pTempFilter->maType ); + Sequence< PropertyValue > aValues2; + + if( aAny >>= aValues2 ) + { + const sal_Int32 nValueCount2( aValues2.getLength() ); + PropertyValue* pValues2 = aValues2.getArray(); + sal_Int32 nValue2; + + for( nValue2 = 0; nValue2 < nValueCount2; nValue2++, pValues2++ ) + { +/* + if( pValues2->Name.equalsAscii( "MediaType" ) ) + { + pValues2->Value >>= pTempFilter->maDocType; + } else +*/ + if( pValues2->Name.equalsAscii( "ClipboardFormat" ) ) + { + OUString aDocType; + pValues2->Value >>= aDocType; + + if( aDocType.match( sDocTypePrefix ) ) + aDocType = aDocType.copy( sDocTypePrefix.getLength() ); + + pTempFilter->maDocType = aDocType; + } + else if( pValues2->Name.equalsAscii( "Extensions" ) ) + { + Sequence< OUString > aExtensions; + if( pValues2->Value >>= aExtensions ) + { + pTempFilter->maExtension = OUString(); + + sal_Int32 nCount3( aExtensions.getLength() ); + OUString* pExtensions = aExtensions.getArray(); + sal_Int32 n; + for( n = 0; n < nCount3; n++ ) + { + if( n > 0 ) + pTempFilter->maExtension += OUString( sal_Unicode(';') ); + pTempFilter->maExtension += (*pExtensions++); + } + } + } + else if( pValues2->Name.equalsAscii( "DocumentIconID" ) ) + { + pValues2->Value >>= pTempFilter->mnDocumentIconID; + } + else if(pValues2->Name.equalsAscii( "Finalized" )) + { + // both the filter and the type may be finalized + sal_Bool bTemp = sal_False; + pValues2->Value >>= bTemp; + pTempFilter->mbReadonly |= bTemp; + } + } + } + } + catch( ::com::sun::star::container::NoSuchElementException& ) + { + DBG_ERROR( "Type not found, user error?" ); // TODO: error? + } + } + + // add entry to internal container and to ui filter list box + maFilterVector.push_back( pTempFilter ); + mpFilterListBox->addFilterEntry( pTempFilter ); + + + pTempFilter = new filter_info_impl; + } + catch( Exception& ) + { + DBG_ERROR( "XMLFilterSettingsDialog::initFilterList exception catched!" ); + } + + } + + delete pTempFilter; + } + + SvLBoxEntry* pEntry = mpFilterListBox->GetEntry( 0 ); + if( pEntry ) + mpFilterListBox->Select( pEntry ); +} + +// ----------------------------------------------------------------------- + +// ----------------------------------------------------------------------- + +application_info_impl::application_info_impl( const sal_Char * pDocumentService, ResId& rUINameRes, const sal_Char * mpXMLImporter, const sal_Char * mpXMLExporter ) +: maDocumentService( pDocumentService, strlen( pDocumentService ), RTL_TEXTENCODING_ASCII_US ), + maDocumentUIName( String( rUINameRes ) ), + maXMLImporter( mpXMLImporter, strlen( mpXMLImporter ), RTL_TEXTENCODING_ASCII_US ), + maXMLExporter( mpXMLExporter, strlen( mpXMLExporter ), RTL_TEXTENCODING_ASCII_US ) +{ +} + +// ----------------------------------------------------------------------- + +std::vector< application_info_impl* >& getApplicationInfos() +{ + static std::vector< application_info_impl* > aInfos; + + if( aInfos.empty() ) + { + ResId aResId1( STR_APPL_NAME_WRITER, *getXSLTDialogResMgr() ); + aInfos.push_back( new application_info_impl( + "com.sun.star.text.TextDocument", + aResId1, + "com.sun.star.comp.Writer.XMLImporter", + "com.sun.star.comp.Writer.XMLExporter" ) ); + + ResId aResId2( STR_APPL_NAME_CALC, *getXSLTDialogResMgr() ); + aInfos.push_back( new application_info_impl( + "com.sun.star.sheet.SpreadsheetDocument", + aResId2, + "com.sun.star.comp.Calc.XMLImporter", + "com.sun.star.comp.Calc.XMLExporter" ) ); + + ResId aResId3( STR_APPL_NAME_IMPRESS, *getXSLTDialogResMgr() ); + aInfos.push_back( new application_info_impl( + "com.sun.star.presentation.PresentationDocument", + aResId3, + "com.sun.star.comp.Impress.XMLImporter", + "com.sun.star.comp.Impress.XMLExporter" ) ); + + ResId aResId4( STR_APPL_NAME_DRAW, *getXSLTDialogResMgr() ); + aInfos.push_back( new application_info_impl( + "com.sun.star.drawing.DrawingDocument", + aResId4, + "com.sun.star.comp.Draw.XMLImporter", + "com.sun.star.comp.Draw.XMLExporter" ) ); + + // --- oasis file formats... + ResId aResId5( STR_APPL_NAME_OASIS_WRITER, *getXSLTDialogResMgr() ); + aInfos.push_back( new application_info_impl( + "com.sun.star.text.TextDocument", + aResId5, + "com.sun.star.comp.Writer.XMLOasisImporter", + "com.sun.star.comp.Writer.XMLOasisExporter" ) ); + + ResId aResId6( STR_APPL_NAME_OASIS_CALC, *getXSLTDialogResMgr() ); + aInfos.push_back( new application_info_impl( + "com.sun.star.sheet.SpreadsheetDocument", + aResId6, + "com.sun.star.comp.Calc.XMLOasisImporter", + "com.sun.star.comp.Calc.XMLOasisExporter" ) ); + + ResId aResId7( STR_APPL_NAME_OASIS_IMPRESS, *getXSLTDialogResMgr() ); + aInfos.push_back( new application_info_impl( + "com.sun.star.presentation.PresentationDocument", + aResId7, + "com.sun.star.comp.Impress.XMLOasisImporter", + "com.sun.star.comp.Impress.XMLOasisExporter" ) ); + + ResId aResId8( STR_APPL_NAME_OASIS_DRAW, *getXSLTDialogResMgr() ); + aInfos.push_back( new application_info_impl( + "com.sun.star.drawing.DrawingDocument", + aResId8, + "com.sun.star.comp.Draw.XMLOasisImporter", + "com.sun.star.comp.Draw.XMLOasisExporter" ) ); +} + + return aInfos; +} + +// ----------------------------------------------------------------------- + +const application_info_impl* getApplicationInfo( const OUString& rServiceName ) +{ + std::vector< application_info_impl* >& rInfos = getApplicationInfos(); + std::vector< application_info_impl* >::iterator aIter( rInfos.begin() ); + while( aIter != rInfos.end() ) + { + // if( rServiceName == (*aIter)->maDocumentService ) + if( rServiceName == (*aIter)->maXMLExporter || + rServiceName == (*aIter)->maXMLImporter) + { + return (*aIter); + } + aIter++; + } + return NULL; +} + +// ----------------------------------------------------------------------- + +OUString getApplicationUIName( const OUString& rServiceName ) +{ + const application_info_impl* pInfo = getApplicationInfo( rServiceName ); + if( pInfo ) + { + return pInfo->maDocumentUIName; + } + else + { + OUString aRet = String( RESID( STR_UNKNOWN_APPLICATION ) ); + if( rServiceName.getLength() ) + { + aRet += OUString::createFromAscii(" ("); + aRet += rServiceName; + aRet += OUString::createFromAscii(")"); + } + return aRet; + } +} + +// ----------------------------------------------------------------------- + +ResMgr* getXSLTDialogResMgr() +{ + return XMLFilterSettingsDialog::mpResMgr; +} + +// ----------------------------------------------------------------------- + +// ----------------------------------------------------------------------- + +long SvxPathControl_Impl::Notify( NotifyEvent& rNEvt ) +{ + long nRet = Control::Notify( rNEvt ); + + if ( m_pFocusCtrl && rNEvt.GetWindow() != m_pFocusCtrl && rNEvt.GetType() == EVENT_GETFOCUS ) + m_pFocusCtrl->GrabFocus(); + return nRet; +} + +#define ITEMID_NAME 1 +#define ITEMID_TYPE 2 + +XMLFilterListBox::XMLFilterListBox( SvxPathControl_Impl * pParent ) +: SvTabListBox( pParent, WB_SORT | WB_HSCROLL | WB_CLIPCHILDREN | WB_TABSTOP ), + mbFirstPaint( true ) +{ + Size aBoxSize( pParent->GetOutputSizePixel() ); + + mpHeaderBar = new HeaderBar( pParent, /*WB_BUTTONSTYLE | */ WB_BOTTOMBORDER ); + mpHeaderBar->SetPosSizePixel( Point( 0, 0 ), Size( aBoxSize.Width(), 16 ) ); + mpHeaderBar->SetEndDragHdl( LINK( this, XMLFilterListBox, HeaderEndDrag_Impl ) ); + + String aStr1( RESID( STR_COLUMN_HEADER_NAME ) ); + String aStr2( RESID( STR_COLUMN_HEADER_TYPE ) ); + + long nTabSize = aBoxSize.Width() / 2; + + mpHeaderBar->InsertItem( ITEMID_NAME, aStr1, nTabSize, + HIB_LEFT | HIB_VCENTER ); + mpHeaderBar->InsertItem( ITEMID_TYPE, aStr2, nTabSize, + HIB_LEFT | HIB_VCENTER ); + + static long nTabs[] = {3, 0, nTabSize, 2*nTabSize }; + Size aHeadSize( mpHeaderBar->GetSizePixel() ); + + WinBits nBits = WB_SORT | WB_HSCROLL | WB_CLIPCHILDREN | WB_TABSTOP; + pParent->SetFocusControl( this ); + SetWindowBits( nBits ); +// SetDoubleClickHdl( aLink ); +// SetSelectHdl( LINK( this, SvxPathTabPage, PathSelect_Impl ) ); + SetSelectionMode( MULTIPLE_SELECTION ); + SetPosSizePixel( Point( 0, aHeadSize.Height() ), Size( aBoxSize.Width(), aBoxSize.Height() - aHeadSize.Height() ) ); + SetTabs( &nTabs[0], MAP_PIXEL ); + SetScrolledHdl( LINK( this, XMLFilterListBox, TabBoxScrollHdl_Impl ) ); + SetHighlightRange(); +// SetHelpId( HID_OPTPATH_CTL_PATH ); +// mpHeaderBar->SetHelpId( HID_OPTPATH_HEADERBAR ); + Show(); + mpHeaderBar->Show(); +} + +// ----------------------------------------------------------------------- + +XMLFilterListBox::~XMLFilterListBox() +{ + delete mpHeaderBar; +} + +// ----------------------------------------------------------------------- + +void XMLFilterListBox::Reset() +{ + Size aBoxSize( Window::GetParent()->GetOutputSizePixel() ); + long nTabSize = aBoxSize.Width() / 2; + static long nTabs[] = {3, 0, nTabSize, 2*nTabSize }; + SetTabs( &nTabs[0], MAP_PIXEL ); + mpHeaderBar->SetItemSize( ITEMID_NAME, nTabSize ); + mpHeaderBar->SetItemSize( ITEMID_TYPE, nTabSize ); +} + +// ----------------------------------------------------------------------- + +void XMLFilterListBox::Paint( const Rectangle& rRect ) +{ + if( mbFirstPaint ) + { + mbFirstPaint = false; + RepaintScrollBars(); + } + + SvTabListBox::Paint( rRect ); +} + +IMPL_LINK( XMLFilterListBox, TabBoxScrollHdl_Impl, SvTabListBox*, /* pList */ ) +{ + mpHeaderBar->SetOffset( -GetXOffset() ); + return 0; +} + +// ----------------------------------------------------------------------- + +IMPL_LINK( XMLFilterListBox, HeaderSelect_Impl, HeaderBar*, pBar ) +{ + if ( pBar && pBar->GetCurItemId() != ITEMID_NAME ) + return 0; + + HeaderBarItemBits nBits = mpHeaderBar->GetItemBits(ITEMID_TYPE); + BOOL bUp = ( ( nBits & HIB_UPARROW ) == HIB_UPARROW ); + SvSortMode eMode = SortAscending; + + if ( bUp ) + { + nBits &= ~HIB_UPARROW; + nBits |= HIB_DOWNARROW; + eMode = SortDescending; + } + else + { + nBits &= ~HIB_DOWNARROW; + nBits |= HIB_UPARROW; + } + mpHeaderBar->SetItemBits( ITEMID_NAME, nBits ); + SvTreeList* pMod = GetModel(); + pMod->SetSortMode( eMode ); + pMod->Resort(); + return 1; +} + +// ----------------------------------------------------------------------- + +IMPL_LINK( XMLFilterListBox, HeaderEndDrag_Impl, HeaderBar*, pBar ) +{ + if ( pBar && !pBar->GetCurItemId() ) + return 0; + + if ( !mpHeaderBar->IsItemMode() ) + { + Size aSz; + USHORT nTabs = mpHeaderBar->GetItemCount(); + long nTmpSz = 0; + long nWidth = mpHeaderBar->GetItemSize(ITEMID_NAME); + long nBarWidth = mpHeaderBar->GetSizePixel().Width(); + + if(nWidth < 30) + mpHeaderBar->SetItemSize( ITEMID_TYPE, 30); + else if ( ( nBarWidth - nWidth ) < 30 ) + mpHeaderBar->SetItemSize( ITEMID_TYPE, nBarWidth - 30 ); + + for ( USHORT i = 1; i <= nTabs; ++i ) + { + long nW = mpHeaderBar->GetItemSize(i); + aSz.Width() = nW + nTmpSz; + nTmpSz += nW; + SetTab( i, PixelToLogic( aSz, MapMode(MAP_APPFONT) ).Width(), MAP_APPFONT ); + } + } + return 1; +} + +// ----------------------------------------------------------------------- + +/** adds a new filter info entry to the ui filter list */ +void XMLFilterListBox::addFilterEntry( const filter_info_impl* pInfo ) +{ + const XubString aEntryStr( getEntryString( pInfo ) ); + InsertEntryToColumn( aEntryStr, LIST_APPEND, 0xffff, (void*)pInfo ); +} + +// ----------------------------------------------------------------------- + +void XMLFilterListBox::changeEntry( const filter_info_impl* pInfo ) +{ + const ULONG nCount = GetEntryCount(); + ULONG nPos; + for( nPos = 0; nPos < nCount; nPos++ ) + { + SvLBoxEntry* pEntry = GetEntry( nPos ); + if( (filter_info_impl*)pEntry->GetUserData() == pInfo ) + { + XubString aEntryText( getEntryString( pInfo ) ); + SetEntryText( aEntryText, pEntry ); + break; + } + } +} + +// ----------------------------------------------------------------------- + +String XMLFilterListBox::getEntryString( const filter_info_impl* pInfo ) const +{ + String aEntryStr( pInfo->maFilterName ); + aEntryStr += '\t'; + // aEntryStr += String( getApplicationUIName( pInfo->maDocumentService ) ); + if ( pInfo->maExportService.getLength() > 0 ) + aEntryStr += String( getApplicationUIName( pInfo->maExportService ) ); + else + aEntryStr += String( getApplicationUIName( pInfo->maImportService ) ); + aEntryStr += ' '; + aEntryStr += '-'; + aEntryStr += ' '; + + if( pInfo->maFlags & 1 ) + { + if( pInfo->maFlags & 2 ) + { + aEntryStr += String( RESID( STR_IMPORT_EXPORT ) ); + } + else + { + aEntryStr += String( RESID( STR_IMPORT_ONLY ) ); + } + } + else if( pInfo->maFlags & 2 ) + { + aEntryStr += String( RESID( STR_EXPORT_ONLY ) ); + } + else + { + aEntryStr += String( RESID( STR_UNDEFINED_FILTER ) ); + } + + return aEntryStr; +} + +// ----------------------------------------------------------------------- + +// ----------------------------------------------------------------------- + +filter_info_impl::filter_info_impl() +: maFlags(0x00080040), + maFileFormatVersion(0), + mnDocumentIconID(0), + mbReadonly(sal_False) +{ +} + +// ----------------------------------------------------------------------- + +filter_info_impl::filter_info_impl( const filter_info_impl& rInfo ) : + maFilterName( rInfo.maFilterName ), + maType( rInfo.maType ), + maDocumentService( rInfo.maDocumentService ), + maFilterService( rInfo.maFilterService ), + maInterfaceName( rInfo.maInterfaceName ), + maComment( rInfo.maComment ), + maExtension( rInfo.maExtension ), + maDTD( rInfo.maDTD ), + maExportXSLT( rInfo.maExportXSLT ), + maImportXSLT( rInfo.maImportXSLT ), + maImportTemplate( rInfo.maImportTemplate ), + maDocType( rInfo.maDocType ), + maImportService( rInfo.maImportService ), + maExportService( rInfo.maExportService ), + maFlags( rInfo.maFlags ), + maFileFormatVersion( rInfo.maFileFormatVersion ), + mnDocumentIconID( rInfo.mnDocumentIconID ), + mbReadonly( rInfo.mbReadonly ) +{ +} + +// ----------------------------------------------------------------------- + +int filter_info_impl::operator==( const filter_info_impl& r ) const +{ + if( maFilterName != r.maFilterName || + maType != r.maType || + maDocumentService != r.maDocumentService || + maFilterService != r.maFilterService || + maInterfaceName != r.maInterfaceName || + maComment != r.maComment || + maExtension != r.maExtension || + maDocType != r.maDocType || + maDTD != r.maDTD || + maExportXSLT != r.maExportXSLT || + maImportXSLT != r.maImportXSLT || + maExportService != r.maExportService || + maImportService != r.maImportService || + maImportTemplate != r.maImportTemplate || + maFlags != r.maFlags || + maFileFormatVersion != r.maFileFormatVersion ) + return false; + + return true; +} + +// ----------------------------------------------------------------------- + +Sequence< OUString > filter_info_impl::getFilterUserData() const +{ + Sequence< OUString > aUserData(8); + + aUserData[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.documentconversion.XSLTFilter" ) ); + /* + const application_info_impl* pInfo = getApplicationInfo( maDocumentService ); + if( pInfo ) + { + aUserData[2] = pInfo->maXMLImporter; + aUserData[3] = pInfo->maXMLExporter; + } + */ + aUserData[2] = maImportService; + aUserData[3] = maExportService; + aUserData[4] = maImportXSLT; + aUserData[5] = maExportXSLT; + aUserData[6] = maDTD; + aUserData[7] = maComment; + + return aUserData; +} + + +// ----------------------------------------------------------------------- + +OUString string_encode( const OUString & rText ) +{ + + static sal_Bool const aCharClass[] + = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* UricNoSlash */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, /* !"#$%&'()*+,-./*/ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, /*0123456789:;<=>?*/ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /*@ABCDEFGHIJKLMNO*/ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, /*PQRSTUVWXYZ[\]^_*/ + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /*`abcdefghijklmno*/ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0 /*pqrstuvwxyz{|}~ */ + }; + + + return Uri::encode( rText, aCharClass, rtl_UriEncodeCheckEscapes, RTL_TEXTENCODING_UTF8 ); +} + +// ----------------------------------------------------------------------- + +OUString string_decode( const OUString & rText ) +{ + return Uri::decode( rText, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 ); +} + +// ----------------------------------------------------------------------- + +bool isFileURL( const ::rtl::OUString & rURL ) +{ + return rURL.compareToAscii( RTL_CONSTASCII_STRINGPARAM("file:") ) == 0; +} + +// ----------------------------------------------------------------------- + +bool copyStreams( Reference< XInputStream > xIS, Reference< XOutputStream > xOS ) +{ + try + { + sal_Int32 nBufferSize = 512; + Sequence< sal_Int8 > aDataBuffer(nBufferSize); + + sal_Int32 nRead; + do + { + nRead = xIS->readBytes( aDataBuffer, nBufferSize ); + + if( nRead ) + { + if( nRead < nBufferSize ) + { + nBufferSize = nRead; + aDataBuffer.realloc(nRead); + } + + xOS->writeBytes( aDataBuffer ); + } + } + while( nRead ); + + xOS->flush(); + + return true; + } + catch(Exception&) + { + DBG_ERROR( "copyStreams() exception catched!" ); + } + + return false; +} + +// ----------------------------------------------------------------------- + +bool createDirectory( OUString& rURL ) +{ + sal_Int32 nLastIndex = sizeof( "file:///" ) - 2; + while( nLastIndex != -1 ) + { + nLastIndex = rURL.indexOf( sal_Unicode('/'), nLastIndex + 1); + if( nLastIndex != -1 ) + { + OUString aDirURL( rURL.copy( 0, nLastIndex ) ); + Directory aDir( aDirURL ); + Directory::RC rc = aDir.open(); + if( rc == Directory::E_NOENT ) + rc = osl::Directory::create( aDirURL ); + + if( rc != Directory::E_None ) + { + return false; + } + } + } + + return true; +} diff --git a/filter/source/xsltdialog/xmlfiltersettingsdialog.hrc b/filter/source/xsltdialog/xmlfiltersettingsdialog.hrc new file mode 100644 index 000000000000..48ed1a2a4ee7 --- /dev/null +++ b/filter/source/xsltdialog/xmlfiltersettingsdialog.hrc @@ -0,0 +1,43 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLFILTERSETTINGSDIALOG_HRC_ +#define _XMLFILTERSETTINGSDIALOG_HRC_ + +#include "xmlfiltercommon.hrc" + +#define CTRL_XML_FILTER_LIST 1 +#define PB_XML_FILTER_NEW 2 +#define PB_XML_FILTER_EDIT 3 +#define PB_XML_FILTER_TEST 4 +#define PB_XML_FILTER_DELETE 5 +#define PB_XML_FILTER_SAVE 6 +#define PB_XML_FILTER_OPEN 7 +#define BTN_XML_FILTER_HELP 8 +#define PB_XML_FILTER_CLOSE 9 + +#endif diff --git a/filter/source/xsltdialog/xmlfiltersettingsdialog.hxx b/filter/source/xsltdialog/xmlfiltersettingsdialog.hxx new file mode 100644 index 000000000000..5abf2bba0df3 --- /dev/null +++ b/filter/source/xsltdialog/xmlfiltersettingsdialog.hxx @@ -0,0 +1,161 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _XMLFILTERSETTINGSDIALOG_HXX_ +#define _XMLFILTERSETTINGSDIALOG_HXX_ + +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/container/XHierarchicalName.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <vcl/wrkwin.hxx> + +#ifndef _SV_BUTTON_HXX +#include <vcl/button.hxx> +#endif +#include <svtools/svtabbx.hxx> +#include <svl/poolitem.hxx> +#include <unotools/moduleoptions.hxx> + +#include "xmlfiltercommon.hxx" + +// -------------------------------------------------------------------- + +class SvxPathControl_Impl : public Control +{ +private: + Control* m_pFocusCtrl; + +public: + SvxPathControl_Impl( Window* pParent, const ResId& rId ) : + Control( pParent, rId ), m_pFocusCtrl( NULL ) {} + + void SetFocusControl( Control* pCtrl ) { m_pFocusCtrl = pCtrl; } + + virtual long Notify( NotifyEvent& rNEvt ); +}; + +// -------------------------------------------------------------------- + +class HeaderBar; + +class XMLFilterListBox : public SvTabListBox +{ +private: + bool mbFirstPaint; + HeaderBar* mpHeaderBar; + + DECL_LINK( TabBoxScrollHdl_Impl, SvTabListBox* ); + DECL_LINK( HeaderSelect_Impl, HeaderBar* ); + DECL_LINK( HeaderEndDrag_Impl, HeaderBar* ); + + String getEntryString( const filter_info_impl* pInfo ) const; + +public: + XMLFilterListBox( SvxPathControl_Impl* pParent ); + ~XMLFilterListBox(); + + void Reset(); + + /** adds a new filter info entry to the ui filter list */ + void addFilterEntry( const filter_info_impl* pInfo ); + + void changeEntry( const filter_info_impl* pInfo ); + + virtual void Paint( const Rectangle& rRect ); +}; + +// -------------------------------------------------------------------- + +class XMLFilterTestDialog; + +class XMLFilterSettingsDialog : public WorkWindow +{ +public: + XMLFilterSettingsDialog( Window* pParent, ResMgr& rResMgr, const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rxMSF ); + virtual ~XMLFilterSettingsDialog(); + + DECL_LINK(ClickHdl_Impl, PushButton * ); + DECL_LINK(SelectionChangedHdl_Impl, void * ); + DECL_LINK(DoubleClickHdl_Impl, void * ); + + void ShowWindow(); + + void onNew(); + void onEdit(); + void onTest(); + void onDelete(); + void onSave(); + void onOpen(); + void onClose(); + + void updateStates(); + + virtual long Notify( NotifyEvent& rNEvt ); + + bool isClosable(); + + static ResMgr* mpResMgr; + +private: + void initFilterList(); + void disposeFilterList(); + + bool insertOrEdit( filter_info_impl* pNewInfo, const filter_info_impl* pOldInfo = NULL ); + + rtl::OUString createUniqueFilterName( const rtl::OUString& rUIName ); + rtl::OUString createUniqueTypeName( const rtl::OUString& rTypeName ); + rtl::OUString createUniqueInterfaceName( const rtl::OUString& rInterfaceName ); + +private: + + com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > mxMSF; + com::sun::star::uno::Reference< com::sun::star::container::XNameContainer > mxFilterContainer; + com::sun::star::uno::Reference< com::sun::star::container::XNameContainer > mxTypeDetection; + com::sun::star::uno::Reference< com::sun::star::container::XNameContainer > mxExtendedTypeDetection; + + std::vector< filter_info_impl* > maFilterVector; + + XMLFilterListBox* mpFilterListBox; + SvxPathControl_Impl maCtrlFilterList; + PushButton maPBNew; + PushButton maPBEdit; + PushButton maPBTest; + PushButton maPBDelete; + PushButton maPBSave; + PushButton maPBOpen; + HelpButton maPBHelp; + PushButton maPBClose; + + bool mbIsClosable; + + ::rtl::OUString sTemplatePath; + ::rtl::OUString sDocTypePrefix; + + SvtModuleOptions maModuleOpt; +}; + +#endif diff --git a/filter/source/xsltdialog/xmlfiltersettingsdialog.src b/filter/source/xsltdialog/xmlfiltersettingsdialog.src new file mode 100644 index 000000000000..b80dff3bfe50 --- /dev/null +++ b/filter/source/xsltdialog/xmlfiltersettingsdialog.src @@ -0,0 +1,139 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "xmlfiltersettingsdialog.hrc" +#include "xmlfilterhelpids.hrc" + +#define BUTTONS_LEFT 248 +#define BUTTONS_TOP 6 +#define BUTTONS_SPACEING 3 +#define BUTTONS_WIDTH 66 +#define BUTTONS_HEIGHT 14 + +WorkWindow DLG_XML_FILTER_SETTINGS_DIALOG +{ + Size = MAP_APPFONT( 320, 154 ); + HelpId = HID_XML_FILTER_SETTINGS_DIALOG; + OutputSize = TRUE ; + SVLook = TRUE ; + Moveable = TRUE ; + Closeable = TRUE ; + Sizeable = FALSE; + DialogControl = TRUE ; + Text [ en-US ] = "XML Filter Settings" ; + + Control CTRL_XML_FILTER_LIST + { + Pos = MAP_APPFONT ( 6 , 6 ) ; + Size = MAP_APPFONT ( 235 , 142 ); + Border = TRUE ; + TabStop = TRUE ; + }; + + PushButton PB_XML_FILTER_NEW + { + Pos = MAP_APPFONT ( BUTTONS_LEFT , BUTTONS_TOP + 0 * BUTTONS_HEIGHT + 0 * BUTTONS_SPACEING ) ; + Size = MAP_APPFONT ( BUTTONS_WIDTH , BUTTONS_HEIGHT ) ; + HelpId = HID_XML_FILTER_NEW; + TabStop = TRUE ; + Text [ en-US ] = "~New..."; + }; + + PushButton PB_XML_FILTER_EDIT + { + Pos = MAP_APPFONT ( BUTTONS_LEFT , BUTTONS_TOP + 1 * BUTTONS_HEIGHT + 1 * BUTTONS_SPACEING ) ; + Size = MAP_APPFONT ( BUTTONS_WIDTH , BUTTONS_HEIGHT ) ; + HelpId = HID_XML_FILTER_EDIT; + TabStop = TRUE ; + Text [ en-US ] = "~Edit..."; + }; + + PushButton PB_XML_FILTER_TEST + { + Pos = MAP_APPFONT ( BUTTONS_LEFT , BUTTONS_TOP + 2 * BUTTONS_HEIGHT + 2 * BUTTONS_SPACEING ) ; + Size = MAP_APPFONT ( BUTTONS_WIDTH , BUTTONS_HEIGHT ) ; + HelpId = HID_XML_FILTER_TEST; + TabStop = TRUE ; + Text [ en-US ] = "~Test XSLTs..."; + }; + + PushButton PB_XML_FILTER_DELETE + { + Pos = MAP_APPFONT ( BUTTONS_LEFT , BUTTONS_TOP + 3 * BUTTONS_HEIGHT + 4 * BUTTONS_SPACEING ) ; + Size = MAP_APPFONT ( BUTTONS_WIDTH , BUTTONS_HEIGHT ) ; + HelpId = HID_XML_FILTER_DELETE; + TabStop = TRUE ; + Text [ en-US ] = "~Delete..."; + }; + + PushButton PB_XML_FILTER_SAVE + { + Pos = MAP_APPFONT ( BUTTONS_LEFT , BUTTONS_TOP + 4 * BUTTONS_HEIGHT + 6 * BUTTONS_SPACEING ) ; + Size = MAP_APPFONT ( BUTTONS_WIDTH , BUTTONS_HEIGHT ) ; + HelpId = HID_XML_FILTER_SAVE; + TabStop = TRUE ; + Text [ en-US ] = "~Save as Package..."; + }; + + PushButton PB_XML_FILTER_OPEN + { + Pos = MAP_APPFONT ( BUTTONS_LEFT , BUTTONS_TOP + 5 * BUTTONS_HEIGHT + 7 * BUTTONS_SPACEING ) ; + Size = MAP_APPFONT ( BUTTONS_WIDTH , BUTTONS_HEIGHT ) ; + HelpId = HID_XML_FILTER_OPEN; + TabStop = TRUE ; + Text [ en-US ] = "~Open Package..."; + TabStop = TRUE ; + }; + + HelpButton BTN_XML_FILTER_HELP + { + Pos = MAP_APPFONT ( BUTTONS_LEFT, BUTTONS_TOP + 6 * BUTTONS_HEIGHT + 9 * BUTTONS_SPACEING ); + Size = MAP_APPFONT ( BUTTONS_WIDTH, BUTTONS_HEIGHT ); + }; + + PushButton PB_XML_FILTER_CLOSE + { + Pos = MAP_APPFONT ( BUTTONS_LEFT , BUTTONS_TOP + 7 * BUTTONS_HEIGHT + 10 * BUTTONS_SPACEING ) ; + Size = MAP_APPFONT ( BUTTONS_WIDTH , BUTTONS_HEIGHT ) ; + HelpId = HID_XML_FILTER_CLOSE; + TabStop = TRUE ; + Text [ en-US ] = "~Close"; + }; + +}; + + + + + + + + + + + + diff --git a/filter/source/xsltdialog/xmlfiltertabdialog.cxx b/filter/source/xsltdialog/xmlfiltertabdialog.cxx new file mode 100644 index 000000000000..63c369610295 --- /dev/null +++ b/filter/source/xsltdialog/xmlfiltertabdialog.cxx @@ -0,0 +1,373 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_filter.hxx" +#include <com/sun/star/container/XNameAccess.hpp> +#ifndef _COM_SUN_STAR_BEANS_NAMEDVALUE_HPP_ +#include <com/sun/star/beans/PropertyValue.hpp> +#endif +#include <tools/resid.hxx> +#include <vcl/msgbox.hxx> +#include <osl/file.hxx> + +#include "xmlfilterdialogstrings.hrc" +#include "xmlfiltertabdialog.hxx" +#include "xmlfiltertabdialog.hrc" +#include "xmlfiltertabpagebasic.hrc" +#include "xmlfiltertabpagexslt.hrc" +#include "xmlfiltertabpagebasic.hxx" +#include "xmlfiltertabpagexslt.hxx" +#include "xmlfiltersettingsdialog.hxx" +#include "xmlfiltersettingsdialog.hrc" +#include "xmlfilterhelpids.hrc" + +using namespace rtl; +using namespace com::sun::star::uno; +using namespace com::sun::star::container; +using namespace com::sun::star::beans; +using namespace com::sun::star::lang; + +XMLFilterTabDialog::XMLFilterTabDialog( Window *pParent, ResMgr& rResMgr, const Reference< XMultiServiceFactory >& rxMSF, const filter_info_impl* pInfo ) : + TabDialog( pParent, ResId( DLG_XML_FILTER_TABDIALOG, rResMgr ) ), + mxMSF( rxMSF ), + mrResMgr( rResMgr ), + maTabCtrl( this, ResId( 1, rResMgr ) ), + maOKBtn( this ), + maCancelBtn( this ), + maHelpBtn( this ) +{ + FreeResource(); + + maTabCtrl.SetHelpId( HID_XML_FILTER_TABPAGE_CTRL ); + + mpOldInfo = pInfo; + mpNewInfo = new filter_info_impl( *mpOldInfo ); + + String aTitle( GetText() ); + aTitle.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM("%s") ), mpNewInfo->maFilterName ); + SetText( aTitle ); + + maTabCtrl.Show(); + maOKBtn.Show(); + maCancelBtn.Show(); + maHelpBtn.Show(); + + maOKBtn.SetClickHdl( LINK( this, XMLFilterTabDialog, OkHdl ) ); + + maTabCtrl.SetActivatePageHdl( LINK( this, XMLFilterTabDialog, ActivatePageHdl ) ); + maTabCtrl.SetDeactivatePageHdl( LINK( this, XMLFilterTabDialog, DeactivatePageHdl ) ); + + mpBasicPage = new XMLFilterTabPageBasic( &maTabCtrl, mrResMgr ); + mpBasicPage->SetInfo( mpNewInfo ); + + maTabCtrl.SetTabPage( RID_XML_FILTER_TABPAGE_BASIC, mpBasicPage ); + + Size aSiz = mpBasicPage->GetSizePixel(); + Size aCtrlSiz = maTabCtrl.GetTabPageSizePixel(); + // set size on TabControl only if smaller than TabPage + if ( aCtrlSiz.Width() < aSiz.Width() || aCtrlSiz.Height() < aSiz.Height() ) + { + maTabCtrl.SetTabPageSizePixel( aSiz ); + aCtrlSiz = aSiz; + } + + mpXSLTPage = new XMLFilterTabPageXSLT( &maTabCtrl, mrResMgr, mxMSF ); + mpXSLTPage->SetInfo( mpNewInfo ); + + maTabCtrl.SetTabPage( RID_XML_FILTER_TABPAGE_XSLT, mpXSLTPage ); + + aSiz = mpXSLTPage->GetSizePixel(); + if ( aCtrlSiz.Width() < aSiz.Width() || aCtrlSiz.Height() < aSiz.Height() ) + { + maTabCtrl.SetTabPageSizePixel( aSiz ); + aCtrlSiz = aSiz; + } + + ActivatePageHdl( &maTabCtrl ); + + AdjustLayout(); +} + +// ----------------------------------------------------------------------- + +XMLFilterTabDialog::~XMLFilterTabDialog() +{ + delete mpBasicPage; + delete mpXSLTPage; + delete mpNewInfo; +} + +// ----------------------------------------------------------------------- + +bool XMLFilterTabDialog::onOk() +{ + mpXSLTPage->FillInfo( mpNewInfo ); + mpBasicPage->FillInfo( mpNewInfo ); + + sal_uInt16 nErrorPage = 0; + sal_uInt16 nErrorId = 0; + Window* pFocusWindow = NULL; + String aReplace1; + String aReplace2; + + // 1. see if the filter name is ok + if( (mpNewInfo->maFilterName.getLength() == 0) || (mpNewInfo->maFilterName != mpOldInfo->maFilterName) ) + { + // if the user deleted the filter name, we reset the original filter name + if( mpNewInfo->maFilterName.getLength() == 0 ) + { + mpNewInfo->maFilterName = mpOldInfo->maFilterName; + } + else + { + try + { + Reference< XNameAccess > xFilterContainer( mxMSF->createInstance( OUString::createFromAscii("com.sun.star.document.FilterFactory" ) ), UNO_QUERY ); + if( xFilterContainer.is() ) + { + if( xFilterContainer->hasByName( mpNewInfo->maFilterName ) ) + { + nErrorPage = RID_XML_FILTER_TABPAGE_BASIC; + nErrorId = STR_ERROR_FILTER_NAME_EXISTS; + pFocusWindow = &(mpBasicPage->maEDFilterName); + aReplace1 = mpNewInfo->maFilterName; + } + + } + } + catch( Exception& ) + { + DBG_ERROR( "XMLFilterTabDialog::onOk exception catched!" ); + } + } + } + + // 2. see if the interface name is ok + if( (mpNewInfo->maInterfaceName.getLength() == 0) || (mpNewInfo->maInterfaceName != mpOldInfo->maInterfaceName) ) + { + // if the user deleted the interface name, we reset the original filter name + if( mpNewInfo->maInterfaceName.getLength() == 0 ) + { + mpNewInfo->maInterfaceName = mpOldInfo->maInterfaceName; + } + else + { + try + { + Reference< XNameAccess > xFilterContainer( mxMSF->createInstance( OUString::createFromAscii("com.sun.star.document.FilterFactory" ) ), UNO_QUERY ); + if( xFilterContainer.is() ) + { + Sequence< OUString > aFilterNames( xFilterContainer->getElementNames() ); + OUString* pFilterName = aFilterNames.getArray(); + + const sal_Int32 nCount = aFilterNames.getLength(); + sal_Int32 nFilter; + + Sequence< PropertyValue > aValues; + for( nFilter = 0; (nFilter < nCount) && (nErrorId == 0); nFilter++, pFilterName++ ) + { + Any aAny( xFilterContainer->getByName( *pFilterName ) ); + if( !(aAny >>= aValues) ) + continue; + + const sal_Int32 nValueCount( aValues.getLength() ); + PropertyValue* pValues = aValues.getArray(); + sal_Int32 nValue; + + for( nValue = 0; (nValue < nValueCount) && (nErrorId == 0); nValue++, pValues++ ) + { + if( pValues->Name.equalsAscii( "UIName" ) ) + { + OUString aInterfaceName; + pValues->Value >>= aInterfaceName; + if( aInterfaceName == mpNewInfo->maInterfaceName ) + { + nErrorPage = RID_XML_FILTER_TABPAGE_BASIC; + nErrorId = STR_ERROR_TYPE_NAME_EXISTS; + pFocusWindow = &(mpBasicPage->maEDInterfaceName); + aReplace1 = mpNewInfo->maInterfaceName; + aReplace2 = *pFilterName; + } + } + } + } + } + } + catch( Exception& ) + { + DBG_ERROR( "XMLFilterTabDialog::onOk exception catched!" ); + } + } + } + + // 3. see if the dtd is valid + if( 0 == nErrorId ) + { + if( (mpNewInfo->maDTD != mpOldInfo->maDTD) && isFileURL( mpNewInfo->maDTD ) ) + { + osl::File aFile( mpNewInfo->maDTD ); + osl::File::RC aRC = aFile.open( OpenFlag_Read ); + if( aRC != osl::File::E_None ) + { + nErrorId = STR_ERROR_DTD_NOT_FOUND; + nErrorPage = RID_XML_FILTER_TABPAGE_XSLT; + pFocusWindow = &(mpXSLTPage->maEDDTDSchema); + } + } + } + + if( 0 == nErrorId ) + { + // 4. see if the export xslt is valid + if( (mpNewInfo->maExportXSLT != mpOldInfo->maExportXSLT) && isFileURL( mpNewInfo->maExportXSLT ) ) + { + osl::File aFile( mpNewInfo->maExportXSLT ); + osl::File::RC aRC = aFile.open( OpenFlag_Read ); + if( aRC != osl::File::E_None ) + { + nErrorId = STR_ERROR_EXPORT_XSLT_NOT_FOUND; + nErrorPage = RID_XML_FILTER_TABPAGE_XSLT; + pFocusWindow = &(mpXSLTPage->maEDExportXSLT); + } + } + } + + if( 0 == nErrorId ) + { + // 5. see if the import xslt is valid + if( (mpNewInfo->maImportXSLT != mpOldInfo->maImportXSLT) && isFileURL( mpNewInfo->maImportXSLT ) ) + { + osl::File aFile( mpNewInfo->maImportXSLT ); + osl::File::RC aRC = aFile.open( OpenFlag_Read ); + if( aRC != osl::File::E_None ) + { + nErrorId = STR_ERROR_IMPORT_XSLT_NOT_FOUND; + nErrorPage = RID_XML_FILTER_TABPAGE_XSLT; + pFocusWindow = &(mpXSLTPage->maEDImportTemplate); + } + } + } + + // see if we have at least an import or an export dtd + if((mpNewInfo->maImportXSLT.getLength() == 0) && (mpNewInfo->maExportXSLT.getLength() == 0) ) + { + nErrorId = STR_ERROR_EXPORT_XSLT_NOT_FOUND; + nErrorPage = RID_XML_FILTER_TABPAGE_XSLT; + pFocusWindow = &(mpXSLTPage->maEDExportXSLT); + } + + if( 0 == nErrorId ) + { + // 6. see if the import template is valid + if( (mpNewInfo->maImportTemplate != mpOldInfo->maImportTemplate) && isFileURL( mpNewInfo->maImportTemplate ) ) + { + osl::File aFile( mpNewInfo->maImportTemplate ); + osl::File::RC aRC = aFile.open( OpenFlag_Read ); + if( aRC != osl::File::E_None ) + { + nErrorId = STR_ERROR_IMPORT_TEMPLATE_NOT_FOUND; + nErrorPage = RID_XML_FILTER_TABPAGE_XSLT; + pFocusWindow = &(mpXSLTPage->maEDImportTemplate); + } + } + } + + if( 0 != nErrorId ) + { + maTabCtrl.SetCurPageId( (USHORT)nErrorPage ); + ActivatePageHdl( &maTabCtrl ); + + ResId aResId( nErrorId, mrResMgr ); + String aMessage( aResId ); + + if( aReplace2.Len() ) + { + aMessage.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM("%s1") ), aReplace1 ); + aMessage.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM("%s2") ), aReplace2 ); + } + else if( aReplace1.Len() ) + { + aMessage.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM("%s") ), aReplace1 ); + } + + ErrorBox aBox(this, (WinBits)(WB_OK), aMessage ); + aBox.Execute(); + + if( pFocusWindow ) + pFocusWindow->GrabFocus(); + + return false; + } + else + { + return true; + } +} + +// ----------------------------------------------------------------------- + +filter_info_impl* XMLFilterTabDialog::getNewFilterInfo() const +{ + return mpNewInfo; +} + +// ----------------------------------------------------------------------- + +IMPL_LINK( XMLFilterTabDialog, CancelHdl, Button*, /* pButton */ ) +{ + Close(); + return 0; +} + +// ----------------------------------------------------------------------- + +IMPL_LINK( XMLFilterTabDialog, OkHdl, Button *, EMPTYARG ) +{ + if( onOk() ) + EndDialog(1); + + return 0; +} + +// ----------------------------------------------------------------------- + +IMPL_LINK( XMLFilterTabDialog, ActivatePageHdl, TabControl *, pTabCtrl ) +{ + const USHORT nId = pTabCtrl->GetCurPageId(); + TabPage* pTabPage = pTabCtrl->GetTabPage( nId ); + pTabPage->Show(); + + return 0; +} + +// ----------------------------------------------------------------------- + +IMPL_LINK( XMLFilterTabDialog, DeactivatePageHdl, TabControl *, /* pTabCtrl */ ) +{ + return TRUE; +} diff --git a/filter/source/xsltdialog/xmlfiltertabdialog.hrc b/filter/source/xsltdialog/xmlfiltertabdialog.hrc new file mode 100644 index 000000000000..a4b9844895e3 --- /dev/null +++ b/filter/source/xsltdialog/xmlfiltertabdialog.hrc @@ -0,0 +1,33 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLFILTERTABDIALOG_HRC_ +#define _XMLFILTERTABDIALOG_HRC_ + +#include "xmlfiltercommon.hrc" + +#endif diff --git a/filter/source/xsltdialog/xmlfiltertabdialog.hxx b/filter/source/xsltdialog/xmlfiltertabdialog.hxx new file mode 100644 index 000000000000..5e514353e11a --- /dev/null +++ b/filter/source/xsltdialog/xmlfiltertabdialog.hxx @@ -0,0 +1,75 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _XMLFILTERTABDIALOG_HXX_ +#define _XMLFILTERTABDIALOG_HXX_ + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <sfx2/tabdlg.hxx> + +class Window; +class ResMgr; + +class filter_info_impl; +class XMLFilterTabPageBasic; +class XMLFilterTabPageXSLT; + +class XMLFilterTabDialog: public TabDialog +{ +public: + XMLFilterTabDialog( Window *pParent, ResMgr& rResMgr, const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rxMSF, const filter_info_impl* pInfo ); + virtual ~XMLFilterTabDialog(); + + ResMgr& getResMgr() { return mrResMgr; } + + bool onOk(); + + filter_info_impl* getNewFilterInfo() const; + +private: + com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > mxMSF; + + DECL_LINK( ActivatePageHdl, TabControl * ); + DECL_LINK( DeactivatePageHdl, TabControl * ); + DECL_LINK( OkHdl, Button * ); + DECL_LINK( CancelHdl, Button * ); + + ResMgr& mrResMgr; + + const filter_info_impl* mpOldInfo; + filter_info_impl* mpNewInfo; + + TabControl maTabCtrl; + OKButton maOKBtn; + CancelButton maCancelBtn; + HelpButton maHelpBtn; + + XMLFilterTabPageBasic* mpBasicPage; + XMLFilterTabPageXSLT* mpXSLTPage; +}; + + +#endif diff --git a/filter/source/xsltdialog/xmlfiltertabdialog.src b/filter/source/xsltdialog/xmlfiltertabdialog.src new file mode 100644 index 000000000000..7bfed35d0b87 --- /dev/null +++ b/filter/source/xsltdialog/xmlfiltertabdialog.src @@ -0,0 +1,65 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "xmlfiltertabdialog.hrc" +#include "xmlfiltertabpagebasic.hrc" +#include "xmlfiltertabpagexslt.hrc" +#include "xmlfilterhelpids.hrc" + +TabDialog DLG_XML_FILTER_TABDIALOG +{ + HelpId = HID_XML_FILTER_TABDIALOG; + OutputSize = TRUE ; + SvLook = TRUE ; + Moveable = TRUE ; + Text [ en-US ] = "XML Filter: %s" ; + TabControl 1 + { + OutputSize = TRUE ; + PageList = + { + PageItem RID_XML_FILTER_TABPAGE_BASIC + { + Identifier = RID_XML_FILTER_TABPAGE_BASIC ; + Text [ en-US ] = "General" ; + }; + PageItem RID_XML_FILTER_TABPAGE_XSLT + { + Identifier = RID_XML_FILTER_TABPAGE_XSLT ; + Text [ en-US ] = "Transformation" ; + }; + }; + }; +}; + + + + + + + + diff --git a/filter/source/xsltdialog/xmlfiltertabpagebasic.cxx b/filter/source/xsltdialog/xmlfiltertabpagebasic.cxx new file mode 100644 index 000000000000..b88e9ff802a4 --- /dev/null +++ b/filter/source/xsltdialog/xmlfiltertabpagebasic.cxx @@ -0,0 +1,153 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_filter.hxx" +#include <rtl/ustrbuf.hxx> + +#include "xmlfilterdialogstrings.hrc" +#include "xmlfiltertabpagebasic.hxx" +#include "xmlfiltertabpagebasic.hrc" +#include "xmlfiltersettingsdialog.hxx" +#include "xmlfilterhelpids.hrc" + +using namespace rtl; + +XMLFilterTabPageBasic::XMLFilterTabPageBasic( Window* pParent, ResMgr& rResMgr ) : + TabPage( pParent, ResId( RID_XML_FILTER_TABPAGE_BASIC, rResMgr ) ), + maFTFilterName( this, ResId( FT_XML_FILTER_NAME, rResMgr ) ), + maEDFilterName( this, ResId( ED_XML_FILTER_NAME, rResMgr ) ), + maFTApplication( this, ResId( FT_XML_APPLICATION, rResMgr ) ), + maCBApplication( this, ResId( CB_XML_APPLICATION, rResMgr ) ), + maFTInterfaceName( this, ResId( FT_XML_INTERFACE_NAME, rResMgr ) ), + maEDInterfaceName( this, ResId( ED_XML_INTERFACE_NAME, rResMgr ) ), + maFTExtension( this, ResId( FT_XML_EXTENSION, rResMgr ) ), + maEDExtension( this, ResId( ED_XML_EXTENSION, rResMgr ) ), + maFTDescription( this, ResId( FT_XML_DESCRIPTION, rResMgr ) ), + maEDDescription( this, ResId( ED_XML_DESCRIPTION, rResMgr ) ) +{ + maCBApplication.SetHelpId( HID_XML_FILTER_APPLICATION ); + maEDDescription.SetHelpId( HID_XML_FILTER_DESCRIPTION ); + + FreeResource(); + + std::vector< application_info_impl* >& rInfos = getApplicationInfos(); + std::vector< application_info_impl* >::iterator aIter( rInfos.begin() ); + while( aIter != rInfos.end() ) + { + XubString aEntry( (*aIter++)->maDocumentUIName ); + maCBApplication.InsertEntry( aEntry ); + } +} + +XMLFilterTabPageBasic::~XMLFilterTabPageBasic() +{ +} + +static OUString checkExtensions( const String& rExtensions ) +{ + const sal_Unicode* pSource = rExtensions.GetBuffer(); + sal_Int32 nCount = rExtensions.Len(); + + String aRet; + while( nCount-- ) + { + switch(*pSource) + { + case sal_Unicode(','): + aRet += sal_Unicode(';'); + break; + case sal_Unicode('.'): + case sal_Unicode('*'): + break; + default: + aRet += *pSource; + } + + pSource++; + } + + return aRet; +} + +bool XMLFilterTabPageBasic::FillInfo( filter_info_impl* pInfo ) +{ + if( pInfo ) + { + if( maEDFilterName.GetText().Len() ) + pInfo->maFilterName = maEDFilterName.GetText(); + + if( maCBApplication.GetText().Len() ) + pInfo->maDocumentService = maCBApplication.GetText(); + + if( maEDInterfaceName.GetText().Len() ) + pInfo->maInterfaceName = maEDInterfaceName.GetText(); + + if( maEDExtension.GetText().Len() ) + pInfo->maExtension = checkExtensions( maEDExtension.GetText() ); + + pInfo->maComment = string_encode( maEDDescription.GetText() ); + + if( pInfo->maDocumentService.getLength() ) + { + std::vector< application_info_impl* >& rInfos = getApplicationInfos(); + std::vector< application_info_impl* >::iterator aIter( rInfos.begin() ); + while( aIter != rInfos.end() ) + { + if( pInfo->maDocumentService == (*aIter)->maDocumentUIName ) + { + pInfo->maDocumentService = (*aIter)->maDocumentService; + pInfo->maExportService = (*aIter)->maXMLExporter; + pInfo->maImportService = (*aIter)->maXMLImporter; + break; + } + aIter++; + } + } + } + + return true; +} + +void XMLFilterTabPageBasic::SetInfo(const filter_info_impl* pInfo) +{ + if( pInfo ) + { + maEDFilterName.SetText( string_decode(pInfo->maFilterName) ); + /* + if( pInfo->maDocumentService.getLength() ) + maCBApplication.SetText( getApplicationUIName( pInfo->maDocumentService ) ); + */ + if( pInfo->maExportService.getLength() ) + maCBApplication.SetText( getApplicationUIName( pInfo->maExportService ) ); + else + maCBApplication.SetText( getApplicationUIName( pInfo->maImportService ) ); + maEDInterfaceName.SetText( string_decode(pInfo->maInterfaceName) ); + maEDExtension.SetText( pInfo->maExtension ); + maEDDescription.SetText( string_decode( pInfo->maComment ) ); + } +} diff --git a/filter/source/xsltdialog/xmlfiltertabpagebasic.hrc b/filter/source/xsltdialog/xmlfiltertabpagebasic.hrc new file mode 100644 index 000000000000..eea4f91e1698 --- /dev/null +++ b/filter/source/xsltdialog/xmlfiltertabpagebasic.hrc @@ -0,0 +1,44 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLFILTERTABPAGEBASIC_HRC_ +#define _XMLFILTERTABPAGEBASIC_HRC_ + +#include "xmlfiltercommon.hrc" + +#define FT_XML_FILTER_NAME 1 +#define ED_XML_FILTER_NAME 2 +#define FT_XML_APPLICATION 3 +#define CB_XML_APPLICATION 4 +#define FT_XML_INTERFACE_NAME 5 +#define ED_XML_INTERFACE_NAME 6 +#define FT_XML_EXTENSION 7 +#define ED_XML_EXTENSION 8 +#define FT_XML_DESCRIPTION 9 +#define ED_XML_DESCRIPTION 10 + +#endif diff --git a/filter/source/xsltdialog/xmlfiltertabpagebasic.hxx b/filter/source/xsltdialog/xmlfiltertabpagebasic.hxx new file mode 100644 index 000000000000..0fd1fcda3cd5 --- /dev/null +++ b/filter/source/xsltdialog/xmlfiltertabpagebasic.hxx @@ -0,0 +1,67 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _XMLFILTERTABPAGEBASIC_HXX_ +#define _XMLFILTERTABPAGEBASIC_HXX_ + +#include <sfx2/tabdlg.hxx> +#include <vcl/fixed.hxx> +#include <vcl/edit.hxx> +#include <vcl/combobox.hxx> +#include <svtools/svmedit.hxx> + +class Window; +class ResMgr; +class filter_info_impl; + +class XMLFilterTabPageBasic : public TabPage +{ +public: + XMLFilterTabPageBasic( Window* pParent, ResMgr& rResMgr ); + virtual ~XMLFilterTabPageBasic(); + + bool FillInfo( filter_info_impl* pInfo ); + void SetInfo(const filter_info_impl* pInfo); + + static rtl::OUString decodeComment( const rtl::OUString& rComment ); + static rtl::OUString encodeComment( const rtl::OUString& rComment ); + + FixedText maFTFilterName; + Edit maEDFilterName; + + FixedText maFTApplication; + ComboBox maCBApplication; + + FixedText maFTInterfaceName; + Edit maEDInterfaceName; + + FixedText maFTExtension; + Edit maEDExtension; + FixedText maFTDescription; + MultiLineEdit maEDDescription; +}; + +#endif diff --git a/filter/source/xsltdialog/xmlfiltertabpagebasic.src b/filter/source/xsltdialog/xmlfiltertabpagebasic.src new file mode 100644 index 000000000000..e2c3ffb15213 --- /dev/null +++ b/filter/source/xsltdialog/xmlfiltertabpagebasic.src @@ -0,0 +1,152 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "xmlfiltertabpagebasic.hrc" +#include "xmlfilterhelpids.hrc" + +#define TAB_PAGE_WIDTH 260 +#define TAB_PAGE_HEIGHT 185 + +#define SPACING 3 + +#define FIRST_ROW_X 6 +#define FIRST_ROW_Y 6 +#define FIRST_ROW_WIDTH 60 + +#define SECOND_ROW_X (FIRST_ROW_X + FIRST_ROW_WIDTH + SPACING) +#define SECOND_ROW_Y 6 +#define SECOND_ROW_WIDTH (TAB_PAGE_WIDTH - SECOND_ROW_X - SPACING) + +#define FIXED_TEXT_OFFSET 2 + +#define ROW_HEIGHT 12 + + +TabPage RID_XML_FILTER_TABPAGE_BASIC +{ + HelpId = HID_XML_FILTER_TABPAGE_BASIC; + Hide = TRUE; + Size = MAP_APPFONT ( TAB_PAGE_WIDTH , TAB_PAGE_HEIGHT ); + Text [ en-US ] = "General"; + + // Filter Name ---------------------------------------------------- + + FixedText FT_XML_FILTER_NAME + { + Pos = MAP_APPFONT ( FIRST_ROW_X , FIRST_ROW_Y + 0 * ROW_HEIGHT + 0 * SPACING + FIXED_TEXT_OFFSET ) ; + Size = MAP_APPFONT ( FIRST_ROW_WIDTH , 8 ) ; + Text [ en-US ] = "Filter name"; + }; + + Edit ED_XML_FILTER_NAME + { + Pos = MAP_APPFONT ( SECOND_ROW_X , SECOND_ROW_Y + 0 * ROW_HEIGHT + 0 * SPACING ) ; + Size = MAP_APPFONT ( 102 , 12 ) ; + HelpId = HID_XML_FILTER_NAME; + Border = TRUE; + }; + + // Application ---------------------------------------------------- + + FixedText FT_XML_APPLICATION + { + Pos = MAP_APPFONT ( FIRST_ROW_X , FIRST_ROW_Y + 1 * ROW_HEIGHT + 1 * SPACING + FIXED_TEXT_OFFSET ) ; + Size = MAP_APPFONT ( FIRST_ROW_WIDTH , 8 ) ; + Text [ en-US ] = "Application"; + }; + + ComboBox CB_XML_APPLICATION + { + Pos = MAP_APPFONT ( SECOND_ROW_X , SECOND_ROW_Y + 1 * ROW_HEIGHT + 1 * SPACING ) ; + Size = MAP_APPFONT ( 102 , 60 ) ; + HelpId = HID_XML_FILTER_APPLICATION; + Border = TRUE ; + TabStop = TRUE ; + DropDown = TRUE ; + Sort = TRUE ; + }; + + // Interface Name ------------------------------------------------- + + FixedText FT_XML_INTERFACE_NAME + { + Pos = MAP_APPFONT ( FIRST_ROW_X , FIRST_ROW_Y + 2 * ROW_HEIGHT + 2 * SPACING ) ; // + FIXED_TEXT_OFFSET ) ; + Size = MAP_APPFONT ( FIRST_ROW_WIDTH , 16 ) ; + Text [ en-US ] = "Name of\nfile type"; + }; + + Edit ED_XML_INTERFACE_NAME + { + Pos = MAP_APPFONT ( SECOND_ROW_X , 2 + SECOND_ROW_Y + 2 * ROW_HEIGHT + 2 * SPACING ) ; + Size = MAP_APPFONT ( 102 , 12 ) ; + HelpId = HID_XML_FILTER_INTERFACE_NAME; + Border = TRUE; + }; + + // Extension ------------------------------------------------------ + + FixedText FT_XML_EXTENSION + { + Pos = MAP_APPFONT ( FIRST_ROW_X , 4 + FIRST_ROW_Y + 3 * ROW_HEIGHT + 3 * SPACING + FIXED_TEXT_OFFSET) ; + Size = MAP_APPFONT ( FIRST_ROW_WIDTH , 8 ) ; + Text [ en-US ] = "File extension"; + }; + + Edit ED_XML_EXTENSION + { + Pos = MAP_APPFONT ( SECOND_ROW_X , 4 + SECOND_ROW_Y + 3 * ROW_HEIGHT + 3 * SPACING ) ; + Size = MAP_APPFONT ( 32 , 12 ) ; + HelpId = HID_XML_FILTER_EXTENSION; + Border = TRUE; + }; + + // Description ---------------------------------------------------- + + FixedText FT_XML_DESCRIPTION + { + Pos = MAP_APPFONT ( FIRST_ROW_X , 4 + FIRST_ROW_Y + 4 * ROW_HEIGHT + 4 * SPACING + FIXED_TEXT_OFFSET ) ; + Size = MAP_APPFONT ( FIRST_ROW_WIDTH , 8 ) ; + Text [ en-US ] = "Comments"; + }; + + MultiLineEdit ED_XML_DESCRIPTION + { + Pos = MAP_APPFONT ( SECOND_ROW_X , 4 + SECOND_ROW_Y + 4 * ROW_HEIGHT + 4 * SPACING ) ; + Size = MAP_APPFONT ( SECOND_ROW_WIDTH , 3*ROW_HEIGHT ) ; + HelpId = HID_XML_FILTER_DESCRIPTION; + Border = TRUE; + IgnoreTab = TRUE ; + }; +}; + + + + + + + + diff --git a/filter/source/xsltdialog/xmlfiltertabpagexslt.cxx b/filter/source/xsltdialog/xmlfiltertabpagexslt.cxx new file mode 100644 index 000000000000..17743a09d321 --- /dev/null +++ b/filter/source/xsltdialog/xmlfiltertabpagexslt.cxx @@ -0,0 +1,221 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_filter.hxx" +#include <com/sun/star/frame/XConfigManager.hpp> + +#include "com/sun/star/ui/dialogs/TemplateDescription.hpp" +#include <sfx2/filedlghelper.hxx> +#include <unotools/localfilehelper.hxx> +#include <osl/file.hxx> +#include <svl/urihelper.hxx> + +#include "xmlfiltertabpagexslt.hxx" +#include "xmlfiltertabpagexslt.hrc" +#include "xmlfiltersettingsdialog.hxx" +#include "xmlfilterhelpids.hrc" + +using namespace ::rtl; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::frame; +using namespace ::com::sun::star::lang; + +XMLFilterTabPageXSLT::XMLFilterTabPageXSLT( Window* pParent, ResMgr& rResMgr, const Reference< XMultiServiceFactory >& rxMSF ) : + TabPage( pParent, ResId( RID_XML_FILTER_TABPAGE_XSLT, rResMgr ) ), + + maFTDocType( this, ResId( FT_XML_DOCTYPE, rResMgr ) ), + maEDDocType( this, ResId( ED_XML_DOCTYPE, rResMgr ) ), + + maFTDTDSchema( this, ResId( FT_XML_DTD_SCHEMA, rResMgr ) ), + maEDDTDSchema( this, ResId( ED_XML_DTD_SCHEMA, rResMgr ), INET_PROT_FILE ), + maPBDTDSchemaBrowse( this, ResId( ED_XML_DTD_SCHEMA_BROWSE, rResMgr ) ), + + maFTExportXSLT( this, ResId( FT_XML_EXPORT_XSLT, rResMgr ) ), + maEDExportXSLT( this, ResId( ED_XML_EXPORT_XSLT, rResMgr ), INET_PROT_FILE ), + maPBExprotXSLT( this, ResId( PB_XML_EXPORT_XSLT_BROWSE, rResMgr ) ), + + maFTImportXSLT( this, ResId( FT_XML_IMPORT_XSLT, rResMgr ) ), + maEDImportXSLT( this, ResId( ED_XML_IMPORT_XSLT, rResMgr ), INET_PROT_FILE ), + maPBImportXSLT( this, ResId( PB_XML_IMPORT_XSLT_BROWSE, rResMgr ) ), + + maFTImportTemplate( this, ResId( FT_XML_IMPORT_TEMPLATE, rResMgr ) ), + maEDImportTemplate( this, ResId( ED_XML_IMPORT_TEMPLATE, rResMgr ), INET_PROT_FILE ), + maPBImportTemplate( this, ResId( PB_XML_IMPORT_TEMPLATE_BROWSE, rResMgr ) ), + + sHTTPSchema( RTL_CONSTASCII_USTRINGPARAM( "http://" ) ), + sSHTTPSchema( RTL_CONSTASCII_USTRINGPARAM( "shttp://" ) ), + sFILESchema( RTL_CONSTASCII_USTRINGPARAM( "file://" ) ), + sFTPSchema( RTL_CONSTASCII_USTRINGPARAM( "ftp://" ) ), + sInstPath( RTL_CONSTASCII_USTRINGPARAM( "$(prog)/" ) ) +{ + FreeResource(); + + try + { + Reference< XConfigManager > xCfgMgr( rxMSF->createInstance(OUString::createFromAscii("com.sun.star.config.SpecialConfigManager")), UNO_QUERY ); + if( xCfgMgr.is() ) + sInstPath = xCfgMgr->substituteVariables( sInstPath ); + } + catch(Exception&) + { + DBG_ERROR( "XMLFilterTabPageXSLT::XMLFilterTabPageXSLT exception catched!" ); + } + + maPBDTDSchemaBrowse.SetClickHdl( LINK ( this, XMLFilterTabPageXSLT, ClickBrowseHdl_Impl ) ); + maPBExprotXSLT.SetClickHdl( LINK ( this, XMLFilterTabPageXSLT, ClickBrowseHdl_Impl ) ); + maPBImportXSLT.SetClickHdl( LINK ( this, XMLFilterTabPageXSLT, ClickBrowseHdl_Impl ) ); + maPBImportTemplate.SetClickHdl( LINK ( this, XMLFilterTabPageXSLT, ClickBrowseHdl_Impl ) ); + + maEDDTDSchema.SetHelpId( HID_XML_FILTER_DTD ); + maEDExportXSLT.SetHelpId( HID_XML_FILTER_EXPORT_XSLT ); + maEDImportXSLT.SetHelpId( HID_XML_FILTER_IMPORT_XSLT ); + maEDImportTemplate.SetHelpId( HID_XML_FILTER_IMPORT_TEMPLATE ); +} + +XMLFilterTabPageXSLT::~XMLFilterTabPageXSLT() +{ +} + +bool XMLFilterTabPageXSLT::FillInfo( filter_info_impl* pInfo ) +{ + if( pInfo ) + { + pInfo->maDocType = maEDDocType.GetText(); + pInfo->maDTD = GetURL( maEDDTDSchema ); + pInfo->maExportXSLT = GetURL( maEDExportXSLT ); + pInfo->maImportXSLT = GetURL( maEDImportXSLT ); + pInfo->maImportTemplate = GetURL( maEDImportTemplate ); + } + + return true; +} + +void XMLFilterTabPageXSLT::SetInfo(const filter_info_impl* pInfo) +{ + if( pInfo ) + { + maEDDocType.SetText( pInfo->maDocType ); + + SetURL( maEDDTDSchema, pInfo->maDTD ); + SetURL( maEDExportXSLT, pInfo->maExportXSLT ); + SetURL( maEDImportXSLT, pInfo->maImportXSLT ); + SetURL( maEDImportTemplate, pInfo->maImportTemplate ); + } +} + +void XMLFilterTabPageXSLT::SetURL( SvtURLBox& rURLBox, const OUString& rURL ) +{ + OUString aPath; + + if( rURL.matchIgnoreAsciiCase( OUString( RTL_CONSTASCII_USTRINGPARAM( "file://" ) ) ) ) + { + osl::FileBase::getSystemPathFromFileURL( rURL, aPath ); + + rURLBox.SetBaseURL( rURL ); + rURLBox.SetText( aPath ); + } + else if( rURL.matchIgnoreAsciiCase( OUString( RTL_CONSTASCII_USTRINGPARAM( "http://" ) ) ) || + rURL.matchIgnoreAsciiCase( OUString( RTL_CONSTASCII_USTRINGPARAM( "shttp://" ) ) ) || + rURL.matchIgnoreAsciiCase( OUString( RTL_CONSTASCII_USTRINGPARAM( "ftp://" ) ) ) ) + { + rURLBox.SetBaseURL( rURL ); + rURLBox.SetText( rURL ); + } + else if( rURL.getLength() ) + { + rtl::OUString aURL( rURL ); + aURL = URIHelper::SmartRel2Abs( sInstPath, aURL, Link(), false ); + osl::FileBase::getSystemPathFromFileURL( aURL, aPath ); + + rURLBox.SetBaseURL( aURL ); + rURLBox.SetText( aPath ); + } + else + { + rURLBox.SetBaseURL( sInstPath ); + String aEmpty; + rURLBox.SetText( aEmpty ); + } +} + +OUString XMLFilterTabPageXSLT::GetURL( SvtURLBox& rURLBox ) +{ + OUString aURL; + OUString aStrPath ( rURLBox.GetText() ); + if( aStrPath.matchIgnoreAsciiCase( OUString( RTL_CONSTASCII_USTRINGPARAM( "http://" ) ) ) || + aStrPath.matchIgnoreAsciiCase( OUString( RTL_CONSTASCII_USTRINGPARAM( "shttp://" ) ) ) || + aStrPath.matchIgnoreAsciiCase( OUString( RTL_CONSTASCII_USTRINGPARAM( "ftp://" ) ) ) ) + { + return aStrPath; + } + else + { + const String aBaseURL ( rURLBox.GetBaseURL() ); + osl::FileBase::getFileURLFromSystemPath( aStrPath, aURL ); + } + + return aURL; +} + +IMPL_LINK ( XMLFilterTabPageXSLT, ClickBrowseHdl_Impl, PushButton *, pButton ) +{ + SvtURLBox* pURLBox; + + if( pButton == &maPBDTDSchemaBrowse ) + { + pURLBox = &maEDDTDSchema; + } + else if( pButton == &maPBExprotXSLT ) + { + pURLBox = &maEDExportXSLT; + } + else if( pButton == &maPBImportXSLT ) + { + pURLBox = &maEDImportXSLT; + } + else + { + pURLBox = &maEDImportTemplate; + } + + // Open Fileopen-Dialog + ::sfx2::FileDialogHelper aDlg( + com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 ); + + aDlg.SetDisplayDirectory( GetURL( *pURLBox ) ); + + if ( aDlg.Execute() == ERRCODE_NONE ) + { + OUString aURL( aDlg.GetPath() ); + + SetURL( *pURLBox, aURL ); + } + + return( 0L ); +} + diff --git a/filter/source/xsltdialog/xmlfiltertabpagexslt.hrc b/filter/source/xsltdialog/xmlfiltertabpagexslt.hrc new file mode 100644 index 000000000000..e5b768da6846 --- /dev/null +++ b/filter/source/xsltdialog/xmlfiltertabpagexslt.hrc @@ -0,0 +1,48 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLFILTERTABPAGEXSLT_HRC_ +#define _XMLFILTERTABPAGEXSLT_HRC_ + +#include "xmlfiltercommon.hrc" + +#define FT_XML_DOCTYPE 1 +#define ED_XML_DOCTYPE 2 +#define FT_XML_DTD_SCHEMA 3 +#define ED_XML_DTD_SCHEMA 4 +#define ED_XML_DTD_SCHEMA_BROWSE 5 +#define FT_XML_EXPORT_XSLT 6 +#define ED_XML_EXPORT_XSLT 7 +#define PB_XML_EXPORT_XSLT_BROWSE 8 +#define FT_XML_IMPORT_XSLT 9 +#define ED_XML_IMPORT_XSLT 10 +#define PB_XML_IMPORT_XSLT_BROWSE 11 +#define FT_XML_IMPORT_TEMPLATE 12 +#define ED_XML_IMPORT_TEMPLATE 13 +#define PB_XML_IMPORT_TEMPLATE_BROWSE 14 + +#endif diff --git a/filter/source/xsltdialog/xmlfiltertabpagexslt.hxx b/filter/source/xsltdialog/xmlfiltertabpagexslt.hxx new file mode 100644 index 000000000000..9aa131e228db --- /dev/null +++ b/filter/source/xsltdialog/xmlfiltertabpagexslt.hxx @@ -0,0 +1,82 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _XMLFILTERTABPAGEXSLT_HXX_ +#define _XMLFILTERTABPAGEXSLT_HXX_ + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <sfx2/tabdlg.hxx> +#include <vcl/fixed.hxx> +#include <vcl/edit.hxx> +#include <vcl/combobox.hxx> +#include <svtools/inettbc.hxx> + +class Window; +class ResMgr; +class filter_info_impl; + +class XMLFilterTabPageXSLT : public TabPage +{ +public: + XMLFilterTabPageXSLT( Window* pParent, ResMgr& rResMgr, const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rxMSF ); + virtual ~XMLFilterTabPageXSLT(); + + bool FillInfo( filter_info_impl* pInfo ); + void SetInfo(const filter_info_impl* pInfo); + + DECL_LINK( ClickBrowseHdl_Impl, PushButton * ); + + FixedText maFTDocType; + Edit maEDDocType; + + FixedText maFTDTDSchema; + SvtURLBox maEDDTDSchema; + PushButton maPBDTDSchemaBrowse; + + FixedText maFTExportXSLT; + SvtURLBox maEDExportXSLT; + PushButton maPBExprotXSLT; + + FixedText maFTImportXSLT; + SvtURLBox maEDImportXSLT; + PushButton maPBImportXSLT; + + FixedText maFTImportTemplate; + SvtURLBox maEDImportTemplate; + PushButton maPBImportTemplate; + +private: + void SetURL( SvtURLBox& rURLBox, const rtl::OUString& rURL ); + rtl::OUString GetURL( SvtURLBox& rURLBox ); + + ::rtl::OUString sHTTPSchema; + ::rtl::OUString sSHTTPSchema; + ::rtl::OUString sFILESchema; + ::rtl::OUString sFTPSchema; + ::rtl::OUString sInstPath; +}; + +#endif diff --git a/filter/source/xsltdialog/xmlfiltertabpagexslt.src b/filter/source/xsltdialog/xmlfiltertabpagexslt.src new file mode 100644 index 000000000000..43a5bb1a6f39 --- /dev/null +++ b/filter/source/xsltdialog/xmlfiltertabpagexslt.src @@ -0,0 +1,176 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "xmlfiltertabpagexslt.hrc" +#include "xmlfilterhelpids.hrc" + +#define TAB_PAGE_WIDTH 260 +#define TAB_PAGE_HEIGHT 120 + +#define SPACING 3 + +#define FIRST_ROW_X 6 +#define FIRST_ROW_Y 6 +#define FIRST_ROW_WIDTH 75 + +#define SECOND_ROW_X (FIRST_ROW_X + FIRST_ROW_WIDTH + SPACING) +#define SECOND_ROW_Y 6 +#define SECOND_ROW_WIDTH (TAB_PAGE_WIDTH - SECOND_ROW_X - 2*SPACING) +#define BROWSE_WIDTH 50 + +#define EDIT_OFFSET 1 +#define FIXED_TEXT_OFFSET 2 + +#define ROW_HEIGHT 14 + + +TabPage RID_XML_FILTER_TABPAGE_XSLT +{ + HelpId = HID_XML_FILTER_TABPAGE_XSLT; + Hide = TRUE; + Size = MAP_APPFONT ( TAB_PAGE_WIDTH , TAB_PAGE_HEIGHT ); + Text [ en-US ] = "Transformation"; + + // DocType -------------------------------------------------------- + + FixedText FT_XML_DOCTYPE + { + Pos = MAP_APPFONT ( FIRST_ROW_X , FIRST_ROW_Y + 0 * ROW_HEIGHT + 0 * SPACING + FIXED_TEXT_OFFSET + EDIT_OFFSET ) ; + Size = MAP_APPFONT ( FIRST_ROW_WIDTH , 8 ) ; + Text [ en-US ] = "DocType"; + }; + + Edit ED_XML_DOCTYPE + { + Pos = MAP_APPFONT ( SECOND_ROW_X , SECOND_ROW_Y + 0 * ROW_HEIGHT + 0 * SPACING + EDIT_OFFSET ) ; + Size = MAP_APPFONT ( SECOND_ROW_WIDTH - SPACING - BROWSE_WIDTH, 12 ) ; + HelpId = HID_XML_FILTER_DOCTYPE; + Border = TRUE; + }; + + // DTD/Schema ----------------------------------------------------- + + FixedText FT_XML_DTD_SCHEMA + { + Pos = MAP_APPFONT ( FIRST_ROW_X , FIRST_ROW_Y + 1 * ROW_HEIGHT + 1 * SPACING + FIXED_TEXT_OFFSET + EDIT_OFFSET ) ; + Size = MAP_APPFONT ( FIRST_ROW_WIDTH , 8 ) ; + Text [ en-US ] = "DTD"; + }; + + ComboBox ED_XML_DTD_SCHEMA + { + Pos = MAP_APPFONT ( SECOND_ROW_X , SECOND_ROW_Y + 1 * ROW_HEIGHT + 1 * SPACING + EDIT_OFFSET ) ; + Size = MAP_APPFONT ( SECOND_ROW_WIDTH - SPACING - BROWSE_WIDTH, 12 ) ; + HelpId = HID_XML_FILTER_DTD; + Border = TRUE; + DropDown = FALSE ; + }; + + PushButton ED_XML_DTD_SCHEMA_BROWSE + { + Pos = MAP_APPFONT ( SECOND_ROW_X + SECOND_ROW_WIDTH - BROWSE_WIDTH , FIRST_ROW_Y + 1 * ROW_HEIGHT + 1 * SPACING ) ; + Size = MAP_APPFONT ( BROWSE_WIDTH , 14 ) ; + HelpId = HID_XML_FILTER_DTD_BROWSE; + Text [ en-US ] = "Browse..."; + }; + + // Export XSLT ---------------------------------------------------- + + FixedText FT_XML_EXPORT_XSLT + { + Pos = MAP_APPFONT ( FIRST_ROW_X , FIRST_ROW_Y + 2 * ROW_HEIGHT + 2 * SPACING + FIXED_TEXT_OFFSET + EDIT_OFFSET ) ; + Size = MAP_APPFONT ( FIRST_ROW_WIDTH, 8 ) ; + Text [ en-US ] = "XSLT for export"; + }; + + ComboBox ED_XML_EXPORT_XSLT + { + Pos = MAP_APPFONT ( SECOND_ROW_X , FIRST_ROW_Y + 2 * ROW_HEIGHT + 2 * SPACING + EDIT_OFFSET ) ; + Size = MAP_APPFONT ( SECOND_ROW_WIDTH - SPACING - BROWSE_WIDTH , 12 ) ; + HelpId = HID_XML_FILTER_EXPORT_XSLT; + Border = TRUE; + }; + + PushButton PB_XML_EXPORT_XSLT_BROWSE + { + Pos = MAP_APPFONT ( SECOND_ROW_X + SECOND_ROW_WIDTH - BROWSE_WIDTH , FIRST_ROW_Y + 2 * ROW_HEIGHT + 2 * SPACING ) ; + Size = MAP_APPFONT ( BROWSE_WIDTH , 14 ) ; + HelpId = HID_XML_FILTER_EXPORT_XSLT_BROWSE; + Text [ en-US ] = "Browse..."; + }; + + // Import XSLT ---------------------------------------------------- + + FixedText FT_XML_IMPORT_XSLT + { + Pos = MAP_APPFONT ( FIRST_ROW_X , FIRST_ROW_Y + 3 * ROW_HEIGHT + 3 * SPACING + FIXED_TEXT_OFFSET + EDIT_OFFSET ) ; + Size = MAP_APPFONT ( FIRST_ROW_WIDTH , 8 ) ; + Text [ en-US ] = "XSLT for import"; + }; + + ComboBox ED_XML_IMPORT_XSLT + { + Pos = MAP_APPFONT ( SECOND_ROW_X , FIRST_ROW_Y + 3 * ROW_HEIGHT + 3 * SPACING + EDIT_OFFSET ) ; + Size = MAP_APPFONT ( SECOND_ROW_WIDTH - SPACING - BROWSE_WIDTH , 12 ) ; + HelpId = HID_XML_FILTER_IMPORT_XSLT; + Border = TRUE; + }; + + PushButton PB_XML_IMPORT_XSLT_BROWSE + { + Pos = MAP_APPFONT ( SECOND_ROW_X + SECOND_ROW_WIDTH - BROWSE_WIDTH , FIRST_ROW_Y + 3 * ROW_HEIGHT + 3 * SPACING ) ; + Size = MAP_APPFONT ( BROWSE_WIDTH , 14 ) ; + HelpId = HID_XML_FILTER_IMPORT_XSLT_BROWSE; + Text [ en-US ] = "Browse..."; + }; + + // Import Template ------------------------------------------------ + + FixedText FT_XML_IMPORT_TEMPLATE + { + Pos = MAP_APPFONT ( FIRST_ROW_X , FIRST_ROW_Y + 4 * ROW_HEIGHT + 4 * SPACING + FIXED_TEXT_OFFSET + EDIT_OFFSET ) ; + Size = MAP_APPFONT ( FIRST_ROW_WIDTH , 8 ) ; + Text [ en-US ] = "Template for import"; + }; + + ComboBox ED_XML_IMPORT_TEMPLATE + { + Pos = MAP_APPFONT ( SECOND_ROW_X , FIRST_ROW_Y + 4 * ROW_HEIGHT + 4 * SPACING + EDIT_OFFSET ) ; + Size = MAP_APPFONT ( SECOND_ROW_WIDTH - SPACING - BROWSE_WIDTH , 12 ) ; + HelpId = HID_XML_FILTER_IMPORT_TEMPLATE; + Border = TRUE; + }; + + PushButton PB_XML_IMPORT_TEMPLATE_BROWSE + { + Pos = MAP_APPFONT ( SECOND_ROW_X + SECOND_ROW_WIDTH - BROWSE_WIDTH , FIRST_ROW_Y + 4 * ROW_HEIGHT + 4 * SPACING ) ; + Size = MAP_APPFONT ( BROWSE_WIDTH , 14 ) ; + HelpId = HID_XML_FILTER_IMPORT_TEMPLATE_BROWSE; + Text [ en-US ] = "Browse..."; + }; +}; + diff --git a/filter/source/xsltdialog/xmlfiltertestdialog.cxx b/filter/source/xsltdialog/xmlfiltertestdialog.cxx new file mode 100644 index 000000000000..30238b08c1b5 --- /dev/null +++ b/filter/source/xsltdialog/xmlfiltertestdialog.cxx @@ -0,0 +1,783 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_filter.hxx" +#include <com/sun/star/frame/XConfigManager.hpp> +#include <com/sun/star/xml/sax/XDocumentHandler.hpp> +#ifndef _COM_SUN_STAR_DOCUMENT_XGRAPHICOBJECTRESOLVER_HXX_ +#include <com/sun/star/document/XGraphicObjectResolver.hpp> +#endif +#ifndef _COM_SUN_STAR_DOCUMENT_XEMBEDDEDOBJECTRESOLVER_HXX_ +#include <com/sun/star/document/XEmbeddedObjectResolver.hpp> +#endif +#include <com/sun/star/xml/XImportFilter.hpp> +#include <com/sun/star/xml/XExportFilter.hpp> +#include <com/sun/star/io/XActiveDataSource.hpp> +#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp> +#include <com/sun/star/frame/XComponentLoader.hpp> +#include <com/sun/star/frame/XStorable.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/frame/XDesktop.hpp> +#include <com/sun/star/document/XFilter.hpp> +#include <comphelper/oslfile2streamwrap.hxx> +#include <com/sun/star/document/XExporter.hpp> +#include <com/sun/star/task/XInteractionHandler.hpp> + +#include "com/sun/star/ui/dialogs/TemplateDescription.hpp" +#include <vcl/svapp.hxx> +#include <vos/mutex.hxx> +#include <sfx2/filedlghelper.hxx> +#include <osl/file.hxx> +#include <unotools/tempfile.hxx> +#include <tools/urlobj.hxx> + +#include "xmlfilterdialogstrings.hrc" +#include "xmlfiltersettingsdialog.hxx" +#include "xmlfiltertestdialog.hxx" +#include "xmlfiltertestdialog.hrc" +#include "xmlfileview.hxx" + + +using namespace rtl; +using namespace utl; +using namespace osl; +using namespace vos; +using namespace comphelper; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::container; +using namespace com::sun::star::document; +using namespace com::sun::star::frame; +using namespace com::sun::star::task; +using namespace com::sun::star::uno; +using namespace com::sun::star::io; +using namespace com::sun::star::xml; +using namespace com::sun::star::xml::sax; + +class GlobalEventListenerImpl : public ::cppu::WeakImplHelper1< com::sun::star::document::XEventListener > +{ +public: + GlobalEventListenerImpl( XMLFilterTestDialog* pDialog ); + + // XEventListener + virtual void SAL_CALL notifyEvent( const com::sun::star::document::EventObject& Event ) throw (RuntimeException); + + // lang::XEventListener + virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& Source ) throw (RuntimeException); +private: + XMLFilterTestDialog* mpDialog; +}; + +GlobalEventListenerImpl::GlobalEventListenerImpl( XMLFilterTestDialog* pDialog ) +: mpDialog( pDialog ) +{ +} + +void SAL_CALL GlobalEventListenerImpl::notifyEvent( const com::sun::star::document::EventObject& Event ) throw (RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + if( (Event.EventName.compareToAscii( RTL_CONSTASCII_STRINGPARAM("OnFocus") ) == 0) || + (Event.EventName.compareToAscii( RTL_CONSTASCII_STRINGPARAM("OnUnload") ) == 0) ) + { + Reference< XComponent > xComp( Event.Source, UNO_QUERY ); + mpDialog->updateCurrentDocumentButtonState( &xComp ); + } +} + +void SAL_CALL GlobalEventListenerImpl::disposing( const com::sun::star::lang::EventObject& /* Source */ ) throw (RuntimeException) +{ +} + +/** returns true if the given component supports the given service */ +static bool checkComponent( Reference< XComponent >& rxComponent, const OUString& rServiceName ) +{ + try + { + Reference< XServiceInfo > xInfo( rxComponent, UNO_QUERY ); + if( xInfo.is() ) + { + if( xInfo->supportsService( rServiceName ) ) + { + // special case for impress documents which supports same service as draw documents + if( rServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.drawing.DrawingDocument" ) ) ) + { + // so if we want a draw we need to check if its not an impress + if( !xInfo->supportsService( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.PresentationDocument") ) ) ) + return true; + } + else + { + return true; + } + } + } + } + catch( Exception& ) + { + DBG_ERROR( "checkComponent exception catched!" ); + } + + return false; +} + +XMLFilterTestDialog::XMLFilterTestDialog( Window* pParent, ResMgr& rResMgr, const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rxMSF ) : + ModalDialog( pParent, ResId( DLG_XML_FILTER_TEST_DIALOG, rResMgr ) ), + mxMSF( rxMSF ), + mrResMgr( rResMgr ), + + maFLExport( this, ResId( FL_EXPORT, rResMgr ) ), + maFTExportXSLT( this, ResId( FT_EXPORT_XSLT, rResMgr ) ), + maFTExportXSLTFile( this, ResId( FT_EXPORT_XSLT_FILE, rResMgr ) ), + maFTTransformDocument( this, ResId( FT_TRANSFORM_DOCUMENT, rResMgr ) ), + maPBExportBrowse( this, ResId( PB_EXPORT_BROWSE, rResMgr ) ), + maPBCurrentDocument( this, ResId( PB_CURRENT_DOCUMENT, rResMgr ) ), + maFTNameOfCurentFile( this, ResId( FT_NAME_OF_CURRENT_FILE, rResMgr ) ), + maFLImport( this, ResId( FL_IMPORT, rResMgr ) ), + maFTImportXSLT( this, ResId( FT_IMPORT_XSLT, rResMgr ) ), + maFTImportXSLTFile( this, ResId( FT_IMPORT_XSLT_FILE, rResMgr ) ), + maFTImportTemplate( this, ResId( FT_IMPORT_TEMPLATE, rResMgr ) ), + maFTImportTemplateFile( this, ResId( FT_IMPORT_TEMPLATE_FILE, rResMgr ) ), + maFTTransformFile( this, ResId( FT_TRANSFORM_FILE, rResMgr ) ), + maCBXDisplaySource( this, ResId( CBX_DISPLAY_SOURCE, rResMgr ) ), + maPBImportBrowse( this, ResId( PB_IMPORT_BROWSE, rResMgr ) ), + maPBRecentDocument( this, ResId( PB_RECENT_DOCUMENT, rResMgr ) ), + maFTNameOfRecentFile( this, ResId( FT_NAME_OF_RECENT_FILE, rResMgr ) ), + maPBClose( this, ResId( PB_CLOSE, rResMgr ) ), + maPBHelp( this, ResId( PB_HELP, rResMgr ) ), + mpSourceDLG( NULL ), + mpFilterInfo( NULL ), + sDTDPath( RTL_CONSTASCII_USTRINGPARAM( "$(inst)/share/dtd/officedocument/1_0/office.dtd" ) ) +{ + FreeResource(); + + maPBExportBrowse.SetClickHdl(LINK( this, XMLFilterTestDialog, ClickHdl_Impl ) ); + maPBCurrentDocument.SetClickHdl(LINK( this, XMLFilterTestDialog, ClickHdl_Impl ) ); + maPBImportBrowse.SetClickHdl(LINK( this, XMLFilterTestDialog, ClickHdl_Impl ) ); + maPBRecentDocument.SetClickHdl(LINK( this, XMLFilterTestDialog, ClickHdl_Impl ) ); + maPBClose.SetClickHdl(LINK( this, XMLFilterTestDialog, ClickHdl_Impl ) ); + + maDialogTitle = GetText(); + + try + { + Reference< XConfigManager > xCfgMgr( mxMSF->createInstance( OUString::createFromAscii("com.sun.star.config.SpecialConfigManager")), UNO_QUERY ); + if( xCfgMgr.is() ) + sDTDPath = xCfgMgr->substituteVariables( sDTDPath ); + + mxGlobalBroadcaster = Reference < XEventBroadcaster >::query( mxMSF->createInstance(::rtl::OUString::createFromAscii("com.sun.star.frame.GlobalEventBroadcaster") ) ); + if ( mxGlobalBroadcaster.is() ) + { + mxGlobalEventListener = new GlobalEventListenerImpl( this ); + mxGlobalBroadcaster->addEventListener( mxGlobalEventListener ); + } + } + catch( Exception& ) + { + DBG_ERROR( "XMLFilterTestDialog::XMLFilterTestDialog exception catched!" ); + } +} + +XMLFilterTestDialog::~XMLFilterTestDialog() +{ + try + { + if( mxGlobalBroadcaster.is() ) + mxGlobalBroadcaster->removeEventListener( mxGlobalEventListener ); + } + catch( Exception& ) + { + DBG_ERROR( "XMLFilterTestDialog::~XMLFilterTestDialog exception catched!" ); + } + + delete mpSourceDLG; + delete mpFilterInfo; +} + +void XMLFilterTestDialog::test( const filter_info_impl& rFilterInfo ) +{ + delete mpFilterInfo; + mpFilterInfo = new filter_info_impl( rFilterInfo ); + + maImportRecentFile = OUString(); + + initDialog(); + + Execute(); +} + +static OUString getFileNameFromURL( OUString& rURL ) +{ + INetURLObject aURL( rURL ); + OUString aName( aURL.getName(INetURLObject::LAST_SEGMENT, sal_True, INetURLObject::DECODE_WITH_CHARSET) ); + return aName; +} + +void XMLFilterTestDialog::updateCurrentDocumentButtonState( Reference< XComponent > * pRef /* = NULL */ ) +{ + if( pRef && pRef->is() ) + { + if( checkComponent( *pRef, mpFilterInfo->maDocumentService ) ) + mxLastFocusModel = *pRef; + } + + bool bExport = (mpFilterInfo->maFlags & 2) == 2; + Reference< XComponent > xCurrentDocument; + if( bExport ) + xCurrentDocument = getFrontMostDocument( mpFilterInfo->maDocumentService ); + maPBCurrentDocument.Enable( bExport && xCurrentDocument.is() ); + maFTNameOfCurentFile.Enable( bExport && xCurrentDocument.is() ); + + if( xCurrentDocument.is() ) + { + OUString aTitle; + Reference< XDocumentPropertiesSupplier > xDPS( xCurrentDocument, UNO_QUERY ); + if( xDPS.is() ) + { + Reference< XDocumentProperties > xProps( xDPS->getDocumentProperties() ); + if( xProps.is() ) + { + aTitle = xProps->getTitle(); + } + } + + if( 0 == aTitle.getLength() ) + { + Reference< XStorable > xStorable( xCurrentDocument, UNO_QUERY ); + if( xStorable.is() ) + { + if( xStorable->hasLocation() ) + { + OUString aURL( xStorable->getLocation() ); + aTitle = getFileNameFromURL( aURL ); + } + } + } + + maFTNameOfCurentFile.SetText( aTitle ); + } +} + +void XMLFilterTestDialog::initDialog() +{ + DBG_ASSERT( mpFilterInfo, "i need a filter I can test!" ); + if( NULL == mpFilterInfo ) + return; + + String aTitle( maDialogTitle ); + aTitle.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM("%s") ), mpFilterInfo->maFilterName ); + SetText( aTitle ); + + String aEmpty; + bool bImport = (mpFilterInfo->maFlags & 1) == 1; + bool bExport = (mpFilterInfo->maFlags & 2) == 2; + + updateCurrentDocumentButtonState(); + + maFLExport.Enable( bExport ); + maFTExportXSLT.Enable( bExport ); + maFTExportXSLTFile.Enable( bExport ); + maFTTransformDocument.Enable( bExport ); + maPBExportBrowse.Enable( bExport ); + + maFTExportXSLTFile.SetText( getFileNameFromURL( mpFilterInfo->maExportXSLT ) ); + + // --- + + maFLImport.Enable( bImport ); + maFTImportXSLT.Enable( bImport ); + maFTImportXSLTFile.Enable( bImport ); + maFTImportTemplate.Enable( bImport && mpFilterInfo->maImportTemplate.getLength() ); + maFTImportTemplateFile.Enable( bImport && mpFilterInfo->maImportTemplate.getLength() ); + maFTTransformFile.Enable( bImport ); + maCBXDisplaySource.Enable( bImport ); + maPBImportBrowse.Enable( bImport ); + maPBRecentDocument.Enable( bImport && maImportRecentFile.getLength() ); + maFTNameOfRecentFile.Enable( bImport && maImportRecentFile.getLength() ); + + maFTImportXSLTFile.SetText( getFileNameFromURL( mpFilterInfo->maImportXSLT ) ); + maFTImportTemplateFile.SetText( getFileNameFromURL( mpFilterInfo->maImportTemplate ) ); + maFTNameOfRecentFile.SetText( getFileNameFromURL( maImportRecentFile ) ); +} + +void XMLFilterTestDialog::onExportBrowse() +{ + try + { + // Open Fileopen-Dialog + ::sfx2::FileDialogHelper aDlg( + com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, + 0 ); + + Reference< XNameAccess > xFilterContainer( mxMSF->createInstance( OUString::createFromAscii("com.sun.star.document.FilterFactory" ) ), UNO_QUERY ); + Reference< XNameAccess > xTypeDetection( mxMSF->createInstance( OUString::createFromAscii("com.sun.star.document.TypeDetection" ) ), UNO_QUERY ); + if( xFilterContainer.is() && xTypeDetection.is() ) + { + Sequence< OUString > aFilterNames( xFilterContainer->getElementNames() ); + OUString* pFilterName = aFilterNames.getArray(); + + for( sal_Int32 nFilter = 0; nFilter < aFilterNames.getLength(); nFilter++, pFilterName++ ) + { + Sequence< PropertyValue > aValues; + + Any aAny( xFilterContainer->getByName( *pFilterName ) ); + if( !(aAny >>= aValues) ) + continue; + + OUString aInterfaceName; + PropertyValue* pValues = aValues.getArray(); + OUString aType, aService; + sal_Int32 nFlags( 0 ); + + int nFound = 0; + + for( sal_Int32 nValue = 0; (nValue < aValues.getLength()) && (nFound != 15); nValue++, pValues++ ) + { + if( pValues->Name.equalsAscii( "Type" ) ) + { + pValues->Value >>= aType; + nFound |= 1; + } + else if( pValues->Name.equalsAscii( "DocumentService" ) ) + { + pValues->Value >>= aService; + nFound |= 2; + } + else if( pValues->Name.equalsAscii( "Flags" ) ) + { + pValues->Value >>= nFlags; + nFound |= 4; + } + if( pValues->Name.equalsAscii( "UIName" ) ) + { + pValues->Value >>= aInterfaceName; + nFound |= 8; + } + + } + + if( (nFound == 15) && (aType.getLength() && aService == mpFilterInfo->maDocumentService) ) + { + // see if this filter is not supressed in dialog + if( (nFlags & 0x1000) == 0 ) + { + aAny = xTypeDetection->getByName( aType ); + Sequence< PropertyValue > aValues2; + + if( aAny >>= aValues2 ) + { + PropertyValue* pValues2 = aValues2.getArray(); + sal_Int32 nValue; + + OUString aExtension; + for( nValue = 0; nValue < aValues2.getLength(); nValue++, pValues2++ ) + { + if( pValues2->Name.equalsAscii( "Extensions" ) ) + { + Sequence< OUString > aExtensions; + if( pValues2->Value >>= aExtensions ) + { + const sal_Int32 nCount( aExtensions.getLength() ); + OUString* pExtensions = aExtensions.getArray(); + sal_Int32 n; + for( n = 0; n < nCount; n++ ) + { + if( n > 0 ) + aExtension += OUString( sal_Unicode(';') ); + aExtension += OUString::createFromAscii("*."); + aExtension += (*pExtensions++); + } + } + } + } + + String aExtensions( aExtension ); + String aFilterName( aInterfaceName ); + aFilterName += String( RTL_CONSTASCII_USTRINGPARAM(" (") ); + aFilterName += aExtensions; + aFilterName += sal_Unicode(')'); + + aDlg.AddFilter( aFilterName, aExtensions ); + + if( (nFlags & 0x100) == 0x100 ) + aDlg.SetCurrentFilter( aFilterName ); + } + } + } + + } + } + + aDlg.SetDisplayDirectory( maExportRecentFile ); + + if ( aDlg.Execute() == ERRCODE_NONE ) + { + maExportRecentFile = aDlg.GetPath(); + + Reference< XComponentLoader > xLoader( mxMSF->createInstance( OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ), UNO_QUERY ); + Reference< XInteractionHandler > xInter( mxMSF->createInstance( OUString::createFromAscii( "com.sun.star.task.InteractionHandler" ) ), UNO_QUERY ); + if( xLoader.is() && xInter.is() ) + { + OUString aFrame( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ); + Sequence< PropertyValue > aArguments(1); + aArguments[0].Name = OUString::createFromAscii( "InteractionHandler" ); + aArguments[0].Value <<= xInter; + Reference< XComponent > xComp( xLoader->loadComponentFromURL( maExportRecentFile, aFrame, 0, aArguments ) ); + if( xComp.is() ) + { + doExport( xComp ); + } + } + } + } + catch(Exception&) + { + DBG_ERROR("XMLFilterTestDialog::onExportBrowse exception caught!"); + } + + initDialog(); +} + +void XMLFilterTestDialog::onExportCurrentDocument() +{ + doExport( getFrontMostDocument( mpFilterInfo->maDocumentService ) ); +} + +void XMLFilterTestDialog::doExport( Reference< XComponent > xComp ) +{ + try + { + Reference< XStorable > xStorable( xComp, UNO_QUERY ); + if( xStorable.is() ) + { + utl::TempFile aTempFile; + OUString aTempFileURL( aTempFile.GetURL() ); + + const application_info_impl* pAppInfo = getApplicationInfo( mpFilterInfo->maExportService ); + if( pAppInfo ) + { + File aOutputFile( aTempFileURL ); + /* File::RC rc = */ aOutputFile.open( OpenFlag_Write ); + + // create xslt exporter + Reference< XOutputStream > xIS( new comphelper::OSLOutputStreamWrapper( aOutputFile ) ); + + int bUseDTD = (mpFilterInfo->maDTD.getLength() != 0) ? 1 : 0 ; + int bUseDocType = (mpFilterInfo->maDocType.getLength() != 0 ) ? 1 : 0; + Sequence< PropertyValue > aSourceData( 2 + bUseDTD + bUseDocType ); + int i = 0; + + aSourceData[i ].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "OutputStream" ) ); + aSourceData[i++].Value <<= xIS; + + aSourceData[i].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "Indent" ) ); + aSourceData[i++].Value <<= (sal_Bool)sal_True; + + if( bUseDTD ) + { + aSourceData[i ].Name = OUString(RTL_CONSTASCII_USTRINGPARAM("DocType_System")); + aSourceData[i++].Value <<= mpFilterInfo->maDTD; + } + + if( bUseDocType ) + { + aSourceData[i ].Name = OUString(RTL_CONSTASCII_USTRINGPARAM("DocType_Public")); + aSourceData[i++].Value <<= mpFilterInfo->maDocType; + } + + Reference< XExportFilter > xExporter( mxMSF->createInstance( OUString::createFromAscii( "com.sun.star.documentconversion.XSLTFilter" ) ), UNO_QUERY ); + Reference< XDocumentHandler > xHandler( xExporter, UNO_QUERY ); + if( xHandler.is() ) + { + Sequence< OUString > aFilterUserData( mpFilterInfo->getFilterUserData() ); + xExporter->exporter( aSourceData, aFilterUserData ); + + Reference< XMultiServiceFactory > xDocFac( xComp, UNO_QUERY ); + + Reference< XEmbeddedObjectResolver > xObjectResolver; + Reference< XGraphicObjectResolver > xGrfResolver; + + if( xDocFac.is() ) + { + try + { + xGrfResolver = Reference< XGraphicObjectResolver >::query( xDocFac->createInstance( OUString::createFromAscii("com.sun.star.document.ExportGraphicObjectResolver") ) ); + xObjectResolver = Reference< XEmbeddedObjectResolver >::query( xDocFac->createInstance( OUString::createFromAscii("com.sun.star.document.ExportEmbeddedObjectResolver") ) ); + } + catch( Exception& ) + { + } + } + + Sequence< Any > aArgs( 1 + ( xGrfResolver.is() ? 1 : 0 ) + ( xObjectResolver.is() ? 1 : 0 ) ); + Any* pArgs = aArgs.getArray(); + if( xGrfResolver.is() ) *pArgs++ <<= xGrfResolver; + if( xObjectResolver.is() ) *pArgs++ <<= xObjectResolver; + + // *pArgs++ <<= xInfoSet; + *pArgs <<= xHandler; + + Reference< XFilter > xFilter( mxMSF->createInstanceWithArguments( pAppInfo->maXMLExporter, aArgs ), UNO_QUERY ); + if( xFilter.is() ) + { + Reference< XExporter > xExporter2( xFilter, UNO_QUERY ); + if( xExporter2.is() ) + { + xExporter2->setSourceDocument( xComp ); + + Sequence< PropertyValue > aDescriptor( 1 ); + aDescriptor[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "FileName" ) ); + aDescriptor[0].Value <<= aTempFileURL; + + if( xFilter->filter( aDescriptor ) ) + displayXMLFile( aTempFileURL ); + } + } + } + } + } + } + catch( Exception& ) + { + DBG_ERROR( "XMLFilterTestDialog::doExport exception catched!" ); + } +} + +void XMLFilterTestDialog::displayXMLFile( const OUString& rURL ) +{ + if( NULL == mpSourceDLG ) + mpSourceDLG = new XMLSourceFileDialog( NULL, mrResMgr, mxMSF ); + + mpSourceDLG->ShowWindow( rURL, mpFilterInfo); +} + +void XMLFilterTestDialog::onImportBrowse() +{ + // Open Fileopen-Dialog + ::sfx2::FileDialogHelper aDlg( + com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 ); + String aFilterName( mpFilterInfo->maInterfaceName ); + String aExtensions; + + int nLastIndex = 0; + int nCurrentIndex = 0; + for( int i = 0; nLastIndex != -1; i++ ) + { + nLastIndex = mpFilterInfo->maExtension.indexOf( sal_Unicode( ';' ), nLastIndex ); + + if( i > 0 ) + aExtensions += ';'; + + aExtensions += String( RTL_CONSTASCII_STRINGPARAM("*.") ); + + if( nLastIndex == -1 ) + { + + aExtensions += String( mpFilterInfo->maExtension.copy( nCurrentIndex ) ); + } + else + { + aExtensions += String( mpFilterInfo->maExtension.copy( nCurrentIndex, nLastIndex - nCurrentIndex ) ); + nCurrentIndex = nLastIndex + 1; + nLastIndex = nCurrentIndex; + } + } + + aFilterName += String( RTL_CONSTASCII_USTRINGPARAM( " (" ) ); + aFilterName += aExtensions; + aFilterName += sal_Unicode(')'); + + aDlg.AddFilter( aFilterName, aExtensions ); + aDlg.SetDisplayDirectory( maImportRecentFile ); + + if ( aDlg.Execute() == ERRCODE_NONE ) + { + maImportRecentFile = aDlg.GetPath(); + import( maImportRecentFile ); + } + + initDialog(); +} + +void XMLFilterTestDialog::onImportRecentDocument() +{ + import( maImportRecentFile ); +} + +void XMLFilterTestDialog::import( const OUString& rURL ) +{ + try + { + Reference< XComponentLoader > xLoader( mxMSF->createInstance( OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ), UNO_QUERY ); + Reference< XInteractionHandler > xInter( mxMSF->createInstance( OUString::createFromAscii( "com.sun.star.task.InteractionHandler" ) ), UNO_QUERY ); + if( xLoader.is() && xInter.is() ) + { + + OUString aFrame( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ); + Sequence< PropertyValue > aArguments(2); + aArguments[0].Name = OUString::createFromAscii( "FilterName" ); + aArguments[0].Value <<= mpFilterInfo->maFilterName; + aArguments[1].Name = OUString::createFromAscii( "InteractionHandler" ); + aArguments[1].Value <<= xInter; + + xLoader->loadComponentFromURL( rURL, aFrame, 0, aArguments ); + } + + if( maCBXDisplaySource.IsChecked() ) + { + TempFile aTempFile; + OUString aTempFileURL( aTempFile.GetURL() ); + + Reference< XImportFilter > xImporter( mxMSF->createInstance( OUString::createFromAscii( "com.sun.star.documentconversion.XSLTFilter" ) ), UNO_QUERY ); + if( xImporter.is() ) + { + osl::File aInputFile( rURL ); + osl::File::RC rc = aInputFile.open( OpenFlag_Read ); + + Reference< XInputStream > xIS( new comphelper::OSLInputStreamWrapper( aInputFile ) ); + + Sequence< PropertyValue > aSourceData( 5 ); + int i = 0; + + aSourceData[i ].Name = OUString::createFromAscii( "InputStream" ); + aSourceData[i++].Value <<= xIS; + + aSourceData[i ].Name = OUString::createFromAscii( "FileName" ); + aSourceData[i++].Value <<= rURL; + + aSourceData[i ].Name = OUString::createFromAscii( "Indent" ); + aSourceData[i++].Value <<= (sal_Bool)sal_True; + + aSourceData[i ].Name = OUString::createFromAscii("DocType_Public"); + aSourceData[i++].Value <<= OUString::createFromAscii("-//OpenOffice.org//DTD OfficeDocument 1.0//EN"); + + aSourceData[i ].Name = OUString::createFromAscii("DocType_System"); + aSourceData[i++].Value <<= sDTDPath; + + Reference< XDocumentHandler > xWriter( mxMSF->createInstance( OUString::createFromAscii( "com.sun.star.xml.sax.Writer" ) ), UNO_QUERY ); + + File aOutputFile( aTempFileURL ); + rc = aOutputFile.open( OpenFlag_Write ); + + Reference< XOutputStream > xOS( new OSLOutputStreamWrapper( aOutputFile ) ); + Reference< XActiveDataSource > xDocSrc( xWriter, UNO_QUERY ); + xDocSrc->setOutputStream( xOS ); + + Sequence< OUString > aFilterUserData( mpFilterInfo->getFilterUserData() ); + xImporter->importer( aSourceData, xWriter, aFilterUserData ); + } + + displayXMLFile( aTempFileURL ); + } + } + catch(Exception&) + { + DBG_ERROR("XMLFilterTestDialog::import catched an exception" ); + } +} + +IMPL_LINK(XMLFilterTestDialog, ClickHdl_Impl, PushButton *, pButton ) +{ + if( &maPBExportBrowse == pButton ) + { + onExportBrowse(); + } + else if( &maPBCurrentDocument == pButton ) + { + onExportCurrentDocument(); + } + else if( &maPBImportBrowse == pButton ) + { + onImportBrowse(); + } + else if( &maPBRecentDocument == pButton ) + { + onImportRecentDocument(); + } + else if( &maPBClose == pButton ) + { + Close(); + } + + return 0; +} + +/** returns the front most open component that supports the given service */ +Reference< XComponent > XMLFilterTestDialog::getFrontMostDocument( const OUString& rServiceName ) +{ + Reference< XComponent > xRet; + + try + { + Reference< XDesktop > xDesktop( mxMSF->createInstance( OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ), UNO_QUERY ); + if( xDesktop.is() ) + { + Reference< XComponent > xTest( mxLastFocusModel ); + if( checkComponent( xTest, rServiceName ) ) + { + xRet = xTest; + } + else + { + xTest = (Reference< XComponent >)xDesktop->getCurrentComponent(); + + if( checkComponent( xTest, rServiceName ) ) + { + xRet = xTest; + } + else + { + Reference< XEnumerationAccess > xAccess( xDesktop->getComponents() ); + if( xAccess.is() ) + { + Reference< XEnumeration > xEnum( xAccess->createEnumeration() ); + if( xEnum.is() ) + { + while( xEnum->hasMoreElements() ) + { + if( (xEnum->nextElement() >>= xTest) && xTest.is() ) + { + if( checkComponent( xTest, rServiceName ) ) + { + xRet = xTest; + break; + } + } + } + } + } + } + } + } + } + catch( Exception& ) + { + DBG_ERROR( "XMLFilterTestDialog::getFrontMostDocument exception catched!" ); + } + + return xRet; +} diff --git a/filter/source/xsltdialog/xmlfiltertestdialog.hrc b/filter/source/xsltdialog/xmlfiltertestdialog.hrc new file mode 100644 index 000000000000..49a2faeb5479 --- /dev/null +++ b/filter/source/xsltdialog/xmlfiltertestdialog.hrc @@ -0,0 +1,53 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLFILTERTESTDIALOG_HRC_ +#define _XMLFILTERTESTDIALOG_HRC_ + +#include "xmlfiltercommon.hrc" + +#define FL_EXPORT 1 +#define FT_EXPORT_XSLT 2 +#define FT_EXPORT_XSLT_FILE 3 +#define FT_TRANSFORM_DOCUMENT 4 +#define PB_EXPORT_BROWSE 5 +#define PB_CURRENT_DOCUMENT 6 +#define FT_NAME_OF_CURRENT_FILE 7 +#define FL_IMPORT 8 +#define FT_IMPORT_XSLT 9 +#define FT_IMPORT_XSLT_FILE 10 +#define FT_IMPORT_TEMPLATE 11 +#define FT_IMPORT_TEMPLATE_FILE 12 +#define FT_TRANSFORM_FILE 13 +#define CBX_DISPLAY_SOURCE 14 +#define PB_IMPORT_BROWSE 15 +#define PB_RECENT_DOCUMENT 16 +#define FT_NAME_OF_RECENT_FILE 17 +#define PB_HELP 18 +#define PB_CLOSE 19 + +#endif diff --git a/filter/source/xsltdialog/xmlfiltertestdialog.hxx b/filter/source/xsltdialog/xmlfiltertestdialog.hxx new file mode 100644 index 000000000000..a287447937f2 --- /dev/null +++ b/filter/source/xsltdialog/xmlfiltertestdialog.hxx @@ -0,0 +1,107 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _XMLFILTERTESTDIALOG_HXX_ +#define _XMLFILTERTESTDIALOG_HXX_ + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/document/XEventBroadcaster.hpp> +#include <vcl/dialog.hxx> + +#ifndef _SV_BUTTON_HXX +#include <vcl/button.hxx> +#endif +#include <vcl/fixed.hxx> +#include <svl/poolitem.hxx> + +class filter_info_impl; +class XMLSourceFileDialog; + +class XMLFilterTestDialog : public ModalDialog +{ +public: + XMLFilterTestDialog( Window* pParent, ResMgr& rResMgr, const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rxMSF ); + virtual ~XMLFilterTestDialog(); + + void test( const filter_info_impl& rFilterInfo ); + + void updateCurrentDocumentButtonState( com::sun::star::uno::Reference< com::sun::star::lang::XComponent > * pRef = NULL ); + +private: + DECL_LINK(ClickHdl_Impl, PushButton * ); + + void onExportBrowse(); + void onExportCurrentDocument(); + void onImportBrowse(); + void onImportRecentDocument(); + void initDialog(); + + com::sun::star::uno::Reference< com::sun::star::lang::XComponent > getFrontMostDocument( const rtl::OUString& rServiceName ); + void import( const rtl::OUString& rURL ); + void displayXMLFile( const rtl::OUString& rURL ); + void doExport( com::sun::star::uno::Reference< com::sun::star::lang::XComponent > xComp ); + +private: + com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > mxMSF; + com::sun::star::uno::Reference< com::sun::star::document::XEventBroadcaster > mxGlobalBroadcaster; + com::sun::star::uno::Reference< com::sun::star::document::XEventListener > mxGlobalEventListener; + com::sun::star::uno::WeakReference< com::sun::star::lang::XComponent > mxLastFocusModel; + + ResMgr& mrResMgr; + + rtl::OUString maImportRecentFile; + rtl::OUString maExportRecentFile; + + FixedLine maFLExport; + FixedText maFTExportXSLT; + FixedText maFTExportXSLTFile; + FixedText maFTTransformDocument; + PushButton maPBExportBrowse; + PushButton maPBCurrentDocument; + FixedText maFTNameOfCurentFile; + FixedLine maFLImport; + FixedText maFTImportXSLT; + FixedText maFTImportXSLTFile; + FixedText maFTImportTemplate; + FixedText maFTImportTemplateFile; + FixedText maFTTransformFile; + CheckBox maCBXDisplaySource; + PushButton maPBImportBrowse; + PushButton maPBRecentDocument; + FixedText maFTNameOfRecentFile; + PushButton maPBClose; + HelpButton maPBHelp; + + XMLSourceFileDialog* mpSourceDLG; + filter_info_impl* mpFilterInfo; + + String maDialogTitle; + + ::rtl::OUString sDTDPath; +}; + +#endif diff --git a/filter/source/xsltdialog/xmlfiltertestdialog.src b/filter/source/xsltdialog/xmlfiltertestdialog.src new file mode 100644 index 000000000000..94127275c9bb --- /dev/null +++ b/filter/source/xsltdialog/xmlfiltertestdialog.src @@ -0,0 +1,210 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "xmlfiltertestdialog.hrc" +#include "xmlfilterhelpids.hrc" + +#define DIALOG_WIDTH 200 +#define DIALOG_HEIGHT 230 + +#define SPACING 3 + +#define FIRST_ROW_X 6 +#define FIRST_ROW_Y 6 +#define COLUMN_WIDTH ((DIALOG_WIDTH-(5*SPACING))/2) + +#define SECOND_ROW_X FIRST_ROW_X + COLUMN_WIDTH+SPACING + +#define FIXED_TEXT_OFFSET 3 + +#define ROW_HEIGHT 14 + +ModalDialog DLG_XML_FILTER_TEST_DIALOG +{ + HelpId = HID_XML_FILTER_TEST_DIALOG; + Size = MAP_APPFONT( DIALOG_WIDTH, DIALOG_HEIGHT ); + OutputSize = TRUE ; + SVLook = TRUE ; + Moveable = TRUE ; + Closeable = TRUE ; + Text [ en-US ] = "Test XML Filter: %s" ; + + FixedLine FL_EXPORT + { + Pos = MAP_APPFONT( 4, FIRST_ROW_Y + 0 * ROW_HEIGHT + 0 * SPACING + FIXED_TEXT_OFFSET); + Size = MAP_APPFONT( DIALOG_WIDTH - 2*SPACING, 8 ); + Text [ en-US ] = "Export"; + }; + + FixedText FT_EXPORT_XSLT + { + Pos = MAP_APPFONT ( FIRST_ROW_X , FIRST_ROW_Y + 1 * ROW_HEIGHT + 1 * SPACING + FIXED_TEXT_OFFSET ) ; + Size = MAP_APPFONT ( COLUMN_WIDTH , 8 ) ; + Text [ en-US ] = "XSLT for export"; + }; + + FixedText FT_EXPORT_XSLT_FILE + { + Pos = MAP_APPFONT ( SECOND_ROW_X , FIRST_ROW_Y + 1 * ROW_HEIGHT + 1 * SPACING + FIXED_TEXT_OFFSET ) ; + Size = MAP_APPFONT ( 2*COLUMN_WIDTH , 8 ) ; + HelpId = HID_XML_FILTER_TEST_EXPORT_XSLT_FILE; + }; + + FixedText FT_TRANSFORM_DOCUMENT + { + Pos = MAP_APPFONT ( FIRST_ROW_X , FIRST_ROW_Y + 2 * ROW_HEIGHT + 2 * SPACING + FIXED_TEXT_OFFSET ) ; + Size = MAP_APPFONT ( COLUMN_WIDTH , 8 ) ; + Text [ en-US ] = "Transform document"; + }; + + PushButton PB_EXPORT_BROWSE + { + Pos = MAP_APPFONT ( SECOND_ROW_X , FIRST_ROW_Y + 2 * ROW_HEIGHT + 2 * SPACING ) ; + Size = MAP_APPFONT ( COLUMN_WIDTH , 14 ) ; + TabStop = TRUE ; + HelpId = HID_XML_FILTER_TEST_EXPORT_BROWSE; + Text [ en-US ] = "~Browse..."; + }; + + PushButton PB_CURRENT_DOCUMENT + { + Pos = MAP_APPFONT ( SECOND_ROW_X , FIRST_ROW_Y + 3 * ROW_HEIGHT + 3 * SPACING ) ; + Size = MAP_APPFONT ( COLUMN_WIDTH , 14 ) ; + HelpId = HID_XML_FILTER_TEST_EXPORT_CURRENT; + TabStop = TRUE ; + Text [ en-US ] = "~Current Document"; + }; + + FixedText FT_NAME_OF_CURRENT_FILE + { + Pos = MAP_APPFONT ( FIRST_ROW_X , FIRST_ROW_Y + 4 * ROW_HEIGHT + 4 * SPACING + FIXED_TEXT_OFFSET ) ; + Size = MAP_APPFONT ( 2*COLUMN_WIDTH , 8 ) ; + HelpId = HID_XML_FILTER_TEST_EXPORT_CURRENT_FILE; + Right = TRUE; + }; + + // import --------------------------------------------------------- + + FixedLine FL_IMPORT + { + Pos = MAP_APPFONT( 4, FIRST_ROW_Y + 5 * ROW_HEIGHT + 5 * SPACING + FIXED_TEXT_OFFSET ); + Size = MAP_APPFONT( DIALOG_WIDTH - 2*SPACING, 8 ); + Text [ en-US ] = "Import"; + }; + + FixedText FT_IMPORT_XSLT + { + Pos = MAP_APPFONT ( FIRST_ROW_X , FIRST_ROW_Y + 6 * ROW_HEIGHT + 6 * SPACING + FIXED_TEXT_OFFSET ) ; + Size = MAP_APPFONT ( COLUMN_WIDTH , 8 ) ; + Text [ en-US ] = "XSLT for import"; + }; + + FixedText FT_IMPORT_XSLT_FILE + { + Pos = MAP_APPFONT ( SECOND_ROW_X , FIRST_ROW_Y + 6 * ROW_HEIGHT + 6 * SPACING + FIXED_TEXT_OFFSET ) ; + Size = MAP_APPFONT ( 2*COLUMN_WIDTH , 8 ) ; + HelpId = HID_XML_FILTER_TEST_IMPORT_XSLT_FILE; + }; + + FixedText FT_IMPORT_TEMPLATE + { + Pos = MAP_APPFONT ( FIRST_ROW_X , FIRST_ROW_Y + 7 * ROW_HEIGHT + 7 * SPACING + FIXED_TEXT_OFFSET ) ; + Size = MAP_APPFONT ( COLUMN_WIDTH , 8 ) ; + Text [ en-US ] = "Template for import"; + }; + + FixedText FT_IMPORT_TEMPLATE_FILE + { + Pos = MAP_APPFONT ( SECOND_ROW_X , FIRST_ROW_Y + 7 * ROW_HEIGHT + 7 * SPACING + FIXED_TEXT_OFFSET ) ; + Size = MAP_APPFONT ( 2*COLUMN_WIDTH , 8 ) ; + HelpId = HID_XML_FILTER_TEST_IMPORT_TEMPLATE_FILE; + }; + + FixedText FT_TRANSFORM_FILE + { + Pos = MAP_APPFONT ( FIRST_ROW_X , FIRST_ROW_Y + 8 * ROW_HEIGHT + 8 * SPACING + FIXED_TEXT_OFFSET ) ; + Size = MAP_APPFONT ( COLUMN_WIDTH , 8 ) ; + Text [ en-US ] = "Transform file"; + }; + + CheckBox CBX_DISPLAY_SOURCE + { + Pos = MAP_APPFONT ( SECOND_ROW_X , FIRST_ROW_Y + 8 * ROW_HEIGHT + 8 * SPACING + 1 ) ; + Size = MAP_APPFONT ( COLUMN_WIDTH , 10 ) ; + HelpId = HID_XML_FILTER_TEST_IMPORT_DISPLAY_SOURCE; + Text [ en-US ] = "~Display source"; + }; + + PushButton PB_IMPORT_BROWSE + { + Pos = MAP_APPFONT ( SECOND_ROW_X , FIRST_ROW_Y + 9 * ROW_HEIGHT + 9 * SPACING ) ; + Size = MAP_APPFONT ( COLUMN_WIDTH , 14 ) ; + HelpId = HID_XML_FILTER_TEST_IMPORT_BROWSE; + TabStop = TRUE ; + Text [ en-US ] = "B~rowse..."; + }; + + PushButton PB_RECENT_DOCUMENT + { + Pos = MAP_APPFONT ( SECOND_ROW_X , FIRST_ROW_Y + 10 * ROW_HEIGHT + 10 * SPACING ) ; + Size = MAP_APPFONT ( COLUMN_WIDTH , 14 ) ; + HelpId = HID_XML_FILTER_TEST_IMPORT_RECENT; + TabStop = TRUE ; + Text [ en-US ] = "~Recent File"; + }; + + FixedText FT_NAME_OF_RECENT_FILE + { + Pos = MAP_APPFONT ( FIRST_ROW_X , FIRST_ROW_Y + 11 * ROW_HEIGHT + 11 * SPACING + FIXED_TEXT_OFFSET ) ; + Size = MAP_APPFONT ( 2*COLUMN_WIDTH, 8 ) ; + HelpId = HID_XML_FILTER_TEST_IMPORT_RECENT_FILE; + Right = TRUE; + }; + + PushButton PB_CLOSE + { + Pos = MAP_APPFONT ( DIALOG_WIDTH - 2*50 - 2*6 , DIALOG_HEIGHT - 6 - 14 ) ; + Size = MAP_APPFONT ( 50 , 14 ) ; + HelpId = HID_XML_FILTER_TEST_CLOSE; + TabStop = TRUE ; + Text [ en-US ] = "~Close"; + }; + + HelpButton PB_HELP + { + Pos = MAP_APPFONT ( DIALOG_WIDTH - 1*50 - 1*6 , DIALOG_HEIGHT - 6 - 14 ); + Size = MAP_APPFONT ( 50, 14 ); + }; +}; + + + + + + + + diff --git a/filter/source/xsltdialog/xsltdlg.component b/filter/source/xsltdialog/xsltdlg.component new file mode 100644 index 000000000000..086208f4f830 --- /dev/null +++ b/filter/source/xsltdialog/xsltdlg.component @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!--********************************************************************** +* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2000, 2010 Oracle and/or its affiliates. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* OpenOffice.org is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 3 +* only, as published by the Free Software Foundation. +* +* OpenOffice.org is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License version 3 for more details +* (a copy is included in the LICENSE file that accompanied this code). +* +* You should have received a copy of the GNU Lesser General Public License +* version 3 along with OpenOffice.org. If not, see +* <http://www.openoffice.org/license.html> +* for a copy of the LGPLv3 License. +* +**********************************************************************--> + +<component loader="com.sun.star.loader.SharedLibrary" + xmlns="http://openoffice.org/2010/uno-components"> + <implementation name="XMLFilterDialogComponent"> + <service name="com.sun.star.comp.ui.XSLTFilterDialog"/> + </implementation> +</component> |