1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 5 * This Source Code Form is subject to the terms of the Mozilla Public 6 * License, v. 2.0. If a copy of the MPL was not distributed with this 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 11 * Licensed to the Apache Software Foundation (ASF) under one or more 12 * contributor license agreements. See the NOTICE file distributed 13 * with this work for additional information regarding copyright 14 * ownership. The ASF licenses this file to you under the Apache 15 * License, Version 2.0 (the "License"); you may not use this file 16 * except in compliance with the License. You may obtain a copy of 17 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 18 */ 19 20 #ifndef INCLUDED_FILTER_SOURCE_XSLTDIALOG_TYPEDETECTIONIMPORT_HXX 21 #define INCLUDED_FILTER_SOURCE_XSLTDIALOG_TYPEDETECTIONIMPORT_HXX 22 23 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 24 #include <com/sun/star/io/XInputStream.hpp> 25 #include <cppuhelper/implbase.hxx> 26 #include <com/sun/star/xml/sax/XDocumentHandler.hpp> 27 28 #include "xmlfilterjar.hxx" 29 30 #include <map> 31 #include <memory> 32 #include <vector> 33 #include <stack> 34 35 namespace com { namespace sun { namespace star { 36 namespace xml { namespace sax { class XAttributeList; } } 37 namespace beans { struct PropertyValue; } 38 } } } 39 40 enum ImportState 41 { 42 e_Root, 43 e_Filters, 44 e_Types, 45 e_Filter, 46 e_Type, 47 e_Property, 48 e_Value, 49 e_Unknown 50 }; 51 52 typedef std::map<OUString, OUString> PropertyMap; 53 54 struct Node 55 { 56 OUString maName; 57 PropertyMap maPropertyMap; 58 }; 59 60 class TypeDetectionImporter : public cppu::WeakImplHelper < css::xml::sax::XDocumentHandler > 61 { 62 public: 63 TypeDetectionImporter(); 64 virtual ~TypeDetectionImporter() override; 65 66 static void doImport( const css::uno::Reference< css::uno::XComponentContext >& rxContext, const css::uno::Reference < css::io::XInputStream >& xOS, 67 std::vector< std::unique_ptr<filter_info_impl> >& rFilters ); 68 69 virtual void SAL_CALL startDocument( ) override; 70 virtual void SAL_CALL endDocument( ) override; 71 virtual void SAL_CALL startElement( const OUString& aName, const css::uno::Reference< css::xml::sax::XAttributeList >& xAttribs ) override; 72 virtual void SAL_CALL endElement( const OUString& aName ) override; 73 virtual void SAL_CALL characters( const OUString& aChars ) override; 74 virtual void SAL_CALL ignorableWhitespace( const OUString& aWhitespaces ) override; 75 virtual void SAL_CALL processingInstruction( const OUString& aTarget, const OUString& aData ) override; 76 virtual void SAL_CALL setDocumentLocator( const css::uno::Reference< css::xml::sax::XLocator >& xLocator ) override; 77 78 private: 79 void fillFilterVector( std::vector< std::unique_ptr<filter_info_impl> >& rFilters ); 80 std::unique_ptr<filter_info_impl> createFilterForNode( Node * pNode ); 81 Node* findTypeNode( const OUString& rType ); 82 83 std::stack< ImportState > maStack; 84 PropertyMap maPropertyMap; 85 86 std::vector< std::unique_ptr<Node> > maFilterNodes; 87 std::vector< std::unique_ptr<Node> > maTypeNodes; 88 89 OUString maValue; 90 OUString maNodeName; 91 OUString maPropertyName; 92 }; 93 #endif 94 95 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 96