LCOV - code coverage report
Current view: top level - libreoffice/forms/source/xforms/submission - replace.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 55 0.0 %
Date: 2012-12-17 Functions: 0 2 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <memory>
      21             : #include "submission.hxx"
      22             : #include "serialization_app_xml.hxx"
      23             : 
      24             : #include <rtl/ustring.hxx>
      25             : #include <rtl/string.hxx>
      26             : 
      27             : #include <comphelper/processfactory.hxx>
      28             : #include <com/sun/star/uno/Reference.hxx>
      29             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      30             : #include <com/sun/star/xml/dom/XDocument.hpp>
      31             : #include <com/sun/star/xml/dom/DocumentBuilder.hpp>
      32             : #include <com/sun/star/frame/XComponentLoader.hpp>
      33             : #include <com/sun/star/frame/FrameSearchFlag.hpp>
      34             : #include <com/sun/star/beans/PropertyValue.hpp>
      35             : #include <com/sun/star/task/InteractionHandler.hpp>
      36             : #include <ucbhelper/content.hxx>
      37             : 
      38             : using namespace com::sun::star::uno;
      39             : using namespace com::sun::star::ucb;
      40             : using namespace com::sun::star::frame;
      41             : using namespace com::sun::star::lang;
      42             : using namespace com::sun::star::beans;
      43             : using namespace com::sun::star::task;
      44             : using namespace com::sun::star::xml::dom;
      45             : 
      46           0 : CSubmission::SubmissionResult CSubmission::replace(const ::rtl::OUString& aReplace, const Reference<XDocument>& aDocument, const Reference<XFrame>& aFrame)
      47             : {
      48           0 :     if (!m_aResultStream.is())
      49           0 :         return CSubmission::UNKNOWN_ERROR;
      50             : 
      51             :     try {
      52           0 :         Reference< XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory();
      53           0 :         Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
      54           0 :         if (aReplace.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("all"))
      55           0 :          || aReplace.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("document"))) {
      56           0 :             Reference< XComponentLoader > xLoader;
      57           0 :             if (aFrame.is())
      58           0 :                 xLoader = Reference< XComponentLoader >(aFrame, UNO_QUERY);
      59             : 
      60           0 :             if (!xLoader.is())
      61           0 :                 xLoader = Reference< XComponentLoader >(xFactory->createInstance(
      62           0 :                     ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop") ) ), UNO_QUERY_THROW);
      63             : 
      64             :             // open the stream from the result...
      65             :             // build media descriptor
      66           0 :             Sequence< PropertyValue > descriptor(2);
      67           0 :             descriptor[0] = PropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("InputStream") ),
      68           0 :                 -1, makeAny(m_aResultStream), PropertyState_DIRECT_VALUE);
      69           0 :             descriptor[1] = PropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ReadOnly") ),
      70           0 :                 -1, makeAny(sal_True), PropertyState_DIRECT_VALUE);
      71             : 
      72           0 :             ::rtl::OUString aURL = m_aURLObj.GetMainURL(INetURLObject::NO_DECODE);
      73           0 :             ::rtl::OUString aTarget = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_default") );
      74           0 :             xLoader->loadComponentFromURL(aURL, aTarget, FrameSearchFlag::ALL, descriptor);
      75             : 
      76           0 :             return CSubmission::SUCCESS;
      77             : 
      78           0 :         } else if (aReplace.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("instance"))) {
      79           0 :             if (aDocument.is()) {
      80             :                 // parse the result stream into a new document
      81           0 :                 Reference< XDocumentBuilder > xBuilder(DocumentBuilder::create(xContext));
      82           0 :                 Reference< XDocument > aNewDocument = xBuilder->parse(m_aResultStream);
      83             : 
      84           0 :                 if (aNewDocument.is()) {
      85             :                     // and replace the content of the current instance
      86           0 :                     Reference< XElement > oldRoot = aDocument->getDocumentElement();
      87           0 :                     Reference< XElement > newRoot = aNewDocument->getDocumentElement();
      88             : 
      89           0 :                     Reference< XNode > aImportedNode = aDocument->importNode(Reference< XNode >(newRoot, UNO_QUERY_THROW), sal_True);
      90           0 :                     Reference< XNode >(aDocument, UNO_QUERY_THROW)->replaceChild(aImportedNode, Reference< XNode >(oldRoot, UNO_QUERY_THROW));
      91           0 :                     return CSubmission::SUCCESS;
      92             :                 } else {
      93           0 :                     return CSubmission::UNKNOWN_ERROR;
      94           0 :                 }
      95             :             } else {
      96             :                 // nothing to replace
      97           0 :                 return CSubmission::UNKNOWN_ERROR;
      98             :             }
      99           0 :         } else if (aReplace.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("none"))) {
     100             :             // do nothing \o/
     101           0 :             return CSubmission::SUCCESS;
     102           0 :         }
     103           0 :     } catch (const Exception& e) {
     104           0 :         ::rtl::OString aMsg("Exception during replace:\n");
     105           0 :         aMsg += OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8);
     106           0 :         OSL_FAIL(aMsg.getStr());
     107             :     }
     108           0 :     return CSubmission::UNKNOWN_ERROR;
     109             : }
     110             : 
     111             : SAL_WNODEPRECATED_DECLARATIONS_PUSH
     112           0 : ::std::auto_ptr< CSerialization > CSubmission::createSerialization(const Reference< XInteractionHandler >& _xHandler,Reference<XCommandEnvironment>& _rOutEnv)
     113             : {
     114             :     // PUT always uses application/xml
     115           0 :     ::std::auto_ptr< CSerialization > apSerialization(new CSerializationAppXML());
     116           0 :     apSerialization->setSource(m_aFragment);
     117           0 :     apSerialization->serialize();
     118             : 
     119             :     // create a commandEnvironment and use the default interaction handler
     120           0 :     CCommandEnvironmentHelper *pHelper = new CCommandEnvironmentHelper;
     121           0 :     if( _xHandler.is() )
     122           0 :         pHelper->m_aInteractionHandler = _xHandler;
     123             :     else
     124             :         pHelper->m_aInteractionHandler.set(
     125           0 :             InteractionHandler::createWithParent(m_xContext, 0), UNO_QUERY_THROW);
     126             : 
     127           0 :     CProgressHandlerHelper *pProgressHelper = new CProgressHandlerHelper;
     128           0 :     pHelper->m_aProgressHandler = Reference< XProgressHandler >(pProgressHelper);
     129             : 
     130             :     // UCB has ownership of environment...
     131           0 :     _rOutEnv = pHelper;
     132           0 :     return apSerialization;
     133             : }
     134             : SAL_WNODEPRECATED_DECLARATIONS_POP
     135             : 
     136             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10