xref: /trunk/main/sfx2/inc/sfx2/DocumentMetadataAccess.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 
102     // ::com::sun::star::rdf::XURI:
103     virtual ::rtl::OUString SAL_CALL getNamespace();
104     virtual ::rtl::OUString SAL_CALL getLocalName();
105 
106     // ::com::sun::star::rdf::XRepositorySupplier:
107     virtual ::com::sun::star::uno::Reference<
108         ::com::sun::star::rdf::XRepository > SAL_CALL getRDFRepository();
109 
110     // ::com::sun::star::rdf::XDocumentMetadataAccess:
111     virtual ::com::sun::star::uno::Reference<
112                 ::com::sun::star::rdf::XMetadatable > SAL_CALL
113         getElementByMetadataReference(
114             const ::com::sun::star::beans::StringPair & i_rReference);
115     virtual ::com::sun::star::uno::Reference<
116                 ::com::sun::star::rdf::XMetadatable > SAL_CALL
117         getElementByURI(const ::com::sun::star::uno::Reference<
118             ::com::sun::star::rdf::XURI > & i_xURI);
119     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference<
120             ::com::sun::star::rdf::XURI > > SAL_CALL getMetadataGraphsWithType(
121             const ::com::sun::star::uno::Reference<
122                 ::com::sun::star::rdf::XURI > & i_xType);
123     virtual ::com::sun::star::uno::Reference<
124                 ::com::sun::star::rdf::XURI> SAL_CALL
125         addMetadataFile(const ::rtl::OUString & i_rFileName,
126             const ::com::sun::star::uno::Sequence<
127                 ::com::sun::star::uno::Reference< ::com::sun::star::rdf::XURI >
128                 > & i_rTypes);
129     virtual ::com::sun::star::uno::Reference<
130                 ::com::sun::star::rdf::XURI> SAL_CALL
131         importMetadataFile(::sal_Int16 i_Format,
132             const ::com::sun::star::uno::Reference<
133                 ::com::sun::star::io::XInputStream > & i_xInStream,
134             const ::rtl::OUString & i_rFileName,
135             const ::com::sun::star::uno::Reference<
136                 ::com::sun::star::rdf::XURI > & i_xBaseURI,
137             const ::com::sun::star::uno::Sequence<
138                 ::com::sun::star::uno::Reference< ::com::sun::star::rdf::XURI >
139                 > & i_rTypes);
140     virtual void SAL_CALL removeMetadataFile(
141             const ::com::sun::star::uno::Reference<
142                 ::com::sun::star::rdf::XURI > & i_xGraphName);
143     virtual void SAL_CALL addContentOrStylesFile(
144             const ::rtl::OUString & i_rFileName);
145     virtual void SAL_CALL removeContentOrStylesFile(
146             const ::rtl::OUString & i_rFileName);
147 
148     virtual void SAL_CALL loadMetadataFromStorage(
149             const ::com::sun::star::uno::Reference<
150                 ::com::sun::star::embed::XStorage > & i_xStorage,
151             const ::com::sun::star::uno::Reference<
152                 ::com::sun::star::rdf::XURI > & i_xBaseURI,
153             const ::com::sun::star::uno::Reference<
154                 ::com::sun::star::task::XInteractionHandler> & i_xHandler);
155     virtual void SAL_CALL storeMetadataToStorage(
156             const ::com::sun::star::uno::Reference<
157                 ::com::sun::star::embed::XStorage > & i_xStorage);
158     virtual void SAL_CALL loadMetadataFromMedium(
159             const ::com::sun::star::uno::Sequence<
160                 ::com::sun::star::beans::PropertyValue > & i_rMedium);
161     virtual void SAL_CALL storeMetadataToMedium(
162             const ::com::sun::star::uno::Sequence<
163                 ::com::sun::star::beans::PropertyValue > & i_rMedium);
164 
165 private:
166     std::auto_ptr<DocumentMetadataAccess_Impl> m_pImpl;
167 };
168 
169 } // namespace sfx2
170 
171 #endif // _SFX_DOCUMENTMETADATAACCESS_HXX_
172