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

Generated by: LCOV version 1.11