xml/legacyminidomparser/XMLDom/SRC/GMXMLCharacterData.cpp
changeset 34 c7e9f1c97567
parent 25 417699dc19c9
child 36 172b09aa4eb6
equal deleted inserted replaced
25:417699dc19c9 34:c7e9f1c97567
     1 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // MDXMLCharacterData.cpp
       
    15 // @file
       
    16 // This class represents a text section of an XML file -
       
    17 // basically it is a chunk of text which has a place in the
       
    18 // object tree but has no children.
       
    19 // 
       
    20 //
       
    21 
       
    22 #include <gmxmldomconstants.h>
       
    23 #include <gmxmlnode.h>
       
    24 #include <gmxmlcharacterdata.h>
       
    25 
       
    26 CMDXMLCharacterData::CMDXMLCharacterData( TDOMNodeType aNodeType, CMDXMLDocument* aOwnerDocument ):
       
    27 CMDXMLNode( aNodeType, false, aOwnerDocument)
       
    28 //
       
    29 // Constructor
       
    30 // @param aNodeType The node type of the derived object
       
    31 // @param aOwnerDocument The Document at the root of the DOM tree.
       
    32 //
       
    33 	{
       
    34 	}
       
    35 
       
    36 EXPORT_C CMDXMLCharacterData::~CMDXMLCharacterData()
       
    37 	{
       
    38 	delete iData;
       
    39 	}
       
    40 
       
    41 EXPORT_C TDesC& CMDXMLCharacterData::Data()
       
    42 //
       
    43 // @return Returns the text of the Character Data section
       
    44 //
       
    45 	{
       
    46 	return *iData;
       
    47 	}
       
    48 
       
    49 EXPORT_C void CMDXMLCharacterData::SetDataL( TDesC& aData )
       
    50 // 
       
    51 // Sets the whole of the Character Data section text
       
    52 // @param aData Text to set.
       
    53 // @leave Can Leave due to OOM
       
    54 //
       
    55 	{
       
    56 	if( iData != NULL )
       
    57 		{
       
    58 		delete iData;
       
    59 		iData = NULL;
       
    60 		}
       
    61 	iData = aData.AllocL();
       
    62 	}
       
    63 
       
    64 EXPORT_C TInt CMDXMLCharacterData::Length()
       
    65 //
       
    66 // @return Returns the length of the text
       
    67 //
       
    68 	{
       
    69 	return iData->Length();;
       
    70 	}
       
    71 
       
    72 EXPORT_C void CMDXMLCharacterData::AppendL( TDesC& aData )
       
    73 //
       
    74 // Appends text to the Character Data section
       
    75 // @param aData Text to append
       
    76 // @leave Can Leave due to OOM
       
    77 //
       
    78 	{
       
    79 	TInt newLength = aData.Length() + iData->Length();
       
    80 	if(newLength > iData->Des().MaxLength())
       
    81 		{
       
    82 		HBufC* newData = HBufC::NewMaxL(newLength);
       
    83 		newData->Des().Copy(iData->Des());
       
    84 		delete iData;
       
    85 		iData = newData;
       
    86 		}
       
    87 	iData->Des().Append(aData);
       
    88 	}
       
    89 
       
    90 EXPORT_C TInt CMDXMLCharacterData::InsertL( TInt aInsertPos, TDesC& aData )
       
    91 //
       
    92 // Inserts text at a point in the Character Data section
       
    93 // @param aInsertPos The position to insert the text (0 means insert at the start)
       
    94 // @param aData Text to insert
       
    95 // @leave Can Leave due to OOM
       
    96 // @return Returns KErrNone if successful or KErrNotFound if the insert position is out of range
       
    97 //
       
    98 	{
       
    99 	TInt retVal = KErrNone;
       
   100 	if((aInsertPos >= 0) && (aInsertPos < iData->Length()))
       
   101 		{
       
   102 		TInt newLength = aData.Length() + iData->Length();
       
   103 		if(newLength > iData->Des().MaxLength())
       
   104 			{
       
   105 			HBufC* newData = HBufC::NewMaxL(newLength);
       
   106 			newData->Des().Copy(iData->Des());
       
   107 			delete iData;
       
   108 			iData = newData;
       
   109 			}
       
   110 		iData->Des().Insert(aInsertPos, aData);
       
   111 		}
       
   112 	else
       
   113 		{
       
   114 		retVal = KErrNotFound;
       
   115 		}
       
   116 	return retVal;
       
   117 	}
       
   118 
       
   119 EXPORT_C TInt CMDXMLCharacterData::ReplaceL( TInt aInsertPos, TInt aLength, TDesC& aData )
       
   120 //
       
   121 // Replaces a block of text in the Character Data section
       
   122 // @param aInsertPos The position to insert the text (0 means insert at the start)
       
   123 // @param aLength The number of characters to replace
       
   124 // @param aData Text to insert
       
   125 // @leave Can Leave due to OOM
       
   126 // @return Returns KErrNone if successful or KErrNotFound if the replace block is out of range
       
   127 //
       
   128 	{
       
   129 	TInt retVal = KErrNone;
       
   130 	if((aInsertPos >= 0) && (aInsertPos < iData->Length()) && (aLength >= 0))
       
   131 		{
       
   132 		TInt newLength = aData.Length() + iData->Length() - aLength;
       
   133 		if(newLength > iData->Des().MaxLength())
       
   134 			{
       
   135 			HBufC* newData = HBufC::NewMaxL(newLength);
       
   136 			newData->Des().Copy(iData->Des());
       
   137 			delete iData;
       
   138 			iData = newData;
       
   139 			}
       
   140 		iData->Des().Replace(aInsertPos, aLength, aData);
       
   141 		}
       
   142 	else
       
   143 		{
       
   144 		retVal = KErrNotFound;
       
   145 		}
       
   146 	return retVal;
       
   147 	}
       
   148 
       
   149 EXPORT_C TBool CMDXMLCharacterData::CheckChildren()
       
   150 //
       
   151 // Check the children of this node for legality - must be defined based on DTD.
       
   152 // For a Character Data section there can be no children so this always returns true.
       
   153 // @return True if the node has legitimate children
       
   154 //
       
   155 	{
       
   156 	return true;
       
   157 	}
       
   158 
       
   159 // End Of File