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