LCOV - code coverage report
Current view: top level - libreoffice/unoxml/source/rdf - CLiteral.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 63 0.0 %
Date: 2012-12-27 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 <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           0 :     virtual ~CLiteral() {}
      44             : 
      45             :     // ::com::sun::star::lang::XServiceInfo:
      46             :     virtual ::rtl::OUString SAL_CALL getImplementationName() throw (css::uno::RuntimeException);
      47             :     virtual ::sal_Bool SAL_CALL supportsService(const ::rtl::OUString & ServiceName) throw (css::uno::RuntimeException);
      48             :     virtual css::uno::Sequence< ::rtl::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 ::rtl::OUString SAL_CALL getStringValue() throw (css::uno::RuntimeException);
      55             : 
      56             :     // ::com::sun::star::rdf::XLiteral:
      57             :     virtual ::rtl::OUString SAL_CALL getValue() throw (css::uno::RuntimeException);
      58             :     virtual ::rtl::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             :     ::rtl::OUString m_Value;
      68             :     ::rtl::OUString m_Language;
      69             :     css::uno::Reference< css::rdf::XURI > m_xDatatype;
      70             : };
      71             : 
      72           0 : CLiteral::CLiteral(css::uno::Reference< css::uno::XComponentContext > const & context) :
      73           0 :     m_xContext(context), m_Value(), m_Language(), m_xDatatype()
      74           0 : {}
      75             : 
      76             : // com.sun.star.uno.XServiceInfo:
      77           0 : ::rtl::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(::rtl::OUString const & serviceName) throw (css::uno::RuntimeException)
      83             : {
      84           0 :     css::uno::Sequence< ::rtl::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< ::rtl::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           0 : void SAL_CALL CLiteral::initialize(const css::uno::Sequence< ::com::sun::star::uno::Any > & aArguments) throw (css::uno::RuntimeException, css::uno::Exception)
      99             : {
     100           0 :     const sal_Int32 len( aArguments.getLength() );
     101           0 :     if (len < 1 || len > 2) {
     102             :             throw css::lang::IllegalArgumentException(
     103             :                 ::rtl::OUString("CLiteral::initialize: "
     104           0 :                     "must give 1 or 2 argument(s)"), *this, 2);
     105             :     }
     106             : 
     107           0 :     ::rtl::OUString arg0;
     108           0 :     if (!(aArguments[0] >>= arg0)) {
     109             :         throw css::lang::IllegalArgumentException(
     110             :             ::rtl::OUString("CLiteral::initialize: "
     111           0 :                 "argument must be string"), *this, 0);
     112             :     }
     113             :     //FIXME: what is legal?
     114             :     if (true) {
     115           0 :         m_Value = arg0;
     116             :     } else {
     117             :         throw css::lang::IllegalArgumentException(
     118             :             ::rtl::OUString("CLiteral::initialize: "
     119             :                 "argument is not valid literal value"), *this, 0);
     120             :     }
     121             : 
     122           0 :     if (len > 1) {
     123           0 :         ::rtl::OUString arg1;
     124           0 :         css::uno::Reference< css::rdf::XURI > xURI;
     125           0 :         if ((aArguments[1] >>= arg1)) {
     126           0 :             if (!arg1.isEmpty()) {
     127           0 :                 m_Language = arg1;
     128             :             } else {
     129             :                 throw css::lang::IllegalArgumentException(
     130             :                     ::rtl::OUString("CLiteral::initialize: "
     131           0 :                         "argument is not valid language"), *this, 1);
     132             :             }
     133           0 :         } else if ((aArguments[1] >>= xURI)) {
     134           0 :             if (xURI.is()) {
     135           0 :                 m_xDatatype = xURI;
     136             :             } else {
     137             :                 throw css::lang::IllegalArgumentException(
     138             :                     ::rtl::OUString("CLiteral::initialize: "
     139           0 :                         "argument is null"), *this, 1);
     140             :             }
     141             :         } else {
     142             :             throw css::lang::IllegalArgumentException(
     143             :                 ::rtl::OUString("CLiteral::initialize: "
     144           0 :                     "argument must be string or URI"), *this, 1);
     145           0 :         }
     146           0 :     }
     147           0 : }
     148             : 
     149             : // ::com::sun::star::rdf::XNode:
     150           0 : ::rtl::OUString SAL_CALL CLiteral::getStringValue() throw (css::uno::RuntimeException)
     151             : {
     152           0 :     if (!m_Language.isEmpty()) {
     153           0 :         ::rtl::OUStringBuffer buf(m_Value);
     154           0 :         buf.appendAscii("@");
     155           0 :         buf.append(m_Language);
     156           0 :         return buf.makeStringAndClear();
     157           0 :     } else if (m_xDatatype.is()) {
     158           0 :         ::rtl::OUStringBuffer buf(m_Value);
     159           0 :         buf.appendAscii("^^");
     160           0 :         buf.append(m_xDatatype->getStringValue());
     161           0 :         return buf.makeStringAndClear();
     162             :     } else {
     163           0 :         return m_Value;
     164             :     }
     165             : }
     166             : 
     167             : // ::com::sun::star::rdf::XLiteral:
     168           0 : ::rtl::OUString SAL_CALL CLiteral::getValue() throw (css::uno::RuntimeException)
     169             : {
     170           0 :     return m_Value;
     171             : }
     172             : 
     173           0 : ::rtl::OUString SAL_CALL CLiteral::getLanguage() throw (css::uno::RuntimeException)
     174             : {
     175           0 :     return m_Language;
     176             : }
     177             : 
     178           0 : css::uno::Reference< css::rdf::XURI > SAL_CALL CLiteral::getDatatype() throw (css::uno::RuntimeException)
     179             : {
     180           0 :     return m_xDatatype;
     181             : }
     182             : 
     183             : } // closing anonymous implementation namespace
     184             : 
     185             : 
     186             : 
     187             : // component helper namespace
     188             : namespace comp_CLiteral {
     189             : 
     190           0 : ::rtl::OUString SAL_CALL _getImplementationName() {
     191           0 :     return ::rtl::OUString( "CLiteral");
     192             : }
     193             : 
     194           0 : css::uno::Sequence< ::rtl::OUString > SAL_CALL _getSupportedServiceNames()
     195             : {
     196           0 :     css::uno::Sequence< ::rtl::OUString > s(1);
     197           0 :     s[0] = ::rtl::OUString( "com.sun.star.rdf.Literal");
     198           0 :     return s;
     199             : }
     200             : 
     201           0 : 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           0 :     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