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