LCOV - code coverage report
Current view: top level - l10ntools/source - uimerge.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 96 0.0 %
Date: 2015-06-13 12:38:46 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 (reinterpret_cast<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 g=\"" << aI->second->sGID.getStr() << "\" i=\""
     117           0 :                 << aI->second->sLID.getStr() << "\">"
     118           0 :                 << helper::QuotHTML(sOut).getStr() << "</e>\n";
     119           0 :         }
     120             : 
     121           0 :         aDestination << "</t>";
     122           0 :         aDestination.close();
     123             : 
     124           0 :         return true;
     125             :     }
     126             : 
     127             : }
     128             : 
     129           0 : bool Merge(
     130             :     const OString &rPOFile,
     131             :     const OString &rSourceFile,
     132             :     const OString &rDestinationDir,
     133             :     const OString &rLanguage )
     134             : {
     135             :     {
     136           0 :         bool bDestinationIsDir(false);
     137             : 
     138           0 :         const OUString aDestDir(OStringToOUString(rDestinationDir, RTL_TEXTENCODING_UTF8));
     139           0 :         OUString aDestDirUrl;
     140           0 :         if (osl::FileBase::E_None == osl::FileBase::getFileURLFromSystemPath(aDestDir, aDestDirUrl))
     141             :         {
     142           0 :             osl::DirectoryItem aTmp;
     143           0 :             if (osl::DirectoryItem::E_None == osl::DirectoryItem::get(aDestDirUrl, aTmp))
     144             :             {
     145           0 :                 osl::FileStatus aDestinationStatus(osl_FileStatus_Mask_Type);
     146           0 :                 if (osl::DirectoryItem::E_None == aTmp.getFileStatus(aDestinationStatus))
     147           0 :                     bDestinationIsDir = aDestinationStatus.isDirectory();
     148           0 :             }
     149             :         }
     150             : 
     151           0 :         if (!bDestinationIsDir)
     152             :         {
     153           0 :             fprintf(stderr, "%s must be a directory\n", rDestinationDir.getStr());
     154           0 :             return false;
     155           0 :         }
     156             :     }
     157             : 
     158           0 :     MergeDataFile aMergeDataFile( rPOFile, rSourceFile, false );
     159           0 :     std::vector<OString> aLanguages;
     160           0 :     if( rLanguage.equalsIgnoreAsciiCase("ALL") )
     161           0 :         aLanguages = aMergeDataFile.GetLanguages();
     162             :     else
     163           0 :         aLanguages.push_back(rLanguage);
     164             : 
     165           0 :     const MergeDataHashMap& rMap = aMergeDataFile.getMap();
     166           0 :     const OString aDestinationDir(rDestinationDir + "/");
     167             : 
     168           0 :     bool bResult = true;
     169           0 :     for(size_t n = 0; n < aLanguages.size(); ++n)
     170             :     {
     171           0 :         OString sCur = aLanguages[ n ];
     172           0 :         if (sCur.isEmpty() || sCur.equalsIgnoreAsciiCase("en-US"))
     173           0 :             continue;
     174           0 :         const OString aDestinationFile(aDestinationDir + sCur + ".ui");
     175           0 :         if (!lcl_MergeLang(rMap, sCur, aDestinationFile))
     176           0 :             bResult = false;
     177           0 :     }
     178             : 
     179           0 :     return bResult;
     180             : }
     181             : 
     182           0 : SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
     183             : {
     184           0 :     int nRetValue = 0;
     185             : 
     186           0 :     common::HandledArgs aArgs;
     187           0 :     if ( !common::handleArguments(argc, argv, aArgs) )
     188             :     {
     189           0 :         common::writeUsage("uiex","*.ui");
     190           0 :         return 1;
     191             :     }
     192             : 
     193           0 :     sInputFileName = aArgs.m_sInputFile;
     194           0 :     sOutputFile = aArgs.m_sOutputFile;
     195             : 
     196           0 :     if (!aArgs.m_bMergeMode)
     197             :     {
     198           0 :         nRetValue = extractTranslations();
     199             :     }
     200             :     else
     201             :     {
     202           0 :         Merge(aArgs.m_sMergeSrc, sInputFileName, sOutputFile, aArgs.m_sLanguage);
     203             :     }
     204             : 
     205           0 :     return nRetValue;
     206           0 : }
     207             : 
     208             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11