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 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 
27 #include "SchemaSimpleTypeContext.hxx"
28 
29 #include "SchemaRestrictionContext.hxx"
30 #include <xmloff/xmltoken.hxx>
31 #include <xmloff/nmspmap.hxx>
32 #include <xmloff/xmlnmspe.hxx>
33 #include <xmloff/xmltkmap.hxx>
34 #include <xmloff/xmluconv.hxx>
35 
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <com/sun/star/xsd/WhiteSpaceTreatment.hpp>
38 
39 #include <tools/debug.hxx>
40 
41 
42 using rtl::OUString;
43 using com::sun::star::uno::Reference;
44 using com::sun::star::uno::Any;
45 using com::sun::star::xml::sax::XAttributeList;
46 using com::sun::star::beans::XPropertySet;
47 using com::sun::star::xforms::XDataTypeRepository;
48 using namespace xmloff::token;
49 
50 
51 
52 
53 static SvXMLTokenMapEntry aAttributes[] =
54 {
55     TOKEN_MAP_ENTRY( NONE, NAME ),
56     XML_TOKEN_MAP_END
57 };
58 
59 static SvXMLTokenMapEntry aChildren[] =
60 {
61     TOKEN_MAP_ENTRY( XSD, RESTRICTION ),
62     XML_TOKEN_MAP_END
63 };
64 
65 
SchemaSimpleTypeContext(SvXMLImport & rImport,sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<XDataTypeRepository> & rRepository)66 SchemaSimpleTypeContext::SchemaSimpleTypeContext(
67     SvXMLImport& rImport,
68     sal_uInt16 nPrefix,
69     const OUString& rLocalName,
70     const Reference<XDataTypeRepository>& rRepository ) :
71         TokenContext( rImport, nPrefix, rLocalName, aAttributes, aChildren ),
72         mxRepository( rRepository )
73 {
74 }
75 
~SchemaSimpleTypeContext()76 SchemaSimpleTypeContext::~SchemaSimpleTypeContext()
77 {
78 }
79 
HandleAttribute(sal_uInt16 nToken,const OUString & rValue)80 void SchemaSimpleTypeContext::HandleAttribute(
81     sal_uInt16 nToken,
82     const OUString& rValue )
83 {
84     if( nToken == XML_NAME )
85     {
86         msTypeName = rValue;
87     }
88 }
89 
HandleChild(sal_uInt16 nToken,sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<XAttributeList> &)90 SvXMLImportContext* SchemaSimpleTypeContext::HandleChild(
91     sal_uInt16 nToken,
92     sal_uInt16 nPrefix,
93     const OUString& rLocalName,
94     const Reference<XAttributeList>& )
95 {
96     SvXMLImportContext* pContext = NULL;
97     switch( nToken )
98     {
99     case XML_RESTRICTION:
100         pContext = new SchemaRestrictionContext( GetImport(),
101                                                  nPrefix, rLocalName,
102                                                  mxRepository, msTypeName );
103         break;
104     default:
105         DBG_ERROR( "Booo!" );
106     }
107 
108     return ( pContext != NULL )
109         ? pContext
110         : new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
111 }
112