LCOV - code coverage report
Current view: top level - unoxml/source/rdf - CLiteral.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 59 0.0 %
Date: 2014-04-14 Functions: 0 14 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 "CNodes.hxx"
      21             : 
      22             : #include <cppuhelper/implbase3.hxx>
      23             : #include <cppuhelper/supportsservice.hxx>
      24             : #include <com/sun/star/lang/XServiceInfo.hpp>
      25             : #include <com/sun/star/lang/XInitialization.hpp>
      26             : #include <com/sun/star/rdf/XLiteral.hpp>
      27             : 
      28             : #include <com/sun/star/lang/IllegalArgumentException.hpp>
      29             : 
      30             : #include <rtl/ustrbuf.hxx>
      31             : 
      32             : 
      33             : /// anonymous implementation namespace
      34             : namespace {
      35             : 
      36             : class CLiteral:
      37             :     public ::cppu::WeakImplHelper3<
      38             :         css::lang::XServiceInfo,
      39             :         css::lang::XInitialization,
      40             :         css::rdf::XLiteral>
      41             : {
      42             : public:
      43             :     explicit CLiteral(css::uno::Reference< css::uno::XComponentContext > const & context);
      44           0 :     virtual ~CLiteral() {}
      45             : 
      46             :     // ::com::sun::star::lang::XServiceInfo:
      47             :     virtual OUString SAL_CALL getImplementationName() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      48             :     virtual sal_Bool SAL_CALL supportsService(const OUString & ServiceName) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      49             :     virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      50             : 
      51             :     // ::com::sun::star::lang::XInitialization:
      52             :     virtual void SAL_CALL initialize(const css::uno::Sequence< ::com::sun::star::uno::Any > & aArguments) throw (css::uno::RuntimeException, css::uno::Exception, std::exception) SAL_OVERRIDE;
      53             : 
      54             :     // ::com::sun::star::rdf::XNode:
      55             :     virtual OUString SAL_CALL getStringValue() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      56             : 
      57             :     // ::com::sun::star::rdf::XLiteral:
      58             :     virtual OUString SAL_CALL getValue() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      59             :     virtual OUString SAL_CALL getLanguage() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      60             :     virtual css::uno::Reference< css::rdf::XURI > SAL_CALL getDatatype() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      61             : 
      62             : private:
      63             :     CLiteral(const CLiteral &); // not defined
      64             :     CLiteral& operator=(const CLiteral &); // not defined
      65             : 
      66             :     css::uno::Reference< css::uno::XComponentContext > m_xContext;
      67             : 
      68             :     OUString m_Value;
      69             :     OUString m_Language;
      70             :     css::uno::Reference< css::rdf::XURI > m_xDatatype;
      71             : };
      72             : 
      73           0 : CLiteral::CLiteral(css::uno::Reference< css::uno::XComponentContext > const & context) :
      74           0 :     m_xContext(context), m_Value(), m_Language(), m_xDatatype()
      75           0 : {}
      76             : 
      77             : // com.sun.star.uno.XServiceInfo:
      78           0 : OUString SAL_CALL CLiteral::getImplementationName() throw (css::uno::RuntimeException, std::exception)
      79             : {
      80           0 :     return comp_CLiteral::_getImplementationName();
      81             : }
      82             : 
      83           0 : sal_Bool SAL_CALL CLiteral::supportsService(OUString const & serviceName) throw (css::uno::RuntimeException, std::exception)
      84             : {
      85           0 :     return cppu::supportsService(this, serviceName);
      86             : }
      87             : 
      88           0 : css::uno::Sequence< OUString > SAL_CALL CLiteral::getSupportedServiceNames() throw (css::uno::RuntimeException, std::exception)
      89             : {
      90           0 :     return comp_CLiteral::_getSupportedServiceNames();
      91             : }
      92             : 
      93             : // ::com::sun::star::lang::XInitialization:
      94           0 : void SAL_CALL CLiteral::initialize(const css::uno::Sequence< ::com::sun::star::uno::Any > & aArguments) throw (css::uno::RuntimeException, css::uno::Exception, std::exception)
      95             : {
      96           0 :     const sal_Int32 len( aArguments.getLength() );
      97           0 :     if (len < 1 || len > 2) {
      98             :             throw css::lang::IllegalArgumentException(
      99             :                 OUString("CLiteral::initialize: "
     100           0 :                     "must give 1 or 2 argument(s)"), *this, 2);
     101             :     }
     102             : 
     103           0 :     OUString arg0;
     104           0 :     if (!(aArguments[0] >>= arg0)) {
     105             :         throw css::lang::IllegalArgumentException(
     106             :             OUString("CLiteral::initialize: "
     107           0 :                 "argument must be string"), *this, 0);
     108             :     }
     109             :     //FIXME: what is legal?
     110             :     if (true) {
     111           0 :         m_Value = arg0;
     112             :     } else {
     113             :         throw css::lang::IllegalArgumentException(
     114             :             OUString("CLiteral::initialize: "
     115             :                 "argument is not valid literal value"), *this, 0);
     116             :     }
     117             : 
     118           0 :     if (len > 1) {
     119           0 :         OUString arg1;
     120           0 :         css::uno::Reference< css::rdf::XURI > xURI;
     121           0 :         if ((aArguments[1] >>= arg1)) {
     122           0 :             if (!arg1.isEmpty()) {
     123           0 :                 m_Language = arg1;
     124             :             } else {
     125             :                 throw css::lang::IllegalArgumentException(
     126             :                     OUString("CLiteral::initialize: "
     127           0 :                         "argument is not valid language"), *this, 1);
     128             :             }
     129           0 :         } else if ((aArguments[1] >>= xURI)) {
     130           0 :             if (xURI.is()) {
     131           0 :                 m_xDatatype = xURI;
     132             :             } else {
     133             :                 throw css::lang::IllegalArgumentException(
     134             :                     OUString("CLiteral::initialize: "
     135           0 :                         "argument is null"), *this, 1);
     136             :             }
     137             :         } else {
     138             :             throw css::lang::IllegalArgumentException(
     139             :                 OUString("CLiteral::initialize: "
     140           0 :                     "argument must be string or URI"), *this, 1);
     141           0 :         }
     142           0 :     }
     143           0 : }
     144             : 
     145             : // ::com::sun::star::rdf::XNode:
     146           0 : OUString SAL_CALL CLiteral::getStringValue() throw (css::uno::RuntimeException, std::exception)
     147             : {
     148           0 :     if (!m_Language.isEmpty()) {
     149           0 :         OUStringBuffer buf(m_Value);
     150           0 :         buf.appendAscii("@");
     151           0 :         buf.append(m_Language);
     152           0 :         return buf.makeStringAndClear();
     153           0 :     } else if (m_xDatatype.is()) {
     154           0 :         OUStringBuffer buf(m_Value);
     155           0 :         buf.appendAscii("^^");
     156           0 :         buf.append(m_xDatatype->getStringValue());
     157           0 :         return buf.makeStringAndClear();
     158             :     } else {
     159           0 :         return m_Value;
     160             :     }
     161             : }
     162             : 
     163             : // ::com::sun::star::rdf::XLiteral:
     164           0 : OUString SAL_CALL CLiteral::getValue() throw (css::uno::RuntimeException, std::exception)
     165             : {
     166           0 :     return m_Value;
     167             : }
     168             : 
     169           0 : OUString SAL_CALL CLiteral::getLanguage() throw (css::uno::RuntimeException, std::exception)
     170             : {
     171           0 :     return m_Language;
     172             : }
     173             : 
     174           0 : css::uno::Reference< css::rdf::XURI > SAL_CALL CLiteral::getDatatype() throw (css::uno::RuntimeException, std::exception)
     175             : {
     176           0 :     return m_xDatatype;
     177             : }
     178             : 
     179             : } // closing anonymous implementation namespace
     180             : 
     181             : 
     182             : 
     183             : // component helper namespace
     184             : namespace comp_CLiteral {
     185             : 
     186           0 : OUString SAL_CALL _getImplementationName() {
     187           0 :     return OUString( "CLiteral");
     188             : }
     189             : 
     190           0 : css::uno::Sequence< OUString > SAL_CALL _getSupportedServiceNames()
     191             : {
     192           0 :     css::uno::Sequence< OUString > s(1);
     193           0 :     s[0] = "com.sun.star.rdf.Literal";
     194           0 :     return s;
     195             : }
     196             : 
     197           0 : css::uno::Reference< css::uno::XInterface > SAL_CALL _create(
     198             :     const css::uno::Reference< css::uno::XComponentContext > & context)
     199             :         SAL_THROW((css::uno::Exception))
     200             : {
     201           0 :     return static_cast< ::cppu::OWeakObject * >(new CLiteral(context));
     202             : }
     203             : 
     204             : } // closing component helper namespace
     205             : 
     206             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10