Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <memory>
30 : : #include "submission.hxx"
31 : : #include "serialization_app_xml.hxx"
32 : :
33 : : #include <rtl/ustring.hxx>
34 : : #include <rtl/string.hxx>
35 : :
36 : : #include <comphelper/processfactory.hxx>
37 : : #include <com/sun/star/uno/Reference.hxx>
38 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
39 : : #include <com/sun/star/xml/dom/XDocument.hpp>
40 : : #include <com/sun/star/xml/dom/XDocumentBuilder.hpp>
41 : : #include <com/sun/star/frame/XComponentLoader.hpp>
42 : : #include <com/sun/star/frame/FrameSearchFlag.hpp>
43 : : #include <com/sun/star/beans/PropertyValue.hpp>
44 : : #include <ucbhelper/content.hxx>
45 : :
46 : : using namespace com::sun::star::uno;
47 : : using namespace com::sun::star::ucb;
48 : : using namespace com::sun::star::frame;
49 : : using namespace com::sun::star::lang;
50 : : using namespace com::sun::star::beans;
51 : : using namespace com::sun::star::task;
52 : : using namespace com::sun::star::xml::dom;
53 : :
54 : 0 : CSubmission::SubmissionResult CSubmission::replace(const ::rtl::OUString& aReplace, const Reference<XDocument>& aDocument, const Reference<XFrame>& aFrame)
55 : : {
56 [ # # ]: 0 : if (!m_aResultStream.is())
57 : 0 : return CSubmission::UNKNOWN_ERROR;
58 : :
59 : : try {
60 [ # # ]: 0 : Reference< XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory();
61 [ # # # # ]: 0 : if (aReplace.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("all"))
[ # # ]
62 : 0 : || aReplace.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("document"))) {
63 : 0 : Reference< XComponentLoader > xLoader;
64 [ # # ]: 0 : if (aFrame.is())
65 [ # # ][ # # ]: 0 : xLoader = Reference< XComponentLoader >(aFrame, UNO_QUERY);
66 : :
67 [ # # ]: 0 : if (!xLoader.is())
68 [ # # ]: 0 : xLoader = Reference< XComponentLoader >(xFactory->createInstance(
69 [ # # ][ # # ]: 0 : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop") ) ), UNO_QUERY_THROW);
[ # # ][ # # ]
70 : :
71 : : // open the stream from the result...
72 : : // build media descriptor
73 [ # # ]: 0 : Sequence< PropertyValue > descriptor(2);
74 [ # # ]: 0 : descriptor[0] = PropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("InputStream") ),
75 [ # # ][ # # ]: 0 : -1, makeAny(m_aResultStream), PropertyState_DIRECT_VALUE);
76 [ # # ]: 0 : descriptor[1] = PropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ReadOnly") ),
77 [ # # ][ # # ]: 0 : -1, makeAny(sal_True), PropertyState_DIRECT_VALUE);
78 : :
79 [ # # ]: 0 : ::rtl::OUString aURL = m_aURLObj.GetMainURL(INetURLObject::NO_DECODE);
80 [ # # ]: 0 : ::rtl::OUString aTarget = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_default") );
81 [ # # ][ # # ]: 0 : xLoader->loadComponentFromURL(aURL, aTarget, FrameSearchFlag::ALL, descriptor);
82 : :
83 [ # # ]: 0 : return CSubmission::SUCCESS;
84 : :
85 [ # # ]: 0 : } else if (aReplace.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("instance"))) {
86 [ # # ]: 0 : if (aDocument.is()) {
87 : : // parse the result stream into a new document
88 [ # # ]: 0 : Reference< XDocumentBuilder > xBuilder(xFactory->createInstance(
89 [ # # ][ # # ]: 0 : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.dom.DocumentBuilder") ) ), UNO_QUERY_THROW);
[ # # ]
90 [ # # ][ # # ]: 0 : Reference< XDocument > aNewDocument = xBuilder->parse(m_aResultStream);
91 : :
92 [ # # ]: 0 : if (aNewDocument.is()) {
93 : : // and replace the content of the current instance
94 [ # # ][ # # ]: 0 : Reference< XElement > oldRoot = aDocument->getDocumentElement();
95 [ # # ][ # # ]: 0 : Reference< XElement > newRoot = aNewDocument->getDocumentElement();
96 : :
97 [ # # ][ # # ]: 0 : Reference< XNode > aImportedNode = aDocument->importNode(Reference< XNode >(newRoot, UNO_QUERY_THROW), sal_True);
[ # # ]
98 [ # # ][ # # ]: 0 : Reference< XNode >(aDocument, UNO_QUERY_THROW)->replaceChild(aImportedNode, Reference< XNode >(oldRoot, UNO_QUERY_THROW));
[ # # ][ # # ]
99 : 0 : return CSubmission::SUCCESS;
100 : : } else {
101 : 0 : return CSubmission::UNKNOWN_ERROR;
102 : 0 : }
103 : : } else {
104 : : // nothing to replace
105 : 0 : return CSubmission::UNKNOWN_ERROR;
106 : : }
107 [ # # ]: 0 : } else if (aReplace.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("none"))) {
108 : : // do nothing \o/
109 : 0 : return CSubmission::SUCCESS;
110 [ # # ]: 0 : }
111 [ # # ]: 0 : } catch (const Exception& e) {
112 : 0 : ::rtl::OString aMsg("Exception during replace:\n");
113 [ # # ]: 0 : aMsg += OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8);
114 : 0 : OSL_FAIL(aMsg.getStr());
115 : : }
116 : 0 : return CSubmission::UNKNOWN_ERROR;
117 : : }
118 : :
119 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
120 : 0 : ::std::auto_ptr< CSerialization > CSubmission::createSerialization(const Reference< XInteractionHandler >& _xHandler,Reference<XCommandEnvironment>& _rOutEnv)
121 : : {
122 : : // PUT always uses application/xml
123 [ # # ]: 0 : ::std::auto_ptr< CSerialization > apSerialization(new CSerializationAppXML());
124 [ # # ]: 0 : apSerialization->setSource(m_aFragment);
125 [ # # ]: 0 : apSerialization->serialize();
126 : :
127 : : // create a commandEnvironment and use the default interaction handler
128 [ # # ]: 0 : CCommandEnvironmentHelper *pHelper = new CCommandEnvironmentHelper;
129 [ # # ]: 0 : if( _xHandler.is() )
130 [ # # ]: 0 : pHelper->m_aInteractionHandler = _xHandler;
131 : : else
132 [ # # ]: 0 : pHelper->m_aInteractionHandler = CSS::uno::Reference< XInteractionHandler >(m_aFactory->createInstance(
133 [ # # ][ # # ]: 0 : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.task.InteractionHandler") ) ), UNO_QUERY);
[ # # ][ # # ]
134 : : OSL_ENSURE(pHelper->m_aInteractionHandler.is(), "failed to create IntreractionHandler");
135 : :
136 [ # # ]: 0 : CProgressHandlerHelper *pProgressHelper = new CProgressHandlerHelper;
137 [ # # ][ # # ]: 0 : pHelper->m_aProgressHandler = Reference< XProgressHandler >(pProgressHelper);
[ # # ]
138 : :
139 : : // UCB has ownership of environment...
140 [ # # ][ # # ]: 0 : _rOutEnv = pHelper;
141 : 0 : return apSerialization;
142 : : }
143 : : SAL_WNODEPRECATED_DECLARATIONS_POP
144 : :
145 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|