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: ----------------------------------------------------------------------*/ 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.27 cvs 372: if (ptr) 1.80 vatton 373: do 374: { 375: if (ptr[i].ThotType == elType.ElTypeNum) 376: { 377: if (doc == 0 || 378: profile == L_Other || (ptr[i].Level & profile)) 379: return ptr[i].XMLname; 380: else 381: invalid = TRUE; 382: } 383: i++; 384: } 385: while (ptr[i].XMLname[0] != EOS); 1.27 cvs 386: } 387: if (invalid) 1.43 cvs 388: return ""; 1.27 cvs 389: else 1.43 cvs 390: return "???"; 1.22 cvs 391: } 1.25 cvs 392: 393: 1.29 cvs 394: /*---------------------------------------------------------------------- 1.80 vatton 395: IsXMLElementInline 396: Generic function which searchs in the mapping tables if a given 397: Thot type is an inline character or not 1.29 cvs 398: ----------------------------------------------------------------------*/ 1.55 vatton 399: ThotBool IsXMLElementInline (ElementType elType, Document doc) 1.29 cvs 400: { 1.34 cvs 401: int i; 402: ThotBool ret = FALSE; 1.45 cvs 403: char *name; 1.34 cvs 404: ElemMapping *ptr; 1.29 cvs 405: 406: if (elType.ElTypeNum > 0) 407: { 408: i = 0; 409: /* Select the table which matches with the element schema */ 410: name = TtaGetSSchemaName (elType.ElSSchema); 1.44 cvs 411: if (strcmp ("MathML", name) == 0) 1.80 vatton 412: ptr = MathMLElemMappingTable; 1.49 vatton 413: else if (strcmp ("SVG", name) == 0) 1.80 vatton 414: ptr = SVGElemMappingTable; 1.52 cvs 415: else if (strcmp ("HTML", name) == 0) 1.80 vatton 416: ptr = XHTMLElemMappingTable; 1.90 ! vatton 417: #ifdef TEMPLATES ! 418: else if (strcmp ("Template", name) == 0) ! 419: ptr = TemplateElemMappingTable; ! 420: #endif /* TEMPLATES */ 1.29 cvs 421: else 1.80 vatton 422: ptr = NULL; 1.29 cvs 423: 424: if (ptr) 1.80 vatton 425: { 426: while (ptr[i].XMLname[0] != EOS && 427: ptr[i].ThotType != elType.ElTypeNum) 428: i++; 429: if (ptr[i].ThotType == elType.ElTypeNum) 430: ret = ptr[i].InlineElem; 431: } 1.29 cvs 432: } 433: return ret; 434: } 435: 1.22 cvs 436: /*---------------------------------------------------------------------- 1.85 vatton 437: MapXMLAttributeValue 1.80 vatton 438: Search in the Attribute Value Mapping Table the entry for the attribute 439: ThotAtt and its value attVal. Returns the corresponding Thot value. 1.59 vatton 440: ----------------------------------------------------------------------*/ 1.64 gully 441: void MapXMLAttributeValue (int XMLtype, char *attVal, const AttributeType *attrType, 1.80 vatton 442: int *value) 1.59 vatton 443: { 444: AttrValueMapping *ptr; 445: int i; 446: 447: /* Select the right table */ 448: if (XMLtype == XHTML_TYPE) 1.60 vatton 449: ptr = XhtmlAttrValueMappingTable; 1.59 vatton 450: else if (XMLtype == MATH_TYPE) 451: ptr = MathMLAttrValueMappingTable; 452: else if (XMLtype == SVG_TYPE) 1.60 vatton 453: ptr = SVGAttrValueMappingTable; 1.89 vatton 454: #ifdef TEMPLATES 455: else if (XMLtype == Template_TYPE) 456: ptr = TemplateAttrValueMappingTable; 457: #endif /* TEMPLATES */ 1.59 vatton 458: else 459: ptr = NULL; 460: 461: *value = 0; 462: i = 0; 463: if (ptr == NULL) 464: return; 1.64 gully 465: while (ptr[i].ThotAttr != attrType->AttrTypeNum && ptr[i].ThotAttr != 0) 1.59 vatton 466: i++; 1.64 gully 467: if (ptr[i].ThotAttr == attrType->AttrTypeNum) 1.59 vatton 468: do 469: if (!strcmp (ptr[i].XMLattrValue, attVal)) 1.80 vatton 470: *value = ptr[i].ThotAttrValue; 1.59 vatton 471: else 1.80 vatton 472: i++; 1.64 gully 473: while (*value == 0 && ptr[i].ThotAttr == attrType->AttrTypeNum); 1.59 vatton 474: } 475: 476: 477: /*---------------------------------------------------------------------- 1.80 vatton 478: MapXMLAttribute 479: Generic function which searchs in the Attribute Mapping Table (table) 480: the entry attrName associated to the element elementName. 481: Returns the corresponding entry or -1. 1.22 cvs 482: ----------------------------------------------------------------------*/ 1.55 vatton 483: int MapXMLAttribute (int XMLtype, char *attrName, char *elementName, 1.80 vatton 484: ThotBool *checkProfile, Document doc, int *thotType) 1.22 cvs 485: { 1.56 vatton 486: AttributeMapping *ptr; 487: char c; 1.66 vatton 488: int i, profile; 1.68 vatton 489: ThotBool xmlformat; 1.24 cvs 490: 1.33 cvs 491: /* Initialization */ 1.55 vatton 492: *checkProfile = TRUE; 1.33 cvs 493: i = 1; 494: *thotType = 0; 1.68 vatton 495: /* case sensitive comparison for xml documents */ 496: xmlformat = (DocumentMeta[doc] && DocumentMeta[doc]->xmlformat); 1.50 cvs 497: 498: /* Select the right table */ 499: if (XMLtype == XHTML_TYPE) 1.69 vatton 500: { 501: ptr = XHTMLAttributeMappingTable; 502: /* no case sensitive whent there is an explicit "text/html" content_type */ 503: if (xmlformat && DocumentMeta[doc] && DocumentMeta[doc]->content_type && 1.80 vatton 504: !strcmp (DocumentMeta[doc]->content_type, "text/html")) 505: xmlformat = FALSE; 1.69 vatton 506: } 1.50 cvs 507: else if (XMLtype == MATH_TYPE) 508: ptr = MathMLAttributeMappingTable; 1.51 cvs 509: else if (XMLtype == SVG_TYPE) 1.50 cvs 510: ptr = SVGAttributeMappingTable; 1.79 tollenae 511: #ifdef TEMPLATES 512: else if (XMLtype == Template_TYPE) 513: ptr = TemplateAttributeMappingTable; 514: #endif /* TEMPLATES */ 1.50 cvs 515: else if (XMLtype == XLINK_TYPE) 516: ptr = XLinkAttributeMappingTable; 1.79 tollenae 517: 1.50 cvs 518: else 519: ptr = NULL; 1.24 cvs 520: if (ptr == NULL) 521: return -1; 1.50 cvs 522: if (strcmp (attrName, "unknown_attr") == 0) 523: { 524: *thotType = ptr[0].ThotAttribute; 525: return 0; 526: } 1.22 cvs 527: 1.56 vatton 528: /* case insensitive for HTML */ 1.68 vatton 529: if (!xmlformat && ptr == XHTMLAttributeMappingTable) 1.56 vatton 530: c = tolower (attrName[0]); 531: else 532: c = attrName[0]; 1.66 vatton 533: 534: profile = TtaGetDocumentProfile (doc); 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.66 vatton 552: else if (profile != L_Other && !(ptr[i].Level & profile)) 1.80 vatton 553: { 554: *checkProfile = FALSE; 555: i++; 556: } 1.22 cvs 557: else 1.80 vatton 558: { 559: /* Special case for the 'name' attribute for 560: elements 'a' and 'map' in xhtml1.1 profile */ 561: if ((profile == L_Xhtml11) && 562: !strcmp (attrName, "name") && elementName && 563: (!strcmp (elementName, "a") || !strcmp (elementName, "map"))) 564: *checkProfile = FALSE; 565: else 566: *thotType = ptr[i].ThotAttribute; 567: return (i); 568: } 1.22 cvs 569: } 1.24 cvs 570: return (-1); 1.25 cvs 571: } 572: 573: 574: /*---------------------------------------------------------------------- 1.80 vatton 575: GetXMLAttributeName 576: Generic function which searchs in the mapping tables the XML name for 577: a given Thot type. 1.25 cvs 578: ----------------------------------------------------------------------*/ 1.55 vatton 579: char *GetXMLAttributeName (AttributeType attrType, ElementType elType, 1.80 vatton 580: Document doc) 1.25 cvs 581: { 582: AttributeMapping *ptr; 1.45 cvs 583: char *name, *tag; 1.66 vatton 584: int i, profile; 1.27 cvs 585: ThotBool invalid = FALSE; 1.25 cvs 586: 1.27 cvs 587: if (attrType.AttrTypeNum > 0) 588: { 1.28 cvs 589: /* get the specific element tag */ 590: if (elType.ElTypeNum > 0) 1.80 vatton 591: tag = GetXMLElementName (elType, doc); 1.28 cvs 592: else 1.80 vatton 593: tag = ""; 1.28 cvs 594: 1.27 cvs 595: i = 0; 596: /* Select the table which matches with the element schema */ 597: name = TtaGetSSchemaName (attrType.AttrSSchema); 1.44 cvs 598: if (strcmp ("MathML", name) == 0) 1.79 tollenae 599: ptr = MathMLAttributeMappingTable; 600: #ifdef _SVG 1.49 vatton 601: else if (strcmp ("SVG", name) == 0) 1.79 tollenae 602: ptr = SVGAttributeMappingTable; 603: #endif /* _SVG */ 1.44 cvs 604: else if (strcmp ("XLink", name) == 0) 1.79 tollenae 605: ptr = XLinkAttributeMappingTable; 606: #ifdef TEMPLATES 607: else if (strcmp ("Template",name) == 0) 608: ptr = TemplateAttributeMappingTable; 609: #endif /* TEMPLATES */ 1.27 cvs 610: else 1.80 vatton 611: ptr = XHTMLAttributeMappingTable; 1.27 cvs 612: 1.66 vatton 613: profile = TtaGetDocumentProfile (doc); 1.70 vatton 614: if (profile == L_Annot) 1.80 vatton 615: profile = L_Other; 1.27 cvs 616: if (ptr) 1.80 vatton 617: do 618: { 619: if (ptr[i].ThotAttribute == attrType.AttrTypeNum && 620: (ptr[i].XMLelement[0] == EOS || 621: !strcmp (ptr[i].XMLelement, tag))) 622: { 623: if (doc != 0 && 624: profile != L_Other && 625: !(ptr[i].Level & profile)) 626: invalid = TRUE; 627: else 628: return ptr[i].XMLattribute; 629: } 630: i++; 631: } 632: while (ptr[i].XMLattribute[0] != EOS); 1.27 cvs 633: } 634: if (invalid) 1.43 cvs 635: return ""; 1.27 cvs 636: else 1.43 cvs 637: return "???"; 1.36 cvs 638: } 639: 640: /*---------------------------------------------------------------------- 1.71 vatton 641: HasADoctype returns TRUE if the document includes a DocType 642: ----------------------------------------------------------------------*/ 1.82 vatton 643: void HasADoctype (Document doc, ThotBool *found, ThotBool *useMath) 1.71 vatton 644: { 645: Element el_doc, el_doctype; 646: ElementType elType; 647: char *s; 1.82 vatton 648: ThotBool useSVG; 1.71 vatton 649: 650: /* Look for a doctype */ 651: el_doc = TtaGetMainRoot (doc); 652: elType = TtaGetElementType (el_doc); 653: /* Search the doctype declaration according to the main schema */ 654: s = TtaGetSSchemaName (elType.ElSSchema); 655: if (strcmp (s, "HTML") == 0) 656: elType.ElTypeNum = HTML_EL_DOCTYPE; 657: else if (strcmp (s, "SVG") == 0) 658: elType.ElTypeNum = SVG_EL_DOCTYPE; 659: else if (strcmp (s, "MathML") == 0) 1.81 vatton 660: elType.ElTypeNum = MathML_EL_DOCTYPE; 1.71 vatton 661: else 662: elType.ElTypeNum = XML_EL_doctype; 663: el_doctype = TtaSearchTypedElement (elType, SearchInTree, el_doc); 1.81 vatton 664: *found = (el_doctype != NULL); 1.82 vatton 665: HasNatures (doc, useMath, &useSVG); 1.71 vatton 666: } 667: 668: 669: /*---------------------------------------------------------------------- 1.80 vatton 670: MapXMLEntity 671: Generic function which searchs in the Entity Mapping Table (table) 672: the entry entityName and give the corresponding decimal value. 673: Returns FALSE if entityName is not found. 1.36 cvs 674: ----------------------------------------------------------------------*/ 1.71 vatton 675: ThotBool MapXMLEntity (int XMLtype, char *entityName, int *entityValue) 1.36 cvs 676: { 677: XmlEntity *ptr; 678: ThotBool found; 1.38 cvs 679: int inf, sup, med, rescomp; 1.36 cvs 680: 1.38 cvs 681: /* Initialization */ 1.36 cvs 682: found = FALSE; 1.42 cvs 683: sup = 0; 1.36 cvs 684: 685: /* Select the right table */ 1.86 vatton 686: if (XMLtype == XHTML_TYPE || XMLtype == Template_TYPE) 1.39 cvs 687: { 688: ptr = XhtmlEntityTable; 689: if (XHTMLSup == 0) 1.80 vatton 690: for (XHTMLSup = 0; ptr[XHTMLSup].charCode > 0; XHTMLSup++); 1.39 cvs 691: sup = XHTMLSup; 692: } 1.36 cvs 693: else if (XMLtype == MATH_TYPE) 1.39 cvs 694: { 695: ptr = MathEntityTable; 696: if (MathSup == 0) 1.80 vatton 697: for (MathSup = 0; ptr[MathSup].charCode > 0; MathSup++); 1.39 cvs 698: sup = MathSup; 699: } 1.36 cvs 700: else 701: ptr = NULL; 702: 1.71 vatton 703: if (ptr) 1.36 cvs 704: { 1.71 vatton 705: inf = 0; 706: while (sup >= inf && !found) 1.80 vatton 707: /* Dichotomic research */ 708: { 709: med = (sup + inf) / 2; 710: rescomp = strcmp (ptr[med].charName, entityName); 711: if (rescomp == 0) 712: { 713: /* entity found */ 714: *entityValue = ptr[med].charCode; 715: found = TRUE; 716: } 717: else 718: { 719: if (rescomp > 0) 720: sup = med - 1; 721: else 722: inf = med + 1; 723: } 724: } 1.36 cvs 725: } 1.82 vatton 726: if (!found && ptr == XhtmlEntityTable) 727: // check MathML entities 728: return MapXMLEntity (MATH_TYPE, entityName, entityValue); 1.38 cvs 729: return found; 1.80 vatton 730: } 1.39 cvs 731: 732: /*---------------------------------------------------------------------- 1.80 vatton 733: MapEntityByCode 734: Generic function which searchs in the Entity Mapping Table (table) 735: the entry with code entityValue and give the corresponding name. 1.81 vatton 736: withMath is TRUE when MathML entities are accepted. 1.80 vatton 737: Returns FALSE if entityValue is not found. 1.39 cvs 738: ----------------------------------------------------------------------*/ 1.81 vatton 739: void MapEntityByCode (int entityValue, Document doc, ThotBool withMath, 740: char **entityName) 1.39 cvs 741: { 742: XmlEntity *ptr; 1.81 vatton 743: ThotBool found; 1.39 cvs 744: int i; 745: 1.81 vatton 746: /* Select the right table */ 1.87 vatton 747: if (withMath) 748: /* look for in the Math entities table */ 749: ptr = MathEntityTable; 750: else 751: ptr = XhtmlEntityTable; 1.40 cvs 752: if (ptr) 753: { 1.41 cvs 754: /* look for in the HTML entities table */ 1.40 cvs 755: found = FALSE; 1.41 cvs 756: while (ptr && !found) 1.80 vatton 757: { 1.82 vatton 758: for (i = 0; ptr[i].charCode != 0 && !found; i++) 1.80 vatton 759: found = (ptr[i].charCode == entityValue); 1.39 cvs 760: 1.80 vatton 761: if (found) 762: { 763: /* entity value found */ 764: i--; 765: *entityName = (char *) (ptr[i].charName); 766: } 1.87 vatton 767: else if (withMath && ptr != XhtmlEntityTable) 1.80 vatton 768: /* look for in the Math entities table */ 1.87 vatton 769: ptr = XhtmlEntityTable; 1.80 vatton 770: else 771: { 772: *entityName = NULL; 773: ptr = NULL; 774: } 775: } 1.40 cvs 776: } 1.39 cvs 777: else 1.40 cvs 778: *entityName = NULL; 1.39 cvs 779: }