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: xmlhelper.cxx,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 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_forms.hxx"
34 #include "xmlhelper.hxx"
36 #include "unohelper.hxx"
37 #include <rtl/ustring.hxx>
38 #include <com/sun/star/uno/Reference.hxx>
39 #include <com/sun/star/xml/dom/XDocumentBuilder.hpp>
42 using com::sun::star::uno::Reference
;
43 using com::sun::star::uno::UNO_QUERY_THROW
;
44 using com::sun::star::container::XNameContainer
;
45 using com::sun::star::xml::dom::XDocumentBuilder
;
49 // determine valid XML name
57 inline sal_uInt8
lcl_getCharClass( sal_Unicode c
)
62 if( (c
>= 'A' && c
<= 'Z')
64 || (c
>= 'a' && c
<= 'z')
65 || (c
>= 0x00C0 && c
<= 0x00D6)
66 || (c
>= 0x00D8 && c
<= 0x00F6)
67 || (c
>= 0x00F8 && c
<= 0x02FF)
68 || (c
>= 0x0370 && c
<= 0x037D)
69 || (c
>= 0x037F && c
<= 0x1FFF)
70 || (c
>= 0x200C && c
<= 0x200D)
71 || (c
>= 0x2070 && c
<= 0x218F)
72 || (c
>= 0x2C00 && c
<= 0x2FEF)
73 || (c
>= 0x3001 && c
<= 0xD7FF)
74 || (c
>= 0xF900 && c
<= 0xFDCF)
75 || (c
>= 0xFDF0 && c
<= 0xFFFD)
78 || (c
>= 0xD800 && c
<= 0xDBFF)
79 || (c
>= 0xDC00 && c
<= 0xDFFF) )
85 || (c
>= '0' && c
<= '9')
87 || (c
>= 0x0300 && c
<= 0x036F)
88 || (c
>= 0x203F && c
<= 0x2040) )
100 bool isValidQName( const OUString
& sName
,
101 const Reference
<XNameContainer
>& /*xNamespaces*/ )
103 sal_Int32 nLength
= sName
.getLength();
104 const sal_Unicode
* pName
= sName
.getStr();
107 sal_Int32 nColon
= 0;
110 bRet
= ( ( lcl_getCharClass( pName
[0] ) & 4 ) != 0 );
111 for( sal_Int32 n
= 1; n
< nLength
; n
++ )
113 sal_uInt8 nClass
= lcl_getCharClass( pName
[n
] );
114 bRet
&= ( ( nClass
& 2 ) != 0 );
125 bool isValidPrefixName( const OUString
& sName
,
126 const Reference
<XNameContainer
>& /*xNamespaces*/ )
128 sal_Int32 nLength
= sName
.getLength();
129 const sal_Unicode
* pName
= sName
.getStr();
134 bRet
= ( ( lcl_getCharClass( pName
[0] ) & 4 ) != 0 );
135 for( sal_Int32 n
= 1; n
< nLength
; n
++ )
136 bRet
&= ( ( lcl_getCharClass( pName
[n
] ) & 8 ) != 0 );
142 Reference
<XDocumentBuilder
> getDocumentBuilder()
144 Reference
<XDocumentBuilder
> xBuilder(
145 xforms::createInstance(
146 OUSTRING("com.sun.star.xml.dom.DocumentBuilder") ),
148 OSL_ENSURE( xBuilder
.is(), "no document builder?" );