1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScriptMetadataImporter.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef _SCRIPTING_STORAGE_SCRIPTMETADATAIMPORTER_HXX_
31 #define _SCRIPTING_STORAGE_SCRIPTMETADATAIMPORTER_HXX_
35 #include <rtl/ustring.h>
36 #include <rtl/ustrbuf.hxx>
37 #include <osl/mutex.hxx>
38 #include <cppuhelper/implbase1.hxx> // helper for component factory
40 #include <com/sun/star/uno/XComponentContext.hpp>
41 #include <com/sun/star/lang/XServiceInfo.hpp>
42 #include <com/sun/star/lang/XInitialization.hpp>
43 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
44 #include <com/sun/star/io/XInputStream.hpp>
46 #include "ScriptData.hxx"
48 namespace scripting_impl
51 #define css ::com::sun::star
52 #define dcsssf ::drafts::com::sun::star::script::framework
54 typedef ::std::vector
< ScriptData
> InfoImpls_vec
;
55 typedef ::std::pair
< ::rtl::OUString
, ::std::pair
< ::rtl::OUString
,
56 ::rtl::OUString
> > strpair_pair
;
59 * Script Meta Data Importer
61 class ScriptMetadataImporter
: public
62 ::cppu::WeakImplHelper1
< css::xml::sax::XExtendedDocumentHandler
>
67 * This function will begin the parser and parse the meta data
69 * @param xInput The XInputStream for the parser which contains the XML
70 * @param parcelURI The parcel's URI in the document or the application
72 * @see css::io::XInputStream
74 void parseMetaData( css::uno::Reference
< css::io::XInputStream
>
75 const & xInput
, const ::rtl::OUString
& parcelURI
,
76 InfoImpls_vec
& io_ScriptDatas
)
77 throw ( css::xml::sax::SAXException
, css::io::IOException
,
78 css::uno::RuntimeException
);
81 * Constructor for the meta-data parser
83 * @param XComponentContext
85 explicit ScriptMetadataImporter(
86 const css::uno::Reference
< css::uno::XComponentContext
>& );
89 * Destructor for the parser
91 virtual ~ScriptMetadataImporter() SAL_THROW( () );
93 // XExtendedDocumentHandler impl
95 * Function to handle the start of CDATA in XML
97 * @see com::sun::star::xml::sax::XExtendedDocumentHandler
99 virtual void SAL_CALL
startCDATA()
100 throw ( css::xml::sax::SAXException
, css::uno::RuntimeException
);
103 * Function to handle the end of CDATA in XML
105 * @see com::sun::star::xml::sax::XExtendedDocumentHandler
107 virtual void SAL_CALL
endCDATA() throw ( css::uno::RuntimeException
);
110 * Function to handle comments in XML
112 * @see com::sun::star::xml::sax::XExtendedDocumentHandler
114 virtual void SAL_CALL
comment( const ::rtl::OUString
& sComment
)
115 throw ( css::xml::sax::SAXException
, css::uno::RuntimeException
);
118 * Function to handle line breaks in XML
120 * @see com::sun::star::xml::sax::XExtendedDocumentHandler
122 virtual void SAL_CALL
allowLineBreak()
123 throw ( css::xml::sax::SAXException
, css::uno::RuntimeException
);
126 * Function to handle unknowns in XML
128 * @see com::sun::star::xml::sax::XExtendedDocumentHandler
130 virtual void SAL_CALL
unknown( const ::rtl::OUString
& sString
)
131 throw ( css::xml::sax::SAXException
, css::uno::RuntimeException
);
134 * Function to handle the start of XML document
136 * @see com::sun::star::xml::sax::XExtendedDocumentHandler
138 // XDocumentHandler impl
139 virtual void SAL_CALL
startDocument()
140 throw ( css::xml::sax::SAXException
, css::uno::RuntimeException
);
143 * Function to handle the end of the XML document
145 * @see com::sun::star::xml::sax::XDocumentHandler
147 virtual void SAL_CALL
endDocument()
148 throw ( css::xml::sax::SAXException
, css::uno::RuntimeException
);
151 * Function to handle the start of an element
153 * @see com::sun::star::xml::sax::XDocumentHandler
155 virtual void SAL_CALL
startElement( const ::rtl::OUString
& aName
,
156 const css::uno::Reference
< css::xml::sax::XAttributeList
> & xAttribs
)
157 throw ( css::xml::sax::SAXException
,
158 css::uno::RuntimeException
);
161 * Function to handle the end of an element
163 * @see com::sun::star::xml::sax::XDocumentHandler
165 virtual void SAL_CALL
endElement( const ::rtl::OUString
& aName
)
166 throw ( css::xml::sax::SAXException
, css::uno::RuntimeException
);
169 * Function to handle characters in elements
171 * @see com::sun::star::xml::sax::XDocumentHandler
173 virtual void SAL_CALL
characters( const ::rtl::OUString
& aChars
)
174 throw ( css::xml::sax::SAXException
, css::uno::RuntimeException
);
177 * Function to handle whitespace
179 * @see com::sun::star::xml::sax::XDocumentHandler
181 virtual void SAL_CALL
ignorableWhitespace( const ::rtl::OUString
& aWhitespaces
)
182 throw ( css::xml::sax::SAXException
, css::uno::RuntimeException
);
185 * Function to handle XML processing instructions
187 * @see com::sun::star::xml::sax::XDocumentHandler
189 virtual void SAL_CALL
processingInstruction(
190 const ::rtl::OUString
& aTarget
, const ::rtl::OUString
& aData
)
191 throw ( css::xml::sax::SAXException
, css::uno::RuntimeException
);
194 * Function to set the document locator
196 * @see com::sun::star::xml::sax::XDocumentHandler
198 virtual void SAL_CALL
setDocumentLocator(
199 const css::uno::Reference
< css::xml::sax::XLocator
>& xLocator
)
200 throw ( css::xml::sax::SAXException
, css::uno::RuntimeException
);
206 /** Vector contains the ScriptData structs */
207 InfoImpls_vec
* mpv_ScriptDatas
;
213 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
215 /** Placeholder for the parcel URI */
216 ::rtl::OUString ms_parcelURI
;
218 /** States for state machine during parsing */
219 enum { PARCEL
, SCRIPT
, LOCALE
, DISPLAYNAME
, DESCRIPTION
, FUNCTIONNAME
,
220 LOGICALNAME
, LANGUAGEDEPPROPS
, LANGDEPPROPS
, FILESET
, FILESETPROPS
,
221 FILES
, FILEPROPS
} m_state
;
223 /** Build up the struct during parsing the meta data */
224 ScriptData m_ScriptData
;
227 ::rtl::OUString ms_localeLang
;
228 ::rtl::OUString ms_localeDisName
;
229 ::rtl::OUStringBuffer
*ms_localeDesc
;
231 props_vec mv_filesetprops
;
233 ::rtl::OUString ms_filename
;
234 ::rtl::OUString ms_filesetname
;
236 props_vec mv_fileprops
;
238 strpairvec_map mm_files
;
240 InfoImpls_vec mv_ScriptDatas
;
243 * Helper function to set the state
246 * The current tag being processed
248 void setState(const ::rtl::OUString
& tagName
);
250 ; // class ScriptMetadataImporter