Annotation of Amaya/amaya/fetchXMLname.c, revision 1.87

1.1       cvs         1: /*
                      2:  *
1.75      vatton      3:  *  (c) COPYRIGHT INRIA and W3C, 1996-2005
1.1       cvs         4:  *  Please first read the full copyright statement in file COPYRIGHT.
                      5:  *
                      6:  */
                      7:  
                      8: /*
                      9:  *
                     10:  * fetchXMLname
                     11:  *
1.46      cvs        12:  * Authors: I. Vatton
                     13:  *          L. Carcone
1.1       cvs        14:  *
                     15:  */
                     16: 
                     17: #define THOT_EXPORT extern
                     18: #include "amaya.h"
                     19: #include "parser.h"
1.24      cvs        20: #include "HTMLnames.h"
                     21: #include "MathMLnames.h"
1.49      vatton     22: #include "SVGnames.h"
1.24      cvs        23: #include "XLinknames.h"
1.77      tollenae   24: #include "Templatename.h"
1.24      cvs        25: 
1.35      cvs        26: /* define some pointers to let other parser functions access the local table */
1.24      cvs        27: int               HTML_ENTRIES = (sizeof(XHTMLElemMappingTable) / sizeof(ElemMapping));
                     28: ElemMapping      *pHTMLGIMapping = XHTMLElemMappingTable;
                     29: AttributeMapping *pHTMLAttributeMapping = XHTMLAttributeMappingTable;
1.14      cvs        30: 
1.35      cvs        31: XmlEntity        *pXhtmlEntityTable = XhtmlEntityTable;
                     32: XmlEntity        *pMathEntityTable = MathEntityTable;
1.1       cvs        33: 
                     34: #include "fetchXMLname_f.h"
                     35: 
1.39      cvs        36: /* Global variables used by the entity mapping */
                     37: static int        XHTMLSup = 0;
                     38: static int        MathSup = 0;
                     39: 
1.1       cvs        40: /*----------------------------------------------------------------------
1.80      vatton     41:   GetXHTMLSSchema returns the XHTML Thot schema for document doc.
1.14      cvs        42:   ----------------------------------------------------------------------*/
1.55      vatton     43: SSchema GetXHTMLSSchema (Document doc)
1.14      cvs        44: {
                     45:   SSchema      XHTMLSSchema;
                     46: 
1.80      vatton     47:   XHTMLSSchema = TtaGetSSchema ("HTML", doc);
                     48:   if (XHTMLSSchema == NULL)
                     49:     XHTMLSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc), NULL,
                     50:                                 "HTML", "HTMLP");
                     51:   return (XHTMLSSchema);
1.14      cvs        52: }
                     53: 
1.54      cvs        54: /*----------------------------------------------------------------------
1.80      vatton     55:   GetMathMLSSchema returns the MathML Thot schema for document doc.
1.1       cvs        56:   ----------------------------------------------------------------------*/
1.55      vatton     57: SSchema GetMathMLSSchema (Document doc)
1.1       cvs        58: {
                     59:   SSchema      MathMLSSchema;
                     60: 
1.43      cvs        61:   MathMLSSchema = TtaGetSSchema ("MathML", doc);
1.13      cvs        62:   if (MathMLSSchema == NULL)
1.80      vatton     63:     MathMLSSchema = TtaNewNature(doc, 
                     64:                                  TtaGetDocumentSSchema(doc), NULL,
                     65:                                  "MathML", "MathMLP");
1.13      cvs        66:   return (MathMLSSchema);
1.1       cvs        67: }
                     68: 
                     69: /*----------------------------------------------------------------------
1.80      vatton     70:   GetSVGSSchema returns the SVG Thot schema for document doc.
1.1       cvs        71:   ----------------------------------------------------------------------*/
1.55      vatton     72: SSchema GetSVGSSchema (Document doc)
1.1       cvs        73: 
                     74: {
1.49      vatton     75:   SSchema      SVGSSchema;
1.1       cvs        76: 
1.49      vatton     77:   SVGSSchema = TtaGetSSchema ("SVG", doc);
                     78:   if (SVGSSchema == NULL)
1.72      quint      79:     SVGSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc), NULL,
1.80      vatton     80:                               "SVG", "SVGP");
1.49      vatton     81:   return (SVGSSchema);
1.1       cvs        82: }
                     83: 
                     84: /*----------------------------------------------------------------------
1.80      vatton     85:   GetXLinkSSchema returns the XLink Thot schema for document doc.
1.13      cvs        86:   ----------------------------------------------------------------------*/
1.55      vatton     87: SSchema GetXLinkSSchema (Document doc)
1.13      cvs        88: 
                     89: {
                     90:   SSchema      XLinkSSchema;
                     91: 
1.43      cvs        92:   XLinkSSchema = TtaGetSSchema ("XLink", doc);
1.13      cvs        93:   if (XLinkSSchema == NULL)
1.72      quint      94:     XLinkSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc), NULL,
1.80      vatton     95:                                 "XLink", "XLinkP");
1.13      cvs        96:   return (XLinkSSchema);
                     97: }
                     98: 
1.76      tollenae   99: /* --------------------------------------------------------------------
                    100:    GetTemplateSSchema returns the Template Thot schema for document doc.
                    101:    --------------------------------------------------------------------*/
                    102: 
                    103: SSchema GetTemplateSSchema (Document doc)
                    104: {
                    105:   SSchema       TemplateSSchema;
                    106:   
                    107:   TemplateSSchema = TtaGetSSchema ("Template",doc);
                    108:   if (TemplateSSchema == NULL)
                    109:     TemplateSSchema = TtaNewNature (doc, TtaGetDocumentSSchema(doc), NULL,
1.80      vatton    110:                                     "Template", "TemplateP");
1.76      tollenae  111:   
                    112:   return (TemplateSSchema);
                    113: }
                    114:     
                    115: 
                    116: 
1.13      cvs       117: /*----------------------------------------------------------------------
1.80      vatton    118:   GetTextSSchema returns the TextFile Thot schema for document doc.
                    119:   (this is not XML, but its useful to have this function here).
1.57      kahan     120:   ----------------------------------------------------------------------*/
1.66      vatton    121: SSchema GetTextSSchema (Document doc)
1.57      kahan     122: 
                    123: {
                    124:   SSchema      XLinkSSchema;
                    125: 
                    126:   XLinkSSchema = TtaGetSSchema ("TextFile", doc);
                    127:   if (XLinkSSchema == NULL)
1.72      quint     128:     XLinkSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc), NULL,
1.80      vatton    129:                                 "TextFile", "TextFileP");
1.57      kahan     130:   return (XLinkSSchema);
                    131: }
                    132: 
1.61      cvs       133: /*----------------------------------------------------------------------
1.80      vatton    134:   GetGenericXMLSSchema
                    135:   Returns the XML Thot schema of name schemaName for the document doc.
1.61      cvs       136:   ----------------------------------------------------------------------*/
                    137: SSchema GetGenericXMLSSchema (char *schemaName, Document doc)
                    138: 
                    139: {
                    140:   SSchema      XMLSSchema;
                    141: 
                    142:   XMLSSchema = TtaGetSSchema (schemaName, doc);
                    143:   if (XMLSSchema == NULL)
1.72      quint     144:     XMLSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc), NULL,
1.80      vatton    145:                               "XML", "XMLP");
1.61      cvs       146:   return (XMLSSchema);
                    147: }
1.57      kahan     148: 
                    149: /*----------------------------------------------------------------------
1.80      vatton    150:   GetGenericXMLSSchemaByUri
                    151:   Returns the XML Thot schema for the document doc.
1.46      cvs       152:   ----------------------------------------------------------------------*/
1.55      vatton    153: SSchema GetGenericXMLSSchemaByUri (char *uriName, Document doc, ThotBool *isnew)
1.46      cvs       154: 
                    155: {
                    156:   SSchema      XMLSSchema;
                    157: 
1.73      cvs       158:   if (uriName == NULL)
                    159:     XMLSSchema = NULL;
                    160:   else
                    161:     XMLSSchema = TtaGetSSchemaByUri (uriName, doc);
                    162: 
1.46      cvs       163:   if (XMLSSchema == NULL)
                    164:     {
1.72      quint     165:       XMLSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc), uriName,
1.80      vatton    166:                                 "XML", "XMLP");
1.46      cvs       167:       *isnew = TRUE;
                    168:     }
                    169:   return (XMLSSchema);
                    170: }
                    171: 
1.76      tollenae  172: 
1.46      cvs       173: /*----------------------------------------------------------------------
1.80      vatton    174:   GetXMLSSchema returns the XML Thot schema for document doc.
1.1       cvs       175:   ----------------------------------------------------------------------*/
1.45      cvs       176: SSchema GetXMLSSchema (int XMLtype, Document doc)
1.38      cvs       177: 
1.1       cvs       178: {
1.14      cvs       179:   if (XMLtype == XHTML_TYPE)
                    180:     return GetXHTMLSSchema (doc);
                    181:   else if (XMLtype == MATH_TYPE)
1.13      cvs       182:     return GetMathMLSSchema (doc);
1.51      cvs       183:   else if (XMLtype == SVG_TYPE)
1.49      vatton    184:     return GetSVGSSchema (doc);
1.13      cvs       185:   else if (XMLtype == XLINK_TYPE)
1.15      cvs       186:     return GetXLinkSSchema (doc);
1.78      cvs       187:   else if (XMLtype == Template_TYPE)
                    188:     return GetTemplateSSchema (doc);
1.13      cvs       189:   else
                    190:     return NULL;
1.1       cvs       191: }
                    192: 
1.82      vatton    193: /*--------------------------------------------------------------------------
                    194:   HasNatures
                    195:   Check if there are MathML and/or SVG natures
                    196:   --------------------------------------------------------------------------*/
                    197: void HasNatures (Document document, ThotBool *useMathML, ThotBool *useSVG)
                    198: {
                    199:   SSchema         nature;
                    200:   char           *ptr;
                    201: 
                    202:   /* look for a MathML or SVG nature within the document */
                    203:   nature = NULL;
                    204:   *useMathML = FALSE;
                    205:   *useSVG = FALSE;
1.83      vatton    206:   if (DocumentMeta[document] && DocumentMeta[document]->compound)
                    207:     do
                    208:       {
                    209:         TtaNextNature (document, &nature);
                    210:         if (nature)
                    211:           {
                    212:             ptr = TtaGetSSchemaName (nature);
                    213:             if (!strcmp (ptr, "MathML"))
                    214:               *useMathML = TRUE;
                    215:             if (!strcmp (ptr, "SVG"))
                    216:               *useSVG = TRUE;
                    217:           }
                    218:       }
                    219:     while (nature);
1.82      vatton    220: }
                    221: 
1.1       cvs       222: /*----------------------------------------------------------------------
1.22      cvs       223:   MapXMLElementType
                    224:   Generic function which searchs in the Element Mapping table, selected
                    225:   by the parameter XMLtype, the entry XMLname and returns the corresponding
                    226:   Thot element type.
1.55      vatton    227:   Returns:
1.80      vatton    228:   - ElTypeNum and ElSSchema into elType  ElTypeNum = 0 if not found.
                    229:   - content information about this entry
                    230:   - checkProfile TRUE if the entry is valid for the current Doc profile.
1.1       cvs       231:   ----------------------------------------------------------------------*/
1.55      vatton    232: void MapXMLElementType (int XMLtype, char *XMLname, ElementType *elType,
1.80      vatton    233:                         char **mappedName, char *content,
                    234:                         ThotBool *checkProfile, Document doc)
1.1       cvs       235: {
1.56      vatton    236:   ElemMapping        *ptr;
                    237:   char                c;
1.66      vatton    238:   int                 i, profile;
1.68      vatton    239:   ThotBool            xmlformat;
1.1       cvs       240: 
1.56      vatton    241:   /* Initialize variables */
                    242:   *mappedName = NULL;
                    243:   *checkProfile = TRUE;
                    244:   elType->ElTypeNum = 0;
1.66      vatton    245:   profile = TtaGetDocumentProfile (doc);
1.70      vatton    246:   if (profile == L_Annot)
                    247:     profile = L_Other;
1.68      vatton    248:   /* case sensitive comparison for xml documents */
                    249:   xmlformat = (DocumentMeta[doc] && DocumentMeta[doc]->xmlformat);
                    250: 
1.56      vatton    251:   /* Select the right table */
                    252:   if (XMLtype == XHTML_TYPE)
1.69      vatton    253:     {
                    254:       ptr = XHTMLElemMappingTable;
                    255:       /* no case sensitive whent there is an explicit "text/html" content_type */
                    256:       if (xmlformat && DocumentMeta[doc] && DocumentMeta[doc]->content_type &&
1.80      vatton    257:           !strcmp (DocumentMeta[doc]->content_type, "text/html"))
                    258:         xmlformat = FALSE;
1.69      vatton    259:     }
1.56      vatton    260:   else if (XMLtype == MATH_TYPE)
                    261:     {
1.66      vatton    262:       if (profile == L_Basic && DocumentTypes[doc] == docHTML)
1.80      vatton    263:         {
                    264:           /* Maths are not allowed in this document */
                    265:           ptr = NULL;
                    266:           *checkProfile = FALSE;
                    267:         }
1.56      vatton    268:       else
1.80      vatton    269:         ptr = MathMLElemMappingTable;
1.56      vatton    270:     }
                    271:   else if (XMLtype == SVG_TYPE)
                    272:     {
1.66      vatton    273:       if (profile == L_Basic && DocumentTypes[doc] == docHTML)
1.80      vatton    274:         {
                    275:           /* Graphics are not allowed in this document */
                    276:           ptr = NULL;
                    277:           *checkProfile = FALSE;
                    278:         }
1.56      vatton    279:       else
1.80      vatton    280:         ptr = SVGElemMappingTable;
1.56      vatton    281:     }
1.77      tollenae  282:   else if (XMLtype == Template_TYPE)
                    283:     {
                    284:       if (profile == L_Basic && DocumentTypes[doc] == docHTML)
1.80      vatton    285:         {
                    286:           /* Graphics are not allowed in this document */
                    287:           ptr = NULL;
                    288:           *checkProfile = FALSE;
                    289:         }
1.77      tollenae  290:       else
1.80      vatton    291:         ptr = TemplateElemMappingTable;
1.77      tollenae  292:     }
1.56      vatton    293:   else
                    294:     ptr = NULL;
1.32      cvs       295:    
1.56      vatton    296:   if (ptr)
                    297:     {
                    298:       /* search in the ElemMappingTable */
                    299:       i = 0;
                    300:       /* case insensitive for HTML */
1.68      vatton    301:       if (!xmlformat && ptr == XHTMLElemMappingTable)
1.80      vatton    302:         c = tolower (XMLname[0]);
1.56      vatton    303:       else
1.80      vatton    304:         c = XMLname[0];
1.56      vatton    305:       /* look for the first concerned entry in the table */
                    306:       while (ptr[i].XMLname[0] < c && ptr[i].XMLname[0] != EOS)
1.80      vatton    307:         i++;     
1.56      vatton    308:       /* look at all entries starting with the right character */
                    309:       do
1.80      vatton    310:         if (!xmlformat && ptr == XHTMLElemMappingTable &&
                    311:             strcasecmp (ptr[i].XMLname, XMLname))
                    312:           /* it's not the tag */
                    313:           i++;
                    314:         else if ((xmlformat || ptr != XHTMLElemMappingTable) &&
                    315:                  strcmp (ptr[i].XMLname, XMLname))
                    316:           /* it's not the tag */
                    317:           i++;
                    318:         else if (profile != L_Other && !(ptr[i].Level & profile))
                    319:           {
                    320:             /* this tag is not valid in the document profile */
                    321:             *checkProfile = FALSE;
                    322:             i++;
                    323:           }
                    324:         else
                    325:           {
                    326:             elType->ElTypeNum = ptr[i].ThotType;
                    327:             if (elType->ElSSchema == NULL)
                    328:               {
                    329:                 if (XMLtype == Template_TYPE)
                    330:                   elType->ElSSchema = GetTemplateSSchema(doc);
                    331:                 else
                    332:                   elType->ElSSchema = GetXMLSSchema (XMLtype, doc);
                    333:               }
                    334:             *mappedName = ptr[i].XMLname;
                    335:             *content = ptr[i].XMLcontents;
                    336:           }
1.56      vatton    337:       while (elType->ElTypeNum <= 0 && ptr[i].XMLname[0] == c);
                    338:     }
1.1       cvs       339: }
                    340: 
                    341: 
                    342: /*----------------------------------------------------------------------
1.80      vatton    343:   GetXMLElementName
                    344:   Generic function which searchs in the mapping tables the XML name for
                    345:   a given Thot type.
1.1       cvs       346:   ----------------------------------------------------------------------*/
1.55      vatton    347: char *GetXMLElementName (ElementType elType, Document doc)
1.1       cvs       348: {
1.46      cvs       349:   ElemMapping  *ptr;
                    350:   char         *name;
1.66      vatton    351:   int           i, profile;
1.46      cvs       352:   ThotBool      invalid = FALSE;
1.27      cvs       353: 
                    354:   if (elType.ElTypeNum > 0)
                    355:     {
                    356:       i = 0;
                    357:       /* Select the table which matches with the element schema */
                    358:       name = TtaGetSSchemaName (elType.ElSSchema);
1.44      cvs       359:       if (strcmp ("MathML", name) == 0)
1.80      vatton    360:         ptr = MathMLElemMappingTable;
1.49      vatton    361:       else if (strcmp ("SVG", name) == 0)
1.80      vatton    362:         ptr = SVGElemMappingTable;
1.63      quint     363:       else if (strcmp ("HTML", name) == 0)
1.80      vatton    364:         ptr = XHTMLElemMappingTable;
1.27      cvs       365:       else
1.80      vatton    366:         ptr = NULL;
1.63      quint     367: 
1.66      vatton    368:       profile = TtaGetDocumentProfile (doc);
1.70      vatton    369:       if (profile == L_Annot)
1.80      vatton    370:         profile = L_Other;
1.27      cvs       371:       if (ptr)
1.80      vatton    372:         do
                    373:           {
                    374:             if (ptr[i].ThotType == elType.ElTypeNum)
                    375:               {
                    376:                 if (doc == 0 || 
                    377:                     profile == L_Other || (ptr[i].Level & profile))
                    378:                   return ptr[i].XMLname;
                    379:                 else
                    380:                   invalid = TRUE;
                    381:               }
                    382:             i++;
                    383:           }
                    384:         while (ptr[i].XMLname[0] != EOS);        
1.27      cvs       385:     }
                    386:   if (invalid)
1.43      cvs       387:     return "";
1.27      cvs       388:   else
1.43      cvs       389:     return "???";
1.22      cvs       390: }
1.25      cvs       391: 
                    392: 
1.29      cvs       393: /*----------------------------------------------------------------------
1.80      vatton    394:   IsXMLElementInline
                    395:   Generic function which searchs in the mapping tables if a given
                    396:   Thot type is an inline character or not
1.29      cvs       397:   ----------------------------------------------------------------------*/
1.55      vatton    398: ThotBool IsXMLElementInline (ElementType elType, Document doc)
1.29      cvs       399: {
1.34      cvs       400:   int            i;
                    401:   ThotBool       ret = FALSE;
1.45      cvs       402:   char          *name;
1.34      cvs       403:   ElemMapping   *ptr;
1.29      cvs       404: 
                    405:   if (elType.ElTypeNum > 0)
                    406:     {
                    407:       i = 0;
                    408:       /* Select the table which matches with the element schema */
                    409:       name = TtaGetSSchemaName (elType.ElSSchema);
1.44      cvs       410:       if (strcmp ("MathML", name) == 0)
1.80      vatton    411:         ptr = MathMLElemMappingTable;
1.49      vatton    412:       else if (strcmp ("SVG", name) == 0)
1.80      vatton    413:         ptr = SVGElemMappingTable;
1.52      cvs       414:       else if (strcmp ("HTML", name) == 0)
1.80      vatton    415:         ptr = XHTMLElemMappingTable;
1.29      cvs       416:       else
1.80      vatton    417:         ptr = NULL;
1.29      cvs       418:       
                    419:       if (ptr)
1.80      vatton    420:         {
                    421:           while (ptr[i].XMLname[0] != EOS &&
                    422:                  ptr[i].ThotType != elType.ElTypeNum)
                    423:             i++;
                    424:           if (ptr[i].ThotType == elType.ElTypeNum)
                    425:             ret = ptr[i].InlineElem;
                    426:         }
1.29      cvs       427:     }
                    428:   return ret;
                    429: }
                    430: 
1.22      cvs       431: /*----------------------------------------------------------------------
1.85      vatton    432:   MapXMLAttributeValue
1.80      vatton    433:   Search in the Attribute Value Mapping Table the entry for the attribute
                    434:   ThotAtt and its value attVal. Returns the corresponding Thot value.
1.59      vatton    435:   ----------------------------------------------------------------------*/
1.64      gully     436: void MapXMLAttributeValue (int XMLtype, char *attVal, const AttributeType *attrType,
1.80      vatton    437:                            int *value)
1.59      vatton    438: {
                    439:   AttrValueMapping   *ptr;
                    440:   int                 i;
                    441: 
                    442:   /* Select the right table */
                    443:   if (XMLtype == XHTML_TYPE)
1.60      vatton    444:     ptr = XhtmlAttrValueMappingTable;
1.59      vatton    445:   else if (XMLtype == MATH_TYPE)
                    446:     ptr = MathMLAttrValueMappingTable;
                    447:   else if (XMLtype == SVG_TYPE)
1.60      vatton    448:     ptr = SVGAttrValueMappingTable;
1.59      vatton    449:   else
                    450:     ptr = NULL;
                    451:   
                    452:   *value = 0;
                    453:   i = 0;
                    454:   if (ptr == NULL)
                    455:     return;
1.64      gully     456:   while (ptr[i].ThotAttr != attrType->AttrTypeNum && ptr[i].ThotAttr != 0)
1.59      vatton    457:     i++;
1.64      gully     458:   if (ptr[i].ThotAttr == attrType->AttrTypeNum)
1.59      vatton    459:     do
                    460:       if (!strcmp (ptr[i].XMLattrValue, attVal))
1.80      vatton    461:         *value = ptr[i].ThotAttrValue;
1.59      vatton    462:       else
1.80      vatton    463:         i++;
1.64      gully     464:     while (*value == 0 && ptr[i].ThotAttr == attrType->AttrTypeNum);
1.59      vatton    465: }
                    466: 
                    467: 
                    468: /*----------------------------------------------------------------------
1.80      vatton    469:   MapXMLAttribute
                    470:   Generic function which searchs in the Attribute Mapping Table (table)
                    471:   the entry attrName associated to the element elementName.
                    472:   Returns the corresponding entry or -1.
1.22      cvs       473:   ----------------------------------------------------------------------*/
1.55      vatton    474: int MapXMLAttribute (int XMLtype, char *attrName, char *elementName,
1.80      vatton    475:                      ThotBool *checkProfile, Document doc, int *thotType)
1.22      cvs       476: {
1.56      vatton    477:   AttributeMapping   *ptr;
                    478:   char                c;
1.66      vatton    479:   int                 i, profile;
1.68      vatton    480:   ThotBool            xmlformat;
1.24      cvs       481: 
1.33      cvs       482:   /* Initialization */
1.55      vatton    483:   *checkProfile = TRUE;
1.33      cvs       484:   i = 1;
                    485:   *thotType = 0;
1.68      vatton    486:   /* case sensitive comparison for xml documents */
                    487:   xmlformat = (DocumentMeta[doc] && DocumentMeta[doc]->xmlformat);
1.50      cvs       488:   
                    489:   /* Select the right table */
                    490:   if (XMLtype == XHTML_TYPE)
1.69      vatton    491:     {
                    492:       ptr = XHTMLAttributeMappingTable;
                    493:       /* no case sensitive whent there is an explicit "text/html" content_type */
                    494:       if (xmlformat && DocumentMeta[doc] && DocumentMeta[doc]->content_type &&
1.80      vatton    495:           !strcmp (DocumentMeta[doc]->content_type, "text/html"))
                    496:         xmlformat = FALSE;
1.69      vatton    497:     }
1.50      cvs       498:   else if (XMLtype == MATH_TYPE)
                    499:     ptr = MathMLAttributeMappingTable;
1.51      cvs       500:   else if (XMLtype == SVG_TYPE)
1.50      cvs       501:     ptr = SVGAttributeMappingTable;
1.79      tollenae  502: #ifdef TEMPLATES
                    503:   else if (XMLtype == Template_TYPE)
                    504:     ptr = TemplateAttributeMappingTable;
                    505: #endif /* TEMPLATES */
1.50      cvs       506:   else if (XMLtype == XLINK_TYPE)
                    507:     ptr = XLinkAttributeMappingTable;
1.79      tollenae  508: 
1.50      cvs       509:   else
                    510:     ptr = NULL;
1.24      cvs       511:   if (ptr == NULL)
                    512:     return -1;
1.50      cvs       513:   if (strcmp (attrName, "unknown_attr") == 0)
                    514:     {
                    515:       *thotType = ptr[0].ThotAttribute;
                    516:       return 0;
                    517:     }
1.22      cvs       518: 
1.56      vatton    519:   /* case insensitive for HTML */
1.68      vatton    520:   if (!xmlformat && ptr == XHTMLAttributeMappingTable)
1.56      vatton    521:     c = tolower (attrName[0]);
                    522:   else
                    523:     c = attrName[0];
1.66      vatton    524: 
                    525:   profile = TtaGetDocumentProfile (doc);
1.70      vatton    526:   if (profile == L_Annot)
                    527:     profile = L_Other;
1.22      cvs       528:   /* look for the first concerned entry in the table */
1.56      vatton    529:   while (ptr[i].XMLattribute[0] < c &&  ptr[i].XMLattribute[0] != EOS)
1.22      cvs       530:     i++;
1.56      vatton    531:   while (ptr[i].XMLattribute[0] == c)
1.22      cvs       532:     {
1.68      vatton    533:       if (!xmlformat && ptr == XHTMLAttributeMappingTable &&
1.80      vatton    534:           (strcasecmp (ptr[i].XMLattribute, attrName) ||
                    535:            (ptr[i].XMLelement[0] != EOS && elementName &&
                    536:             strcasecmp (ptr[i].XMLelement, elementName))))
                    537:         i++;
1.68      vatton    538:       else if ((xmlformat || ptr != XHTMLAttributeMappingTable) &&
1.80      vatton    539:                (strcmp (ptr[i].XMLattribute, attrName) ||
                    540:                 (ptr[i].XMLelement[0] != EOS && elementName &&
                    541:                  strcmp (ptr[i].XMLelement, elementName))))
                    542:         i++;
1.66      vatton    543:       else if (profile != L_Other && !(ptr[i].Level & profile))
1.80      vatton    544:         {
                    545:           *checkProfile = FALSE;
                    546:           i++;
                    547:         }
1.22      cvs       548:       else
1.80      vatton    549:         {
                    550:           /* Special case for the 'name' attribute for 
                    551:              elements 'a' and 'map' in xhtml1.1 profile */
                    552:           if ((profile == L_Xhtml11) &&
                    553:               !strcmp (attrName, "name") && elementName &&
                    554:               (!strcmp (elementName, "a") || !strcmp (elementName, "map")))
                    555:             *checkProfile = FALSE;
                    556:           else
                    557:             *thotType = ptr[i].ThotAttribute;
                    558:           return (i);
                    559:         }
1.22      cvs       560:     }
1.24      cvs       561:   return (-1);
1.25      cvs       562: }
                    563: 
                    564: 
                    565: /*----------------------------------------------------------------------
1.80      vatton    566:   GetXMLAttributeName
                    567:   Generic function which searchs in the mapping tables the XML name for
                    568:   a given Thot type.
1.25      cvs       569:   ----------------------------------------------------------------------*/
1.55      vatton    570: char *GetXMLAttributeName (AttributeType attrType, ElementType elType,
1.80      vatton    571:                            Document doc)
1.25      cvs       572: {
                    573:   AttributeMapping   *ptr;
1.45      cvs       574:   char               *name, *tag;
1.66      vatton    575:   int                 i, profile;
1.27      cvs       576:   ThotBool            invalid = FALSE;
1.25      cvs       577: 
1.27      cvs       578:   if (attrType.AttrTypeNum > 0)
                    579:     {
1.28      cvs       580:       /* get the specific element tag */
                    581:       if (elType.ElTypeNum > 0)
1.80      vatton    582:         tag = GetXMLElementName (elType, doc);
1.28      cvs       583:       else
1.80      vatton    584:         tag = "";
1.28      cvs       585: 
1.27      cvs       586:       i = 0;
                    587:       /* Select the table which matches with the element schema */
                    588:       name = TtaGetSSchemaName (attrType.AttrSSchema);
1.44      cvs       589:       if (strcmp ("MathML", name) == 0)
1.79      tollenae  590:         ptr = MathMLAttributeMappingTable;
                    591: #ifdef _SVG
1.49      vatton    592:       else if (strcmp ("SVG", name) == 0)
1.79      tollenae  593:         ptr = SVGAttributeMappingTable;
                    594: #endif /* _SVG */
1.44      cvs       595:       else if (strcmp ("XLink", name) == 0)
1.79      tollenae  596:         ptr = XLinkAttributeMappingTable;
                    597: #ifdef TEMPLATES
                    598:       else if (strcmp ("Template",name) == 0)
                    599:         ptr = TemplateAttributeMappingTable;
                    600: #endif /* TEMPLATES */
1.27      cvs       601:       else
1.80      vatton    602:         ptr = XHTMLAttributeMappingTable;
1.27      cvs       603:       
1.66      vatton    604:       profile = TtaGetDocumentProfile (doc);
1.70      vatton    605:       if (profile == L_Annot)
1.80      vatton    606:         profile = L_Other;
1.27      cvs       607:       if (ptr)
1.80      vatton    608:         do
                    609:           {
                    610:             if (ptr[i].ThotAttribute == attrType.AttrTypeNum &&
                    611:                 (ptr[i].XMLelement[0] == EOS ||
                    612:                  !strcmp (ptr[i].XMLelement, tag)))
                    613:               {
                    614:                 if (doc != 0 &&
                    615:                     profile != L_Other &&
                    616:                     !(ptr[i].Level & profile))
                    617:                   invalid = TRUE;
                    618:                 else
                    619:                   return ptr[i].XMLattribute;
                    620:               }
                    621:             i++;
                    622:           }
                    623:         while (ptr[i].XMLattribute[0] != EOS);   
1.27      cvs       624:     }
                    625:   if (invalid)
1.43      cvs       626:     return "";
1.27      cvs       627:   else
1.43      cvs       628:     return "???";
1.36      cvs       629: }
                    630: 
                    631: /*----------------------------------------------------------------------
1.71      vatton    632:   HasADoctype returns TRUE if the document includes a DocType
                    633:   ----------------------------------------------------------------------*/
1.82      vatton    634: void HasADoctype (Document doc, ThotBool *found, ThotBool *useMath)
1.71      vatton    635: {
                    636:   Element         el_doc, el_doctype;
                    637:   ElementType     elType;
                    638:   char           *s;
1.82      vatton    639:   ThotBool        useSVG;
1.71      vatton    640: 
                    641:   /* Look for a doctype */
                    642:   el_doc = TtaGetMainRoot (doc);
                    643:   elType = TtaGetElementType (el_doc);
                    644:   /* Search the doctype declaration according to the main schema */
                    645:   s = TtaGetSSchemaName (elType.ElSSchema);
                    646:   if (strcmp (s, "HTML") == 0)
                    647:     elType.ElTypeNum = HTML_EL_DOCTYPE;
                    648:   else if (strcmp (s, "SVG") == 0)
                    649:     elType.ElTypeNum = SVG_EL_DOCTYPE;
                    650:   else if (strcmp (s, "MathML") == 0)
1.81      vatton    651:     elType.ElTypeNum = MathML_EL_DOCTYPE;
1.71      vatton    652:   else
                    653:     elType.ElTypeNum = XML_EL_doctype;
                    654:   el_doctype = TtaSearchTypedElement (elType, SearchInTree, el_doc);
1.81      vatton    655:   *found = (el_doctype != NULL);
1.82      vatton    656:   HasNatures (doc, useMath, &useSVG);
1.71      vatton    657: }
                    658: 
                    659: 
                    660: /*----------------------------------------------------------------------
1.80      vatton    661:   MapXMLEntity
                    662:   Generic function which searchs in the Entity Mapping Table (table)
                    663:   the entry entityName and give the corresponding decimal value.
                    664:   Returns FALSE if entityName is not found.
1.36      cvs       665:   ----------------------------------------------------------------------*/
1.71      vatton    666: ThotBool MapXMLEntity (int XMLtype, char *entityName, int *entityValue)
1.36      cvs       667: {
                    668:   XmlEntity  *ptr;
                    669:   ThotBool    found;
1.38      cvs       670:   int         inf, sup, med, rescomp;
1.36      cvs       671: 
1.38      cvs       672:   /* Initialization */
1.36      cvs       673:   found = FALSE;
1.42      cvs       674:   sup = 0;
1.36      cvs       675: 
                    676:   /* Select the right table */
1.86      vatton    677:   if (XMLtype == XHTML_TYPE || XMLtype == Template_TYPE)
1.39      cvs       678:     {
                    679:       ptr = XhtmlEntityTable;
                    680:       if (XHTMLSup == 0)
1.80      vatton    681:         for (XHTMLSup = 0; ptr[XHTMLSup].charCode > 0; XHTMLSup++);
1.39      cvs       682:       sup = XHTMLSup;
                    683:     }
1.36      cvs       684:   else if (XMLtype == MATH_TYPE)
1.39      cvs       685:     {
                    686:       ptr = MathEntityTable;
                    687:       if (MathSup == 0)
1.80      vatton    688:         for (MathSup = 0; ptr[MathSup].charCode > 0; MathSup++);
1.39      cvs       689:       sup = MathSup;
                    690:     }
1.36      cvs       691:   else
                    692:     ptr = NULL;
                    693:   
1.71      vatton    694:   if (ptr)
1.36      cvs       695:     {
1.71      vatton    696:       inf = 0;
                    697:       while (sup >= inf && !found)
1.80      vatton    698:         /* Dichotomic research */
                    699:         {
                    700:           med = (sup + inf) / 2;
                    701:           rescomp = strcmp (ptr[med].charName, entityName);
                    702:           if (rescomp == 0)
                    703:             {
                    704:               /* entity found */
                    705:               *entityValue = ptr[med].charCode;
                    706:               found = TRUE;
                    707:             }
                    708:           else
                    709:             {
                    710:               if (rescomp > 0)
                    711:                 sup = med - 1;
                    712:               else
                    713:                 inf = med + 1;
                    714:             }
                    715:         }
1.36      cvs       716:     }
1.82      vatton    717:   if (!found && ptr == XhtmlEntityTable)
                    718:     // check MathML entities
                    719:     return MapXMLEntity (MATH_TYPE, entityName, entityValue);
1.38      cvs       720:   return found;
1.80      vatton    721: }
1.39      cvs       722: 
                    723: /*----------------------------------------------------------------------
1.80      vatton    724:   MapEntityByCode
                    725:   Generic function which searchs in the Entity Mapping Table (table)
                    726:   the entry with code entityValue and give the corresponding name.
1.81      vatton    727:   withMath is TRUE when MathML entities are accepted.
1.80      vatton    728:   Returns FALSE if entityValue is not found.
1.39      cvs       729:   ----------------------------------------------------------------------*/
1.81      vatton    730: void MapEntityByCode (int entityValue, Document doc, ThotBool withMath,
                    731:                       char **entityName)
1.39      cvs       732: {
                    733:   XmlEntity  *ptr;
1.81      vatton    734:   ThotBool    found;
1.39      cvs       735:   int         i;
                    736: 
1.81      vatton    737:   /* Select the right table */
1.87    ! vatton    738:   if (withMath)
        !           739:     /* look for in the Math entities table */
        !           740:     ptr = MathEntityTable;
        !           741:   else
        !           742:     ptr = XhtmlEntityTable;
1.40      cvs       743:   if (ptr)
                    744:     {
1.41      cvs       745:       /* look for in the HTML entities table */
1.40      cvs       746:       found = FALSE;
1.41      cvs       747:       while (ptr && !found)
1.80      vatton    748:         {
1.82      vatton    749:           for (i = 0; ptr[i].charCode != 0 && !found; i++)
1.80      vatton    750:             found = (ptr[i].charCode == entityValue);
1.39      cvs       751:   
1.80      vatton    752:           if (found)
                    753:             {
                    754:               /* entity value found */
                    755:               i--;
                    756:               *entityName = (char *) (ptr[i].charName);
                    757:             }
1.87    ! vatton    758:           else if (withMath && ptr != XhtmlEntityTable)
1.80      vatton    759:             /* look for in the Math entities table */
1.87    ! vatton    760:             ptr = XhtmlEntityTable;
1.80      vatton    761:           else
                    762:             {
                    763:               *entityName = NULL;
                    764:               ptr = NULL;
                    765:             }
                    766:         }
1.40      cvs       767:     }
1.39      cvs       768:   else
1.40      cvs       769:     *entityName = NULL;
1.39      cvs       770: }

Webmaster