LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/l10ntools/source - uimerge.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 97 0.0 %
Date: 2013-07-09 Functions: 0 7 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             : 
      10             : #include <sal/main.h>
      11             : 
      12             : #include <osl/file.hxx>
      13             : 
      14             : #include <rtl/strbuf.hxx>
      15             : 
      16             : #include <libexslt/exslt.h>
      17             : #include <libxslt/transform.h>
      18             : #include <libxslt/xslt.h>
      19             : #include <libxslt/xsltutils.h>
      20             : 
      21             : #include <stdio.h>
      22             : 
      23             : #include "common.hxx"
      24             : #include "helper.hxx"
      25             : #include "export.hxx"
      26             : #include "tokens.h"
      27             : #include "po.hxx"
      28             : #include <iostream>
      29             : #include <fstream>
      30             : #include <vector>
      31             : 
      32           0 : OString sInputFileName;
      33           0 : OString sOutputFile;
      34             : 
      35           0 : int extractTranslations()
      36             : {
      37           0 :     PoOfstream aPOStream( sOutputFile, PoOfstream::APP);
      38           0 :     if (!aPOStream.isOpen())
      39             :     {
      40           0 :         fprintf(stderr, "cannot open %s\n", sOutputFile.getStr());
      41           0 :         return 1;
      42             :     }
      43             : 
      44           0 :     exsltRegisterAll();
      45             : 
      46           0 :     OString sStyleSheet = OString(getenv("SRC_ROOT"))  + OString("/solenv/bin/uilangfilter.xslt");
      47             : 
      48           0 :     xsltStylesheetPtr stylesheet = xsltParseStylesheetFile ((const xmlChar *)sStyleSheet.getStr());
      49             : 
      50           0 :     xmlDocPtr doc = xmlParseFile(sInputFileName.getStr());
      51             : 
      52           0 :     xmlDocPtr res = xsltApplyStylesheet(stylesheet, doc, NULL);
      53             : 
      54           0 :     for( xmlNodePtr nodeLevel1 = res->children; nodeLevel1 != NULL; nodeLevel1 = nodeLevel1->next)
      55             :     {
      56           0 :         for( xmlNodePtr nodeLevel2 = nodeLevel1->children; nodeLevel2 != NULL; nodeLevel2 = nodeLevel2->next)
      57             :         {
      58           0 :             if (nodeLevel2->type == XML_ELEMENT_NODE)
      59             :             {
      60           0 :                 std::vector<OString> vIDs;
      61           0 :                 for(xmlAttrPtr attribute = nodeLevel2->properties; attribute != NULL; attribute = attribute->next)
      62             :                 {
      63           0 :                     xmlChar *content = xmlNodeListGetString(res, attribute->children, 1);
      64           0 :                     vIDs.push_back(helper::xmlStrToOString(content));
      65           0 :                     xmlFree(content);
      66             :                 }
      67           0 :                 OString sText = helper::UnQuotHTML(helper::xmlStrToOString(xmlNodeGetContent(nodeLevel2)));
      68             :                 common::writePoEntry(
      69           0 :                     "Uiex", aPOStream, sInputFileName, vIDs[0],
      70           0 :                     (vIDs.size()>=2) ? vIDs[1] : OString(),
      71           0 :                     (vIDs.size()>=3) ? vIDs[2] : OString(),
      72           0 :                     OString(), sText);
      73             :             }
      74             :         }
      75             :     }
      76             : 
      77           0 :     xmlFreeDoc(res);
      78             : 
      79           0 :     xmlFreeDoc(doc);
      80             : 
      81           0 :     xsltFreeStylesheet(stylesheet);
      82             : 
      83           0 :     aPOStream.close();
      84             : 
      85           0 :     return 0;
      86             : }
      87             : 
      88             : namespace
      89             : {
      90           0 :     bool lcl_MergeLang(
      91             :             const MergeDataHashMap &rMap,
      92             :             const OString &rLanguage,
      93             :             const OString &rDestinationFile)
      94             :     {
      95             :         std::ofstream aDestination(
      96           0 :             rDestinationFile.getStr(), std::ios_base::out | std::ios_base::trunc);
      97           0 :         if (!aDestination.is_open()) {
      98           0 :             return false;
      99             :         }
     100             : 
     101           0 :         aDestination << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
     102           0 :         aDestination << "<t>\n";
     103             : 
     104           0 :         for (MergeDataHashMap::const_iterator aI = rMap.begin(), aEnd = rMap.end(); aI != aEnd; ++aI)
     105             :         {
     106           0 :             if (aI->second->sGID.isEmpty())
     107           0 :                 continue;
     108             : 
     109           0 :             MergeEntrys* pEntrys = aI->second->GetMergeEntries();
     110           0 :             OString sOut;
     111           0 :             pEntrys->GetText( sOut, STRING_TYP_TEXT, rLanguage );
     112             : 
     113           0 :             if (sOut.isEmpty())
     114           0 :                 continue;
     115             : 
     116           0 :             aDestination << " <e "
     117           0 :                 << "g=\"" << aI->second->sGID.getStr() << "\" "
     118           0 :                 << "i=\"" << aI->second->sLID.getStr() << "\">"
     119           0 :                 << helper::QuotHTML(sOut).getStr() << "</e>\n";
     120           0 :         }
     121             : 
     122           0 :         aDestination << "</t>";
     123           0 :         aDestination.close();
     124             : 
     125           0 :         return true;
     126             :     }
     127             : 
     128             : }
     129             : 
     130           0 : bool Merge(
     131             :     const OString &rPOFile,
     132             :     const OString &rSourceFile,
     133             :     const OString &rDestinationDir,
     134             :     const OString &rLanguage )
     135             : {
     136             :     {
     137           0 :         bool bDestinationIsDir(false);
     138             : 
     139           0 :         const OUString aDestDir(OStringToOUString(rDestinationDir, RTL_TEXTENCODING_UTF8));
     140           0 :         OUString aDestDirUrl;
     141           0 :         if (osl::FileBase::E_None == osl::FileBase::getFileURLFromSystemPath(aDestDir, aDestDirUrl))
     142             :         {
     143           0 :             osl::DirectoryItem aTmp;
     144           0 :             if (osl::DirectoryItem::E_None == osl::DirectoryItem::get(aDestDirUrl, aTmp))
     145             :             {
     146           0 :                 osl::FileStatus aDestinationStatus(osl_FileStatus_Mask_Type);
     147           0 :                 if (osl::DirectoryItem::E_None == aTmp.getFileStatus(aDestinationStatus))
     148           0 :                     bDestinationIsDir = aDestinationStatus.isDirectory();
     149           0 :             }
     150             :         }
     151             : 
     152           0 :         if (!bDestinationIsDir)
     153             :         {
     154           0 :             fprintf(stderr, "%s must be a directory\n", rDestinationDir.getStr());
     155           0 :             return false;
     156           0 :         }
     157             :     }
     158             : 
     159           0 :     MergeDataFile aMergeDataFile( rPOFile, rSourceFile, sal_False );
     160           0 :     std::vector<OString> aLanguages;
     161           0 :     if( rLanguage.equalsIgnoreAsciiCase("ALL") )
     162           0 :         aLanguages = aMergeDataFile.GetLanguages();
     163             :     else
     164           0 :         aLanguages.push_back(rLanguage);
     165             : 
     166           0 :     const MergeDataHashMap& rMap = aMergeDataFile.getMap();
     167           0 :     const OString aDestinationDir(rDestinationDir + "/");
     168             : 
     169           0 :     bool bResult = true;
     170           0 :     for(size_t n = 0; n < aLanguages.size(); ++n)
     171             :     {
     172           0 :         OString sCur = aLanguages[ n ];
     173           0 :         if (sCur.isEmpty() || sCur.equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("en-US")))
     174           0 :             continue;
     175           0 :         const OString aDestinationFile(aDestinationDir + sCur + ".ui");
     176           0 :         if (!lcl_MergeLang(rMap, sCur, aDestinationFile))
     177           0 :             bResult = false;
     178           0 :     }
     179             : 
     180           0 :     return bResult;
     181             : }
     182             : 
     183           0 : SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
     184             : {
     185           0 :     int nRetValue = 0;
     186             : 
     187           0 :     common::HandledArgs aArgs;
     188           0 :     if ( !common::handleArguments(argc, argv, aArgs) )
     189             :     {
     190           0 :         common::writeUsage("uiex","*.ui");
     191           0 :         return 1;
     192             :     }
     193             : 
     194           0 :     sInputFileName = aArgs.m_sInputFile;
     195           0 :     sOutputFile = aArgs.m_sOutputFile;
     196             : 
     197           0 :     if (!aArgs.m_bMergeMode)
     198             :     {
     199           0 :         nRetValue = extractTranslations();
     200             :     }
     201             :     else
     202             :     {
     203           0 :         Merge(aArgs.m_sMergeSrc, sInputFileName, sOutputFile, aArgs.m_sLanguage);
     204             :     }
     205             : 
     206           0 :     return nRetValue;
     207           0 : }
     208             : 
     209             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10