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