1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #ifndef _SCRIPTING_STORAGE_SCRIPTMETADATAIMPORTER_HXX_ 28 #define _SCRIPTING_STORAGE_SCRIPTMETADATAIMPORTER_HXX_ 29 30 #include <vector> 31 32 #include <rtl/ustring.h> 33 #include <rtl/ustrbuf.hxx> 34 #include <osl/mutex.hxx> 35 #include <cppuhelper/implbase1.hxx> // helper for component factory 36 37 #include <com/sun/star/uno/XComponentContext.hpp> 38 #include <com/sun/star/lang/XServiceInfo.hpp> 39 #include <com/sun/star/lang/XInitialization.hpp> 40 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp> 41 #include <com/sun/star/io/XInputStream.hpp> 42 43 #include "ScriptData.hxx" 44 45 namespace scripting_impl 46 { 47 // for simplification 48 #define css ::com::sun::star 49 #define dcsssf ::drafts::com::sun::star::script::framework 50 51 typedef ::std::vector< ScriptData > InfoImpls_vec; 52 typedef ::std::pair< ::rtl::OUString, ::std::pair< ::rtl::OUString, 53 ::rtl::OUString > > strpair_pair; 54 55 /** 56 * Script Meta Data Importer 57 */ 58 class ScriptMetadataImporter : public 59 ::cppu::WeakImplHelper1< css::xml::sax::XExtendedDocumentHandler > 60 { 61 public: 62 63 /** 64 * This function will begin the parser and parse the meta data 65 * 66 * @param xInput The XInputStream for the parser which contains the XML 67 * @param parcelURI The parcel's URI in the document or the application 68 * 69 * @see css::io::XInputStream 70 */ 71 void parseMetaData( css::uno::Reference< css::io::XInputStream > 72 const & xInput, const ::rtl::OUString & parcelURI, 73 InfoImpls_vec & io_ScriptDatas ) 74 throw ( css::xml::sax::SAXException, css::io::IOException, 75 css::uno::RuntimeException ); 76 77 /** 78 * Constructor for the meta-data parser 79 * 80 * @param XComponentContext 81 */ 82 explicit ScriptMetadataImporter( 83 const css::uno::Reference< css::uno::XComponentContext >& ); 84 85 /** 86 * Destructor for the parser 87 */ 88 virtual ~ScriptMetadataImporter() SAL_THROW( () ); 89 90 // XExtendedDocumentHandler impl 91 /** 92 * Function to handle the start of CDATA in XML 93 * 94 * @see com::sun::star::xml::sax::XExtendedDocumentHandler 95 */ 96 virtual void SAL_CALL startCDATA() 97 throw ( css::xml::sax::SAXException, css::uno::RuntimeException ); 98 99 /** 100 * Function to handle the end of CDATA in XML 101 * 102 * @see com::sun::star::xml::sax::XExtendedDocumentHandler 103 */ 104 virtual void SAL_CALL endCDATA() throw ( css::uno::RuntimeException ); 105 106 /** 107 * Function to handle comments in XML 108 * 109 * @see com::sun::star::xml::sax::XExtendedDocumentHandler 110 */ 111 virtual void SAL_CALL comment( const ::rtl::OUString & sComment ) 112 throw ( css::xml::sax::SAXException, css::uno::RuntimeException ); 113 114 /** 115 * Function to handle line breaks in XML 116 * 117 * @see com::sun::star::xml::sax::XExtendedDocumentHandler 118 */ 119 virtual void SAL_CALL allowLineBreak() 120 throw ( css::xml::sax::SAXException, css::uno::RuntimeException ); 121 122 /** 123 * Function to handle unknowns in XML 124 * 125 * @see com::sun::star::xml::sax::XExtendedDocumentHandler 126 */ 127 virtual void SAL_CALL unknown( const ::rtl::OUString & sString ) 128 throw ( css::xml::sax::SAXException, css::uno::RuntimeException ); 129 130 /** 131 * Function to handle the start of XML document 132 * 133 * @see com::sun::star::xml::sax::XExtendedDocumentHandler 134 */ 135 // XDocumentHandler impl 136 virtual void SAL_CALL startDocument() 137 throw ( css::xml::sax::SAXException, css::uno::RuntimeException ); 138 139 /** 140 * Function to handle the end of the XML document 141 * 142 * @see com::sun::star::xml::sax::XDocumentHandler 143 */ 144 virtual void SAL_CALL endDocument() 145 throw ( css::xml::sax::SAXException, css::uno::RuntimeException ); 146 147 /** 148 * Function to handle the start of an element 149 * 150 * @see com::sun::star::xml::sax::XDocumentHandler 151 */ 152 virtual void SAL_CALL startElement( const ::rtl::OUString& aName, 153 const css::uno::Reference< css::xml::sax::XAttributeList > & xAttribs ) 154 throw ( css::xml::sax::SAXException, 155 css::uno::RuntimeException ); 156 157 /** 158 * Function to handle the end of an element 159 * 160 * @see com::sun::star::xml::sax::XDocumentHandler 161 */ 162 virtual void SAL_CALL endElement( const ::rtl::OUString & aName ) 163 throw ( css::xml::sax::SAXException, css::uno::RuntimeException ); 164 165 /** 166 * Function to handle characters in elements 167 * 168 * @see com::sun::star::xml::sax::XDocumentHandler 169 */ 170 virtual void SAL_CALL characters( const ::rtl::OUString & aChars ) 171 throw ( css::xml::sax::SAXException, css::uno::RuntimeException ); 172 173 /** 174 * Function to handle whitespace 175 * 176 * @see com::sun::star::xml::sax::XDocumentHandler 177 */ 178 virtual void SAL_CALL ignorableWhitespace( const ::rtl::OUString & aWhitespaces ) 179 throw ( css::xml::sax::SAXException, css::uno::RuntimeException ); 180 181 /** 182 * Function to handle XML processing instructions 183 * 184 * @see com::sun::star::xml::sax::XDocumentHandler 185 */ 186 virtual void SAL_CALL processingInstruction( 187 const ::rtl::OUString & aTarget, const ::rtl::OUString & aData ) 188 throw ( css::xml::sax::SAXException, css::uno::RuntimeException ); 189 190 /** 191 * Function to set the document locator 192 * 193 * @see com::sun::star::xml::sax::XDocumentHandler 194 */ 195 virtual void SAL_CALL setDocumentLocator( 196 const css::uno::Reference< css::xml::sax::XLocator >& xLocator ) 197 throw ( css::xml::sax::SAXException, css::uno::RuntimeException ); 198 199 200 201 private: 202 203 /** Vector contains the ScriptData structs */ 204 InfoImpls_vec* mpv_ScriptDatas; 205 206 /** @internal */ 207 osl::Mutex m_mutex; 208 209 /** @internal */ 210 css::uno::Reference< css::uno::XComponentContext > m_xContext; 211 212 /** Placeholder for the parcel URI */ 213 ::rtl::OUString ms_parcelURI; 214 215 /** States for state machine during parsing */ 216 enum { PARCEL, SCRIPT, LOCALE, DISPLAYNAME, DESCRIPTION, FUNCTIONNAME, 217 LOGICALNAME, LANGUAGEDEPPROPS, LANGDEPPROPS, FILESET, FILESETPROPS, 218 FILES, FILEPROPS } m_state; 219 220 /** Build up the struct during parsing the meta data */ 221 ScriptData m_ScriptData; 222 223 /** @internal */ 224 ::rtl::OUString ms_localeLang; 225 ::rtl::OUString ms_localeDisName; 226 ::rtl::OUStringBuffer *ms_localeDesc; 227 228 props_vec mv_filesetprops; 229 230 ::rtl::OUString ms_filename; 231 ::rtl::OUString ms_filesetname; 232 233 props_vec mv_fileprops; 234 235 strpairvec_map mm_files; 236 237 InfoImpls_vec mv_ScriptDatas; 238 239 /** 240 * Helper function to set the state 241 * 242 * @param tagName 243 * The current tag being processed 244 */ 245 void setState(const ::rtl::OUString & tagName); 246 } 247 ; // class ScriptMetadataImporter 248 249 } 250 251 #endif 252