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