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