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

Generated by: LCOV version 1.10