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

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;
        !           206:   do
        !           207:     {
        !           208:       TtaNextNature (document, &nature);
        !           209:       if (nature)
        !           210:         {
        !           211:           ptr = TtaGetSSchemaName (nature);
        !           212:           if (!strcmp (ptr, "MathML"))
        !           213:             *useMathML = TRUE;
        !           214:           if (!strcmp (ptr, "SVG"))
        !           215:             *useSVG = TRUE;
        !           216:         }
        !           217:     }
        !           218:   while (nature);
        !           219: }
        !           220: 
1.1       cvs       221: /*----------------------------------------------------------------------
1.22      cvs       222:   MapXMLElementType
                    223:   Generic function which searchs in the Element Mapping table, selected
                    224:   by the parameter XMLtype, the entry XMLname and returns the corresponding
                    225:   Thot element type.
1.55      vatton    226:   Returns:
1.80      vatton    227:   - ElTypeNum and ElSSchema into elType  ElTypeNum = 0 if not found.
                    228:   - content information about this entry
                    229:   - checkProfile TRUE if the entry is valid for the current Doc profile.
1.1       cvs       230:   ----------------------------------------------------------------------*/
1.55      vatton    231: void MapXMLElementType (int XMLtype, char *XMLname, ElementType *elType,
1.80      vatton    232:                         char **mappedName, char *content,
                    233:                         ThotBool *checkProfile, Document doc)
1.1       cvs       234: {
1.56      vatton    235:   ElemMapping        *ptr;
                    236:   char                c;
1.66      vatton    237:   int                 i, profile;
1.68      vatton    238:   ThotBool            xmlformat;
1.1       cvs       239: 
1.56      vatton    240:   /* Initialize variables */
                    241:   *mappedName = NULL;
                    242:   *checkProfile = TRUE;
                    243:   elType->ElTypeNum = 0;
1.66      vatton    244:   profile = TtaGetDocumentProfile (doc);
1.70      vatton    245:   if (profile == L_Annot)
                    246:     profile = L_Other;
1.68      vatton    247:   /* case sensitive comparison for xml documents */
                    248:   xmlformat = (DocumentMeta[doc] && DocumentMeta[doc]->xmlformat);
                    249: 
1.56      vatton    250:   /* Select the right table */
                    251:   if (XMLtype == XHTML_TYPE)
1.69      vatton    252:     {
                    253:       ptr = XHTMLElemMappingTable;
                    254:       /* no case sensitive whent there is an explicit "text/html" content_type */
                    255:       if (xmlformat && DocumentMeta[doc] && DocumentMeta[doc]->content_type &&
1.80      vatton    256:           !strcmp (DocumentMeta[doc]->content_type, "text/html"))
                    257:         xmlformat = FALSE;
1.69      vatton    258:     }
1.56      vatton    259:   else if (XMLtype == MATH_TYPE)
                    260:     {
1.66      vatton    261:       if (profile == L_Basic && DocumentTypes[doc] == docHTML)
1.80      vatton    262:         {
                    263:           /* Maths are not allowed in this document */
                    264:           ptr = NULL;
                    265:           *checkProfile = FALSE;
                    266:         }
1.56      vatton    267:       else
1.80      vatton    268:         ptr = MathMLElemMappingTable;
1.56      vatton    269:     }
                    270:   else if (XMLtype == SVG_TYPE)
                    271:     {
1.66      vatton    272:       if (profile == L_Basic && DocumentTypes[doc] == docHTML)
1.80      vatton    273:         {
                    274:           /* Graphics are not allowed in this document */
                    275:           ptr = NULL;
                    276:           *checkProfile = FALSE;
                    277:         }
1.56      vatton    278:       else
1.80      vatton    279:         ptr = SVGElemMappingTable;
1.56      vatton    280:     }
1.77      tollenae  281:   else if (XMLtype == Template_TYPE)
                    282:     {
                    283:       if (profile == L_Basic && DocumentTypes[doc] == docHTML)
1.80      vatton    284:         {
                    285:           /* Graphics are not allowed in this document */
                    286:           ptr = NULL;
                    287:           *checkProfile = FALSE;
                    288:         }
1.77      tollenae  289:       else
1.80      vatton    290:         ptr = TemplateElemMappingTable;
1.77      tollenae  291:     }
1.56      vatton    292:   else
                    293:     ptr = NULL;
1.32      cvs       294:    
1.56      vatton    295:   if (ptr)
                    296:     {
                    297:       /* search in the ElemMappingTable */
                    298:       i = 0;
                    299:       /* case insensitive for HTML */
1.68      vatton    300:       if (!xmlformat && ptr == XHTMLElemMappingTable)
1.80      vatton    301:         c = tolower (XMLname[0]);
1.56      vatton    302:       else
1.80      vatton    303:         c = XMLname[0];
1.56      vatton    304:       /* look for the first concerned entry in the table */
                    305:       while (ptr[i].XMLname[0] < c && ptr[i].XMLname[0] != EOS)
1.80      vatton    306:         i++;     
1.56      vatton    307:       /* look at all entries starting with the right character */
                    308:       do
1.80      vatton    309:         if (!xmlformat && ptr == XHTMLElemMappingTable &&
                    310:             strcasecmp (ptr[i].XMLname, XMLname))
                    311:           /* it's not the tag */
                    312:           i++;
                    313:         else if ((xmlformat || ptr != XHTMLElemMappingTable) &&
                    314:                  strcmp (ptr[i].XMLname, XMLname))
                    315:           /* it's not the tag */
                    316:           i++;
                    317:         else if (profile != L_Other && !(ptr[i].Level & profile))
                    318:           {
                    319:             /* this tag is not valid in the document profile */
                    320:             *checkProfile = FALSE;
                    321:             i++;
                    322:           }
                    323:         else
                    324:           {
                    325:             elType->ElTypeNum = ptr[i].ThotType;
                    326:             if (elType->ElSSchema == NULL)
                    327:               {
                    328:                 if (XMLtype == Template_TYPE)
                    329:                   elType->ElSSchema = GetTemplateSSchema(doc);
                    330:                 else
                    331:                   elType->ElSSchema = GetXMLSSchema (XMLtype, doc);
                    332:               }
                    333:             *mappedName = ptr[i].XMLname;
                    334:             *content = ptr[i].XMLcontents;
                    335:           }
1.56      vatton    336:       while (elType->ElTypeNum <= 0 && ptr[i].XMLname[0] == c);
                    337:     }
1.1       cvs       338: }
                    339: 
                    340: 
                    341: /*----------------------------------------------------------------------
1.80      vatton    342:   GetXMLElementName
                    343:   Generic function which searchs in the mapping tables the XML name for
                    344:   a given Thot type.
1.1       cvs       345:   ----------------------------------------------------------------------*/
1.55      vatton    346: char *GetXMLElementName (ElementType elType, Document doc)
1.1       cvs       347: {
1.46      cvs       348:   ElemMapping  *ptr;
                    349:   char         *name;
1.66      vatton    350:   int           i, profile;
1.46      cvs       351:   ThotBool      invalid = FALSE;
1.27      cvs       352: 
                    353:   if (elType.ElTypeNum > 0)
                    354:     {
                    355:       i = 0;
                    356:       /* Select the table which matches with the element schema */
                    357:       name = TtaGetSSchemaName (elType.ElSSchema);
1.44      cvs       358:       if (strcmp ("MathML", name) == 0)
1.80      vatton    359:         ptr = MathMLElemMappingTable;
1.49      vatton    360:       else if (strcmp ("SVG", name) == 0)
1.80      vatton    361:         ptr = SVGElemMappingTable;
1.63      quint     362:       else if (strcmp ("HTML", name) == 0)
1.80      vatton    363:         ptr = XHTMLElemMappingTable;
1.27      cvs       364:       else
1.80      vatton    365:         ptr = NULL;
1.63      quint     366: 
1.66      vatton    367:       profile = TtaGetDocumentProfile (doc);
1.70      vatton    368:       if (profile == L_Annot)
1.80      vatton    369:         profile = L_Other;
1.27      cvs       370:       if (ptr)
1.80      vatton    371:         do
                    372:           {
                    373:             if (ptr[i].ThotType == elType.ElTypeNum)
                    374:               {
                    375:                 if (doc == 0 || 
                    376:                     profile == L_Other || (ptr[i].Level & profile))
                    377:                   return ptr[i].XMLname;
                    378:                 else
                    379:                   invalid = TRUE;
                    380:               }
                    381:             i++;
                    382:           }
                    383:         while (ptr[i].XMLname[0] != EOS);        
1.27      cvs       384:     }
                    385:   if (invalid)
1.43      cvs       386:     return "";
1.27      cvs       387:   else
1.43      cvs       388:     return "???";
1.22      cvs       389: }
1.25      cvs       390: 
                    391: 
1.29      cvs       392: 
                    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.80      vatton    432:   MapMathMLAttributeValue
                    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 */
                    677:   if (XMLtype == XHTML_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 */
                    738:   ptr = XhtmlEntityTable;
1.40      cvs       739:   if (ptr)
                    740:     {
1.41      cvs       741:       /* look for in the HTML entities table */
1.40      cvs       742:       found = FALSE;
1.41      cvs       743:       while (ptr && !found)
1.80      vatton    744:         {
1.82    ! vatton    745:           for (i = 0; ptr[i].charCode != 0 && !found; i++)
1.80      vatton    746:             found = (ptr[i].charCode == entityValue);
1.39      cvs       747:   
1.80      vatton    748:           if (found)
                    749:             {
                    750:               /* entity value found */
                    751:               i--;
                    752:               *entityName = (char *) (ptr[i].charName);
                    753:             }
1.81      vatton    754:           else if (withMath && ptr != MathEntityTable)
1.80      vatton    755:             /* look for in the Math entities table */
                    756:             ptr = MathEntityTable;
                    757:           else
                    758:             {
                    759:               *entityName = NULL;
                    760:               ptr = NULL;
                    761:             }
                    762:         }
1.40      cvs       763:     }
1.39      cvs       764:   else
1.40      cvs       765:     *entityName = NULL;
1.39      cvs       766: }

Webmaster