Xlat_MsgCatalog.cpp
上传用户:huihehuasu
上传日期:2007-01-10
资源大小:6948k
文件大小:7k
源码类别:

xml/soap/webservice

开发平台:

C/C++

  1. /*
  2.  * The Apache Software License, Version 1.1
  3.  * 
  4.  * Copyright (c) 1999-2000 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  * 
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  * 
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer. 
  13.  * 
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  * 
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:  
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  * 
  26.  * 4. The names "Xerces" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written 
  29.  *    permission, please contact apache@apache.org.
  30.  * 
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  * 
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  * 
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation, and was
  51.  * originally based on software copyright (c) 1999, International
  52.  * Business Machines, Inc., http://www.ibm.com .  For more information
  53.  * on the Apache Software Foundation, please see
  54.  * <http://www.apache.org/>.
  55.  */
  56. /*
  57.  * $Log: Xlat_MsgCatalog.cpp,v $
  58.  * Revision 1.5  2000/03/02 19:55:53  roddey
  59.  * This checkin includes many changes done while waiting for the
  60.  * 1.1.0 code to be finished. I can't list them all here, but a list is
  61.  * available elsewhere.
  62.  *
  63.  * Revision 1.4  2000/02/06 07:48:42  rahulj
  64.  * Year 2K copyright swat.
  65.  *
  66.  * Revision 1.3  2000/01/05 20:24:58  roddey
  67.  * Some changes to simplify life for the Messge Catalog message loader. The formatter
  68.  * for the message loader now spits out a simple header of ids that allows the loader to
  69.  * be independent of hard coded set numbers.
  70.  *
  71.  * Revision 1.2  1999/12/20 22:51:09  roddey
  72.  * Updated to deal with the new transcoder interface.
  73.  *
  74.  * Revision 1.1.1.1  1999/11/09 01:01:24  twl
  75.  * Initial checkin
  76.  *
  77.  * Revision 1.5  1999/11/08 20:42:06  rahul
  78.  * Swat for adding in Product name and CVS comment log variable.
  79.  *
  80.  */
  81. // ---------------------------------------------------------------------------
  82. //  Includes
  83. // ---------------------------------------------------------------------------
  84. #include "Xlat.hpp"
  85. // ---------------------------------------------------------------------------
  86. //  MsgCatFormatter: Constructors and Destructor
  87. // ---------------------------------------------------------------------------
  88. MsgCatFormatter::MsgCatFormatter() :
  89.     fOutFl(0)
  90.     , fTranscoder(0)
  91. {
  92.     //
  93.     //  Try to create a transcoder for the format that we were told
  94.     //  to output in.
  95.     //
  96.     //  <TBD> Right now we are just using an LCP transcoding, which is not
  97.     //  really the right thing to do!
  98.     //
  99.     fTranscoder = XMLPlatformUtils::fgTransService->makeNewLCPTranscoder();
  100.     if (!fTranscoder)
  101.     {
  102.         wprintf(L"Could not create LCP transcodern");
  103.         throw ErrReturn_NoTranscoder;
  104.     }
  105. }
  106. MsgCatFormatter::~MsgCatFormatter()
  107. {
  108. }
  109. // ---------------------------------------------------------------------------
  110. //  MsgCatFormatter: Implementation of the formatter interface
  111. // ---------------------------------------------------------------------------
  112. void MsgCatFormatter::endDomain(const   XMLCh* const    domainName
  113.                                 , const unsigned int    msgCount)
  114. {
  115.     fwprintf(fOutFl, L"nn");
  116. }
  117. void MsgCatFormatter::endMsgType(const MsgTypes type)
  118. {
  119. }
  120. void MsgCatFormatter::endOutput()
  121. {
  122.     // Close the output files
  123.     fclose(fOutFl);
  124.     fclose(fOutHpp);
  125. }
  126. void
  127. MsgCatFormatter::nextMessage(const  XMLCh* const            msgText
  128.                             , const XMLCh* const            msgId
  129.                             , const unsigned int            messageId
  130.                             , const unsigned int            curId)
  131. {
  132.     //
  133.     //  We have to transcode the message text to UTF-8 in order to be able
  134.     //  to write it out to a message catalog (which is not Unicode enabled.)
  135.     //  If the text is just US-ASCII, this won't have any effect, but don't
  136.     //  bother checking, just do it simple and stupid.
  137.     //
  138.     char* outData = fTranscoder->transcode(msgText);
  139.     fwprintf(fOutFl, L"%3d  %Sn", curId, outData);
  140.     delete [] outData;
  141. }
  142. void MsgCatFormatter::startDomain(  const   XMLCh* const    domainName
  143.                                     , const XMLCh* const    nameSpace)
  144. {
  145.     // Output a constant to the header file
  146.     fwprintf(fOutHpp, L"const unsigned int CatId_%s = %d;n", nameSpace, fSeqId);
  147.     //
  148.     //  Output the leading part of the array declaration. Its just an
  149.     //  array of pointers to Unicode chars.
  150.     //
  151.     fwprintf(fOutFl, L"$set %un", fSeqId);
  152.     // And bump the sequence id
  153.     fSeqId++;
  154. }
  155. void MsgCatFormatter::startMsgType(const MsgTypes type)
  156. {
  157. }
  158. void MsgCatFormatter::startOutput(  const   XMLCh* const    locale
  159.                                     , const XMLCh* const    outPath)
  160. {
  161.     //
  162.     //  Ok, lets try to open the the output file. All of the messages
  163.     //  for all the domains are put into a single Msg file, which can be
  164.     //  compiled into the program.
  165.     //
  166.     //  CppErrMsgs_xxxx.Msg
  167.     //
  168.     //  where xxx is the locale suffix passed in.
  169.     //
  170.     const unsigned int bufSize = 4095;
  171.     XMLCh tmpBuf[bufSize + 1];
  172.     swprintf(tmpBuf, L"%s/%s_%s.Msg", outPath, L"XMLMsgCat", locale);
  173.     fOutFl = _wfopen(tmpBuf, L"wt");
  174.     if (!fOutFl)
  175.     {
  176.         wprintf(L"Could not open the output file: %snn", tmpBuf);
  177.         throw ErrReturn_OutFileOpenFailed;
  178.     }
  179.     // Set the message delimiter
  180.     fwprintf(fOutFl, L"$quote "n");
  181.     swprintf(tmpBuf, L"%s/%s.hpp", outPath, L"XMLMsgCat_Ids");
  182.     fOutHpp = _wfopen(tmpBuf, L"wt");
  183.     if (!fOutHpp)
  184.     {
  185.         wprintf(L"Could not open the output file: %snn", tmpBuf);
  186.         throw ErrReturn_OutFileOpenFailed;
  187.     }
  188.     // Reset the sequence id
  189.     fSeqId = 1;
  190. }