aknlayoutcompiler/src/MLEqCompDataParse.cpp
changeset 0 f58d6ec98e88
child 1 b700e12870ca
equal deleted inserted replaced
-1:000000000000 0:f58d6ec98e88
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *    
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // disable "identifier was truncated to '255' characters in the browser information" warning
       
    21 #pragma warning(disable: 4786 4250 4503 4541)
       
    22 
       
    23 
       
    24 #include "MLEqCompDataParse.h"
       
    25 
       
    26 #include <akndef.hrh>
       
    27 
       
    28 #include <sstream>
       
    29 #include <fstream>
       
    30 #include <algorithm>
       
    31 #include <iostream> // !!! for debug output only
       
    32 
       
    33 extern string whiteSpace;
       
    34 
       
    35 
       
    36 // 
       
    37 // const data
       
    38 //
       
    39 
       
    40 const string KEqListParseRoot = "MasterLayout";
       
    41 
       
    42 const string KEqListParseComponent = "Component";
       
    43 const string KEqListParseComponentId = "compId";
       
    44 const string KEqListParseComponentLevel = "level";
       
    45 const string KEqListParseComponentName = "name";
       
    46 const string KEqListParseComponentPureSection = "pureSection";
       
    47 const string KEqListParseComponentType = "type";
       
    48 
       
    49 
       
    50 const string KEqCompDataParseRoot = "Layout";
       
    51 
       
    52 const string KEqCompDataParseRootAttributeMasterName = "MasterName";
       
    53 const string KEqCompDataParseRootAttributeLayoutName = "LayoutName";
       
    54 const string KEqCompDataParseRootAttributeVariantName = "variant_name";
       
    55 const string KEqCompDataParseRootAttributeResolutionHeight = "resolutionHeight";
       
    56 const string KEqCompDataParseRootAttributeResolutionWidth = "resolutionWidth";
       
    57 const string KEqCompDataParseRootAttributeCreatedOn = "createdOn";
       
    58 
       
    59 const string KEqCompDataParseNodeComponent = "Component";
       
    60 const string KEqCompDataParseNodeComponentAttributeName = "name";
       
    61 const string KEqCompDataParseNodeComponentAttributeId = "id";
       
    62 const string KEqCompDataParseNodeComponentAttributeType = "type";
       
    63 const string KEqCompDataParseNodeComponentAttributeDrawingOrder = "drawingorder";
       
    64 const string KEqCompDataParseNodeComponentAttributeMirror = "mirror";
       
    65 const string KEqCompDataParseNodeComponentAttributeMaxVariety = "maxVariety";
       
    66 
       
    67 const string KEqCompDataParseTextComponentTypeScreen= "0"; // "Screen";
       
    68 const string KEqCompDataParseTextComponentTypeContainer= "1"; // "Container";
       
    69 const string KEqCompDataParseTextComponentTypePane= "2"; // "Pane";
       
    70 const string KEqCompDataParseTextComponentTypeGraphic= "3"; // "Graphic";
       
    71 const string KEqCompDataParseTextComponentTypeText= "4"; // "Text";
       
    72 
       
    73 const string KEqCompDataParseTextComponentMirrorTrue= "true";
       
    74 
       
    75 const string KEqCompDataParseNodeOption = "option";
       
    76 const string KEqCompDataParseNodeParentInfo = "ParentInfo";
       
    77 const string KEqCompDataParseNodeLayoutInfo = "LayoutInfo";
       
    78 const string KEqCompDataParseNodeAttributeInfo = "AttributeInfo";
       
    79 const string KEqCompDataParseNodeAttrSets = "attrsets";
       
    80 
       
    81 const string KEqCompDataParseNodeParent = "parent";
       
    82 const string KEqCompDataParseNodeParentOption = "option";
       
    83 const string KEqCompDataParseNodeParentOptionAttributeVariety = "variety";
       
    84 const string KEqCompDataParseNodeParentInfoParentAttributeId = "id";
       
    85 const string KEqCompDataParseNodeParentInfoParentAttributeVariety = "variety";
       
    86 
       
    87 const string KEqCompDataParseNodeLayoutInfoParam = "Param";
       
    88 const string KEqCompDataParseNodeLayoutInfoParamAttributeName = "name";
       
    89 
       
    90 const string KEqCompDataParseNodeValue = "Value";
       
    91 const string KEqCompDataParseNodeVarietyIndex = "varietyIndex";
       
    92 const string KEqCompDataParseNodeVarietyIndexValue = "value";
       
    93 const string KEqCompDataParseNodeOptionSetNo = "optionSetNo";
       
    94 const string KEqCompDataParseNodeOptionSetNoValue = "value";
       
    95 const string KEqCompDataParseNodeCalc = "calc";
       
    96 const string KEqCompDataParseNodeFormulae = "Formulae";
       
    97 const string KEqCompDataParseNodeFormula = "Formula";
       
    98 const string KEqCompDataParseNodeFormulaFormulaStr = "formulaStr";
       
    99 const string KEqCompDataParseNodeFormulaZoomId = "zId";
       
   100 
       
   101 const string KEqCompDataParseNodeCalcAttributeValue = "value";
       
   102 const string KEqCompDataParseNodeCalcAttributeColNumber = "colNumber";
       
   103 const string KEqCompDataParseNodeCalcAttributeRowNumber = "rowNumber";
       
   104 const string KEqCompDataParseNodeCalcAttributeShowInTable = "showInTable";
       
   105 const string KEqCompDataParseNodeCalcAttributeShowInTableTrue = "true";
       
   106 const string KEqCompDataParseNodeCalcAttributeShowInTableFalse = "false";
       
   107 const string KEqCompDataParseNodeCalcAttributeZoom = "zoom";
       
   108 const string KEqCompDataParseNodeCalcAttributeZoomNormal = "normal";
       
   109 const string KEqCompDataParseNodeCalcAttributeZoomVerySmall = "-2 zoom";
       
   110 const string KEqCompDataParseNodeCalcAttributeZoomSmall = "-1 zoom";
       
   111 const string KEqCompDataParseNodeCalcAttributeZoomLarge = "+1 zoom";
       
   112 const string KEqCompDataParseNodeCalcAttributeZoomVeryLarge = "+2 zoom";
       
   113 
       
   114 const string KEqCompDataParseTextFontPrimary = "qfn_primary";
       
   115 const string KEqCompDataParseTextFontSecondary = "qfn_secondary";
       
   116 const string KEqCompDataParseTextFontTitle = "qfn_title";
       
   117 const string KEqCompDataParseTextFontPrimarySmall = "qfn_primary_small"; // is that the correct text?
       
   118 const string KEqCompDataParseTextFontDigital = "qfn_digital";
       
   119 
       
   120 const string KEqCompDataParseTextParamNameLeft = "Left";
       
   121 const string KEqCompDataParseTextParamShortNameLeft = "l";
       
   122 const string KEqCompDataParseTextParamNameRight = "Right";
       
   123 const string KEqCompDataParseTextParamShortNameRight = "r";
       
   124 const string KEqCompDataParseTextParamNameTop = "Top";
       
   125 const string KEqCompDataParseTextParamShortNameTop = "t";
       
   126 const string KEqCompDataParseTextParamNameBottom = "Bottom";
       
   127 const string KEqCompDataParseTextParamShortNameBottom = "b";
       
   128 const string KEqCompDataParseTextParamNameWidth = "Width";
       
   129 const string KEqCompDataParseTextParamShortNameWidth = "w";
       
   130 const string KEqCompDataParseTextParamNameHeight = "Height";
       
   131 const string KEqCompDataParseTextParamShortNameHeight = "h";
       
   132 const string KEqCompDataParseTextParamNameJustification = "Justification";
       
   133 const string KEqCompDataParseTextParamShortNameJustification = "j";
       
   134 const string KEqCompDataParseTextParamNameType = "Type";
       
   135 const string KEqCompDataParseTextParamShortNameType = "Type";
       
   136 
       
   137 // these have been changed to lower case, so that matching
       
   138 // can be performed independent of case
       
   139 const string KEqCompDataParseTextParamTypeCalcValueNone = "none";
       
   140 const string KEqCompDataParseTextParamTypeCalcValueLeft = "left";
       
   141 const string KEqCompDataParseTextParamTypeCalcValueCenter = "center";
       
   142 const string KEqCompDataParseTextParamTypeCalcValueRight = "right";
       
   143 const string KEqCompDataParseTextParamTypeCalcValueBidi = "bidi";
       
   144 
       
   145 const string KEqCompDataParseNodeAttributeInfoOption = "option";
       
   146 const string KEqCompDataParseNodeAttributeInfoOptionAttributeVariety = "variety";
       
   147 const string KEqCompDataParseNodeAttributeInfoAttributeSet = "attributeset";
       
   148 const string KEqCompDataParseNodeAttributeInfoAttributeSetAttributeName = "name";
       
   149 
       
   150 const string KEqParChildParseRoot = "ParChildRelation";
       
   151 const string KEqParChildParseComponent = "Component";
       
   152 const string KEqParChildParseComponentId = "id";
       
   153 const string KEqParChildParseComponentParent = "parent";
       
   154 const string KEqParChildParseComponentParentId = "parId";
       
   155 
       
   156 //
       
   157 // class TMLEqCompDataParseFormula
       
   158 //
       
   159 TMLEqCompDataParseFormula::TMLEqCompDataParseFormula()
       
   160 	: 
       
   161 	TMLEqCompDataFormula(),
       
   162 	iSaxFormulaString()
       
   163 	{
       
   164 
       
   165 	};
       
   166 
       
   167 MSaxLayoutEqHandler* TMLEqCompDataParseFormula::HandleSax(const std::string& aElement, const TAttribs& aAttribs)
       
   168 	{
       
   169 	if(aElement == KEqCompDataParseNodeFormula)
       
   170 		{
       
   171 		HandleSaxFormulaAttributes(aElement, aAttribs);
       
   172 		}
       
   173 	return this;
       
   174 	};
       
   175 
       
   176 void TMLEqCompDataParseFormula::HandleSaxEnd(const std::string& aElement)
       
   177 	{
       
   178 
       
   179 	};
       
   180 
       
   181 void TMLEqCompDataParseFormula::HandleSaxFormulaAttributes(const std::string& aElement, const TAttribs& aAttribs)
       
   182 	{
       
   183 //	<Formula 
       
   184 //			formulaStr="3301_l-(pr199+pr197)" 
       
   185 //			lowerMargin="-1.0" 
       
   186 //			maxLimit="-1.0" 
       
   187 //			minLimit="-1.0" 
       
   188 //			prefNo="1" 
       
   189 //			sizer="-1" 
       
   190 //			upperMargin="-1.0" 
       
   191 //			zId="232" />
       
   192 
       
   193 	iFormulaString = aAttribs.getValue(KEqCompDataParseNodeFormulaFormulaStr);
       
   194 
       
   195 	string zoomIdStr = aAttribs.getValue(KEqCompDataParseNodeFormulaZoomId);
       
   196 	if(!zoomIdStr.empty())
       
   197 		iZoomId = CdlTkUtil::ParseInt(zoomIdStr);
       
   198 	else
       
   199 		iZoomId = -1; // @todo maybe could use dummy = 252?
       
   200 	}
       
   201 
       
   202 
       
   203 //
       
   204 // class TMLEqCompDataParseValuesOptionSet
       
   205 //
       
   206 TMLEqCompDataParseValuesOptionSet::TMLEqCompDataParseValuesOptionSet()
       
   207 	:
       
   208 	TMLEqCompDataValuesOptionSet(),
       
   209 	iSaxFormula(0),
       
   210 	iSaxFormulaNo(0),
       
   211 	iSaxOptionSetNo(-1)
       
   212 	{
       
   213 
       
   214 	};
       
   215 
       
   216 MSaxLayoutEqHandler* TMLEqCompDataParseValuesOptionSet::HandleSax(const std::string& aElement, const TAttribs& aAttribs)
       
   217 	{
       
   218 //	<Value>
       
   219 //		<optionIndex value="0"/>
       
   220 //		<varietyIndex variety="0"/>
       
   221 //		<optionSetName orientation="3" value="Option0 (lists)"/>
       
   222 //		<optionSetNo value="0"/>
       
   223 //		<Formulae>
       
   224 //		...
       
   225 //		</Formulae>
       
   226 //		<Comment value=""/>
       
   227 //	</Value>
       
   228 
       
   229 	if (aElement == KEqCompDataParseNodeOptionSetNo)
       
   230 		{
       
   231 		HandleSaxOptionSetNo(aElement, aAttribs);
       
   232 		}
       
   233 	else if (aElement == KEqCompDataParseNodeFormulae)
       
   234 		{
       
   235 		return HandleSaxFormula(aElement, aAttribs);
       
   236 		}
       
   237 
       
   238 	return this;
       
   239 	};
       
   240 
       
   241 void TMLEqCompDataParseValuesOptionSet::HandleSaxEnd(const std::string& aElement)
       
   242 	{
       
   243 	if(aElement == KEqCompDataParseNodeFormulae)
       
   244 		{
       
   245 		push_back(*iSaxFormula);
       
   246 		delete iSaxFormula;
       
   247 		iSaxFormula = 0;
       
   248 		}
       
   249 	};
       
   250 
       
   251 void TMLEqCompDataParseValuesOptionSet::HandleSaxOptionSetNo(const std::string& /*aElement*/, const TAttribs& aAttribs)
       
   252 	{
       
   253 //	<optionSetNo value="1"/>
       
   254 
       
   255 	string optionSetNoStr = aAttribs.getValue(KEqCompDataParseNodeOptionSetNoValue);
       
   256 	iSaxOptionSetNo = CdlTkUtil::ParseInt(optionSetNoStr); // defaults to zero
       
   257 	}
       
   258 
       
   259 
       
   260 MSaxLayoutEqHandler* TMLEqCompDataParseValuesOptionSet::HandleSaxFormula(const std::string& /*aElement*/, const TAttribs& aAttribs)
       
   261 	{
       
   262 //	<Formula ... />
       
   263 
       
   264 	delete iSaxFormula;
       
   265 	iSaxFormula = 0;
       
   266 	iSaxFormula = new TMLEqCompDataParseFormula();
       
   267 	return iSaxFormula;
       
   268 	}
       
   269 
       
   270 
       
   271 
       
   272 //
       
   273 //  TMLEqCompDataParseValues
       
   274 //
       
   275 
       
   276 TMLEqCompDataParseValues::TMLEqCompDataParseValues(TMLEqCompDataLine* aLine)
       
   277 	: 
       
   278 	TMLEqCompDataValues(aLine), 
       
   279 	iSaxOptionSet(0)
       
   280 	{
       
   281 
       
   282 	}
       
   283 
       
   284 MSaxLayoutEqHandler* TMLEqCompDataParseValues::HandleSax(const std::string& aElement, const TAttribs& aAttribs)
       
   285 	{
       
   286 
       
   287 //	<Param name="Left">
       
   288 //		<Value>
       
   289 //			...
       
   290 //		</Value>
       
   291 //	</Param>
       
   292 
       
   293 	if (aElement == KEqCompDataParseNodeValue)
       
   294 		{
       
   295 		return HandleSaxOptionSet(aElement, aAttribs);
       
   296 		}
       
   297 
       
   298 	return this;
       
   299 	}
       
   300 
       
   301 void TMLEqCompDataParseValues::HandleSaxEnd(const std::string& aElement)
       
   302 	{
       
   303 	if (aElement == KEqCompDataParseNodeValue)
       
   304 		{
       
   305 		iOptionSets.insert(make_pair(iSaxOptionSet->OptionSetNo(), *iSaxOptionSet));
       
   306 		delete iSaxOptionSet;
       
   307 		iSaxOptionSet = 0;
       
   308 		}
       
   309 	}
       
   310 
       
   311 MSaxLayoutEqHandler* TMLEqCompDataParseValues::HandleSaxOptionSet(const std::string& /*aElement*/, const TAttribs& aAttribs)
       
   312 	{
       
   313 	delete iSaxOptionSet;
       
   314 	iSaxOptionSet = 0;
       
   315 	iSaxOptionSet = new TMLEqCompDataParseValuesOptionSet;
       
   316 	return iSaxOptionSet;
       
   317 	};
       
   318 
       
   319 
       
   320 void TMLEqCompDataParseValues::ConvertValueStr(std::string& aValueStr)
       
   321 	{
       
   322 	int valueInt = 0;
       
   323 	if(iName == KEqCompDataParseTextParamShortNameType)
       
   324 		{
       
   325 		if(aValueStr == KEqCompDataParseTextFontPrimary) 
       
   326 			valueInt = ELayoutCompilerFontCategoryPrimary;
       
   327 		else if(aValueStr == KEqCompDataParseTextFontSecondary)
       
   328 			valueInt = ELayoutCompilerFontCategorySecondary;
       
   329 		else if(aValueStr == KEqCompDataParseTextFontTitle)
       
   330 			valueInt = ELayoutCompilerFontCategoryTitle;
       
   331 		else if(aValueStr == KEqCompDataParseTextFontPrimarySmall) 
       
   332 			valueInt = ELayoutCompilerFontCategoryPrimarySmall;
       
   333 		else if(aValueStr == KEqCompDataParseTextFontDigital)
       
   334 			valueInt = ELayoutCompilerFontCategoryDigital;
       
   335 		else
       
   336 			valueInt = ELayoutCompilerFontCategoryUndefined;
       
   337 		aValueStr = CdlTkUtil::IntToString(valueInt);
       
   338 		}
       
   339 	else if(iName == KEqCompDataParseTextParamShortNameJustification)
       
   340 		{
       
   341 		// jusitication does not have consistent capitalization
       
   342 		string lowerValueStr = CdlTkUtil::ToLower(aValueStr);
       
   343 		if(lowerValueStr == KEqCompDataParseTextParamTypeCalcValueNone) 
       
   344 			valueInt = ELayoutAlignNone;
       
   345 		else if(lowerValueStr == KEqCompDataParseTextParamTypeCalcValueLeft) 
       
   346 			valueInt = ELayoutAlignLeft;
       
   347 		else if(lowerValueStr == KEqCompDataParseTextParamTypeCalcValueRight) 
       
   348 			valueInt = ELayoutAlignRight;
       
   349 		else if(lowerValueStr == KEqCompDataParseTextParamTypeCalcValueCenter) 
       
   350 			valueInt = ELayoutAlignCenter;
       
   351 		else if(lowerValueStr == KEqCompDataParseTextParamTypeCalcValueBidi) 
       
   352 			valueInt = ELayoutAlignBidi;
       
   353 		else 
       
   354 			valueInt = ELayoutAlignNone;
       
   355 		aValueStr = CdlTkUtil::IntToString(valueInt);
       
   356 		}
       
   357 	}
       
   358 
       
   359 int TMLEqCompDataParseValues::ConvertZoomStr(const std::string& aZoomStr)
       
   360 	{
       
   361 	int zoomInt = EAknUiZoomAutomatic;
       
   362 	string lowerZoomStr = CdlTkUtil::ToLower(aZoomStr);
       
   363 	if(lowerZoomStr.empty())
       
   364 		zoomInt = EAknUiZoomNormal;
       
   365 	else if(lowerZoomStr == KEqCompDataParseNodeCalcAttributeZoomVerySmall) 
       
   366 		zoomInt = EAknUiZoomVerySmall;
       
   367 	else if(lowerZoomStr == KEqCompDataParseNodeCalcAttributeZoomSmall) 
       
   368 		zoomInt = EAknUiZoomSmall;
       
   369 	else if(lowerZoomStr == KEqCompDataParseNodeCalcAttributeZoomLarge) 
       
   370 		zoomInt = EAknUiZoomLarge;
       
   371 	else if(lowerZoomStr == KEqCompDataParseNodeCalcAttributeZoomVeryLarge) 
       
   372 		zoomInt = EAknUiZoomVeryLarge;
       
   373 	return zoomInt;
       
   374 	}
       
   375 
       
   376 
       
   377 
       
   378 //
       
   379 //  TMLEqCompDataParseLine
       
   380 //
       
   381 
       
   382 TMLEqCompDataParseLine::TMLEqCompDataParseLine()
       
   383 	: 
       
   384 	TMLEqCompDataLine(), 
       
   385 	iSaxValues(0)
       
   386 //	iSaxParentInfo(0),
       
   387 //	iSaxAttributeInfo(0)
       
   388 	{
       
   389 	}
       
   390 
       
   391 MSaxLayoutEqHandler* TMLEqCompDataParseLine::HandleSax(const std::string& aElement, const TAttribs& aAttribs)
       
   392 	{
       
   393 	if(aElement == KEqCompDataParseNodeComponent)
       
   394 		{
       
   395 		HandleSaxAttributes(aAttribs);
       
   396 		}
       
   397 	else if(aElement == KEqCompDataParseNodeLayoutInfoParam)
       
   398 		{
       
   399 		//	<LayoutInfo>
       
   400 		//		<Param name="Left">
       
   401 		//		...
       
   402 		//	</LayoutInfo>
       
   403 		return HandleSaxParam(aElement, aAttribs);
       
   404 		}
       
   405 // @todo need to implement attribute parsing
       
   406 /*
       
   407 	else if(aElement == KEqCompDataParseNodeAttributeInfo)
       
   408 		{
       
   409 		return HandleSaxAttributeInfo(aElement, aAttribs);
       
   410 		}
       
   411 */
       
   412 	return this;
       
   413 	}
       
   414 
       
   415 
       
   416 void TMLEqCompDataParseLine::HandleSaxAttributes(const TAttribs& aAttribs)
       
   417 	{
       
   418 // there are three different forms of component, stored in different files
       
   419 // but they all refer to the same components
       
   420 
       
   421 //	<Component 
       
   422 //		catRefId="3449" 
       
   423 //		componentCategory="0" 
       
   424 //		creationTime="1150805213430" 
       
   425 //		id="5129" 
       
   426 //		independent="false" 
       
   427 //		keepLocalCopy="true" 
       
   428 //		maxVariety="0" 
       
   429 //		type="4">
       
   430 
       
   431 	string idStr = aAttribs.getValue(KEqCompDataParseNodeComponentAttributeId);
       
   432 	iId = CdlTkUtil::ParseInt(idStr);
       
   433 
       
   434 	string name = aAttribs.getValue(KEqCompDataParseNodeComponentAttributeName);
       
   435 	if(!name.empty())
       
   436 		iName = name;
       
   437 
       
   438 	string typeStr = aAttribs.getValue(KEqCompDataParseNodeComponentAttributeType);
       
   439 	if(typeStr == KEqCompDataParseTextComponentTypeScreen)
       
   440 		{
       
   441 		iType = EScreenComponent;
       
   442 		}
       
   443 	else if(typeStr == KEqCompDataParseTextComponentTypeContainer)
       
   444 		{
       
   445 		iType = EContainerComponent;
       
   446 		}
       
   447 	else if(typeStr == KEqCompDataParseTextComponentTypePane)
       
   448 		{
       
   449 		iType = EPaneComponent;
       
   450 		}
       
   451 	else if(typeStr == KEqCompDataParseTextComponentTypeGraphic)
       
   452 		{
       
   453 		iType = EGraphicComponent;
       
   454 		}
       
   455 	else if(typeStr == KEqCompDataParseTextComponentTypeText)
       
   456 		{
       
   457 		iType = ETextComponent;
       
   458 		}
       
   459 	else
       
   460 		{
       
   461 		iType = EUnknownComponent;
       
   462 		}
       
   463 
       
   464 	// @todo don't know where drawing order is defined!
       
   465 //	string drawingOrderStr = aAttribs.getValue(KEqCompDataParseNodeComponentAttributeDrawingOrder);
       
   466 //	iDrawingOrder = CdlTkUtil::ParseInt(drawingOrderStr);
       
   467 
       
   468 		// @todo need to work out orientation from which 
       
   469 //	string mirroredStr = aAttribs.getValue(KEqCompDataParseNodeComponentAttributeMirror);
       
   470 //	iIsMirroredHorizontally = (mirroredStr == KEqCompDataParseTextComponentMirrorTrue); // will be false if empty, eg for a non-mirrored layout
       
   471 
       
   472 	}
       
   473 
       
   474 MSaxLayoutEqHandler* TMLEqCompDataParseLine::HandleSaxParam(const std::string& /*aElement*/, const TAttribs& aAttribs)
       
   475 	{
       
   476 	delete iSaxValues;
       
   477 	iSaxValues = 0;
       
   478 	iSaxValues = new TMLEqCompDataParseValues(this);
       
   479 
       
   480 	string nameStr = aAttribs.getValue(KEqCompDataParseNodeLayoutInfoParamAttributeName);
       
   481 	iSaxValues->iName = ShortParamName(nameStr);
       
   482 
       
   483 	return iSaxValues;
       
   484 	}
       
   485 
       
   486 void TMLEqCompDataParseLine::HandleSaxEnd(const std::string& aElement)
       
   487 	{
       
   488 	if(aElement == KEqCompDataParseNodeLayoutInfoParam)
       
   489 		{
       
   490 		insert(make_pair(iSaxValues->iName, *iSaxValues));
       
   491 		delete iSaxValues;
       
   492 		iSaxValues = 0;
       
   493 		}
       
   494 	}
       
   495 
       
   496 string TMLEqCompDataParseLine::ShortParamName(string& aName)
       
   497 	{
       
   498 	string shortName = aName;
       
   499 	if(aName == KEqCompDataParseTextParamNameLeft)
       
   500 		shortName = KEqCompDataParseTextParamShortNameLeft;
       
   501 	else if(aName == KEqCompDataParseTextParamNameRight)
       
   502 		shortName = KEqCompDataParseTextParamShortNameRight;
       
   503 	else if(aName == KEqCompDataParseTextParamNameTop)
       
   504 		shortName = KEqCompDataParseTextParamShortNameTop;
       
   505 	else if(aName == KEqCompDataParseTextParamNameBottom)
       
   506 		shortName = KEqCompDataParseTextParamShortNameBottom;
       
   507 	else if(aName == KEqCompDataParseTextParamNameWidth)
       
   508 		shortName = KEqCompDataParseTextParamShortNameWidth;
       
   509 	else if(aName == KEqCompDataParseTextParamNameHeight)
       
   510 		shortName = KEqCompDataParseTextParamShortNameHeight;
       
   511 	else if(aName == KEqCompDataParseTextParamNameJustification)
       
   512 		shortName = KEqCompDataParseTextParamShortNameJustification;
       
   513 	else if(aName == KEqCompDataParseTextParamNameType)
       
   514 		shortName = KEqCompDataParseTextParamShortNameType;
       
   515 	return shortName;
       
   516 	}
       
   517 
       
   518 
       
   519 //
       
   520 // class TMLEqListParseComponent
       
   521 //
       
   522 TMLEqListParseComponent::TMLEqListParseComponent()
       
   523 	{
       
   524 
       
   525 	}
       
   526 
       
   527 MSaxLayoutEqHandler* TMLEqListParseComponent::HandleSax(const std::string& aElement, const TAttribs& aAttribs)
       
   528 	{
       
   529 // <Component 
       
   530 //		compId="5129" 
       
   531 //		level="2" 
       
   532 //		name="list_form2_midp_pane_t1" 
       
   533 //		pureSection="false" 
       
   534 //		type="4">
       
   535 
       
   536 	if(aElement == KEqListParseComponent)
       
   537 		{
       
   538 		string idStr = aAttribs.getValue(KEqListParseComponentId);
       
   539 		iId = CdlTkUtil::ParseInt(idStr);
       
   540 
       
   541 		iName = aAttribs.getValue(KEqListParseComponentName);
       
   542 		}
       
   543 
       
   544 	return this;
       
   545 	}
       
   546 
       
   547 void TMLEqListParseComponent::HandleSaxEnd(const std::string& aElement)
       
   548 	{
       
   549 	// nothing to do
       
   550 	}
       
   551 
       
   552 
       
   553 //
       
   554 // class TMLEqParChildParseComponent
       
   555 //
       
   556 TMLEqParChildParseComponent::TMLEqParChildParseComponent()
       
   557 	{
       
   558 
       
   559 	}
       
   560 
       
   561 MSaxLayoutEqHandler* TMLEqParChildParseComponent::HandleSax(const std::string& aElement, const TAttribs& aAttribs)
       
   562 	{
       
   563 //	<Component id="5198">
       
   564 //		<parent parId="529"/>
       
   565 //		<Option id="0" orientation="1" parOptionId="102"/>
       
   566 //		<Option id="0" orientation="2" parOptionId="102"/>
       
   567 //		<Option id="1" orientation="1" parOptionId="103"/>
       
   568 //		<Option id="1" orientation="2" parOptionId="103"/>
       
   569 //		<Option id="2" orientation="1" parOptionId="104"/>
       
   570 //		<Option id="2" orientation="2" parOptionId="104"/>
       
   571 //		<Option id="3" orientation="1" parOptionId="105"/>
       
   572 //		<Option id="3" orientation="2" parOptionId="105"/>
       
   573 //		<Document docParId="529" docSiblingLevel="1"/>
       
   574 //	</Component>
       
   575 
       
   576 	if(aElement == KEqParChildParseComponent)
       
   577 		{
       
   578 		string idStr = aAttribs.getValue(KEqParChildParseComponentId);
       
   579 		iId = CdlTkUtil::ParseInt(idStr);
       
   580 		}
       
   581 	else if(aElement == KEqParChildParseComponentParent)
       
   582 		{
       
   583 		HandleSaxParent(aElement, aAttribs);
       
   584 		}
       
   585 
       
   586 	return this;
       
   587 	}
       
   588 
       
   589 void TMLEqParChildParseComponent::HandleSaxEnd(const std::string& aElement)
       
   590 	{
       
   591 	// nothing to do
       
   592 	}
       
   593 
       
   594 void TMLEqParChildParseComponent::HandleSaxParent(const std::string& aElement, const TAttribs& aAttribs)
       
   595 	{
       
   596 //		<parent parId="529"/>
       
   597 
       
   598 		string parentIdStr = aAttribs.getValue(KEqParChildParseComponentParentId);
       
   599 		iParentId = CdlTkUtil::ParseInt(parentIdStr);
       
   600 
       
   601 		// @todo must implement a conversion for dummy components that have non-integer component ids.
       
   602 /*
       
   603 	if(iId == 0)
       
   604 		{
       
   605 		// this must be a dummy component, so have to fabricate a component id
       
   606 		if(iName == "text_primary")
       
   607 			iId = -1;
       
   608 		else if(iName == "text_secondary")
       
   609 			iId = -2;
       
   610 		else if(iName == "text_title")
       
   611 			iId = -3;
       
   612 		else if(iName == "text_primary_small")
       
   613 			iId = -4;
       
   614 		}
       
   615 */
       
   616 	}
       
   617 
       
   618 
       
   619 //
       
   620 // class TMLEqCompDataParseLayout
       
   621 //
       
   622 
       
   623 MSaxLayoutEqHandler* TMLEqCompDataParseLayout::HandleSax(const std::string& aElement, const TAttribs& aAttribs)
       
   624 	{
       
   625 	if(aElement == KEqListParseRoot || aElement == KEqCompDataParseRoot || aElement == KEqParChildParseRoot)
       
   626 		{
       
   627 		iSaxLayoutType = aElement;
       
   628 		return this;
       
   629 		}
       
   630 	else if(aElement == KEqListParseComponent || aElement == KEqCompDataParseNodeComponent || aElement == KEqParChildParseComponent)
       
   631 		{
       
   632 		return HandleSaxComponent(aElement, aAttribs);
       
   633 		}
       
   634 	else
       
   635 		return this;
       
   636 	}
       
   637 
       
   638 void TMLEqCompDataParseLayout::HandleSaxEnd(const std::string& aElement)
       
   639 	{
       
   640 	}
       
   641 
       
   642 MSaxLayoutEqHandler* TMLEqCompDataParseLayout::HandleSaxComponent(const std::string& aElement, const TAttribs& aAttribs)
       
   643 	{
       
   644 
       
   645 	/// @todo not yet handling par child component!
       
   646 // <Component id="5198">
       
   647 
       
   648 	MSaxLayoutEqHandler* handler = NULL;
       
   649 	if(iSaxLayoutType == KEqListParseRoot)
       
   650 		{
       
   651 		TMLEqListParseComponent* line = new TMLEqListParseComponent();
       
   652 		line->HandleSax(aElement, aAttribs);
       
   653 		iListComponents.insert(make_pair(line->iId, line));
       
   654 		handler = line;
       
   655 		}
       
   656 	else if(iSaxLayoutType == KEqCompDataParseRoot)
       
   657 		{
       
   658 		TMLEqCompDataParseLine* line = new TMLEqCompDataParseLine();
       
   659 		line->HandleSax(aElement, aAttribs);
       
   660 		iComponents.insert(make_pair(line->iId, line));
       
   661 		handler = line;
       
   662 		}
       
   663 	else if(iSaxLayoutType == KEqParChildParseRoot)
       
   664 		{
       
   665 		TMLEqParChildParseComponent* line = new TMLEqParChildParseComponent();
       
   666 		line->HandleSax(aElement, aAttribs);
       
   667 		iParChildComponents.insert(make_pair(line->iId, line));
       
   668 		handler = line;
       
   669 		}
       
   670 	return handler;
       
   671 	}
       
   672 
       
   673 // this is the entry point into the parser
       
   674 auto_ptr<TMLEqCompDataParseLayout> TMLEqCompDataParseLayout::Parse(
       
   675 	const string& aListName, 
       
   676 	const string& aCompDataName, 
       
   677 	const string& aParChildName)
       
   678 	{
       
   679 	auto_ptr<TMLEqCompDataParseLayout> layout(new TMLEqCompDataParseLayout);
       
   680 	layout->iName = aCompDataName;
       
   681 
       
   682 	// SAX parsing method
       
   683 	TEqLayoutSaxParser saxParser(layout.get());
       
   684 
       
   685 	cout << "reading MLEqCompData(SAX) " << aListName << " + " << aCompDataName << " + " << aParChildName << endl;
       
   686 	saxParser.Parse(aListName);
       
   687 	saxParser.Parse(aCompDataName);
       
   688 	saxParser.Parse(aParChildName);
       
   689 
       
   690 	return layout;
       
   691 	}
       
   692 
       
   693 
       
   694 //
       
   695 // class TEqLayoutSaxParser
       
   696 //
       
   697 TEqLayoutSaxParser::TEqLayoutSaxParser(MSaxLayoutEqHandler* aHandler)
       
   698 	{ 
       
   699 	iStack.push(aHandler);
       
   700 	}
       
   701 
       
   702 void TEqLayoutSaxParser::Parse(const std::string& aFileName)
       
   703 	{
       
   704 	SAX::basic_InputSource<std::string> is(aFileName);
       
   705 	SAX::XMLReader<std::string> parser;
       
   706 	parser.setContentHandler(*this);
       
   707 	parser.setErrorHandler(*this);
       
   708 	parser.parse(is);
       
   709 	}
       
   710 
       
   711 void TEqLayoutSaxParser::startElement(const std::string& /*namespaceURI*/, const std::string& localName,
       
   712                               const std::string& /*qName*/, const SAX::basic_Attributes<std::string>& atts)
       
   713     {
       
   714 	MSaxLayoutEqHandler* handler = iStack.top();
       
   715 	if (!handler)
       
   716 		throw GeneralErr("SAX: No element handler");
       
   717 	MSaxLayoutEqHandler* next = handler->HandleSax(localName, atts);
       
   718 	iStack.push(next);
       
   719     }
       
   720 
       
   721 void TEqLayoutSaxParser::endElement(const std::string& /*namespaceURI*/, const std::string& localName,
       
   722                             const std::string& /*qName*/)
       
   723     {
       
   724 	iStack.pop();
       
   725 	MSaxLayoutEqHandler* handler = iStack.top();
       
   726 	if (handler)
       
   727 		handler->HandleSaxEnd(localName);
       
   728     }
       
   729 
       
   730 
       
   731 void TEqLayoutSaxParser::warning(const TException& aException) 
       
   732     {
       
   733 	cerr << aException.what();
       
   734     }
       
   735 
       
   736 void TEqLayoutSaxParser::error(const TException& aException) 
       
   737     {
       
   738 	cerr << aException.what();
       
   739     }
       
   740 
       
   741 void TEqLayoutSaxParser::fatalError(const TException& aException)
       
   742     {
       
   743 	cerr << aException.what();
       
   744     }
       
   745 
       
   746 
       
   747 // End of File