masterfix DEV300: #i10000# build fix
[LibreOffice.git] / forms / source / xforms / xmlhelper.cxx
bloba8aaa19aea3429ec073320084b9ea7ad32624bc7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_forms.hxx"
31 #include "xmlhelper.hxx"
33 #include "unohelper.hxx"
34 #include <rtl/ustring.hxx>
35 #include <com/sun/star/uno/Reference.hxx>
36 #include <com/sun/star/xml/dom/XDocumentBuilder.hpp>
38 using rtl::OUString;
39 using com::sun::star::uno::Reference;
40 using com::sun::star::uno::UNO_QUERY_THROW;
41 using com::sun::star::container::XNameContainer;
42 using com::sun::star::xml::dom::XDocumentBuilder;
46 // determine valid XML name
49 // character class:
50 // 1: NameStartChar
51 // 2: NameChar
52 // 4: NCNameStartChar
53 // 8: NCNameChar
54 inline sal_uInt8 lcl_getCharClass( sal_Unicode c )
56 sal_uInt8 nClass = 0;
58 // NameStartChar
59 if( (c >= 'A' && c <= 'Z')
60 || c == '_'
61 || (c >= 'a' && c <= 'z')
62 || (c >= 0x00C0 && c <= 0x00D6)
63 || (c >= 0x00D8 && c <= 0x00F6)
64 || (c >= 0x00F8 && c <= 0x02FF)
65 || (c >= 0x0370 && c <= 0x037D)
66 || (c >= 0x037F && c <= 0x1FFF)
67 || (c >= 0x200C && c <= 0x200D)
68 || (c >= 0x2070 && c <= 0x218F)
69 || (c >= 0x2C00 && c <= 0x2FEF)
70 || (c >= 0x3001 && c <= 0xD7FF)
71 || (c >= 0xF900 && c <= 0xFDCF)
72 || (c >= 0xFDF0 && c <= 0xFFFD)
74 // surrogates
75 || (c >= 0xD800 && c <= 0xDBFF)
76 || (c >= 0xDC00 && c <= 0xDFFF) )
78 nClass = 15;
80 else if( c == '-'
81 || c == '.'
82 || (c >= '0' && c <= '9')
83 || (c == 0x00B7)
84 || (c >= 0x0300 && c <= 0x036F)
85 || (c >= 0x203F && c <= 0x2040) )
87 nClass = 10;
89 else if( c == ':' )
91 nClass = 3;
94 return nClass;
97 bool isValidQName( const OUString& sName,
98 const Reference<XNameContainer>& /*xNamespaces*/ )
100 sal_Int32 nLength = sName.getLength();
101 const sal_Unicode* pName = sName.getStr();
103 bool bRet = false;
104 sal_Int32 nColon = 0;
105 if( nLength > 0 )
107 bRet = ( ( lcl_getCharClass( pName[0] ) & 4 ) != 0 );
108 for( sal_Int32 n = 1; n < nLength; n++ )
110 sal_uInt8 nClass = lcl_getCharClass( pName[n] );
111 bRet &= ( ( nClass & 2 ) != 0 );
112 if( nClass == 3 )
113 nColon++;
116 if( nColon > 1 )
117 bRet = sal_False;
119 return bRet;
122 bool isValidPrefixName( const OUString& sName,
123 const Reference<XNameContainer>& /*xNamespaces*/ )
125 sal_Int32 nLength = sName.getLength();
126 const sal_Unicode* pName = sName.getStr();
127 bool bRet = false;
129 if( nLength > 0 )
131 bRet = ( ( lcl_getCharClass( pName[0] ) & 4 ) != 0 );
132 for( sal_Int32 n = 1; n < nLength; n++ )
133 bRet &= ( ( lcl_getCharClass( pName[n] ) & 8 ) != 0 );
136 return bRet;
139 Reference<XDocumentBuilder> getDocumentBuilder()
141 Reference<XDocumentBuilder> xBuilder(
142 xforms::createInstance(
143 OUSTRING("com.sun.star.xml.dom.DocumentBuilder") ),
144 UNO_QUERY_THROW );
145 OSL_ENSURE( xBuilder.is(), "no document builder?" );
146 return xBuilder;