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 #ifndef EXTENSIONS_SOURCE_PROPCTRLR_XSDVALIDATIONHELPER_HXX
25 #define EXTENSIONS_SOURCE_PROPCTRLR_XSDVALIDATIONHELPER_HXX
26 
27 #include "eformshelper.hxx"
28 #include "xsddatatypes.hxx"
29 
30 /** === begin UNO includes === **/
31 #include <com/sun/star/xsd/XDataType.hpp>
32 #include <com/sun/star/beans/XPropertySet.hpp>
33 /** === end UNO includes === **/
34 #include <rtl/ref.hxx>
35 
36 //........................................................................
37 namespace pcr
38 {
39 //........................................................................
40 
41     class XSDDataType;
42 	//====================================================================
43 	//= XSDValidationHelper
44 	//====================================================================
45     class XSDValidationHelper : public EFormsHelper
46 	{
47     private:
48         bool    m_bInspectingFormattedField;
49     public:
isInspectingFormattedField() const50         bool    isInspectingFormattedField() const { return m_bInspectingFormattedField; }
51 
52     public:
53         XSDValidationHelper(
54             ::osl::Mutex& _rMutex,
55             const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxIntrospectee,
56             const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& _rxContextDocument
57         );
58 
59         /** retrieves the names of all XForms models in the document the control lives in
60         */
61         void    getAvailableDataTypeNames( ::std::vector< ::rtl::OUString >& /* [out] */ _rNames ) const SAL_THROW(());
62 
63         /** retrieves a particular data type given by name
64         */
65         ::rtl::Reference< XSDDataType >
66                 getDataTypeByName( const ::rtl::OUString& _rName ) const SAL_THROW(());
67 
68         /** retrieves the DataType instance which the control model is currently validated against
69 
70             If there is a binding set at our control model, which at the same time acts as validator,
71             and if this validator is bound to an XDataType, then this data type is retrieved here.
72         */
73         ::rtl::Reference< XSDDataType >
74                 getValidatingDataType( ) const SAL_THROW(());
75 
76         /** retrieves the name of the data type which the control model is currently validated against
77 
78             @seealso getValidatingDataType
79         */
80         ::rtl::OUString
81                 getValidatingDataTypeName( ) const SAL_THROW(());
82 
83         /** binds the validator to a new data type
84 
85             To be called with an active binding only.
86         */
87         void    setValidatingDataTypeByName( const ::rtl::OUString& _rName ) const SAL_THROW(());
88 
89         /** removes the data type given by name from the data type repository
90         */
91         bool    removeDataTypeFromRepository( const ::rtl::OUString& _rName ) const SAL_THROW(());
92 
93         /** creates a new data type, which is a clone of an existing data type
94         */
95         bool    cloneDataType( const ::rtl::Reference< XSDDataType >& _pDataType, const ::rtl::OUString& _rNewName ) const SAL_THROW(());
96 
97         /** retrieves the name of the basic data type which has the given class
98         */
99         ::rtl::OUString
100                 getBasicTypeNameForClass( sal_Int16 _eClass ) const SAL_THROW(());
101 
102         /** copy a data type from one model to another
103 
104             If a data type with the given name already exists in the target model, then nothing
105             happens. In particular, the facets of the data type are not copied.
106         */
107         void    copyDataType( const ::rtl::OUString& _rFromModel, const ::rtl::OUString& _rToModel,
108                     const ::rtl::OUString& _rDataTypeName ) const SAL_THROW(());
109 
110         /** finds (and sets) a default format for the formatted field we're inspecting,
111             according to the current data type the control value is evaluated against
112         */
113         void findDefaultFormatForIntrospectee() SAL_THROW(());
114 
115     private:
116         /** retrieves the data type repository associated with the current model
117         */
118         ::com::sun::star::uno::Reference< ::com::sun::star::xforms::XDataTypeRepository >
119                 getDataTypeRepository() const SAL_THROW((::com::sun::star::uno::Exception));
120 
121         /** retrieves the data type repository associated with any model
122         */
123         ::com::sun::star::uno::Reference< ::com::sun::star::xforms::XDataTypeRepository >
124                 getDataTypeRepository( const ::rtl::OUString& _rModelName ) const SAL_THROW((::com::sun::star::uno::Exception));
125 
126         /** retrieves the data type object for the given name
127         */
128         ::com::sun::star::uno::Reference< ::com::sun::star::xsd::XDataType >
129             getDataType( const ::rtl::OUString& _rName ) const
130                 SAL_THROW((::com::sun::star::uno::Exception));
131 
132         /** retrieves the name of the basic data type which has the given class, in the given repository
133         */
134         ::rtl::OUString
135                 getBasicTypeNameForClass(
136                     sal_Int16 _nClass,
137                     ::com::sun::star::uno::Reference< ::com::sun::star::xforms::XDataTypeRepository > _rxRepository
138                 ) const SAL_THROW(());
139 	};
140 
141 //........................................................................
142 } // namespace pcr
143 //........................................................................
144 
145 #endif // EXTENSIONS_SOURCE_PROPCTRLR_XSDVALIDATIONHELPER_HXX
146 
147