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