smlerror.cpp
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:13k
源码类别:

Symbian

开发平台:

Visual C++

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Source last modified: $Id: smlerror.cpp,v 1.2.12.2 2004/07/13 18:24:26 bobclark Exp $
  3.  * 
  4.  * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved.
  5.  * 
  6.  * The contents of this file, and the files included with this file,
  7.  * are subject to the current version of the RealNetworks Public
  8.  * Source License (the "RPSL") available at
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed
  10.  * the file under the current version of the RealNetworks Community
  11.  * Source License (the "RCSL") available at
  12.  * http://www.helixcommunity.org/content/rcsl, in which case the RCSL
  13.  * will apply. You may also obtain the license terms directly from
  14.  * RealNetworks.  You may not use this file except in compliance with
  15.  * the RPSL or, if you have a valid RCSL with RealNetworks applicable
  16.  * to this file, the RCSL.  Please see the applicable RPSL or RCSL for
  17.  * the rights, obligations and limitations governing use of the
  18.  * contents of the file.
  19.  * 
  20.  * Alternatively, the contents of this file may be used under the
  21.  * terms of the GNU General Public License Version 2 or later (the
  22.  * "GPL") in which case the provisions of the GPL are applicable
  23.  * instead of those above. If you wish to allow use of your version of
  24.  * this file only under the terms of the GPL, and not to allow others
  25.  * to use your version of this file under the terms of either the RPSL
  26.  * or RCSL, indicate your decision by deleting the provisions above
  27.  * and replace them with the notice and other provisions required by
  28.  * the GPL. If you do not delete the provisions above, a recipient may
  29.  * use your version of this file under the terms of any one of the
  30.  * RPSL, the RCSL or the GPL.
  31.  * 
  32.  * This file is part of the Helix DNA Technology. RealNetworks is the
  33.  * developer of the Original Code and owns the copyrights in the
  34.  * portions it created.
  35.  * 
  36.  * This file, and the files included with this file, is distributed
  37.  * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
  38.  * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
  39.  * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
  40.  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
  41.  * ENJOYMENT OR NON-INFRINGEMENT.
  42.  * 
  43.  * Technology Compatibility Kit Test Suite(s) Location:
  44.  *    http://www.helixcommunity.org/content/tck
  45.  * 
  46.  * Contributor(s):
  47.  * 
  48.  * ***** END LICENSE BLOCK ***** */
  49. #include <stdio.h>
  50. #include "hxtypes.h"
  51. #include "hxcom.h"
  52. #include "hxcomm.h"
  53. #include "hxerror.h"
  54. #include "hxxres.h"
  55. #include "hxxrsmg.h"
  56. #include "hxwintyp.h"
  57. #include "hxslist.h"
  58. #include "hxstring.h"
  59. #include "hxstack.h"
  60. #include "hxstrutl.h"
  61. #include "xmlres.h"
  62. #include "smilres.h"
  63. #include "xmlreslt.h"
  64. #include "hxxml.h"
  65. #include "hxxmlprs.h"
  66. #include "sm1parse.h"
  67. #include "sm1error.h"
  68. #ifdef _WINDOWS
  69. extern HINSTANCE g_hInstance;
  70. #endif
  71. const int MAX_ERROR_STRING = 1024;
  72. CSmil1ErrorHandler::CSmil1ErrorHandler(IUnknown* pContext):
  73.     m_pContext(pContext)
  74. {
  75.     if(m_pContext)
  76.     {
  77. m_pContext->AddRef();
  78.     }
  79. }
  80. CSmil1ErrorHandler::~CSmil1ErrorHandler()
  81. {
  82.     HX_RELEASE(m_pContext);
  83. }
  84. void
  85. CSmil1ErrorHandler::Report(const char* pErrorText)
  86. {
  87.     IHXErrorMessages* pErrorMessage = 0;
  88.     if(m_pContext &&
  89. pErrorText &&
  90. HXR_OK == m_pContext->QueryInterface(
  91. IID_IHXErrorMessages, (void**)&pErrorMessage))
  92.     {
  93. pErrorMessage->Report(HXLOG_ERR, HXR_BAD_FORMAT,
  94.     0, pErrorText, NULL);
  95.         HX_RELEASE(pErrorMessage);
  96.     }
  97. }
  98. HX_RESULT
  99. CSmil1ErrorHandler::GetErrorString(UINT32 ulErrorStringID,
  100.   char* pErrorStringBuffer)
  101. {
  102.     HX_RESULT rc = HXR_FAIL;
  103.     const char* pErrorString = NULL;
  104.     IHXExternalResourceManager* pResMgr = NULL;
  105.     if(HXR_OK == m_pContext->QueryInterface(IID_IHXExternalResourceManager,
  106.     (void**)&pResMgr))
  107.     {
  108. IHXExternalResourceReader* pResRdr = NULL;
  109. if(HXR_OK == pResMgr->CreateExternalResourceReader(
  110.      CORE_RESOURCE_SHORT_NAME, pResRdr))
  111. {
  112. #ifdef _WINDOWS
  113.     char szDLLPath[1024]; /* Flawfinder: ignore */
  114.     GetModuleFileName((HMODULE)g_hInstance, szDLLPath, sizeof(szDLLPath));
  115.     pResRdr->SetDefaultResourceFile(szDLLPath);
  116. #endif
  117.     IHXXResource* pRes = pResRdr->GetResource(HX_RT_STRING,
  118. ulErrorStringID);
  119.     if(pRes)
  120.     {
  121. strcpy(pErrorStringBuffer, (const char*)pRes->ResourceData()); /* Flawfinder: ignore */
  122. rc = HXR_OK;
  123.     }
  124.     HX_RELEASE(pRes);
  125.     HX_RELEASE(pResRdr);
  126. }
  127. HX_RELEASE(pResMgr);
  128.     }
  129.     return rc;
  130. }
  131. //     CSmil1XMLSyntaxErrorHandler methods
  132. static const struct
  133. {
  134.     UINT32     m_ulErrorTag;
  135.     UINT32     m_ulErrorStringID;
  136. } XMLSyntaxErrorStringTable[] =
  137. {
  138.     { HXR_XML_GENERALERROR,     IDS_ERR_XML_GENERALERROR },
  139.     { HXR_XML_BADENDTAG,     IDS_ERR_XML_BADENDTAG },
  140.     { HXR_XML_NOCLOSE,     IDS_ERR_XML_NOCLOSE },
  141.     { HXR_XML_BADATTRIBUTE,     IDS_ERR_XML_BADATTRIBUTE },
  142.     { HXR_XML_NOVALUE,     IDS_ERR_XML_MISSINGQUOTE },
  143.     { HXR_XML_MISSINGQUOTE,     IDS_ERR_XML_MISSINGQUOTE },
  144.     { HXR_XML_NOTAGTYPE,     IDS_ERR_XML_NOTAGTYPE },
  145.     { HXR_XML_ILLEGALID,     IDS_ERR_XML_ILLEGALID },
  146.     { HXR_XML_DUPATTRIBUTE,     IDS_ERR_XML_DUPATTRIBUTE },
  147.     { HXR_XML_COMMENT_B4_PROCINST,     IDS_ERR_XML_COMMENT_B4_PROCINST },
  148.     { HXR_XML_SYNTAX,     IDS_ERR_XML_SYNTAX },
  149.     { HXR_XML_NO_ELEMENTS,     IDS_ERR_XML_NO_ELEMENTS },
  150. // removed INVALID_TOKEN, replaced with specific errors below
  151. //    { HXR_XML_INVALID_TOKEN,     IDS_ERR_XML_INVALID_TOKEN },
  152.     { HXR_XML_UNCLOSED_TOKEN,     IDS_ERR_XML_UNCLOSED_TOKEN  },
  153.     { HXR_XML_PARTIAL_CHAR,     IDS_ERR_XML_PARTIAL_CHAR },
  154.     { HXR_XML_TAG_MISMATCH,     IDS_ERR_XML_TAG_MISMATCH },
  155. // use DUPATTRIBUTE instead
  156. //    { HXR_XML_DUPLICATE_ATTRIBUTE,     IDS_ERR_XML_DUPLICATE_ATTRIBUTE },
  157.     { HXR_XML_JUNK_AFTER_DOC_ELEMENT,     IDS_ERR_XML_JUNK_AFTER_DOC_ELEMENT },
  158.     { HXR_XML_PARAM_ENTITY_REF,     IDS_ERR_XML_PARAM_ENTITY_REF },
  159.     { HXR_XML_UNDEFINED_ENTITY,     IDS_ERR_XML_UNDEFINED_ENTITY },
  160.     { HXR_XML_RECURSIVE_ENTITY_REF,     IDS_ERR_XML_RECURSIVE_ENTITY_REF },
  161.     { HXR_XML_ASYNC_ENTITY,     IDS_ERR_XML_ASYNC_ENTITY },
  162.     { HXR_XML_BAD_CHAR_REF,     IDS_ERR_XML_BAD_CHAR_REF },
  163.     { HXR_XML_BINARY_ENTITY_REF,     IDS_ERR_XML_BINARY_ENTITY_REF },
  164.     { PNR_XML_ATTRIBUTE_EXTEHXAL_ENTITY_REF, IDS_ERR_XML_ATTRIBUTE_EXTERNAL_ENTITY_REF },
  165.     { HXR_XML_MISPLACED_XML_PI,     IDS_ERR_XML_MISPLACED_XML_PI },
  166.     { HXR_XML_UNKNOWN_ENCODING,     IDS_ERR_XML_UNKNOWN_ENCODING },
  167.     { HXR_XML_INCORRECT_ENCODING,     IDS_ERR_XML_INCORRECT_ENCODING },
  168.     { HXR_XML_UNCLOSED_CDATA_SECTION,     IDS_ERR_XML_UNCLOSED_CDATA_SECTION },
  169.     { PNR_XML_EXTEHXAL_ENTITY_HANDLING, IDS_ERR_XML_EXTERNAL_ENTITY_HANDLING },
  170.     { HXR_XML_NOT_STANDALONE,     IDS_ERR_XML_NOT_STANDALONE },
  171.     { HXR_XML_INVALID_NAME,     IDS_ERR_XML_INVALID_NAME },
  172.     { HXR_XML_INVALID_CHAR_IN_DOC,     IDS_ERR_XML_INVALID_CHAR_IN_DOC },
  173.     { HXR_XML_TWO_DASHES_NOT_ALLOWED_IN_COMMENT, IDS_ERR_XML_TWO_DASHES_NOT_ALLOWED_IN_COMMENT },
  174.     { HXR_XML_INVALID_DECL,     IDS_ERR_XML_INVALID_DECL },
  175.     { HXR_XML_INVALID_PI,     IDS_ERR_XML_INVALID_PI },
  176.     { HXR_XML_INVALID_PI_TARGET,     IDS_ERR_XML_INVALID_PI_TARGET },
  177.     { HXR_XML_INVALID_CDATA,     IDS_ERR_XML_INVALID_CDATA },
  178.     { HXR_XML_NO_CLOSING_GT,     IDS_ERR_XML_NO_CLOSING_GT },
  179.     { HXR_XML_INVALID_HEX_CHAR_REF,     IDS_ERR_XML_INVALID_HEX_CHAR_REF },
  180.     { HXR_XML_INVALID_CHAR_REF,     IDS_ERR_XML_INVALID_CHAR_REF },
  181.     { HXR_XML_INVALID_REF,     IDS_ERR_XML_INVALID_REF },
  182.     { HXR_XML_MISSING_EQUALS,     IDS_ERR_XML_MISSING_EQUALS },
  183. // use MISSINGQUOTE instead
  184. //    { HXR_XML_MISSING_QUOT_APOS,     IDS_ERR_XML_MISSING_QUOT_APOS },
  185.     { HXR_XML_MISSING_REQ_SPACE,     IDS_ERR_XML_MISSING_REQ_SPACE },
  186.     { HXR_XML_LT_NOT_ALLOWED,     IDS_ERR_XML_LT_NOT_ALLOWED },
  187.     { HXR_XML_EXPECTED_GT,     IDS_ERR_XML_EXPECTED_GT },
  188.     { HXR_XML_INVALID_GT_AFFT_2_RSQB_IN_CONTENT, IDS_ERR_XML_INVALID_GT_AFFT_2_RSQB_IN_CONTENT },
  189.     { HXR_XML_INVALID_COMMENT,     IDS_ERR_XML_INVALID_COMMENT }
  190. };
  191. CSmil1XMLSyntaxErrorHandler::CSmil1XMLSyntaxErrorHandler(IUnknown* pContext):
  192.     CSmil1ErrorHandler(pContext)
  193. {
  194. }
  195. CSmil1XMLSyntaxErrorHandler::~CSmil1XMLSyntaxErrorHandler()
  196. {
  197. }
  198. void
  199. CSmil1XMLSyntaxErrorHandler::GetReportString(UINT32 ulErrorID,
  200.     char* pErrorString)
  201. {
  202.     UINT32 ulErrorStringID = XMLSyntaxErrorStringTable[0].m_ulErrorStringID;
  203.     for (int i = 0; 
  204. i < sizeof(XMLSyntaxErrorStringTable) / 
  205.     sizeof(XMLSyntaxErrorStringTable[0]); 
  206. ++i)
  207.     {
  208. if(XMLSyntaxErrorStringTable[i].m_ulErrorTag == ulErrorID)
  209. {
  210.     ulErrorStringID = XMLSyntaxErrorStringTable[i].m_ulErrorStringID;
  211.     break;
  212. }
  213.     }
  214.     if (GetErrorString(ulErrorStringID, pErrorString) != HXR_OK)
  215.     {
  216. strcpy(pErrorString, "Error Strings can not be loaded %d: %sn"); /* Flawfinder: ignore */
  217.     }
  218. }
  219. void
  220. CSmil1XMLSyntaxErrorHandler::ReportError(UINT32 ulErrorID,
  221. const char* pErrorText,
  222. UINT32 ulLineNumber)
  223. {
  224.     UINT32 ulErrorStringID = XMLSyntaxErrorStringTable[0].m_ulErrorStringID;
  225.     for (int i = 0; 
  226. i < sizeof(XMLSyntaxErrorStringTable) / 
  227.     sizeof(XMLSyntaxErrorStringTable[0]); 
  228. ++i)
  229.     {
  230. if(XMLSyntaxErrorStringTable[i].m_ulErrorTag == ulErrorID)
  231. {
  232.     ulErrorStringID = XMLSyntaxErrorStringTable[i].m_ulErrorStringID;
  233.     break;
  234. }
  235.     }
  236.     char szErrorString[MAX_ERROR_STRING]; /* Flawfinder: ignore */
  237.     if(HXR_OK == GetErrorString(ulErrorStringID,
  238. szErrorString))
  239.     {
  240. CHXString errorText;
  241. errorText.Format(szErrorString, ulLineNumber, NULL==pErrorText?"(unknown)":pErrorText);
  242. Report(errorText);
  243.     }
  244. }
  245. //  CSmil1SMILSyntaxErrorHandler methods
  246. static const struct
  247. {
  248.     SMILErrorTag    m_ulErrorTag;
  249.     UINT32     m_ulErrorStringID;
  250. } SMILSyntaxErrorStringTable[] =
  251. {
  252.     { SMILErrorGeneralError,     IDS_ERR_SMIL_GENERALERROR },
  253.     { SMILErrorBadXML,     IDS_ERR_SMIL_BADXML },
  254.     { SMILErrorNotSMIL,     IDS_ERR_SMIL_NOTSMIL },
  255.     { SMILErrorDuplicateID,     IDS_ERR_SMIL_DUPLICATEID },
  256.     { SMILErrorNonexistentID,     IDS_ERR_SMIL_NONEXISTENTID },
  257.     { SMILErrorNoBodyTag,     IDS_ERR_SMIL_NOBODYTAG },
  258.     { SMILErrorNoBodyElements,     IDS_ERR_SMIL_NOBODYELEMENTS },
  259.     { SMILErrorUnrecognizedTag,     IDS_ERR_SMIL_UNRECOGNIZEDTAG },
  260.     { SMILErrorUnrecognizedAttribute,     IDS_ERR_SMIL_UNRECOGNIZEDATTRIBUTE },
  261.     { SMILErrorUnexpectedTag,     IDS_ERR_SMIL_UNEXPECTEDTAG },
  262.     { SMILErrorBadDuration,     IDS_ERR_SMIL_BADDURATION },
  263.     { SMILErrorBadAttribute,     IDS_ERR_SMIL_BADATTRIBUTE },
  264.     { SMILErrorBadFragment,     IDS_ERR_SMIL_BADFRAGMENT },
  265.     { SMILErrorRequiredAttributeMissing,    IDS_ERR_SMIL_REQUIREDATTRIBUTEMISSING },
  266.     { SMILErrorSyncAttributeMissing,     IDS_ERR_SMIL_SYNCATTRIBUTEOUTOFSCOPE },
  267.     { SMILErrorUnexpectedContent,     IDS_ERR_SMIL_UNEXPECTEDCONTENT },
  268.     { SMILErrorSMIL10Document,     IDS_ERR_SMIL_SMIL10DOCUMENT },
  269.     { SMILErrorIndefiniteNotSupported,     IDS_ERR_SMIL_INDEFINITENOTSUPPORTED },
  270.     { SMILErrorMetaDatatype,     IDS_ERR_SMIL_METADATATYPE },
  271.     { SMILErrorRootLayoutHeightWidthRequired,    IDS_ERR_SMIL_ROOTHEIGHTWIDTHREQUIRED },
  272.     { SMILErrorBadID,     IDS_ERR_SMIL_BADID },
  273.     { SMILErrorNoSources,     IDS_ERR_SMIL_NOSOURCES }
  274. };
  275. CSmil1SMILSyntaxErrorHandler::CSmil1SMILSyntaxErrorHandler(IUnknown* pContext):
  276.     CSmil1ErrorHandler(pContext)
  277. {
  278. }
  279. CSmil1SMILSyntaxErrorHandler::~CSmil1SMILSyntaxErrorHandler()
  280. {
  281. }
  282. void
  283. CSmil1SMILSyntaxErrorHandler::GetReportString(SMILErrorTag tag,
  284.     char* pErrorString)
  285. {
  286.     UINT32 ulErrorStringID = SMILSyntaxErrorStringTable[0].m_ulErrorStringID;
  287.     for (int i = 0; 
  288. i < sizeof(SMILSyntaxErrorStringTable) / 
  289.     sizeof(SMILSyntaxErrorStringTable[0]); 
  290. ++i)
  291.     {
  292. if(SMILSyntaxErrorStringTable[i].m_ulErrorTag == tag)
  293. {
  294.     ulErrorStringID = SMILSyntaxErrorStringTable[i].m_ulErrorStringID;
  295.     break;
  296. }
  297.     }
  298.     
  299.     if (GetErrorString(ulErrorStringID, pErrorString) != HXR_OK)
  300.     {
  301. strcpy(pErrorString, "Error Strings can not be loaded %d: %sn"); /* Flawfinder: ignore */
  302.     }
  303. }
  304. void
  305. CSmil1SMILSyntaxErrorHandler::ReportError(SMILErrorTag tag,
  306. const char* pErrorText,
  307. UINT32 ulLineNumber)
  308. {
  309.     UINT32 ulErrorStringID = SMILSyntaxErrorStringTable[0].m_ulErrorStringID;
  310.     for (int i = 0; 
  311. i < sizeof(SMILSyntaxErrorStringTable) / 
  312.     sizeof(SMILSyntaxErrorStringTable[0]); 
  313. ++i)
  314.     {
  315. if(SMILSyntaxErrorStringTable[i].m_ulErrorTag == tag)
  316. {
  317.     ulErrorStringID = SMILSyntaxErrorStringTable[i].m_ulErrorStringID;
  318.     break;
  319. }
  320.     }
  321.     char szErrorString[MAX_ERROR_STRING]; /* Flawfinder: ignore */
  322.     if(HXR_OK == GetErrorString(ulErrorStringID,
  323. szErrorString))
  324.     {
  325. CHXString errorText;
  326. errorText.Format(szErrorString, ulLineNumber, NULL==pErrorText?"(unknown)":pErrorText);
  327. Report(errorText);
  328.     }
  329. }