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 _SFX_DOCUMENTMETADATAACCESS_HXX_
25 #define _SFX_DOCUMENTMETADATAACCESS_HXX_
26 
27 #include <sal/config.h>
28 
29 #include <sfx2/dllapi.h>
30 
31 #include <com/sun/star/uno/XComponentContext.hpp>
32 #include <com/sun/star/rdf/XDocumentMetadataAccess.hpp>
33 #include <com/sun/star/rdf/XRepositorySupplier.hpp>
34 
35 #include <cppuhelper/implbase1.hxx>
36 
37 #include <boost/utility.hpp>
38 
39 #include <memory>
40 
41 
42 /** Implementation of the interface com.sun.star.rdf.XDocumentMetadataAccess
43 
44     This is not a service only because it needs some kind of XML ID registry
45     from the document, and i do not like defining an API for that.
46     Also, the implementation does _no_ locking, so make sure access is
47     protected externally.
48 
49     @author mst
50  */
51 
52 namespace com { namespace sun { namespace star { namespace embed {
53     class XStorage;
54 } } } }
55 
56 namespace sfx2 {
57 
58 
59 /** create a base URI for loading metadata from an ODF (sub)document.
60 
61     @param i_xContext   component context
62     @param i_xStorage   storage for the document; FileSystemStorage is allowed
63     @param i_rPkgURI    the URI for the package
64     @param i_rSubDocument   (optional) path of the subdocument in package
65 
66     @return a base URI suitable for XDocumentMetadataAccess::loadFromStorage
67  */
68 ::com::sun::star::uno::Reference< ::com::sun::star::rdf::XURI> SFX2_DLLPUBLIC
69 createBaseURI(
70     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext>
71         const & i_xContext,
72     ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage>
73         const & i_xStorage,
74     ::rtl::OUString const & i_rPkgURI,
75     ::rtl::OUString const & i_rSubDocument = ::rtl::OUString());
76 
77 
78 class IXmlIdRegistrySupplier;
79 struct DocumentMetadataAccess_Impl;
80 
81 
82 class SFX2_DLLPUBLIC DocumentMetadataAccess :
83     private boost::noncopyable,
84     public ::cppu::WeakImplHelper1<
85         ::com::sun::star::rdf::XDocumentMetadataAccess>
86 {
87 public:
88     explicit DocumentMetadataAccess(::com::sun::star::uno::Reference<
89                 ::com::sun::star::uno::XComponentContext > const & i_xContext,
90                 IXmlIdRegistrySupplier const & i_rRegistrySupplier,
91                 ::rtl::OUString const & i_rBaseURI);
92     // N.B.: in contrast to previous, this constructor does _not_ initialize!
93     //       caller must immediately call loadFromStorage/Medium!
94     explicit DocumentMetadataAccess(::com::sun::star::uno::Reference<
95                 ::com::sun::star::uno::XComponentContext > const & i_xContext,
96                 IXmlIdRegistrySupplier const & i_rRegistrySupplier);
97     virtual ~DocumentMetadataAccess();
98 
99     // ::com::sun::star::rdf::XNode:
100     virtual ::rtl::OUString SAL_CALL getStringValue()
101         throw (::com::sun::star::uno::RuntimeException);
102 
103     // ::com::sun::star::rdf::XURI:
104     virtual ::rtl::OUString SAL_CALL getNamespace()
105         throw (::com::sun::star::uno::RuntimeException);
106     virtual ::rtl::OUString SAL_CALL getLocalName()
107         throw (::com::sun::star::uno::RuntimeException);
108 
109     // ::com::sun::star::rdf::XRepositorySupplier:
110     virtual ::com::sun::star::uno::Reference<
111         ::com::sun::star::rdf::XRepository > SAL_CALL getRDFRepository()
112         throw (::com::sun::star::uno::RuntimeException);
113 
114     // ::com::sun::star::rdf::XDocumentMetadataAccess:
115     virtual ::com::sun::star::uno::Reference<
116                 ::com::sun::star::rdf::XMetadatable > SAL_CALL
117         getElementByMetadataReference(
118             const ::com::sun::star::beans::StringPair & i_rReference)
119         throw (::com::sun::star::uno::RuntimeException);
120     virtual ::com::sun::star::uno::Reference<
121                 ::com::sun::star::rdf::XMetadatable > SAL_CALL
122         getElementByURI(const ::com::sun::star::uno::Reference<
123             ::com::sun::star::rdf::XURI > & i_xURI)
124         throw (::com::sun::star::uno::RuntimeException,
125             ::com::sun::star::lang::IllegalArgumentException);
126     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference<
127             ::com::sun::star::rdf::XURI > > SAL_CALL getMetadataGraphsWithType(
128             const ::com::sun::star::uno::Reference<
129                 ::com::sun::star::rdf::XURI > & i_xType)
130         throw (::com::sun::star::uno::RuntimeException,
131             ::com::sun::star::lang::IllegalArgumentException);
132     virtual ::com::sun::star::uno::Reference<
133                 ::com::sun::star::rdf::XURI> SAL_CALL
134         addMetadataFile(const ::rtl::OUString & i_rFileName,
135             const ::com::sun::star::uno::Sequence<
136                 ::com::sun::star::uno::Reference< ::com::sun::star::rdf::XURI >
137                 > & i_rTypes)
138         throw (::com::sun::star::uno::RuntimeException,
139             ::com::sun::star::lang::IllegalArgumentException,
140             ::com::sun::star::container::ElementExistException);
141     virtual ::com::sun::star::uno::Reference<
142                 ::com::sun::star::rdf::XURI> SAL_CALL
143         importMetadataFile(::sal_Int16 i_Format,
144             const ::com::sun::star::uno::Reference<
145                 ::com::sun::star::io::XInputStream > & i_xInStream,
146             const ::rtl::OUString & i_rFileName,
147             const ::com::sun::star::uno::Reference<
148                 ::com::sun::star::rdf::XURI > & i_xBaseURI,
149             const ::com::sun::star::uno::Sequence<
150                 ::com::sun::star::uno::Reference< ::com::sun::star::rdf::XURI >
151                 > & i_rTypes)
152         throw (::com::sun::star::uno::RuntimeException,
153             ::com::sun::star::lang::IllegalArgumentException,
154             ::com::sun::star::datatransfer::UnsupportedFlavorException,
155             ::com::sun::star::container::ElementExistException,
156             ::com::sun::star::rdf::ParseException,
157             ::com::sun::star::io::IOException);
158     virtual void SAL_CALL removeMetadataFile(
159             const ::com::sun::star::uno::Reference<
160                 ::com::sun::star::rdf::XURI > & i_xGraphName)
161         throw (::com::sun::star::uno::RuntimeException,
162             ::com::sun::star::lang::IllegalArgumentException,
163             ::com::sun::star::container::NoSuchElementException);
164     virtual void SAL_CALL addContentOrStylesFile(
165             const ::rtl::OUString & i_rFileName)
166         throw (::com::sun::star::uno::RuntimeException,
167             ::com::sun::star::lang::IllegalArgumentException,
168             ::com::sun::star::container::ElementExistException);
169     virtual void SAL_CALL removeContentOrStylesFile(
170             const ::rtl::OUString & i_rFileName)
171         throw (::com::sun::star::uno::RuntimeException,
172             ::com::sun::star::lang::IllegalArgumentException,
173             ::com::sun::star::container::NoSuchElementException);
174 
175     virtual void SAL_CALL loadMetadataFromStorage(
176             const ::com::sun::star::uno::Reference<
177                 ::com::sun::star::embed::XStorage > & i_xStorage,
178             const ::com::sun::star::uno::Reference<
179                 ::com::sun::star::rdf::XURI > & i_xBaseURI,
180             const ::com::sun::star::uno::Reference<
181                 ::com::sun::star::task::XInteractionHandler> & i_xHandler)
182         throw (::com::sun::star::uno::RuntimeException,
183             ::com::sun::star::lang::IllegalArgumentException,
184             ::com::sun::star::lang::WrappedTargetException);
185     virtual void SAL_CALL storeMetadataToStorage(
186             const ::com::sun::star::uno::Reference<
187                 ::com::sun::star::embed::XStorage > & i_xStorage)
188         throw (::com::sun::star::uno::RuntimeException,
189             ::com::sun::star::lang::IllegalArgumentException,
190             ::com::sun::star::lang::WrappedTargetException);
191     virtual void SAL_CALL loadMetadataFromMedium(
192             const ::com::sun::star::uno::Sequence<
193                 ::com::sun::star::beans::PropertyValue > & i_rMedium)
194         throw (::com::sun::star::uno::RuntimeException,
195             ::com::sun::star::lang::IllegalArgumentException,
196             ::com::sun::star::lang::WrappedTargetException);
197     virtual void SAL_CALL storeMetadataToMedium(
198             const ::com::sun::star::uno::Sequence<
199                 ::com::sun::star::beans::PropertyValue > & i_rMedium)
200         throw (::com::sun::star::uno::RuntimeException,
201             ::com::sun::star::lang::IllegalArgumentException,
202             ::com::sun::star::lang::WrappedTargetException);
203 
204 private:
205     std::auto_ptr<DocumentMetadataAccess_Impl> m_pImpl;
206 };
207 
208 } // namespace sfx2
209 
210 #endif // _SFX_DOCUMENTMETADATAACCESS_HXX_
211 
212