LCOV - code coverage report
Current view: top level - unoxml/source/rdf - CLiteral.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 48 59 81.4 %
Date: 2014-11-03 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         972 :     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         486 : CLiteral::CLiteral(css::uno::Reference< css::uno::XComponentContext > const & context) :
      73         486 :     m_xContext(context), m_Value(), m_Language(), m_xDatatype()
      74         486 : {}
      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         486 : void SAL_CALL CLiteral::initialize(const css::uno::Sequence< css::uno::Any > & aArguments) throw (css::uno::RuntimeException, css::uno::Exception, std::exception)
      94             : {
      95         486 :     const sal_Int32 len( aArguments.getLength() );
      96         486 :     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         486 :     OUString arg0;
     103         486 :     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         486 :         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         486 :     if (len > 1) {
     118          88 :         OUString arg1;
     119         176 :         css::uno::Reference< css::rdf::XURI > xURI;
     120          88 :         if ((aArguments[1] >>= arg1)) {
     121          12 :             if (!arg1.isEmpty()) {
     122          12 :                 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          76 :         } else if ((aArguments[1] >>= xURI)) {
     129          76 :             if (xURI.is()) {
     130          76 :                 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          88 :         }
     141         486 :     }
     142         486 : }
     143             : 
     144             : // css::rdf::XNode:
     145         368 : OUString SAL_CALL CLiteral::getStringValue() throw (css::uno::RuntimeException, std::exception)
     146             : {
     147         368 :     if (!m_Language.isEmpty()) {
     148          22 :         OUStringBuffer buf(m_Value);
     149          22 :         buf.appendAscii("@");
     150          22 :         buf.append(m_Language);
     151          22 :         return buf.makeStringAndClear();
     152         346 :     } else if (m_xDatatype.is()) {
     153          92 :         OUStringBuffer buf(m_Value);
     154          92 :         buf.appendAscii("^^");
     155          92 :         buf.append(m_xDatatype->getStringValue());
     156          92 :         return buf.makeStringAndClear();
     157             :     } else {
     158         254 :         return m_Value;
     159             :     }
     160             : }
     161             : 
     162             : // css::rdf::XLiteral:
     163         238 : OUString SAL_CALL CLiteral::getValue() throw (css::uno::RuntimeException, std::exception)
     164             : {
     165         238 :     return m_Value;
     166             : }
     167             : 
     168          86 : OUString SAL_CALL CLiteral::getLanguage() throw (css::uno::RuntimeException, std::exception)
     169             : {
     170          86 :     return m_Language;
     171             : }
     172             : 
     173         120 : css::uno::Reference< css::rdf::XURI > SAL_CALL CLiteral::getDatatype() throw (css::uno::RuntimeException, std::exception)
     174             : {
     175         120 :     return m_xDatatype;
     176             : }
     177             : 
     178             : } // closing anonymous implementation namespace
     179             : 
     180             : 
     181             : 
     182             : // component helper namespace
     183             : namespace comp_CLiteral {
     184             : 
     185         140 : OUString SAL_CALL _getImplementationName() {
     186         140 :     return OUString( "CLiteral");
     187             : }
     188             : 
     189           6 : css::uno::Sequence< OUString > SAL_CALL _getSupportedServiceNames()
     190             : {
     191           6 :     css::uno::Sequence< OUString > s(1);
     192           6 :     s[0] = "com.sun.star.rdf.Literal";
     193           6 :     return s;
     194             : }
     195             : 
     196         486 : css::uno::Reference< css::uno::XInterface > SAL_CALL _create(
     197             :     const css::uno::Reference< css::uno::XComponentContext > & context)
     198             : {
     199         486 :     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.10