Changeset 12567


Ignore:
Timestamp:
2006-08-25T16:47:40+12:00 (18 years ago)
Author:
kjdon
Message:

changed the special metadata formatting for Language and Date. Now these both output macros rather than a final result. Language codes get turned into _iso639:iso639xx_, dates (yyyy-?mm-?dd) get turned into _format:date_(yyyy,mm,dd). This is now controlled by a new option for metadata names [format:Date]. Without this, Dates and Languages get output as raw text. format must coma after cgiSafe and before parent/sibling/child. If its used with a different metadata name, eg [format:dc.Title] the output will be _format:dc.Title_(title value), and the user can define _dc.Title_ macro in format package to handle it.

Location:
trunk/gsdl/src/recpt
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/recpt/formattools.cpp

    r11328 r12567  
    172172    return substr(it+1, end);
    173173  }
     174
    174175  return meta_name;
    175176
    176177}
    177 // returns a date of form 31 _textmonthnn_ 1999
    178 // input is date of type 19991231
     178// returns a date of form _format:date_(year, month, day)
     179// input is date of type yyyy-?mm-?dd
    179180// at least the year must be present in date
    180181text_t format_date (const text_t &date) {
     
    185186
    186187  text_t year = substr (datebegin, datebegin+4);
    187 
    188   if (date.size() < 6) return year;
    189 
    190   text_t month = substr (datebegin+4, datebegin+6);
     188  int chars_seen_so_far = 4;
     189
     190  if (date[chars_seen_so_far] == '-') ++chars_seen_so_far ;
     191  if (date.size() < chars_seen_so_far+2) return "_format:date_("+year+")";
     192 
     193  text_t month = substr (datebegin+chars_seen_so_far, datebegin+chars_seen_so_far+2);
    191194  int imonth = month.getint();
    192   if (imonth <= 0 || imonth > 12) return year;
    193   month = "_textmonth" + month + "_";
    194 
    195   if (date.size() < 8) return month + " " + year;
    196 
    197   text_t day = substr (datebegin+6, datebegin+8);
     195  if (imonth <= 0 || imonth > 12) return "_format:date_("+year+")";
     196 
     197  chars_seen_so_far += 2;
     198  if (date[chars_seen_so_far] == '-') ++chars_seen_so_far ;
     199 
     200  if (date.size() < chars_seen_so_far+2) return "_format:date_("+year+","+month+")";
     201
     202  text_t day = substr (datebegin+chars_seen_so_far, datebegin+chars_seen_so_far+2);
    198203  if (day[0] == '0') day = substr (day.begin()+1, day.end());
    199204  int iday = day.getint();
    200   if (iday <= 0 || iday > 31) return month + " " + year;
    201    
    202   return day + " " + month + " " + year;
     205  if (iday <= 0 || iday > 31) return "_format:date_("+year+","+month+")";
     206   
     207  return "_format:date_("+year+","+month+","+day+")";
    203208
    204209
    205210// converts an iso639 language code to its English equivalent
    206 // I realize that this isn't the pretiest or most efficient implementation,
    207 // hopefully this ugly Language (and Date too) formatting won't survive to
    208 // see gsdl-3.0
     211// should we be checking that the macro exists??
    209212text_t iso639 (const text_t &langcode) {
    210 
    211   if (langcode == "aa") return "Afar";
    212   if (langcode == "ab") return "Abkhazian";
    213   if (langcode == "af") return "Afrikaans";
    214   if (langcode == "am") return "Amharic";
    215   if (langcode == "ar") return "Arabic";
    216   if (langcode == "as") return "Assamese";
    217   if (langcode == "ay") return "Aymara";
    218   if (langcode == "az") return "Azerbaijani";
    219  
    220   if (langcode == "ba") return "Bashkir";
    221   if (langcode == "be") return "Byelorussian";
    222   if (langcode == "bg") return "Bulgarian";
    223   if (langcode == "bh") return "Bihari";
    224   if (langcode == "bi") return "Bislama";
    225   if (langcode == "bn") return "Bengali; Bangla";
    226   if (langcode == "bo") return "Tibetan";
    227   if (langcode == "br") return "Breton";
    228  
    229   if (langcode == "ca") return "Catalan";
    230   if (langcode == "co") return "Corsican";
    231   if (langcode == "cs") return "Czech";
    232   if (langcode == "cy") return "Welsh";
    233  
    234   if (langcode == "da") return "Danish";
    235   if (langcode == "de") return "German";
    236   if (langcode == "dz") return "Bhutani";
    237  
    238   if (langcode == "el") return "Greek";
    239   if (langcode == "en") return "English";
    240   if (langcode == "eo") return "Esperanto";
    241   if (langcode == "es") return "Spanish";
    242   if (langcode == "et") return "Estonian";
    243   if (langcode == "eu") return "Basque";
    244  
    245   if (langcode == "fa") return "Persian";
    246   if (langcode == "fi") return "Finnish";
    247   if (langcode == "fj") return "Fiji";
    248   if (langcode == "fo") return "Faroese";
    249   if (langcode == "fr") return "French";
    250   if (langcode == "fy") return "Frisian";
    251  
    252   if (langcode == "ga") return "Irish";
    253   if (langcode == "gd") return "Scots Gaelic";
    254   if (langcode == "gl") return "Galician";
    255   if (langcode == "gn") return "Guarani";
    256   if (langcode == "gu") return "Gujarati";
    257  
    258   if (langcode == "ha") return "Hausa";
    259   if (langcode == "hi") return "Hindi";
    260   if (langcode == "hr") return "Croatian";
    261   if (langcode == "hu") return "Hungarian";
    262   if (langcode == "hy") return "Armenian";
    263  
    264   if (langcode == "ia") return "Interlingua";
    265   if (langcode == "ie") return "Interlingue";
    266   if (langcode == "ik") return "Inupiak";
    267   if (langcode == "in") return "Indonesian";
    268   if (langcode == "is") return "Icelandic";
    269   if (langcode == "it") return "Italian";
    270   if (langcode == "iw") return "Hebrew";
    271  
    272   if (langcode == "ja") return "Japanese";
    273   if (langcode == "ji") return "Yiddish";
    274   if (langcode == "jw") return "Javanese";
    275  
    276   if (langcode == "ka") return "Georgian";
    277   if (langcode == "kk") return "Kazakh";
    278   if (langcode == "kl") return "Greenlandic";
    279   if (langcode == "km") return "Cambodian";
    280   if (langcode == "kn") return "Kannada";
    281   if (langcode == "ko") return "Korean";
    282   if (langcode == "ks") return "Kashmiri";
    283   if (langcode == "ku") return "Kurdish";
    284   if (langcode == "ky") return "Kirghiz";
    285  
    286   if (langcode == "la") return "Latin";
    287   if (langcode == "ln") return "Lingala";
    288   if (langcode == "lo") return "Laothian";
    289   if (langcode == "lt") return "Lithuanian";
    290   if (langcode == "lv") return "Latvian, Lettish";
    291  
    292   if (langcode == "mg") return "Malagasy";
    293   if (langcode == "mi") return "Maori";
    294   if (langcode == "mk") return "Macedonian";
    295   if (langcode == "ml") return "Malayalam";
    296   if (langcode == "mn") return "Mongolian";
    297   if (langcode == "mo") return "Moldavian";
    298   if (langcode == "mr") return "Marathi";
    299   if (langcode == "ms") return "Malay";
    300   if (langcode == "mt") return "Maltese";
    301   if (langcode == "my") return "Burmese";
    302  
    303   if (langcode == "na") return "Nauru";
    304   if (langcode == "ne") return "Nepali";
    305   if (langcode == "nl") return "Dutch";
    306   if (langcode == "no") return "Norwegian";
    307  
    308   if (langcode == "oc") return "Occitan";
    309   if (langcode == "om") return "(Afan) Oromo";
    310   if (langcode == "or") return "Oriya";
    311  
    312   if (langcode == "pa") return "Punjabi";
    313   if (langcode == "pl") return "Polish";
    314   if (langcode == "ps") return "Pashto, Pushto";
    315   if (langcode == "pt") return "Portuguese";
    316  
    317   if (langcode == "qu") return "Quechua";
    318   if (langcode == "rm") return "Rhaeto-Romance";
    319   if (langcode == "rn") return "Kirundi";
    320   if (langcode == "ro") return "Romanian";
    321   if (langcode == "ru") return "Russian";
    322   if (langcode == "rw") return "Kinyarwanda";
    323  
    324   if (langcode == "sa") return "Sanskrit";
    325   if (langcode == "sd") return "Sindhi";
    326   if (langcode == "sg") return "Sangro";
    327   if (langcode == "sh") return "Serbo-Croatian";
    328   if (langcode == "si") return "Singhalese";
    329   if (langcode == "sk") return "Slovak";
    330   if (langcode == "sl") return "Slovenian";
    331   if (langcode == "sm") return "Samoan";
    332   if (langcode == "sn") return "Shona";
    333   if (langcode == "so") return "Somali";
    334   if (langcode == "sq") return "Albanian";
    335   if (langcode == "sr") return "Serbian";
    336   if (langcode == "ss") return "Siswati";
    337   if (langcode == "st") return "Sesotho";
    338   if (langcode == "su") return "Sudanese";
    339   if (langcode == "sv") return "Swedish";
    340   if (langcode == "sw") return "Swahili";
    341  
    342   if (langcode == "ta") return "Tamil";
    343   if (langcode == "te") return "Tegulu";
    344   if (langcode == "tg") return "Tajik";
    345   if (langcode == "th") return "Thai";
    346   if (langcode == "ti") return "Tigrinya";
    347   if (langcode == "tk") return "Turkmen";
    348   if (langcode == "tl") return "Tagalog";
    349   if (langcode == "tn") return "Setswana";
    350   if (langcode == "to") return "Tonga";
    351   if (langcode == "tr") return "Turkish";
    352   if (langcode == "ts") return "Tsonga";
    353   if (langcode == "tt") return "Tatar";
    354   if (langcode == "tw") return "Twi";
    355  
    356   if (langcode == "uk") return "Ukrainian";
    357   if (langcode == "ur") return "Urdu";
    358   if (langcode == "uz") return "Uzbek";
    359  
    360   if (langcode == "vi") return "Vietnamese";
    361   if (langcode == "vo") return "Volapuk";
    362  
    363   if (langcode == "wo") return "Wolof";
    364  
    365   if (langcode == "xh") return "Xhosa";
    366  
    367   if (langcode == "yo") return "Yoruba";
    368  
    369   if (langcode == "zh") return "Chinese";
    370   if (langcode == "zu") return "Zulu";
    371   return langcode;
    372 }
     213  if (langcode.empty()) return "";
     214  return "_iso639:iso639"+langcode+"_";
     215}
     216
    373217
    374218text_t get_href (const text_t &link) {
     
    618462    meta = substr (meta.begin()+8, meta.end());
    619463  }
     464  if (meta.size() > 7 && (substr(meta.begin(), meta.begin()+7) == "format:")) {   
     465    metaoption.metacommand |= mSpecial;
     466    meta = substr (meta.begin()+7, meta.end());
     467  }
    620468
    621469  if (meta.size() > 7 && (substr (meta.begin(), meta.begin()+6) == "parent")) {
     
    988836    for (int i=start_i; i<=end_i; ++i) {
    989837      if (!first) tmp += meta.siblingoptions;
    990       if (no_ns_metaname == "Date") tmp += format_date (metainfo.values[i]);
    991       else if (no_ns_metaname == "Language") tmp += iso639(metainfo.values[i]);
     838      if (meta.metacommand & mSpecial) {
     839    // special formatting
     840    if (no_ns_metaname == "Date") tmp += format_date (metainfo.values[i]);
     841    else if (no_ns_metaname == "Language") tmp += iso639(metainfo.values[i]);
     842    else tmp += "_format:"+meta.metaname+"_("+metainfo.values[i]+")";
     843      }
    992844      else tmp += metainfo.values[i];
    993845      first = false;
     
    1000852      return "";
    1001853    }
    1002     if (no_ns_metaname == "Date") tmp += format_date (metainfo.values[position]);
    1003     else if (no_ns_metaname == "Language") tmp += iso639(metainfo.values[position]);
     854    if (meta.metacommand & mSpecial) {
     855      // special formatting
     856      if (no_ns_metaname == "Date") tmp += format_date (metainfo.values[position]);
     857      else if (no_ns_metaname == "Language") tmp += iso639(metainfo.values[position]);
     858      else tmp += "_format:"+meta.metaname+"_("+metainfo.values[position]+")";
     859    }
    1004860    else tmp += metainfo.values[position];
    1005861  }
     
    1126982   
    1127983}
    1128 
    1129 
    1130 // note: all the format_date stuff is assuming that all Date metadata is going to
    1131 // be of the form yyyymmdd, this is of course, crap ;)
    1132984
    1133985static text_t get_meta (const text_t& collection, recptproto* collectproto,
  • trunk/gsdl/src/recpt/formattools.h

    r10415 r12567  
    3838        comDocumentButtonExpandContents, comDocumentButtonExpandText, comOID, comRank, comCollection};
    3939
    40 enum mcommand_t {mNone=0, mCgiSafe=1, mParent=2, mSibling=4, mChild=8};
     40enum mcommand_t {mNone=0, mCgiSafe=1, mParent=2, mSibling=4, mChild=8, mSpecial=16};
    4141
    4242enum pcommand_t {pNone, pImmediate, pTop, pAll};
Note: See TracChangeset for help on using the changeset viewer.