LCOV - code coverage report
Current view: top level - unoxml/source/rdf - CLiteral.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 48 59 81.4 %
Date: 2014-04-11 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 <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         486 :     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         243 : CLiteral::CLiteral(css::uno::Reference< css::uno::XComponentContext > const & context) :
      74         243 :     m_xContext(context), m_Value(), m_Language(), m_xDatatype()
      75         243 : {}
      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         243 : 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         243 :     const sal_Int32 len( aArguments.getLength() );
      97         243 :     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         243 :     OUString arg0;
     104         243 :     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         243 :         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         243 :     if (len > 1) {
     119          44 :         OUString arg1;
     120          88 :         css::uno::Reference< css::rdf::XURI > xURI;
     121          44 :         if ((aArguments[1] >>= arg1)) {
     122           6 :             if (!arg1.isEmpty()) {
     123           6 :                 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          38 :         } else if ((aArguments[1] >>= xURI)) {
     130          38 :             if (xURI.is()) {
     131          38 :                 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          44 :         }
     142         243 :     }
     143         243 : }
     144             : 
     145             : // ::com::sun::star::rdf::XNode:
     146         184 : OUString SAL_CALL CLiteral::getStringValue() throw (css::uno::RuntimeException, std::exception)
     147             : {
     148         184 :     if (!m_Language.isEmpty()) {
     149          11 :         OUStringBuffer buf(m_Value);
     150          11 :         buf.appendAscii("@");
     151          11 :         buf.append(m_Language);
     152          11 :         return buf.makeStringAndClear();
     153         173 :     } else if (m_xDatatype.is()) {
     154          46 :         OUStringBuffer buf(m_Value);
     155          46 :         buf.appendAscii("^^");
     156          46 :         buf.append(m_xDatatype->getStringValue());
     157          46 :         return buf.makeStringAndClear();
     158             :     } else {
     159         127 :         return m_Value;
     160             :     }
     161             : }
     162             : 
     163             : // ::com::sun::star::rdf::XLiteral:
     164         119 : OUString SAL_CALL CLiteral::getValue() throw (css::uno::RuntimeException, std::exception)
     165             : {
     166         119 :     return m_Value;
     167             : }
     168             : 
     169          43 : OUString SAL_CALL CLiteral::getLanguage() throw (css::uno::RuntimeException, std::exception)
     170             : {
     171          43 :     return m_Language;
     172             : }
     173             : 
     174          60 : css::uno::Reference< css::rdf::XURI > SAL_CALL CLiteral::getDatatype() throw (css::uno::RuntimeException, std::exception)
     175             : {
     176          60 :     return m_xDatatype;
     177             : }
     178             : 
     179             : } // closing anonymous implementation namespace
     180             : 
     181             : 
     182             : 
     183             : // component helper namespace
     184             : namespace comp_CLiteral {
     185             : 
     186          62 : OUString SAL_CALL _getImplementationName() {
     187          62 :     return OUString( "CLiteral");
     188             : }
     189             : 
     190           3 : css::uno::Sequence< OUString > SAL_CALL _getSupportedServiceNames()
     191             : {
     192           3 :     css::uno::Sequence< OUString > s(1);
     193           3 :     s[0] = "com.sun.star.rdf.Literal";
     194           3 :     return s;
     195             : }
     196             : 
     197         243 : 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         243 :     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