webengine/wmlengine/src/markup/src/MARKUPWBXMLModule.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Thu, 07 Jan 2010 13:31:38 +0200
changeset 37 cb62a4f66ebe
parent 0 dd21522fd290
child 65 5bfc169077b2
permissions -rw-r--r--
Revision: 200951 Kit: 201001

/*
* Copyright (c) 2000 - 2001 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of the License "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description: 
*
*/

#include "nw_markup_wbxmlmodulei.h"
#include <nw_dom_element.h>
#include "nw_hed_domhelper.h"

/* ------------------------------------------------------------------------- *
   class definition
 * ------------------------------------------------------------------------- */

/* ------------------------------------------------------------------------- */
const
NW_Markup_WBXMLModule_Class_t NW_Markup_WBXMLModule_Class = {
  { /* NW_Object_Core            */
    /* super                     */ &NW_Markup_Module_Class,
    /* queryInterface            */ _NW_Object_Base_QueryInterface
  },
  { /* NW_Markup_Module	         */
    /* getElementHandler         */ _NW_Markup_WBXMLModule_GetElementHandler
  },
  { /* NW_Markup_WBXMLModule	 */
    /* numElementHandlers        */ 0,
    /* elementHandlers           */ NULL,
  }
};

/* ------------------------------------------------------------------------- *
   virtual methods
 * ------------------------------------------------------------------------- */

/* ------------------------------------------------------------------------- */
NW_Markup_ElementHandler_t*
_NW_Markup_WBXMLModule_GetElementHandler (const NW_Markup_Module_t* module,
                                         const NW_DOM_ElementNode_t* domElement)
{
  NW_Uint32 numElementHandlers;
  const NW_Markup_WBXMLModule_ElementHandlerEntry_t* elementHandlers;
  NW_Uint16 tagToken;
  NW_Uint32 index;

  /* traverse our list of ElementHandlers looking for a match for our token */
  tagToken = NW_HED_DomHelper_GetElementToken (domElement);
  numElementHandlers = NW_Markup_WBXMLModule_GetClassPart (module).numElementHandlers;
  elementHandlers = NW_Markup_WBXMLModule_GetClassPart (module).elementHandlers;
  for (index = 0; index < numElementHandlers; index++) {
    if (elementHandlers[index].tagToken == tagToken) {
      return elementHandlers[index].elementHandler;
    }
  }

  /* if no element handler is found we must return NULL */
  return NULL;
}

/* ------------------------------------------------------------------------- */
NW_Markup_ElementHandler_t*
NW_Markup_WBXMLModule_GetHandler (const NW_Markup_Module_t* module,
                                         NW_Uint16 tagToken)
{
  const NW_Markup_WBXMLModule_ElementHandlerEntry_t* elementHandlers;

  // traverse our list of ElementHandlers looking for a match for our token 
  NW_Uint32 numElementHandlers = NW_Markup_WBXMLModule_GetClassPart (module).numElementHandlers;
  elementHandlers = NW_Markup_WBXMLModule_GetClassPart (module).elementHandlers;
  NW_Uint16 moduleStartToken = elementHandlers[0].tagToken;
  NW_Uint16 moduleEndToken = (NW_Uint16)(moduleStartToken + numElementHandlers);
  // if the token is within the range, getthe element handler
  if ((tagToken >= moduleStartToken) && (tagToken < moduleEndToken))
      {
        // get the index
      NW_Uint16 index = (NW_Uint16)(tagToken - moduleStartToken);
      return elementHandlers[index].elementHandler;
      }

  /* if no element handler is found we must return NULL */
  return NULL;
}