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 SD_FRAMEWORK_RESOURCE_ID_HXX
25 #define SD_FRAMEWORK_RESOURCE_ID_HXX
26 
27 #include <com/sun/star/drawing/framework/XResourceId.hpp>
28 #include <com/sun/star/lang/XInitialization.hpp>
29 #include <com/sun/star/util/XURLTransformer.hpp>
30 #include <cppuhelper/compbase2.hxx>
31 #include <boost/scoped_ptr.hpp>
32 
33 namespace css = ::com::sun::star;
34 
35 
36 namespace {
37 
38 typedef ::cppu::WeakImplHelper2 <
39     css::drawing::framework::XResourceId,
40     css::lang::XInitialization
41     > ResourceIdInterfaceBase;
42 
43 } // end of anonymous namespace.
44 
45 
46 
47 
48 namespace sd { namespace framework {
49 
50 /** Implementation of the css::drawing::framework::ResourceId
51     service and the css::drawing::framework::XResourceId
52     interface.
53 */
54 class ResourceId
55     : public ResourceIdInterfaceBase
56 {
57 public:
58     /** Create a new, empty resource id.
59     */
60     ResourceId (void);
61 
62     /** Create a new resource id that is described by the given URLs.
63         @param rsResourceURLs
64             The first URL specifies the type of resource.  The other URLs
65             describe its anchor.
66             The set of URLs may be empty.  The result is then the same as
67             returned by ResourceId() default constructor.
68     */
69     ResourceId (const ::std::vector<rtl::OUString>& rsResourceURLs);
70 
71     /** Create a new resource id that has an empty anchor.
72         @param rsResourceURL
73             When this resource URL is empty then the resulting ResourceId
74             object is identical to when the ResourceId() default constructor
75             had been called.
76     */
77     ResourceId (
78         const ::rtl::OUString& rsResourceURL);
79 
80     /** Create a new resource id for the given resource type and an anchor
81         that is specified by a single URL.  This constructor can be used for
82         example for views that are bound to panes.
83         @param rsResourceURL
84             The URL of the actual resource.
85         @param rsAnchorURL
86             The single URL of the anchor.
87     */
88     ResourceId (
89         const ::rtl::OUString& rsResourceURL,
90         const ::rtl::OUString& rsAnchorURL);
91 
92     /** Create a new resource id for the specified resource type and the
93         given list of anchor URLs.
94         @param rsResourceURL
95             The URL of the actual resource.
96         @param rsAnchorURLs
97             The possibly empty list of anchor URLs.
98     */
99     ResourceId (
100         const ::rtl::OUString& rsResourceURL,
101         const ::std::vector<rtl::OUString>& rAnchorURLs);
102 
103     /** Create a new resource id with an anchor that consists of a sequence
104         of URLs that is extended by a further URL.
105         @param rsResourceURL
106             The URL of the actual resource.
107         @param rsFirstAnchorURL
108             This URL extends the anchor given by rAnchorURLs.
109         @param rAnchorURLs
110             An anchor as it is returned by XResourceId::getAnchorURLs().
111     */
112     ResourceId (
113         const ::rtl::OUString& rsResourceURL,
114         const ::rtl::OUString& rsFirstAnchorURL,
115         const css::uno::Sequence<rtl::OUString>& rAnchorURLs);
116 
117     virtual ~ResourceId (void);
118 
119     /** Return the list of URLs of both the resource URL and the anchor
120         URLs.
121     */
122     const ::std::vector<rtl::OUString>& GetResourceURLs (void) const;
123 
124     //===== XResourceId =======================================================
125 
126     virtual ::rtl::OUString SAL_CALL
127         getResourceURL (void)
128         throw(css::uno::RuntimeException);
129 
130     virtual css::util::URL SAL_CALL
131         getFullResourceURL (void)
132         throw(css::uno::RuntimeException);
133 
134     virtual sal_Bool SAL_CALL
135         hasAnchor (void)
136         throw (css::uno::RuntimeException);
137 
138     virtual css::uno::Reference<
139         css::drawing::framework::XResourceId> SAL_CALL
140         getAnchor (void)
141         throw (css::uno::RuntimeException);
142 
143     virtual css::uno::Sequence<rtl::OUString> SAL_CALL
144         getAnchorURLs (void)
145         throw (css::uno::RuntimeException);
146 
147     virtual ::rtl::OUString SAL_CALL
148         getResourceTypePrefix (void)
149         throw (css::uno::RuntimeException);
150 
151     virtual sal_Int16 SAL_CALL
152         compareTo (const css::uno::Reference<
153             css::drawing::framework::XResourceId>& rxResourceId)
154         throw (css::uno::RuntimeException);
155 
156     virtual sal_Bool SAL_CALL
157         isBoundTo (
158             const css::uno::Reference<
159                 css::drawing::framework::XResourceId>& rxResourceId,
160             css::drawing::framework::AnchorBindingMode eMode)
161         throw(css::uno::RuntimeException);
162 
163     virtual sal_Bool SAL_CALL
164         isBoundToURL (
165             const ::rtl::OUString& rsAnchorURL,
166             css::drawing::framework::AnchorBindingMode eMode)
167         throw (css::uno::RuntimeException);
168 
169     virtual css::uno::Reference<
170         css::drawing::framework::XResourceId> SAL_CALL
171         clone (void)
172         throw(css::uno::RuntimeException);
173 
174     //===== XInitialization ===================================================
175 
176     void SAL_CALL initialize (
177         const css::uno::Sequence<css::uno::Any>& aArguments)
178         throw (css::uno::RuntimeException);
179 
180 private:
181     /** The set of URLs that consist of the resource URL at index 0 and the
182         anchor URLs and indices 1 and above.
183     */
184     ::std::vector<rtl::OUString> maResourceURLs;
185 
186     ::boost::scoped_ptr<css::util::URL> mpURL;
187 
188     static css::uno::WeakReference<css::util::XURLTransformer> mxURLTransformerWeak;
189 
190     /** Compare the called ResourceId object to the given ResourceId object.
191         This uses the implementation of both objects to speed up the
192         comparison.
193     */
194     sal_Int16 CompareToLocalImplementation (const ResourceId& rId) const;
195 
196     /** Compare the called ResourceId object to the given XResourceId object
197         reference.  The comparison is done via the UNO interface.  Namely,
198         it uses the getResourceURL() and the getAnchorURLs() methods to get
199         access to the URLs of the given objec.
200     */
201     sal_Int16 CompareToExternalImplementation (const css::uno::Reference<
202         css::drawing::framework::XResourceId>& rxId) const;
203 
204     /** Return whether the called ResourceId object is bound to the anchor
205         consisting of the URLs given by psFirstAnchorURL and paAnchorURLs.
206         @param psFirstAnchorURL
207             Optional first URL of the anchor. This can be missing or present
208             independently of paAnchorURLs.
209         @param paAnchorURLs
210             Optional set of additional anchor URLs.  This can be missing or
211             present independently of psFirstAnchorURL.
212         @param eMode
213             This specifies whether the called resource has to be directly
214             bound to the given anchor in order to return <TRUE/> or whether
215             it can be bound indirectly, too.
216     */
217     bool IsBoundToAnchor (
218         const rtl::OUString* psFirstAnchorURL,
219         const css::uno::Sequence<rtl::OUString>* paAnchorURLs,
220         css::drawing::framework::AnchorBindingMode eMode) const;
221 
222     /** Return whether the called ResourceId object is bound to the anchor
223         consisting of the URLs in rResourceURLs.
224         @param rResourceURLs
225             A possibly empty list of anchor URLs.
226         @param eMode
227             This specifies whether the called resource has to be directly
228             bound to the given anchor in order to return <TRUE/> or whether
229             it can be bound indirectly, too.
230     */
231     bool IsBoundToAnchor (
232         const ::std::vector<rtl::OUString>& rResourceURLs,
233         css::drawing::framework::AnchorBindingMode eMode) const;
234 
235     void ParseResourceURL (void);
236 };
237 
238 } } // end of namespace sd::framework
239 
240 #endif
241