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 _XMLSCRIPT_XML_HELPER_HXX_
28 #define _XMLSCRIPT_XML_HELPER_HXX_
29 
30 #include <vector>
31 #include <rtl/byteseq.hxx>
32 #include <cppuhelper/implbase1.hxx>
33 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
34 #include <com/sun/star/io/XInputStream.hpp>
35 #include <com/sun/star/io/XOutputStream.hpp>
36 
37 
38 namespace xmlscript
39 {
40 
41 /*##################################################################################################
42 
43 	EXPORTING
44 
45 ##################################################################################################*/
46 
47 //==================================================================================================
48 class XMLElement
49 	: public ::cppu::WeakImplHelper1< ::com::sun::star::xml::sax::XAttributeList >
50 {
51 public:
52 	inline XMLElement( ::rtl::OUString const & name )
53 		SAL_THROW( () )
54 		: _name( name )
55 		{}
56 
57 	/** Adds a sub element of element.
58 
59 		@param xElem element reference
60 	*/
61 	void SAL_CALL addSubElement(
62         ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > const & xElem )
63 		SAL_THROW( () );
64 
65 	/** Gets sub element of given index.  The index follows order in which sub elements were added.
66 
67 		@param nIndex index of sub element
68 	*/
69 	::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > SAL_CALL getSubElement( sal_Int32 nIndex )
70 		SAL_THROW( () );
71 
72 	/** Adds an attribute to elements.
73 
74 		@param rAttrName qname of attribute
75 		@param rValue value string of element
76 	*/
77 	void SAL_CALL addAttribute( ::rtl::OUString const & rAttrName, ::rtl::OUString const & rValue )
78 		SAL_THROW( () );
79 
80 	/** Gets the tag name (qname) of element.
81 
82 		@return
83 				qname of element
84 	*/
85 	inline ::rtl::OUString SAL_CALL getName() SAL_THROW( () )
86 		{ return _name; }
87 
88 	/** Dumps out element (and all sub elements).
89 
90 		@param xOut document handler to be written to
91 	*/
92 	void SAL_CALL dump(
93         ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > const & xOut );
94 	/** Dumps out sub elements (and all further sub elements).
95 
96 		@param xOut document handler to be written to
97 	*/
98 	void SAL_CALL dumpSubElements(
99         ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > const & xOut );
100 
101 	// XAttributeList
102 	virtual sal_Int16 SAL_CALL getLength()
103 		throw (::com::sun::star::uno::RuntimeException);
104 	virtual ::rtl::OUString SAL_CALL getNameByIndex( sal_Int16 nPos )
105 		throw (::com::sun::star::uno::RuntimeException);
106 	virtual ::rtl::OUString SAL_CALL getTypeByIndex( sal_Int16 nPos )
107 		throw (::com::sun::star::uno::RuntimeException);
108 	virtual ::rtl::OUString SAL_CALL getTypeByName( ::rtl::OUString const & rName )
109 		throw (::com::sun::star::uno::RuntimeException);
110 	virtual ::rtl::OUString SAL_CALL getValueByIndex( sal_Int16 nPos )
111 		throw (::com::sun::star::uno::RuntimeException);
112 	virtual ::rtl::OUString SAL_CALL getValueByName( ::rtl::OUString const & rName )
113 		throw (::com::sun::star::uno::RuntimeException);
114 
115 protected:
116 	::rtl::OUString _name;
117 
118 	::std::vector< ::rtl::OUString > _attrNames;
119 	::std::vector< ::rtl::OUString > _attrValues;
120 
121 	::std::vector< ::com::sun::star::uno::Reference<
122 				   ::com::sun::star::xml::sax::XAttributeList > > _subElems;
123 };
124 
125 
126 /*##################################################################################################
127 
128 	STREAMING
129 
130 ##################################################################################################*/
131 
132 //==================================================================================================
133 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >
134 SAL_CALL createInputStream(
135 	::rtl::ByteSequence const & rInData )
136 	SAL_THROW( () );
137 
138 //==================================================================================================
139 ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >
140 SAL_CALL createOutputStream(
141 	::rtl::ByteSequence * pOutData )
142 	SAL_THROW( () );
143 
144 }
145 
146 #endif
147