Kaydet (Commit) 5310a84c authored tarafından Niklas Nebel's avatar Niklas Nebel

#80820# support era element

üst 5dc9aca6
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: xmlnumfe.cxx,v $ * $RCSfile: xmlnumfe.cxx,v $
* *
* $Revision: 1.6 $ * $Revision: 1.7 $
* *
* last change: $Author: er $ $Date: 2000-11-24 19:41:01 $ * last change: $Author: nn $ $Date: 2000-11-29 20:37:27 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -388,6 +388,20 @@ void SvXMLNumFmtExport::WriteYearElement_Impl( sal_Bool bLong ) ...@@ -388,6 +388,20 @@ void SvXMLNumFmtExport::WriteYearElement_Impl( sal_Bool bLong )
pAttrList->Clear(); pAttrList->Clear();
} }
void SvXMLNumFmtExport::WriteEraElement_Impl( sal_Bool bLong )
{
OUString sElem = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_era ) );
AddStyleAttr_Impl( bLong ); // adds to pAttrList
xHandler->ignorableWhitespace( sWS );
xHandler->startElement( sElem, xAttrList );
xHandler->endElement( sElem );
pAttrList->Clear();
}
void SvXMLNumFmtExport::WriteDayOfWeekElement_Impl( sal_Bool bLong ) void SvXMLNumFmtExport::WriteDayOfWeekElement_Impl( sal_Bool bLong )
{ {
OUString sElem = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER, OUString sElem = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
...@@ -862,8 +876,8 @@ void SvXMLNumFmtExport::ExportPart_Impl( SvNumberformat& rFormat, sal_uInt32 nKe ...@@ -862,8 +876,8 @@ void SvXMLNumFmtExport::ExportPart_Impl( SvNumberformat& rFormat, sal_uInt32 nKe
// only used for some built-in formats // only used for some built-in formats
BOOL bSystemDate = ( eBuiltIn == NF_DATE_SYSTEM_SHORT || BOOL bSystemDate = ( eBuiltIn == NF_DATE_SYSTEM_SHORT ||
eBuiltIn == NF_DATE_SYSTEM_LONG || eBuiltIn == NF_DATE_SYSTEM_LONG ||
eBuiltIn == NF_DATETIME_SYSTEM_SHORT_HHMM ); eBuiltIn == NF_DATETIME_SYSTEM_SHORT_HHMM ) && rFormat.GetComment().Len();
BOOL bLongSysDate = ( eBuiltIn == NF_DATE_SYSTEM_LONG ); BOOL bLongSysDate = ( eBuiltIn == NF_DATE_SYSTEM_LONG ) && rFormat.GetComment().Len();
if ( bSystemDate ) if ( bSystemDate )
{ {
sAttrName = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER, sAttrName = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
...@@ -1071,9 +1085,11 @@ void SvXMLNumFmtExport::ExportPart_Impl( SvNumberformat& rFormat, sal_uInt32 nKe ...@@ -1071,9 +1085,11 @@ void SvXMLNumFmtExport::ExportPart_Impl( SvNumberformat& rFormat, sal_uInt32 nKe
case NF_KEY_NN: case NF_KEY_NN:
case NF_KEY_NNN: case NF_KEY_NNN:
case NF_KEY_NNNN: case NF_KEY_NNNN:
case NF_KEY_AAA:
case NF_KEY_AAAA:
{ {
sal_Bool bLong = ( nElemType == NF_KEY_NNN || nElemType == NF_KEY_NNNN || sal_Bool bLong = ( nElemType == NF_KEY_NNN || nElemType == NF_KEY_NNNN ||
nElemType == NF_KEY_DDDD ); nElemType == NF_KEY_DDDD || nElemType == NF_KEY_AAAA );
WriteDayOfWeekElement_Impl( bSystemDate ? bLongSysDate : bLong ); WriteDayOfWeekElement_Impl( bSystemDate ? bLongSysDate : bLong );
if ( nElemType == NF_KEY_NNNN ) if ( nElemType == NF_KEY_NNNN )
{ {
...@@ -1095,11 +1111,23 @@ void SvXMLNumFmtExport::ExportPart_Impl( SvNumberformat& rFormat, sal_uInt32 nKe ...@@ -1095,11 +1111,23 @@ void SvXMLNumFmtExport::ExportPart_Impl( SvNumberformat& rFormat, sal_uInt32 nKe
break; break;
case NF_KEY_YY: case NF_KEY_YY:
case NF_KEY_YYYY: case NF_KEY_YYYY:
case NF_KEY_EC:
case NF_KEY_EEC:
{ {
sal_Bool bLong = ( nElemType == NF_KEY_YYYY ); //! add calendar attribute for E and EE?
sal_Bool bLong = ( nElemType == NF_KEY_YYYY || nElemType == NF_KEY_EEC );
WriteYearElement_Impl( bSystemDate ? bLongSysDate : bLong ); WriteYearElement_Impl( bSystemDate ? bLongSysDate : bLong );
} }
break; break;
case NF_KEY_G:
case NF_KEY_GG:
case NF_KEY_GGG:
{
//! distinguish GG and GGG
sal_Bool bLong = ( nElemType == NF_KEY_GGG );
WriteEraElement_Impl( bSystemDate ? bLongSysDate : bLong );
}
break;
case NF_KEY_Q: case NF_KEY_Q:
case NF_KEY_QQ: case NF_KEY_QQ:
{ {
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: xmlnumfi.cxx,v $ * $RCSfile: xmlnumfi.cxx,v $
* *
* $Revision: 1.2 $ * $Revision: 1.3 $
* *
* last change: $Author: er $ $Date: 2000-11-24 19:41:01 $ * last change: $Author: nn $ $Date: 2000-11-29 20:37:27 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -236,6 +236,7 @@ enum SvXMLStyleTokens ...@@ -236,6 +236,7 @@ enum SvXMLStyleTokens
XML_TOK_STYLE_DAY, XML_TOK_STYLE_DAY,
XML_TOK_STYLE_MONTH, XML_TOK_STYLE_MONTH,
XML_TOK_STYLE_YEAR, XML_TOK_STYLE_YEAR,
XML_TOK_STYLE_ERA,
XML_TOK_STYLE_DAY_OF_WEEK, XML_TOK_STYLE_DAY_OF_WEEK,
XML_TOK_STYLE_WEEK_OF_YEAR, XML_TOK_STYLE_WEEK_OF_YEAR,
XML_TOK_STYLE_QUARTER, XML_TOK_STYLE_QUARTER,
...@@ -326,6 +327,7 @@ static __FAR_DATA SvXMLTokenMapEntry aStyleElemMap[] = ...@@ -326,6 +327,7 @@ static __FAR_DATA SvXMLTokenMapEntry aStyleElemMap[] =
{ XML_NAMESPACE_NUMBER, sXML_day, XML_TOK_STYLE_DAY }, { XML_NAMESPACE_NUMBER, sXML_day, XML_TOK_STYLE_DAY },
{ XML_NAMESPACE_NUMBER, sXML_month, XML_TOK_STYLE_MONTH }, { XML_NAMESPACE_NUMBER, sXML_month, XML_TOK_STYLE_MONTH },
{ XML_NAMESPACE_NUMBER, sXML_year, XML_TOK_STYLE_YEAR }, { XML_NAMESPACE_NUMBER, sXML_year, XML_TOK_STYLE_YEAR },
{ XML_NAMESPACE_NUMBER, sXML_era, XML_TOK_STYLE_ERA },
{ XML_NAMESPACE_NUMBER, sXML_day_of_week, XML_TOK_STYLE_DAY_OF_WEEK }, { XML_NAMESPACE_NUMBER, sXML_day_of_week, XML_TOK_STYLE_DAY_OF_WEEK },
{ XML_NAMESPACE_NUMBER, sXML_week_of_year, XML_TOK_STYLE_WEEK_OF_YEAR }, { XML_NAMESPACE_NUMBER, sXML_week_of_year, XML_TOK_STYLE_WEEK_OF_YEAR },
{ XML_NAMESPACE_NUMBER, sXML_quarter, XML_TOK_STYLE_QUARTER }, { XML_NAMESPACE_NUMBER, sXML_quarter, XML_TOK_STYLE_QUARTER },
...@@ -709,8 +711,11 @@ void SvXMLNumFmtElementContext::EndElement() ...@@ -709,8 +711,11 @@ void SvXMLNumFmtElementContext::EndElement()
// skip separator constant after long day of week // skip separator constant after long day of week
// (NF_KEY_NNNN contains the separator) // (NF_KEY_NNNN contains the separator)
//!aContent.setLength(0); //! doesn't work, #76293# if ( rParent.ReplaceNfKeyword( NF_KEY_NNN, NF_KEY_NNNN ) )
aContent = OUStringBuffer(); {
//!aContent.setLength(0); //! doesn't work, #76293#
aContent = OUStringBuffer();
}
rParent.SetHasLongDoW( sal_False ); // only once rParent.SetHasLongDoW( sal_False ); // only once
} }
...@@ -776,7 +781,18 @@ void SvXMLNumFmtElementContext::EndElement() ...@@ -776,7 +781,18 @@ void SvXMLNumFmtElementContext::EndElement()
if ( rParent.IsFromSystem() ) if ( rParent.IsFromSystem() )
bEffLong = bLong ? rParent.GetInternational().IsLongDateCentury() : bEffLong = bLong ? rParent.GetInternational().IsLongDateCentury() :
rParent.GetInternational().IsDateCentury(); rParent.GetInternational().IsDateCentury();
rParent.AddNfKeyword( bEffLong ? NF_KEY_YYYY : NF_KEY_YY ); // Y after G (era) is replaced by E
if ( rParent.HasEra() )
rParent.AddNfKeyword( bEffLong ? NF_KEY_EEC : NF_KEY_EC );
else
rParent.AddNfKeyword( bEffLong ? NF_KEY_YYYY : NF_KEY_YY );
break;
case XML_TOK_STYLE_ERA:
if ( rParent.IsFromSystem() )
bEffLong = bLong ? rParent.GetInternational().IsLongDateCentury() :
rParent.GetInternational().IsDateCentury();
rParent.AddNfKeyword( bEffLong ? NF_KEY_GGG : NF_KEY_G );
// HasEra flag is set
break; break;
case XML_TOK_STYLE_DAY_OF_WEEK: case XML_TOK_STYLE_DAY_OF_WEEK:
if ( rParent.IsFromSystem() && bLong ) if ( rParent.IsFromSystem() && bLong )
...@@ -865,6 +881,7 @@ SvXMLNumFormatContext::SvXMLNumFormatContext( SvXMLImport& rImport, ...@@ -865,6 +881,7 @@ SvXMLNumFormatContext::SvXMLNumFormatContext( SvXMLImport& rImport,
bAutoInt( FALSE ), bAutoInt( FALSE ),
bHasExtraText( FALSE ), bHasExtraText( FALSE ),
bHasLongDoW( FALSE ), bHasLongDoW( FALSE ),
bHasEra( FALSE ),
bHasDateTime( FALSE ), bHasDateTime( FALSE ),
bHasMap( sal_False ), bHasMap( sal_False ),
pStyles( &rStyles ), pStyles( &rStyles ),
...@@ -946,6 +963,7 @@ SvXMLImportContext* SvXMLNumFormatContext::CreateChildContext( ...@@ -946,6 +963,7 @@ SvXMLImportContext* SvXMLNumFormatContext::CreateChildContext(
case XML_TOK_STYLE_DAY: case XML_TOK_STYLE_DAY:
case XML_TOK_STYLE_MONTH: case XML_TOK_STYLE_MONTH:
case XML_TOK_STYLE_YEAR: case XML_TOK_STYLE_YEAR:
case XML_TOK_STYLE_ERA:
case XML_TOK_STYLE_DAY_OF_WEEK: case XML_TOK_STYLE_DAY_OF_WEEK:
case XML_TOK_STYLE_WEEK_OF_YEAR: case XML_TOK_STYLE_WEEK_OF_YEAR:
case XML_TOK_STYLE_QUARTER: case XML_TOK_STYLE_QUARTER:
...@@ -1055,6 +1073,8 @@ void SvXMLNumFormatContext::CreateAndInsert(sal_Bool bOverwrite) ...@@ -1055,6 +1073,8 @@ void SvXMLNumFormatContext::CreateAndInsert(sal_Bool bOverwrite)
// instead of automatic date format, use fixed formats if bFromSystem is not set // instead of automatic date format, use fixed formats if bFromSystem is not set
//! prevent use of automatic formats in other cases, force user-defined format? //! prevent use of automatic formats in other cases, force user-defined format?
sal_uInt32 nNewIndex = nIndex;
NfIndexTableOffset eOffset = pFormatter->GetIndexTableOffset( nIndex ); NfIndexTableOffset eOffset = pFormatter->GetIndexTableOffset( nIndex );
if ( eOffset == NF_DATE_SYSTEM_SHORT ) if ( eOffset == NF_DATE_SYSTEM_SHORT )
{ {
...@@ -1062,9 +1082,9 @@ void SvXMLNumFormatContext::CreateAndInsert(sal_Bool bOverwrite) ...@@ -1062,9 +1082,9 @@ void SvXMLNumFormatContext::CreateAndInsert(sal_Bool bOverwrite)
if ( rInt.IsDateDayLeadingZero() && rInt.IsDateMonthLeadingZero() ) if ( rInt.IsDateDayLeadingZero() && rInt.IsDateMonthLeadingZero() )
{ {
if ( rInt.IsDateCentury() ) if ( rInt.IsDateCentury() )
nIndex = pFormatter->GetFormatIndex( NF_DATE_SYS_DDMMYYYY, nFormatLang ); nNewIndex = pFormatter->GetFormatIndex( NF_DATE_SYS_DDMMYYYY, nFormatLang );
else else
nIndex = pFormatter->GetFormatIndex( NF_DATE_SYS_DDMMYY, nFormatLang ); nNewIndex = pFormatter->GetFormatIndex( NF_DATE_SYS_DDMMYY, nFormatLang );
} }
} }
else if ( eOffset == NF_DATE_SYSTEM_LONG ) else if ( eOffset == NF_DATE_SYSTEM_LONG )
...@@ -1077,14 +1097,24 @@ void SvXMLNumFormatContext::CreateAndInsert(sal_Bool bOverwrite) ...@@ -1077,14 +1097,24 @@ void SvXMLNumFormatContext::CreateAndInsert(sal_Bool bOverwrite)
if ( eMonth == MONTH_LONG && bCentury ) if ( eMonth == MONTH_LONG && bCentury )
{ {
if ( rInt.GetLongDateDayOfWeekFormat() == DAYOFWEEK_LONG ) if ( rInt.GetLongDateDayOfWeekFormat() == DAYOFWEEK_LONG )
nIndex = pFormatter->GetFormatIndex( NF_DATE_SYS_NNNNDMMMMYYYY, nFormatLang ); nNewIndex = pFormatter->GetFormatIndex( NF_DATE_SYS_NNNNDMMMMYYYY, nFormatLang );
else else
nIndex = pFormatter->GetFormatIndex( NF_DATE_SYS_NNDMMMMYYYY, nFormatLang ); nNewIndex = pFormatter->GetFormatIndex( NF_DATE_SYS_NNDMMMMYYYY, nFormatLang );
} }
else if ( eMonth == MONTH_SHORT && !bCentury ) else if ( eMonth == MONTH_SHORT && !bCentury )
nIndex = pFormatter->GetFormatIndex( NF_DATE_SYS_NNDMMMYY, nFormatLang ); nNewIndex = pFormatter->GetFormatIndex( NF_DATE_SYS_NNDMMMYY, nFormatLang );
} }
} }
if ( nNewIndex != nIndex )
{
// verify the fixed format really matches the format string
// (not the case with some formats from locale data)
const SvNumberformat* pFixedFormat = pFormatter->GetEntry( nNewIndex );
if ( pFixedFormat && pFixedFormat->GetFormatstring() == String(sFormat) )
nIndex = nNewIndex;
}
} }
if ( nIndex != NUMBERFORMAT_ENTRY_NOT_FOUND && !bAutoOrder ) if ( nIndex != NUMBERFORMAT_ENTRY_NOT_FOUND && !bAutoOrder )
...@@ -1224,8 +1254,14 @@ void SvXMLNumFormatContext::AddNfKeyword( sal_uInt16 nIndex ) ...@@ -1224,8 +1254,14 @@ void SvXMLNumFormatContext::AddNfKeyword( sal_uInt16 nIndex )
if (!pFormatter) if (!pFormatter)
return; return;
if ( nIndex == NF_KEY_G || nIndex == NF_KEY_GG || nIndex == NF_KEY_GGG )
bHasEra = sal_True;
if ( nIndex == NF_KEY_NNNN ) if ( nIndex == NF_KEY_NNNN )
{
nIndex = NF_KEY_NNN;
bHasLongDoW = sal_True; // to remove string constant with separator bHasLongDoW = sal_True; // to remove string constant with separator
}
String sKeyword = pFormatter->GetKeyword( nFormatLang, nIndex ); String sKeyword = pFormatter->GetKeyword( nFormatLang, nIndex );
...@@ -1246,6 +1282,45 @@ void SvXMLNumFormatContext::AddNfKeyword( sal_uInt16 nIndex ) ...@@ -1246,6 +1282,45 @@ void SvXMLNumFormatContext::AddNfKeyword( sal_uInt16 nIndex )
aFormatCode.append( sKeyword ); aFormatCode.append( sKeyword );
} }
sal_Bool lcl_IsAtEnd( rtl::OUStringBuffer& rBuffer, const String& rToken )
{
sal_Int32 nBufLen = rBuffer.getLength();
xub_StrLen nTokLen = rToken.Len();
if ( nTokLen > nBufLen )
return sal_False;
sal_Int32 nStartPos = nTokLen - nBufLen;
for ( xub_StrLen nTokPos = 0; nTokPos < nTokLen; nTokPos++ )
if ( rToken.GetChar( nTokPos ) != rBuffer.charAt( nStartPos + nTokPos ) )
return sal_False;
return sal_True;
}
sal_Bool SvXMLNumFormatContext::ReplaceNfKeyword( sal_uInt16 nOld, sal_uInt16 nNew )
{
// replaces one keyword with another if it is found at the end of the code
SvNumberFormatter* pFormatter = pData->GetNumberFormatter();
if (!pFormatter)
return sal_False;
String sOldStr = pFormatter->GetKeyword( nFormatLang, nOld );
if ( lcl_IsAtEnd( aFormatCode, sOldStr ) )
{
// remove old keyword
aFormatCode.setLength( aFormatCode.getLength() - sOldStr.Len() );
// add new keyword
String sNewStr = pFormatter->GetKeyword( nFormatLang, nNew );
aFormatCode.append( sNewStr );
return sal_True; // changed
}
return sal_False; // not found
}
void SvXMLNumFormatContext::AddCondition( ) void SvXMLNumFormatContext::AddCondition( )
{ {
rtl::OUString rApplyName = sMapName; rtl::OUString rApplyName = sMapName;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment