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

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

Webmaster