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