1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 #ifndef _SCRIPTING_STORAGE_SCRIPTMETADATAIMPORTER_HXX_ 24 #define _SCRIPTING_STORAGE_SCRIPTMETADATAIMPORTER_HXX_ 25 26 #include <vector> 27 28 #include <rtl/ustring.h> 29 #include <rtl/ustrbuf.hxx> 30 #include <osl/mutex.hxx> 31 #include <cppuhelper/implbase1.hxx> // helper for component factory 32 33 #include <com/sun/star/uno/XComponentContext.hpp> 34 #include <com/sun/star/lang/XServiceInfo.hpp> 35 #include <com/sun/star/lang/XInitialization.hpp> 36 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp> 37 #include <com/sun/star/io/XInputStream.hpp> 38 39 #include "ScriptData.hxx" 40 41 namespace scripting_impl 42 { 43 // for simplification 44 #define css ::com::sun::star 45 #define dcsssf ::drafts::com::sun::star::script::framework 46 47 typedef ::std::vector< ScriptData > InfoImpls_vec; 48 typedef ::std::pair< ::rtl::OUString, ::std::pair< ::rtl::OUString, 49 ::rtl::OUString > > strpair_pair; 50 51 /** 52 * Script Meta Data Importer 53 */ 54 class ScriptMetadataImporter : public 55 ::cppu::WeakImplHelper1< css::xml::sax::XExtendedDocumentHandler > 56 { 57 public: 58 59 /** 60 * This function will begin the parser and parse the meta data 61 * 62 * @param xInput The XInputStream for the parser which contains the XML 63 * @param parcelURI The parcel's URI in the document or the application 64 * 65 * @see css::io::XInputStream 66 */ 67 void parseMetaData( css::uno::Reference< css::io::XInputStream > 68 const & xInput, const ::rtl::OUString & parcelURI, 69 InfoImpls_vec & io_ScriptDatas ); 70 71 /** 72 * Constructor for the meta-data parser 73 * 74 * @param XComponentContext 75 */ 76 explicit ScriptMetadataImporter( 77 const css::uno::Reference< css::uno::XComponentContext >& ); 78 79 /** 80 * Destructor for the parser 81 */ 82 virtual ~ScriptMetadataImporter() SAL_THROW( () ); 83 84 // XExtendedDocumentHandler impl 85 /** 86 * Function to handle the start of CDATA in XML 87 * 88 * @see com::sun::star::xml::sax::XExtendedDocumentHandler 89 */ 90 virtual void SAL_CALL startCDATA(); 91 92 /** 93 * Function to handle the end of CDATA in XML 94 * 95 * @see com::sun::star::xml::sax::XExtendedDocumentHandler 96 */ 97 virtual void SAL_CALL endCDATA(); 98 99 /** 100 * Function to handle comments in XML 101 * 102 * @see com::sun::star::xml::sax::XExtendedDocumentHandler 103 */ 104 virtual void SAL_CALL comment( const ::rtl::OUString & sComment ); 105 106 /** 107 * Function to handle line breaks in XML 108 * 109 * @see com::sun::star::xml::sax::XExtendedDocumentHandler 110 */ 111 virtual void SAL_CALL allowLineBreak(); 112 113 /** 114 * Function to handle unknowns in XML 115 * 116 * @see com::sun::star::xml::sax::XExtendedDocumentHandler 117 */ 118 virtual void SAL_CALL unknown( const ::rtl::OUString & sString ); 119 120 /** 121 * Function to handle the start of XML document 122 * 123 * @see com::sun::star::xml::sax::XExtendedDocumentHandler 124 */ 125 // XDocumentHandler impl 126 virtual void SAL_CALL startDocument(); 127 128 /** 129 * Function to handle the end of the XML document 130 * 131 * @see com::sun::star::xml::sax::XDocumentHandler 132 */ 133 virtual void SAL_CALL endDocument(); 134 135 /** 136 * Function to handle the start of an element 137 * 138 * @see com::sun::star::xml::sax::XDocumentHandler 139 */ 140 virtual void SAL_CALL startElement( const ::rtl::OUString& aName, 141 const css::uno::Reference< css::xml::sax::XAttributeList > & xAttribs ); 142 143 /** 144 * Function to handle the end of an element 145 * 146 * @see com::sun::star::xml::sax::XDocumentHandler 147 */ 148 virtual void SAL_CALL endElement( const ::rtl::OUString & aName ); 149 150 /** 151 * Function to handle characters in elements 152 * 153 * @see com::sun::star::xml::sax::XDocumentHandler 154 */ 155 virtual void SAL_CALL characters( const ::rtl::OUString & aChars ); 156 157 /** 158 * Function to handle whitespace 159 * 160 * @see com::sun::star::xml::sax::XDocumentHandler 161 */ 162 virtual void SAL_CALL ignorableWhitespace( const ::rtl::OUString & aWhitespaces ); 163 164 /** 165 * Function to handle XML processing instructions 166 * 167 * @see com::sun::star::xml::sax::XDocumentHandler 168 */ 169 virtual void SAL_CALL processingInstruction( 170 const ::rtl::OUString & aTarget, const ::rtl::OUString & aData ); 171 172 /** 173 * Function to set the document locator 174 * 175 * @see com::sun::star::xml::sax::XDocumentHandler 176 */ 177 virtual void SAL_CALL setDocumentLocator( 178 const css::uno::Reference< css::xml::sax::XLocator >& xLocator ); 179 180 181 182 private: 183 184 /** Vector contains the ScriptData structs */ 185 InfoImpls_vec* mpv_ScriptDatas; 186 187 /** @internal */ 188 osl::Mutex m_mutex; 189 190 /** @internal */ 191 css::uno::Reference< css::uno::XComponentContext > m_xContext; 192 193 /** Placeholder for the parcel URI */ 194 ::rtl::OUString ms_parcelURI; 195 196 /** States for state machine during parsing */ 197 enum { PARCEL, SCRIPT, LOCALE, DISPLAYNAME, DESCRIPTION, FUNCTIONNAME, 198 LOGICALNAME, LANGUAGEDEPPROPS, LANGDEPPROPS, FILESET, FILESETPROPS, 199 FILES, FILEPROPS } m_state; 200 201 /** Build up the struct during parsing the meta data */ 202 ScriptData m_ScriptData; 203 204 /** @internal */ 205 ::rtl::OUString ms_localeLang; 206 ::rtl::OUString ms_localeDisName; 207 ::rtl::OUStringBuffer *ms_localeDesc; 208 209 props_vec mv_filesetprops; 210 211 ::rtl::OUString ms_filename; 212 ::rtl::OUString ms_filesetname; 213 214 props_vec mv_fileprops; 215 216 strpairvec_map mm_files; 217 218 InfoImpls_vec mv_ScriptDatas; 219 220 /** 221 * Helper function to set the state 222 * 223 * @param tagName 224 * The current tag being processed 225 */ 226 void setState(const ::rtl::OUString & tagName); 227 } 228 ; // class ScriptMetadataImporter 229 230 } 231 232 #endif 233