Annotation of Amaya/amaya/XHTMLbuilder.c, revision 1.83
1.1 cvs 1: /*
2: *
1.78 vatton 3: * (c) COPYRIGHT INRIA and W3C, 1996-2003
1.1 cvs 4: * Please first read the full copyright statement in file COPYRIGHT.
5: *
6: */
7:
8: /*
1.30 cvs 9: * XHTMLbuilder.c
1.23 cvs 10: * Builds the corresponding abstract tree for a Thot document of type HTML.
1.1 cvs 11: *
1.20 cvs 12: * Authors: L. Carcone
13: * V. Quint
1.1 cvs 14: */
15:
16: #define THOT_EXPORT extern
17: #include "amaya.h"
18: #include "css.h"
1.2 cvs 19: #include "parser.h"
20: #include "HTML.h"
1.30 cvs 21: #include "fetchHTMLname.h"
1.2 cvs 22:
1.13 cvs 23: #include "css_f.h"
1.76 vatton 24: #include "EDITstyle_f.h"
1.13 cvs 25: #include "fetchXMLname_f.h"
1.30 cvs 26: #include "fetchHTMLname_f.h"
1.22 cvs 27: #include "html2thot_f.h"
1.1 cvs 28: #include "HTMLactions_f.h"
29: #include "HTMLedit_f.h"
1.22 cvs 30: #include "HTMLform_f.h"
1.1 cvs 31: #include "HTMLimage_f.h"
32: #include "HTMLtable_f.h"
33: #include "HTMLimage_f.h"
34: #include "UIcss_f.h"
1.13 cvs 35: #include "styleparser_f.h"
1.2 cvs 36: #include "XHTMLbuilder_f.h"
1.13 cvs 37: #include "Xml2thot_f.h"
1.1 cvs 38:
39: /* maximum length of a Thot structure schema name */
40: #define MAX_SS_NAME_LENGTH 32
41:
1.30 cvs 42: #define MaxMsgLength 200
43:
1.47 cvs 44: /* Elements that cannot contain text as immediate children.
45: When some text is present in the HTML file it must be
46: surrounded by a Pseudo_paragraph element */
47: static int NoTextChild[] =
48: {
49: HTML_EL_Document, HTML_EL_HTML, HTML_EL_HEAD, HTML_EL_BODY,
50: HTML_EL_Definition_List, HTML_EL_Block_Quote, HTML_EL_Directory,
51: HTML_EL_Form, HTML_EL_Menu, HTML_EL_FIELDSET,
52: HTML_EL_Numbered_List, HTML_EL_Option_Menu,
53: HTML_EL_Unnumbered_List, HTML_EL_Definition, HTML_EL_List_Item,
54: HTML_EL_MAP, HTML_EL_map, HTML_EL_Applet,
55: HTML_EL_Object, HTML_EL_IFRAME, HTML_EL_NOFRAMES,
56: HTML_EL_Division, HTML_EL_Center, HTML_EL_NOSCRIPT,
57: HTML_EL_Data_cell, HTML_EL_Heading_cell,
58: 0};
59:
1.28 cvs 60: /* Define a pointer to let parser functions access the HTML entity table */
61: extern XmlEntity *pXhtmlEntityTable;
1.6 cvs 62:
1.30 cvs 63: /* maximum size of error messages */
64: #define MaxMsgLength 200
65:
1.6 cvs 66: /*----------------------------------------------------------------------
1.15 cvs 67: ParseCharset:
1.6 cvs 68: Parses the element HTTP-EQUIV and looks for the charset value.
69: ----------------------------------------------------------------------*/
1.30 cvs 70: void ParseCharset (Element el, Document doc)
71:
1.6 cvs 72: {
1.15 cvs 73: AttributeType attrType;
74: Attribute attr;
75: SSchema docSSchema;
76: CHARSET charset;
1.39 cvs 77: char *text, *text2, *ptrText, *str;
78: char charsetname[MAX_LENGTH];
1.15 cvs 79: int length;
1.6 cvs 80: int pos, index = 0;
81:
1.15 cvs 82: charset = TtaGetDocumentCharset (doc);
83: if (charset != UNDEFINED_CHARSET)
84: /* the charset was already defined by the http header */
85: return;
1.6 cvs 86:
87: docSSchema = TtaGetDocumentSSchema (doc);
88: attrType.AttrSSchema = docSSchema;
89: attrType.AttrTypeNum = HTML_ATTR_http_equiv;
90: attr = TtaGetAttribute (el, attrType);
91: if (attr != NULL)
92: {
93: /* There is a HTTP-EQUIV attribute */
94: length = TtaGetTextAttributeLength (attr);
95: if (length > 0)
96: {
1.37 cvs 97: text = TtaGetMemory (length + 1);
1.6 cvs 98: TtaGiveTextAttributeValue (attr, text, &length);
1.37 cvs 99: if (!strcasecmp (text, "content-type"))
1.6 cvs 100: {
101: attrType.AttrTypeNum = HTML_ATTR_meta_content;
102: attr = TtaGetAttribute (el, attrType);
103: if (attr != NULL)
104: {
105: length = TtaGetTextAttributeLength (attr);
106: if (length > 0)
107: {
1.37 cvs 108: text2 = TtaGetMemory (length + 1);
1.6 cvs 109: TtaGiveTextAttributeValue (attr, text2, &length);
110: ptrText = text2;
111: while (*ptrText)
112: {
1.53 vatton 113: *ptrText = tolower (*ptrText);
1.6 cvs 114: ptrText++;
115: }
116:
1.37 cvs 117: str = strstr (text2, "charset=");
1.6 cvs 118: if (str)
119: {
120: pos = str - text2 + 8;
1.37 cvs 121: while (text2[pos] != SPACE &&
122: text2[pos] != TAB && text2[pos] != EOS)
1.6 cvs 123: charsetname[index++] = text2[pos++];
1.37 cvs 124: charsetname[index] = EOS;
1.15 cvs 125: charset = TtaGetCharset (charsetname);
126: if (charset != UNDEFINED_CHARSET)
1.77 cvs 127: TtaSetDocumentCharset (doc, charset, FALSE);
1.6 cvs 128: }
129: TtaFreeMemory (text2);
130: }
131: }
132: }
133: TtaFreeMemory (text);
134: }
135: }
136: }
137:
1.23 cvs 138: /*----------------------------------------------------------------------
1.47 cvs 139: XhtmlCannotContainText
140: Return TRUE if element el is a block element.
141: ----------------------------------------------------------------------*/
142: ThotBool XhtmlCannotContainText (ElementType elType)
143:
144: {
145: int i;
146: ThotBool ret;
147:
148: if (strcmp (TtaGetSSchemaName (elType.ElSSchema), "HTML"))
149: /* not an HTML element */
150: ret = TRUE;
151: else
152: {
153: ret = FALSE;
154: i = 0;
155: while (NoTextChild[i] > 0 && NoTextChild[i] != elType.ElTypeNum)
156: i++;
157: if (NoTextChild[i] == elType.ElTypeNum)
158: ret = TRUE;
159: }
160: return ret;
1.23 cvs 161: }
162:
1.6 cvs 163: /*----------------------------------------------------------------------
164: XhtmlElementComplete
1.20 cvs 165: Complete Xhtml elements.
1.6 cvs 166: Check its attributes and its contents.
167: ----------------------------------------------------------------------*/
1.72 cvs 168: void XhtmlElementComplete (ParserData *context, Element el, int *error)
1.30 cvs 169:
170: {
1.72 cvs 171: Document doc;
1.30 cvs 172: ElementType elType, newElType, childType;
173: Element constElem, child, desc, leaf, prev, next, last,
1.62 quint 174: elFrames, lastFrame, lastChild, parent, picture, content;
1.30 cvs 175: Attribute attr;
176: AttributeType attrType;
177: Language lang;
1.41 cvs 178: char *text;
1.39 cvs 179: char lastChar[2];
1.79 quint 180: char *name1, *data;
1.30 cvs 181: int length;
182: SSchema docSSchema;
1.62 quint 183: ThotBool isImage;
184: PresentationValue pval;
185: PresentationContext ctxt;
1.6 cvs 186:
187: *error = 0;
1.72 cvs 188: doc = context->doc;
1.6 cvs 189: docSSchema = TtaGetDocumentSSchema (doc);
190:
191: elType = TtaGetElementType (el);
192: /* is this a block-level element in a character-level element? */
1.56 cvs 193: if (!IsXMLElementInline (elType, doc) &&
1.24 cvs 194: elType.ElTypeNum != HTML_EL_Comment_ &&
195: elType.ElTypeNum != HTML_EL_XMLPI)
1.6 cvs 196: BlockInCharLevelElem (el);
197:
198: newElType.ElSSchema = elType.ElSSchema;
199: switch (elType.ElTypeNum)
200: {
1.62 quint 201: case HTML_EL_Object: /* it's an object */
1.79 quint 202: data = NULL;
1.62 quint 203: isImage = FALSE;
204: /* is there a type attribute on the object element? */
205: attrType.AttrSSchema = elType.ElSSchema;
206: attrType.AttrTypeNum = HTML_ATTR_Object_type;
1.6 cvs 207: attr = TtaGetAttribute (el, attrType);
1.62 quint 208: if (attr)
209: /* there is a type attribute. Get its value to see if the object
210: represents an image */
1.6 cvs 211: {
212: length = TtaGetTextAttributeLength (attr);
213: if (length > 0)
214: {
1.37 cvs 215: name1 = TtaGetMemory (length + 1);
1.6 cvs 216: TtaGiveTextAttributeValue (attr, name1, &length);
1.68 kahan 217: if (!strcmp (name1, AM_MATHML_MIME_TYPE) ||
1.62 quint 218: !strcmp (name1, "application/postscript") ||
219: !strcmp (name1, "image/x-bitmap") ||
220: !strcmp (name1, "image/x-xpixmap") ||
221: !strcmp (name1, "image/gif") ||
222: !strcmp (name1, "image/jpeg") ||
223: !strcmp (name1, "image/png") ||
1.67 kahan 224: !strcmp (name1, "image/svg") ||
1.83 ! cvs 225: !strcmp (name1, AM_SVG_MIME_TYPE) ||
! 226: !strcmp (name1, AM_XHTML_MIME_TYPE) ||
! 227: !strcmp (name1, "text/html") ||
! 228: !strcmp (name1, "text/htm") ||
! 229: !strcmp (name1, AM_GENERIC_XML_MIME_TYPE))
1.62 quint 230: isImage = TRUE;
231: TtaFreeMemory (name1);
232: }
233: }
1.79 quint 234:
235: attrType.AttrTypeNum = HTML_ATTR_data;
236: attr = TtaGetAttribute (el, attrType);
237: if (attr)
238: /* the object has a data attribute */
239: {
240: length = TtaGetTextAttributeLength (attr);
241: if (length > 0)
242: {
243: data = TtaGetMemory (length + 1);
244: TtaGiveTextAttributeValue (attr, data, &length);
245: if (!isImage)
246: if (!strcmp (&data[length-3], "mml") ||
247: !strcmp (&data[length-3], "gif") ||
248: !strcmp (&data[length-3], "jpg") ||
249: !strcmp (&data[length-4], "jpeg") ||
250: !strcmp (&data[length-3], "png") ||
251: !strcmp (&data[length-3], "svg") ||
1.80 cvs 252: !strcmp (&data[length-4], "svgz") ||
1.83 ! cvs 253: !strcmp (&data[length-3], "htm") ||
! 254: !strcmp (&data[length-4], "html") ||
! 255: !strcmp (&data[length-3], "xml"))
1.79 quint 256: isImage = TRUE;
257: }
258: }
1.62 quint 259: picture = NULL; /* no PICTURE element yet */
260: child = TtaGetFirstChild (el);
261: if (isImage)
262: /* the object represents an image. We need a PICTURE element as
263: child of the object to hold the image */
264: {
265: if (child)
266: {
267: elType = TtaGetElementType (child);
268: if (elType.ElTypeNum == HTML_EL_PICTURE_UNIT)
269: /* there is already a PICTURE element */
270: picture = child;
271: }
1.79 quint 272: /* if the object element has no PICTURE element as its first child
1.62 quint 273: create one */
274: if (!picture)
275: {
276: elType.ElTypeNum = HTML_EL_PICTURE_UNIT;
277: picture = TtaNewTree (doc, elType, "");
278: if (child)
279: TtaInsertSibling (picture, child, TRUE, doc);
280: else
281: TtaInsertFirstChild (&picture, el, doc);
282: child = picture;
283: }
284: /* copy attribute data of the object into the SRC attribute of
285: the PICTURE element */
1.79 quint 286: if (data)
287: /* the object has a data attribute */
288: {
289: attrType.AttrTypeNum = HTML_ATTR_SRC;
290: attr = TtaGetAttribute (picture, attrType);
291: if (attr == NULL)
292: {
293: attr = TtaNewAttribute (attrType);
294: TtaAttachAttribute (picture, attr, doc);
295: }
296: TtaSetAttributeText (attr, data, picture, doc);
297: }
298: attrType.AttrTypeNum = HTML_ATTR_Height_;
1.62 quint 299: attr = TtaGetAttribute (el, attrType);
300: if (attr)
1.79 quint 301: /* the Object has a height attribute. Applies it to the
302: picture element */
303: {
304: length = TtaGetTextAttributeLength (attr);
305: if (length > 0)
306: {
307: text = TtaGetMemory (length + 1);
308: TtaGiveTextAttributeValue (attr, text, &length);
309: /* create the corresponding attribute IntHeightPercent or */
310: /* IntHeightPxl */
311: CreateAttrHeightPercentPxl (text, el, doc, -1);
312: TtaFreeMemory (text);
313: }
314: }
315: attrType.AttrTypeNum = HTML_ATTR_Width__;
316: attr = TtaGetAttribute (el, attrType);
317: if (attr)
318: /* the Object has a width attribute. Applies it to the
319: picture element */
1.62 quint 320: {
321: length = TtaGetTextAttributeLength (attr);
322: if (length > 0)
1.6 cvs 323: {
1.79 quint 324: text = TtaGetMemory (length + 1);
325: TtaGiveTextAttributeValue (attr, text, &length);
326: /* create the corresponding attribute IntWidthPercent or */
327: /* IntWidthPxl */
328: CreateAttrWidthPercentPxl (text, el, doc, -1);
329: TtaFreeMemory (text);
1.6 cvs 330: }
331: }
332: }
333: /* is the Object_Content element already created ? */
1.62 quint 334: if (child)
335: /* the object element has at least 1 child element */
336: {
337: content = NULL;
338: desc = child;
1.6 cvs 339: elType = TtaGetElementType (desc);
1.62 quint 340: if (elType.ElTypeNum != HTML_EL_Object_Content)
341: {
342: TtaNextSibling(&desc);
343: if (desc)
344: elType = TtaGetElementType (desc);
345: }
346: /* is it the Object_Content element ? */
347: if (elType.ElTypeNum == HTML_EL_Object_Content)
348: content = desc;
349: else
1.6 cvs 350: {
1.62 quint 351: /* create an Object_Content element */
352: elType.ElTypeNum = HTML_EL_Object_Content;
353: content = TtaNewElement (doc, elType);
354: if (picture)
355: TtaInsertSibling (content, picture, FALSE, doc);
356: else
357: TtaInsertSibling (content, child, TRUE, doc);
358: /* move previous existing children into Object_Content */
1.6 cvs 359: child = TtaGetLastChild(el);
1.62 quint 360: while (child != content)
361: {
362: TtaRemoveTree (child, doc);
363: TtaInsertFirstChild (&child, content, doc);
364: child = TtaGetLastChild(el);
365: }
366: }
367: if (picture && content)
368: /* there is a picture element. The Object_Content must not be
369: displayed in the main view */
370: {
371: ctxt = TtaGetSpecificStyleContext (doc);
372: /* the presentation rule to be set is not a CSS rule */
373: ctxt->cssSpecificity = 0;
374: ctxt->destroy = FALSE;
375: pval.typed_data.unit = STYLE_UNIT_PX;
376: pval.typed_data.value = 0;
377: pval.typed_data.real = FALSE;
378: TtaSetStylePresentation (PRVisibility, content, NULL, ctxt, pval);
1.6 cvs 379: }
380: }
1.79 quint 381: if (data)
382: TtaFreeMemory (data);
1.6 cvs 383: break;
1.62 quint 384:
1.6 cvs 385: case HTML_EL_Unnumbered_List:
386: case HTML_EL_Numbered_List:
387: case HTML_EL_Menu:
388: case HTML_EL_Directory:
389: /* It's a List element. It should only have List_Item children.
390: If it has List element chidren, move these List elements
391: within their previous List_Item sibling. This is to fix
392: a bug in document generated by Mozilla. */
393: prev = NULL;
394: next = NULL;
395: child = TtaGetFirstChild (el);
396: while (child != NULL)
397: {
398: next = child;
399: TtaNextSibling (&next);
400: elType = TtaGetElementType (child);
401: if (elType.ElTypeNum == HTML_EL_Unnumbered_List ||
402: elType.ElTypeNum == HTML_EL_Numbered_List ||
403: elType.ElTypeNum == HTML_EL_Menu ||
404: elType.ElTypeNum == HTML_EL_Directory)
405: /* this list element is a child of another list element */
406: if (prev)
407: {
408: elType = TtaGetElementType (prev);
409: if (elType.ElTypeNum == HTML_EL_List_Item)
410: {
411: /* get the last child of the previous List_Item */
412: desc = TtaGetFirstChild (prev);
413: last = NULL;
414: while (desc)
415: {
416: last = desc;
417: TtaNextSibling (&desc);
418: }
419: /* move the list element after the last child of the
420: previous List_Item */
421: TtaRemoveTree (child, doc);
422: if (last)
423: TtaInsertSibling (child, last, FALSE, doc);
424: else
425: TtaInsertFirstChild (&child, prev, doc);
426: child = prev;
427: }
428: }
429: prev = child;
430: child = next;
431: }
432: break;
433:
434: case HTML_EL_FRAMESET:
435: /* The FRAMESET element is now complete. Gather all its FRAMESET
436: and FRAME children and wrap them up in a Frames element */
437: elFrames = NULL; lastFrame = NULL;
438: lastChild = NULL;
439: child = TtaGetFirstChild (el);
440: while (child != NULL)
441: {
442: next = child;
443: TtaNextSibling (&next);
444: elType = TtaGetElementType (child);
445: if (elType.ElTypeNum == HTML_EL_FRAMESET ||
446: elType.ElTypeNum == HTML_EL_FRAME ||
447: elType.ElTypeNum == HTML_EL_Comment_)
448: {
449: /* create the Frames element if it does not exist */
450: if (elFrames == NULL)
451: {
452: newElType.ElSSchema = docSSchema;
453: newElType.ElTypeNum = HTML_EL_Frames;
454: elFrames = TtaNewElement (doc, newElType);
1.63 cvs 455: if (DocumentMeta[doc]->xmlformat)
456: XmlSetElemLineNumber (elFrames);
457: else
458: SetHtmlElemLineNumber (elFrames);
1.6 cvs 459: TtaInsertSibling (elFrames, child, TRUE, doc);
460: }
461: /* move the element as the last child of the Frames element */
462: TtaRemoveTree (child, doc);
463: if (lastFrame == NULL)
464: TtaInsertFirstChild (&child, elFrames, doc);
465: else
466: TtaInsertSibling (child, lastFrame, FALSE, doc);
467: lastFrame = child;
468: }
469: child = next;
470: }
471: break;
472:
473: case HTML_EL_Input: /* it's an INPUT without any TYPE attribute */
474: /* Create a child of type Text_Input */
475: elType.ElTypeNum = HTML_EL_Text_Input;
476: child = TtaNewTree (doc, elType, "");
1.63 cvs 477: if (DocumentMeta[doc]->xmlformat)
478: XmlSetElemLineNumber (child);
479: else
480: SetHtmlElemLineNumber (child);
1.6 cvs 481: TtaInsertFirstChild (&child, el, doc);
482: /* now, process it like a Text_Input element */
483:
484: case HTML_EL_Text_Input:
485: case HTML_EL_Password_Input:
486: case HTML_EL_File_Input:
487: /* get element Inserted_Text */
488: child = TtaGetFirstChild (el);
489: if (child != NULL)
490: {
491: attrType.AttrSSchema = docSSchema;
492: attrType.AttrTypeNum = HTML_ATTR_Value_;
493: attr = TtaGetAttribute (el, attrType);
494: if (attr != NULL)
495: {
496: /* copy the value of attribute "value" into the first text
497: leaf of element */
498: length = TtaGetTextAttributeLength (attr);
499: if (length > 0)
500: {
501: /* get the text leaf */
502: leaf = TtaGetFirstChild (child);
503: if (leaf != NULL)
504: {
505: childType = TtaGetElementType (leaf);
506: if (childType.ElTypeNum == HTML_EL_TEXT_UNIT)
507: {
508: /* copy attribute value into the text leaf */
1.37 cvs 509: text = TtaGetMemory (length + 1);
1.6 cvs 510: TtaGiveTextAttributeValue (attr, text, &length);
511: TtaSetTextContent (leaf, text,
512: TtaGetDefaultLanguage (), doc);
513: TtaFreeMemory (text);
514: }
515: }
516: }
517: }
518: }
519: break;
520:
521: case HTML_EL_META:
1.15 cvs 522: ParseCharset (el, doc);
1.6 cvs 523: break;
524:
525: case HTML_EL_STYLE_: /* it's a STYLE element */
1.60 vatton 526: case HTML_EL_SCRIPT_: /* it's a SCRIPT element */
1.6 cvs 527: case HTML_EL_Preformatted: /* it's a PRE */
528: /* if the last line of the Preformatted is empty, remove it */
529: leaf = XmlLastLeafInElement (el);
530: if (leaf != NULL)
531: {
532: elType = TtaGetElementType (leaf);
533: if (elType.ElTypeNum == HTML_EL_TEXT_UNIT)
534: /* the last leaf is a TEXT element */
535: {
536: length = TtaGetTextLength (leaf);
537: if (length > 0)
538: {
539: TtaGiveSubString (leaf, lastChar, length, 1);
540: if (lastChar[0] == EOL)
541: /* last character is new line, delete it */
542: {
543: if (length == 1)
544: /* empty TEXT element */
545: TtaDeleteTree (leaf, doc);
546: else
547: /* remove the last character */
548: TtaDeleteTextContent (leaf, length, 1, doc);
549: }
550: }
551: }
552: }
1.75 kahan 553: if (DocumentMeta[doc] && DocumentMeta[doc]->xmlformat)
1.63 cvs 554: {
555: if (IsXmlParsingCSS ())
556: {
557: text = GetStyleContents (el);
558: if (text)
559: {
1.71 vatton 560: ReadCSSRules (doc, NULL, text, NULL,
1.82 quint 561: TtaGetElementLineNumber (el), FALSE, el);
1.63 cvs 562: TtaFreeMemory (text);
563: }
564: SetXmlParsingCSS (FALSE);
565: }
566: }
567: else
1.6 cvs 568: {
1.63 cvs 569: if (IsHtmlParsingCSS ())
1.6 cvs 570: {
1.63 cvs 571: text = GetStyleContents (el);
572: if (text)
573: {
1.71 vatton 574: ReadCSSRules (doc, NULL, text, NULL,
1.82 quint 575: TtaGetElementLineNumber (el), FALSE, el);
1.63 cvs 576: TtaFreeMemory (text);
577: }
578: SetHtmlParsingCSS (FALSE);
1.6 cvs 579: }
580: }
581: /* and continue as if it were a Preformatted or a Script */
582: break;
583:
584: case HTML_EL_Text_Area: /* it's a Text_Area */
1.69 cvs 585: if (DocumentMeta[doc]->xmlformat)
586: SetParsingTextArea (FALSE);
587: else
588: SetHtmlParsingTextArea (FALSE);
1.6 cvs 589: child = TtaGetFirstChild (el);
590: if (child == NULL)
591: /* it's an empty Text_Area */
592: /* insert a Inserted_Text element in the element */
593: {
594: newElType.ElTypeNum = HTML_EL_Inserted_Text;
595: child = TtaNewTree (doc, newElType, "");
596: TtaInsertFirstChild (&child, el, doc);
597: }
598: else
599: {
600: /* save the text into Default_Value attribute */
601: attrType.AttrSSchema = docSSchema;
602: attrType.AttrTypeNum = HTML_ATTR_Default_Value;
603: if (TtaGetAttribute (el, attrType) == NULL)
604: /* attribute Default_Value is missing */
605: {
606: attr = TtaNewAttribute (attrType);
607: TtaAttachAttribute (el, attr, doc);
608: desc = TtaGetFirstChild (child);
609: length = TtaGetTextLength (desc) + 1;
1.37 cvs 610: text = TtaGetMemory (length);
1.6 cvs 611: TtaGiveTextContent (desc, text, &length, &lang);
612: TtaSetAttributeText (attr, text, el, doc);
613: TtaFreeMemory (text);
614: }
615: }
616: /* insert a Frame element */
617: newElType.ElTypeNum = HTML_EL_Frame;
618: constElem = TtaNewTree (doc, newElType, "");
619: TtaInsertSibling (constElem, child, FALSE, doc);
620: break;
621:
622: case HTML_EL_Radio_Input:
623: case HTML_EL_Checkbox_Input:
624: /* put an attribute Checked if it is missing */
625: attrType.AttrSSchema = docSSchema;
626: attrType.AttrTypeNum = HTML_ATTR_Checked;
627: if (TtaGetAttribute (el, attrType) == NULL)
628: /* attribute Checked is missing */
629: {
630: attr = TtaNewAttribute (attrType);
631: TtaAttachAttribute (el, attr, doc);
632: TtaSetAttributeValue (attr, HTML_ATTR_Checked_VAL_No_, el, doc);
633: }
634: break;
635:
636: case HTML_EL_Option_Menu:
637: /* Check that at least one option has a SELECTED attribute */
638: OnlyOneOptionSelected (el, doc, TRUE);
639: break;
640:
641: case HTML_EL_PICTURE_UNIT:
642: break;
643:
644: case HTML_EL_LINK:
645: CheckCSSLink (el, doc, docSSchema);
646: break;
647:
648: case HTML_EL_Data_cell:
649: case HTML_EL_Heading_cell:
650: /* insert a pseudo paragraph into empty cells */
651: child = TtaGetFirstChild (el);
652: if (child == NULL)
653: {
654: elType.ElTypeNum = HTML_EL_Pseudo_paragraph;
655: child = TtaNewTree (doc, elType, "");
656: if (child != NULL)
657: TtaInsertFirstChild (&child, el, doc);
658: }
659:
1.80 cvs 660: /* detect whether we are parsing a whole table or just a cell */
1.63 cvs 661: if (DocumentMeta[doc]->xmlformat)
662: {
663: if (IsWithinXmlTable ())
664: NewCell (el, doc, FALSE);
665: }
666: else
667: {
668: if (IsWithinHtmlTable ())
669: NewCell (el, doc, FALSE);
670: }
1.6 cvs 671: break;
672:
673: case HTML_EL_Table:
674: CheckTable (el, doc);
675: SubWithinTable ();
676: break;
677:
678: case HTML_EL_TITLE:
679: /* show the TITLE in the main window */
680: UpdateTitle (el, doc);
681: break;
1.41 cvs 682:
683: case HTML_EL_rbc:
684: /* an rbc element has been read. Its parent should be a complex_ruby.
685: Change the type of the parent, as simple_ruby are created by
686: default */
687: parent = TtaGetParent (el);
688: if (parent)
689: {
690: newElType = TtaGetElementType (parent);
691: if (newElType.ElSSchema == elType.ElSSchema &&
692: newElType.ElTypeNum == HTML_EL_simple_ruby)
693: ChangeElementType (parent, HTML_EL_complex_ruby);
694: }
695: break;
696:
697: case HTML_EL_rtc1:
698: /* an rtc element has been parsed. If it has already a rtc1 sibling,
699: change its type to rtc2 */
700: prev = el;
701: do
702: {
703: TtaPreviousSibling(&prev);
704: if (prev)
705: {
706: newElType = TtaGetElementType (prev);
707: if (newElType.ElSSchema == elType.ElSSchema &&
708: newElType.ElTypeNum == HTML_EL_rtc1)
709: {
710: ChangeElementType (el, HTML_EL_rtc2);
711: prev = NULL;
712: }
713: }
714: }
715: while (prev);
716: break;
717:
1.6 cvs 718: default:
719: break;
720: }
721: }
1.1 cvs 722:
723: /*----------------------------------------------------------------------
1.30 cvs 724: PutInContent
725: Put the string ChrString in the leaf of current element.
726: ----------------------------------------------------------------------*/
1.39 cvs 727: Element PutInContent (char *ChrString, ParserData *context)
1.30 cvs 728:
729: {
730: Element el, child;
731: ElementType elType;
732: int length;
733:
734: el = NULL;
735: if (context->lastElement != NULL)
736: {
737: /* search first leaf of current element */
738: el = context->lastElement;
739: do
740: {
741: child = TtaGetFirstChild (el);
742: if (child != NULL)
743: el = child;
744: }
745: while (child != NULL);
746: elType = TtaGetElementType (el);
747: length = 0;
748: if (elType.ElTypeNum == 1)
749: length = TtaGetTextLength (el);
750: if (length == 0)
751: TtaSetTextContent (el, ChrString, context->language, context->doc);
752: else
753: TtaAppendTextContent (el, ChrString, context->doc);
754: }
755: return el;
756: }
757:
758: /*----------------------------------------------------------------------
1.51 cvs 759: UnknownXhtmlNameSpace
1.65 cvs 760: The element doesn't belong to a supported namespace
1.51 cvs 761: ----------------------------------------------------------------------*/
1.65 cvs 762: void UnknownXhtmlNameSpace (ParserData *context,
763: Element *unknownEl,
764: char* content)
1.51 cvs 765: {
766: ElementType elType;
1.65 cvs 767: Element elText;
1.51 cvs 768:
769: /* Create a new Invalid_element */
770: elType.ElSSchema = GetXMLSSchema (XHTML_TYPE, context->doc);
771: elType.ElTypeNum = HTML_EL_Unknown_namespace;
1.65 cvs 772: *unknownEl = TtaNewElement (context->doc, elType);
773: if (*unknownEl != NULL)
1.51 cvs 774: {
1.65 cvs 775: XmlSetElemLineNumber (*unknownEl);
776: InsertXmlElement (unknownEl);
1.51 cvs 777: context->lastElementClosed = TRUE;
778: elType.ElTypeNum = HTML_EL_TEXT_UNIT;
779: elText = TtaNewElement (context->doc, elType);
780: XmlSetElemLineNumber (elText);
1.65 cvs 781: TtaInsertFirstChild (&elText, *unknownEl, context->doc);
1.51 cvs 782: TtaSetTextContent (elText, content, context->language, context->doc);
783: TtaSetAccessRight (elText, ReadOnly, context->doc);
784: }
785: }
786:
787: /*----------------------------------------------------------------------
1.30 cvs 788: CreateHTMLAttribute
789: create an attribute of type attrType for the element el.
790: ----------------------------------------------------------------------*/
791: void CreateHTMLAttribute (Element el,
792: AttributeType attrType,
1.46 cvs 793: char* text,
1.30 cvs 794: ThotBool isInvalid,
795: Document doc,
796: Attribute *lastAttribute,
797: Element *lastAttrElement)
798:
799: {
800: int attrKind;
801: int length;
1.39 cvs 802: char *buffer;
1.30 cvs 803: Attribute attr, oldAttr;
804:
805: if (attrType.AttrTypeNum != 0)
806: {
807: oldAttr = TtaGetAttribute (el, attrType);
808: if (oldAttr != NULL)
809: /* this attribute already exists */
810: attr = oldAttr;
811: else
812: /* create a new attribute and attach it to the element */
813: {
814: attr = TtaNewAttribute (attrType);
815: TtaAttachAttribute (el, attr, doc);
816: }
817: *lastAttribute = attr;
818: *lastAttrElement = el;
819:
820: TtaGiveAttributeType (attr, &attrType, &attrKind);
821: if (attrKind == 0) /* enumerate */
822: TtaSetAttributeValue (attr, 1, el, doc);
823:
824: /* attribute BORDER without any value (ThotBool attribute) is */
825: /* considered as BORDER=1 */
826: if (attrType.AttrTypeNum == HTML_ATTR_Border)
827: TtaSetAttributeValue (attr, 1, el, doc);
828:
829: if (isInvalid)
830: /* Copy the name of the invalid attribute as the content */
831: /* of the Invalid_attribute attribute. */
832: {
1.37 cvs 833: length = strlen (text) + 2;
1.30 cvs 834: length += TtaGetTextAttributeLength (attr);
1.37 cvs 835: buffer = TtaGetMemory (length + 1);
1.30 cvs 836: TtaGiveTextAttributeValue (attr, buffer, &length);
1.37 cvs 837: strcat (buffer, " ");
838: strcat (buffer, text);
1.30 cvs 839: TtaSetAttributeText (attr, buffer, el, doc);
840: TtaFreeMemory (buffer);
841: }
842: }
843: }
844:
845: /*----------------------------------------------------------------------
846: HTMLTypeAttrValue
847: Value val has been read for the HTML attribute TYPE.
848: Create a child for the current Thot element INPUT accordingly.
849: ----------------------------------------------------------------------*/
1.46 cvs 850: void HTMLTypeAttrValue (char *val,
1.30 cvs 851: Attribute lastAttribute,
852: Element lastAttrElement,
853: ParserData *context)
854:
855: {
856: ElementType elType;
857: Element newChild;
858: AttributeType attrType;
859: Attribute attr;
1.39 cvs 860: char msgBuffer[MaxMsgLength];
1.30 cvs 861: int value;
862: int numberOfLinesRead;
863:
864: value = MapAttrValue (DummyAttribute, val);
865: if (value < 0)
866: {
1.37 cvs 867: if (strlen (val) > MaxMsgLength - 40)
868: val[MaxMsgLength - 40] = EOS;
869: sprintf (msgBuffer, "Unknown attribute value \"type = %s\"", val);
1.42 cvs 870: HTMLParseError (context->doc, msgBuffer);
1.30 cvs 871: attrType.AttrSSchema = TtaGetDocumentSSchema (context->doc);
872: attrType.AttrTypeNum = pHTMLAttributeMapping[0].ThotAttribute;
1.37 cvs 873: sprintf (msgBuffer, "type=%s", val);
1.30 cvs 874: CreateHTMLAttribute (context->lastElement, attrType, msgBuffer, TRUE,
875: context->doc, &lastAttribute, &lastAttrElement);
876: }
877: else
878: {
879: elType = TtaGetElementType (context->lastElement);
880: if (elType.ElTypeNum != HTML_EL_Input)
881: {
1.37 cvs 882: if (strlen (val) > MaxMsgLength - 40)
883: val[MaxMsgLength - 40] = EOS;
884: sprintf (msgBuffer, "Duplicate attribute \"type = %s\"", val);
1.30 cvs 885: }
886: else
887: {
888: elType.ElSSchema = TtaGetDocumentSSchema (context->doc);
889: elType.ElTypeNum = value;
890: newChild = TtaNewTree (context->doc, elType, "");
891: numberOfLinesRead = 0;
892: TtaSetElementLineNumber (newChild, numberOfLinesRead);
893: TtaInsertFirstChild (&newChild, context->lastElement, context->doc);
894: if (value == HTML_EL_PICTURE_UNIT)
895: {
896: /* add the attribute IsInput to input pictures */
897: attrType.AttrSSchema = elType.ElSSchema;
898: attrType.AttrTypeNum = HTML_ATTR_IsInput;
899: attr = TtaNewAttribute (attrType);
900: TtaAttachAttribute (newChild, attr, context->doc);
901: }
902: }
903: }
904: }
905:
906: /*----------------------------------------------------------------------
907: XhtmlTypeAttrValue
908: Value val has been read for the HTML attribute TYPE.
909: Create a child for the current Thot element INPUT accordingly.
910: ----------------------------------------------------------------------*/
1.46 cvs 911: void XhtmlTypeAttrValue (char *val,
1.30 cvs 912: Attribute currentAttribute,
913: Element lastAttrElement,
914: ParserData *context)
915:
916: {
917: ElementType elType;
918: Element newChild;
919: AttributeType attrType;
920: Attribute attr;
1.39 cvs 921: char msgBuffer[MaxMsgLength];
1.30 cvs 922: int value;
923: ThotBool level;
924:
925: attrType.AttrTypeNum = DummyAttribute;
926: MapHTMLAttributeValue (val, attrType, &value);
927: if (value < 0)
928: {
1.37 cvs 929: sprintf (msgBuffer, "Unknown attribute value \"type=%s\"", val);
1.30 cvs 930: XmlParseError (errorParsing, msgBuffer, 0);
1.36 cvs 931: MapHTMLAttribute ("unknown_attr", &attrType, NULL,
1.30 cvs 932: &level, context->doc);
1.37 cvs 933: sprintf (msgBuffer, "type=%s", val);
1.30 cvs 934: CreateHTMLAttribute (context->lastElement, attrType, msgBuffer, TRUE,
935: context->doc, ¤tAttribute, &lastAttrElement);
936: }
937: else
938: {
939: elType = TtaGetElementType (context->lastElement);
940: if (elType.ElTypeNum != HTML_EL_Input)
941: {
1.37 cvs 942: sprintf (msgBuffer, "Duplicate attribute \"type = %s\"", val);
1.30 cvs 943: XmlParseError (errorParsing, msgBuffer, 0);
944: }
945: else
946: {
947: elType.ElTypeNum = value;
948: newChild = TtaNewTree (context->doc, elType, "");
949: XmlSetElemLineNumber (newChild);
950: TtaInsertFirstChild (&newChild, context->lastElement, context->doc);
951: if (value == HTML_EL_PICTURE_UNIT)
952: {
953: /* add the attribute IsInput to input pictures */
954: attrType.AttrSSchema = elType.ElSSchema;
955: attrType.AttrTypeNum = HTML_ATTR_IsInput;
956: attr = TtaNewAttribute (attrType);
957: TtaAttachAttribute (newChild, attr, context->doc);
958: }
959: }
960: }
961: }
962:
963: /*----------------------------------------------------------------------
964: CreateAttrWidthPercentPxl
1.79 quint 965: an HTML attribute "width" has been created for a Table, an image,
966: an Object of a HR.
1.30 cvs 967: Create the corresponding attribute IntWidthPercent or IntWidthPxl.
968: oldWidth is -1 or the old image width.
969: ----------------------------------------------------------------------*/
1.58 vatton 970: void CreateAttrWidthPercentPxl (char *buffer, Element el,
971: Document doc, int oldWidth)
1.30 cvs 972: {
973: AttributeType attrTypePxl, attrTypePercent;
974: Attribute attrOld, attrNew;
975: int length, val;
1.39 cvs 976: char msgBuffer[MaxMsgLength];
1.79 quint 977: ElementType elType, childType;
978: Element origEl, child;
1.30 cvs 979: int w, h;
980: ThotBool isImage;
981:
1.79 quint 982: origEl = el;
1.30 cvs 983: elType = TtaGetElementType (el);
984: isImage = (elType.ElTypeNum == HTML_EL_PICTURE_UNIT ||
985: elType.ElTypeNum == HTML_EL_Data_cell ||
1.79 quint 986: elType.ElTypeNum == HTML_EL_Heading_cell ||
987: elType.ElTypeNum == HTML_EL_Object);
988: if (elType.ElTypeNum == HTML_EL_Object)
989: /* the width attribute is attached to an Object element */
990: {
991: child = TtaGetFirstChild (el);
992: if (child)
993: {
994: childType = TtaGetElementType (child);
995: if (childType.ElTypeNum == HTML_EL_PICTURE_UNIT)
996: /* the Object element is of type image. apply the width
997: attribute to the actual image element */
998: el = child;
999: }
1000: }
1.30 cvs 1001: /* remove trailing spaces */
1.37 cvs 1002: length = strlen (buffer) - 1;
1.30 cvs 1003: while (length > 0 && buffer[length] <= SPACE)
1004: length--;
1005: attrTypePxl.AttrSSchema = TtaGetDocumentSSchema (doc);
1006: attrTypePercent.AttrSSchema = TtaGetDocumentSSchema (doc);
1007: attrTypePxl.AttrTypeNum = HTML_ATTR_IntWidthPxl;
1008: attrTypePercent.AttrTypeNum = HTML_ATTR_IntWidthPercent;
1009: /* is the last character a '%' ? */
1010: if (buffer[length] == '%')
1011: {
1012: /* remove IntWidthPxl */
1013: attrOld = TtaGetAttribute (el, attrTypePxl);
1014: /* update IntWidthPercent */
1015: attrNew = TtaGetAttribute (el, attrTypePercent);
1016: if (attrNew == NULL)
1017: {
1018: attrNew = TtaNewAttribute (attrTypePercent);
1019: TtaAttachAttribute (el, attrNew, doc);
1020: }
1021: else if (isImage && oldWidth == -1)
1022: {
1023: if (attrOld == NULL)
1024: oldWidth = TtaGetAttributeValue (attrNew);
1025: else
1026: oldWidth = TtaGetAttributeValue (attrOld);
1027: }
1028: }
1029: else
1030: {
1031: /* remove IntWidthPercent */
1032: attrOld = TtaGetAttribute (el, attrTypePercent);
1033: /* update IntWidthPxl */
1034: attrNew = TtaGetAttribute (el, attrTypePxl);
1035: if (attrNew == NULL)
1036: {
1037: attrNew = TtaNewAttribute (attrTypePxl);
1038: TtaAttachAttribute (el, attrNew, doc);
1039: }
1040: else if (isImage && oldWidth == -1)
1041: {
1042: TtaGiveBoxSize (el, doc, 1, UnPixel, &w, &h);
1043: if (attrOld == NULL)
1044: oldWidth = w * TtaGetAttributeValue (attrNew) / 100;
1045: else
1046: oldWidth = w * TtaGetAttributeValue (attrOld) / 100;
1047: }
1048: }
1049:
1050: if (attrOld != NULL)
1051: TtaRemoveAttribute (el, attrOld, doc);
1.43 cvs 1052: if (sscanf (buffer, "%d", &val))
1.30 cvs 1053: TtaSetAttributeValue (attrNew, val, el, doc);
1054: else
1055: /* its not a number. Delete attribute and send an error message */
1056: {
1057: TtaRemoveAttribute (el, attrNew, doc);
1.37 cvs 1058: if (strlen (buffer) > MaxMsgLength - 30)
1.30 cvs 1059: buffer[MaxMsgLength - 30] = EOS;
1.37 cvs 1060: sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
1.42 cvs 1061: HTMLParseError (doc, msgBuffer);
1.30 cvs 1062: }
1063: if (isImage)
1.79 quint 1064: UpdateImageMap (origEl, doc, oldWidth, -1);
1.30 cvs 1065: }
1066:
1067: /*----------------------------------------------------------------------
1.58 vatton 1068: CreateAttrHeightPercentPxl
1.79 quint 1069: an HTML attribute "width" has been created for a Table, an image,
1070: an Object or a HR.
1.58 vatton 1071: Create the corresponding attribute IntHeightPercent or IntHeightPxl.
1072: oldHeight is -1 or the old image width.
1073: ----------------------------------------------------------------------*/
1074: void CreateAttrHeightPercentPxl (char *buffer, Element el,
1075: Document doc, int oldHeight)
1076: {
1077: AttributeType attrTypePxl, attrTypePercent;
1078: Attribute attrOld, attrNew;
1079: int length, val;
1080: char msgBuffer[MaxMsgLength];
1.79 quint 1081: ElementType elType, childType;
1082: Element origEl, child;
1.58 vatton 1083: int w, h;
1084: ThotBool isImage;
1085:
1.79 quint 1086: origEl = el;
1.58 vatton 1087: elType = TtaGetElementType (el);
1088: isImage = (elType.ElTypeNum == HTML_EL_PICTURE_UNIT ||
1089: elType.ElTypeNum == HTML_EL_Data_cell ||
1.79 quint 1090: elType.ElTypeNum == HTML_EL_Heading_cell ||
1091: elType.ElTypeNum == HTML_EL_Object);
1092: if (elType.ElTypeNum == HTML_EL_Object)
1093: /* the height attribute is attached to an Object element */
1094: {
1095: child = TtaGetFirstChild (el);
1.81 cvs 1096: if (!child)
1097: return;
1098: else
1.79 quint 1099: {
1100: childType = TtaGetElementType (child);
1101: if (childType.ElTypeNum == HTML_EL_PICTURE_UNIT)
1102: /* the Object element is of type image. apply the width
1103: attribute to the actual image element */
1104: el = child;
1.81 cvs 1105: else
1106: return;
1.79 quint 1107: }
1108: }
1.58 vatton 1109: /* remove trailing spaces */
1110: length = strlen (buffer) - 1;
1111: while (length > 0 && buffer[length] <= SPACE)
1112: length--;
1113: attrTypePxl.AttrSSchema = TtaGetDocumentSSchema (doc);
1114: attrTypePercent.AttrSSchema = TtaGetDocumentSSchema (doc);
1115: attrTypePxl.AttrTypeNum = HTML_ATTR_IntHeightPxl;
1116: attrTypePercent.AttrTypeNum = HTML_ATTR_IntHeightPercent;
1117: /* is the last character a '%' ? */
1118: if (buffer[length] == '%')
1119: {
1120: /* remove IntHeightPxl */
1121: attrOld = TtaGetAttribute (el, attrTypePxl);
1122: /* update IntHeightPercent */
1123: attrNew = TtaGetAttribute (el, attrTypePercent);
1124: if (attrNew == NULL)
1125: {
1126: attrNew = TtaNewAttribute (attrTypePercent);
1127: TtaAttachAttribute (el, attrNew, doc);
1128: }
1129: else if (isImage && oldHeight == -1)
1130: {
1131: if (attrOld == NULL)
1132: oldHeight = TtaGetAttributeValue (attrNew);
1133: else
1134: oldHeight = TtaGetAttributeValue (attrOld);
1135: }
1136: }
1137: else
1138: {
1139: /* remove IntHeightPercent */
1140: attrOld = TtaGetAttribute (el, attrTypePercent);
1141: /* update IntHeightPxl */
1142: attrNew = TtaGetAttribute (el, attrTypePxl);
1143: if (attrNew == NULL)
1144: {
1145: attrNew = TtaNewAttribute (attrTypePxl);
1146: TtaAttachAttribute (el, attrNew, doc);
1147: }
1148: else if (isImage && oldHeight == -1)
1149: {
1150: TtaGiveBoxSize (el, doc, 1, UnPixel, &w, &h);
1151: if (attrOld == NULL)
1152: oldHeight = w * TtaGetAttributeValue (attrNew) / 100;
1153: else
1154: oldHeight = w * TtaGetAttributeValue (attrOld) / 100;
1155: }
1156: }
1157:
1158: if (attrOld != NULL)
1159: TtaRemoveAttribute (el, attrOld, doc);
1160: if (sscanf (buffer, "%d", &val))
1161: TtaSetAttributeValue (attrNew, val, el, doc);
1162: else
1163: /* its not a number. Delete attribute and send an error message */
1164: {
1165: TtaRemoveAttribute (el, attrNew, doc);
1166: if (strlen (buffer) > MaxMsgLength - 30)
1167: buffer[MaxMsgLength - 30] = EOS;
1168: sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
1169: HTMLParseError (doc, msgBuffer);
1170: }
1171: if (isImage)
1.79 quint 1172: UpdateImageMap (origEl, doc, oldHeight, -1);
1.58 vatton 1173: }
1174:
1175: /*----------------------------------------------------------------------
1.30 cvs 1176: CreateAttrIntSize
1177: an HTML attribute "size" has been created for a Font element.
1178: Create the corresponding internal attribute.
1179: ----------------------------------------------------------------------*/
1.46 cvs 1180: void CreateAttrIntSize (char *buffer, Element el, Document doc)
1.30 cvs 1181:
1182: {
1183: AttributeType attrType;
1184: int val, ind, factor, delta;
1185: Attribute attr;
1.37 cvs 1186: char msgBuffer[MaxMsgLength];
1.30 cvs 1187:
1188: /* is the first character a '+' or a '-' ? */
1189: ind = 0;
1190: factor = 1;
1191: delta = 0;
1192: if (buffer[0] == '+')
1193: {
1194: attrType.AttrTypeNum = HTML_ATTR_IntSizeIncr;
1195: ind++;
1196: factor = 2;
1197: }
1198: else if (buffer[0] == '-')
1199: {
1200: attrType.AttrTypeNum = HTML_ATTR_IntSizeDecr;
1201: ind++;
1202: factor = 2;
1203: }
1204: else
1205: {
1206: attrType.AttrTypeNum = HTML_ATTR_IntSizeRel;
1207: delta = 1;
1208: }
1209: attrType.AttrSSchema = TtaGetDocumentSSchema (doc);
1210: attr = TtaGetAttribute (el, attrType);
1.43 cvs 1211: if (sscanf (&buffer[ind], "%d", &val))
1.30 cvs 1212: {
1213: val = val * factor + delta;
1214: if (attr == NULL)
1215: {
1216: /* this attribute doesn't exist, create it */
1217: attr = TtaNewAttribute (attrType);
1218: TtaAttachAttribute (el, attr, doc);
1219: }
1220: TtaSetAttributeValue (attr, val, el, doc);
1221: }
1222: else
1223: /* its not a number. Delete attribute and send an error message */
1224: {
1225: if (attr)
1226: TtaRemoveAttribute (el, attr, doc);
1.37 cvs 1227: if (strlen (buffer) > MaxMsgLength - 30)
1.30 cvs 1228: buffer[MaxMsgLength - 30] = EOS;
1.37 cvs 1229: sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
1.42 cvs 1230: HTMLParseError (doc, msgBuffer);
1.30 cvs 1231: }
1232: }
1233: /*----------------------------------------------------------------------
1234: EndOfHTMLAttributeValue
1235: Filling of an HTML attribute value
1236: ----------------------------------------------------------------------*/
1.48 vatton 1237: void EndOfHTMLAttributeValue (char *attrValue,
1238: AttributeMapping *lastMappedAttr,
1239: Attribute currentAttribute,
1240: Element lastAttrElement,
1241: ThotBool UnknownAttr,
1242: ParserData *context,
1243: ThotBool isXML)
1.30 cvs 1244: {
1.48 vatton 1245: AttributeType attrType, attrType1;
1246: Attribute attr;
1.79 quint 1247: ElementType elType;
1.48 vatton 1248: Element child, root;
1249: Language lang;
1250: char translation;
1251: char shape;
1252: char *buffer;
1253: char *attrName;
1254: char msgBuffer[MaxMsgLength];
1255: int val;
1256: int length;
1257: int attrKind;
1258: ThotBool done = FALSE;
1.30 cvs 1259:
1.48 vatton 1260: /* treatments of some particular HTML attributes */
1261: if (!strcmp (lastMappedAttr->XMLattribute, "style"))
1262: {
1263: TtaSetAttributeText (currentAttribute, attrValue,
1264: lastAttrElement, context->doc);
1265: ParseHTMLSpecificStyle (context->lastElement, attrValue,
1.61 quint 1266: context->doc, 100, FALSE);
1.48 vatton 1267: done = TRUE;
1268: }
1269: else
1270: {
1271: if (!strcmp (lastMappedAttr->XMLattribute, "link"))
1272: HTMLSetAlinkColor (context->doc, attrValue);
1273: else if (!strcmp (lastMappedAttr->XMLattribute, "alink"))
1274: HTMLSetAactiveColor (context->doc, attrValue);
1275: else if (!strcmp (lastMappedAttr->XMLattribute, "vlink"))
1276: HTMLSetAvisitedColor (context->doc, attrValue);
1277: }
1.30 cvs 1278:
1.48 vatton 1279: if (!done)
1280: {
1281: val = 0;
1282: translation = lastMappedAttr->AttrOrContent;
1283: switch (translation)
1284: {
1285: case 'C': /* Content */
1286: child = PutInContent (attrValue, context);
1287: if (child != NULL)
1288: TtaAppendTextContent (child, "\" ", context->doc);
1289: break;
1290:
1291: case 'A':
1292: if (currentAttribute != NULL)
1293: {
1294: TtaGiveAttributeType (currentAttribute, &attrType, &attrKind);
1295: switch (attrKind)
1296: {
1297: case 0: /* enumerate */
1298: if (isXML)
1299: MapHTMLAttributeValue (attrValue, attrType, &val);
1300: else
1301: val = MapAttrValue (lastMappedAttr->ThotAttribute,
1.40 cvs 1302: attrValue);
1.48 vatton 1303: if (val < 0)
1304: {
1305: TtaGiveAttributeType (currentAttribute,
1306: &attrType, &attrKind);
1307: attrName = TtaGetAttributeName (attrType);
1308: sprintf (msgBuffer,
1.51 cvs 1309: "Invalid attribute value \"%s = %s\"",
1.48 vatton 1310: attrName, attrValue);
1311: if (isXML)
1312: XmlParseError (errorParsing, msgBuffer, 0);
1313: else
1.51 cvs 1314: {
1315: HTMLParseError (context->doc, msgBuffer);
1.48 vatton 1316: /* remove the attribute and replace it by an */
1.51 cvs 1317: /* Invalid_attribute (not for XHTML) */
1318: TtaRemoveAttribute (lastAttrElement,
1319: currentAttribute, context->doc);
1.48 vatton 1320: attrType.AttrSSchema =
1321: TtaGetDocumentSSchema (context->doc);
1322: attrType.AttrTypeNum =
1323: pHTMLAttributeMapping[0].ThotAttribute;
1.51 cvs 1324: sprintf (msgBuffer, "%s=%s", attrName, attrValue);
1325: CreateHTMLAttribute (lastAttrElement, attrType,
1326: msgBuffer, TRUE, context->doc,
1327: ¤tAttribute,
1328: &lastAttrElement);
1.48 vatton 1329: }
1330: }
1331: else
1332: TtaSetAttributeValue (currentAttribute, val,
1333: lastAttrElement, context->doc);
1334: break;
1335: case 1: /* integer */
1336: if (attrType.AttrTypeNum == HTML_ATTR_Border &&
1337: !strcasecmp (attrValue, "border"))
1338: {
1339: /* border="border" for a table */
1340: val = 1;
1341: TtaSetAttributeValue (currentAttribute, val,
1.30 cvs 1342: lastAttrElement, context->doc);
1.48 vatton 1343: }
1344: else if (sscanf (attrValue, "%d", &val))
1345: TtaSetAttributeValue (currentAttribute, val,
1346: lastAttrElement, context->doc);
1347: else
1348: {
1349: TtaRemoveAttribute (lastAttrElement, currentAttribute,
1350: context->doc);
1351: sprintf (msgBuffer,
1352: "Unknown attribute value \"%s\"",
1353: attrValue);
1354: if (isXML)
1355: XmlParseError (errorParsing, msgBuffer, 0);
1356: else
1357: HTMLParseError (context->doc, msgBuffer);
1358: }
1359: break;
1360: case 2: /* text */
1361: if (!UnknownAttr)
1362: {
1363: TtaSetAttributeText (currentAttribute, attrValue,
1364: lastAttrElement, context->doc);
1.55 cvs 1365: if (attrType.AttrTypeNum == HTML_ATTR_Language)
1.48 vatton 1366: {
1367: /* it's a LANG attribute value */
1368: lang = TtaGetLanguageIdFromName (attrValue);
1.70 vatton 1369: if (lang < 0)
1.48 vatton 1370: {
1371: sprintf (msgBuffer,
1372: "warning - unsupported language: %s",
1373: attrValue);
1374: if (isXML)
1375: XmlParseError (errorParsing, msgBuffer, 0);
1376: else
1377: HTMLParseError (context->doc, msgBuffer);
1378: }
1379: else
1380: {
1381: /* change current language */
1382: context->language = lang;
1383: if (isXML)
1384: SetLanguagInXmlStack (lang);
1385: else
1386: SetLanguagInHTMLStack (lang);
1387: }
1388: root = TtaGetRootElement (context->doc);
1389: if (lastAttrElement == root)
1390: /* it's a LANG attribute on the root element */
1391: /* set the RealLang attribute */
1392: {
1393: attrType1.AttrSSchema = TtaGetDocumentSSchema (context->doc);
1394: attrType1.AttrTypeNum = HTML_ATTR_RealLang;
1395: /* this attribute could be already present,
1396: (lang and xml:lang attributes) */
1397: if (!TtaGetAttribute (lastAttrElement,
1398: attrType1))
1399: /* it's not present. Add it */
1400: {
1401: attr = TtaNewAttribute (attrType1);
1402: TtaAttachAttribute (lastAttrElement,
1403: attr, context->doc);
1404: TtaSetAttributeValue (attr,
1405: HTML_ATTR_RealLang_VAL_Yes_,
1406: lastAttrElement,
1407: context->doc);
1408: }
1409: }
1410: }
1411: else if (attrType.AttrTypeNum == HTML_ATTR_accesskey)
1412: TtaAddAccessKey (context->doc, (unsigned int)attrValue[0],
1413: lastAttrElement);
1414: }
1415: else
1416: {
1.51 cvs 1417: /* this is the content of an invalid attribute */
1418: /* append it to the current Invalid_attribute */
1419: if (!isXML)
1420: {
1421: length = strlen (attrValue) + 2;
1422: length += TtaGetTextAttributeLength (currentAttribute);
1423: buffer = TtaGetMemory (length + 1);
1424: TtaGiveTextAttributeValue (currentAttribute,
1425: buffer, &length);
1426: strcat (buffer, "=");
1427: strcat (buffer, attrValue);
1428: TtaSetAttributeText (currentAttribute, buffer,
1429: lastAttrElement, context->doc);
1430: TtaFreeMemory (buffer);
1431: }
1.48 vatton 1432: }
1433: break;
1434: case 3: /* reference */
1435: break;
1436: }
1437: }
1438: break;
1439:
1440: case SPACE:
1441: if (isXML)
1442: XhtmlTypeAttrValue (attrValue, currentAttribute,
1.30 cvs 1443: lastAttrElement, context);
1.48 vatton 1444: else
1445: HTMLTypeAttrValue (attrValue, currentAttribute,
1446: lastAttrElement, context);
1447: break;
1448:
1.30 cvs 1449: default:
1450: break;
1.48 vatton 1451: }
1.30 cvs 1452:
1453: if (lastMappedAttr->ThotAttribute == HTML_ATTR_Width__)
1.79 quint 1454: /* HTML attribute "width" */
1455: {
1456: /* if it's an Object element, wait until all attributes are handled,
1457: especially the data attribute that may generate the image to
1458: which the width has to be applied */
1459: elType = TtaGetElementType (lastAttrElement);
1460: if (elType.ElTypeNum != HTML_EL_Object)
1461: /* create the corresponding attribute IntWidthPercent or */
1462: /* IntWidthPxl */
1463: CreateAttrWidthPercentPxl (attrValue, lastAttrElement,
1464: context->doc, -1);
1465: }
1.58 vatton 1466: else if (lastMappedAttr->ThotAttribute == HTML_ATTR_Height_)
1.79 quint 1467: /* HTML attribute "height" */
1468: {
1469: /* if it's an Object element, wait until all attributes are handled,
1470: especially the data attribute that may generate the image to
1471: which the height has to be applied */
1472: elType = TtaGetElementType (lastAttrElement);
1473: if (elType.ElTypeNum != HTML_EL_Object)
1474: /* create the corresponding attribute IntHeightPercent or */
1475: /* IntHeightPxl */
1476: CreateAttrHeightPercentPxl (attrValue, lastAttrElement,
1477: context->doc, -1);
1478: }
1.48 vatton 1479: else if (!strcmp (lastMappedAttr->XMLattribute, "size"))
1480: {
1481: TtaGiveAttributeType (currentAttribute, &attrType, &attrKind);
1482: if (attrType.AttrTypeNum == HTML_ATTR_Font_size)
1483: CreateAttrIntSize (attrValue, lastAttrElement, context->doc);
1484: }
1485: else if (!strcmp (lastMappedAttr->XMLattribute, "shape"))
1486: {
1487: child = TtaGetFirstChild (lastAttrElement);
1488: if (child != NULL)
1489: {
1490: switch (val)
1491: {
1492: case HTML_ATTR_shape_VAL_rectangle:
1493: shape = 'R';
1494: break;
1495: case HTML_ATTR_shape_VAL_circle:
1496: shape = 'a';
1497: break;
1498: case HTML_ATTR_shape_VAL_polygon:
1499: shape = 'p';
1500: break;
1501: default:
1502: shape = SPACE;
1503: break;
1504: }
1505: TtaSetGraphicsShape (child, shape, context->doc);
1506: }
1507: }
1508: else if (!strcmp (lastMappedAttr->XMLattribute, "value"))
1509: {
1510: elType = TtaGetElementType (lastAttrElement);
1511: if (elType.ElTypeNum == HTML_EL_Text_Input ||
1512: elType.ElTypeNum == HTML_EL_Password_Input ||
1513: elType.ElTypeNum == HTML_EL_File_Input ||
1514: elType.ElTypeNum == HTML_EL_Input)
1515: /* create a Default_Value attribute with the same content */
1516: {
1517: attrType1.AttrSSchema = attrType.AttrSSchema;
1518: attrType1.AttrTypeNum = HTML_ATTR_Default_Value;
1519: attr = TtaNewAttribute (attrType1);
1520: TtaAttachAttribute (lastAttrElement, attr, context->doc);
1521: TtaSetAttributeText (attr, attrValue,
1522: lastAttrElement, context->doc);
1523: }
1524: }
1.30 cvs 1525: else
1.48 vatton 1526: {
1527: /* Some HTML attributes are equivalent to a CSS property: */
1528: /* background -> background */
1529: /* bgcolor -> background */
1530: /* text -> color */
1531: /* color -> color */
1532: if (!strcmp (lastMappedAttr->XMLattribute, "background"))
1533: {
1534: if (strlen (attrValue) > MaxMsgLength - 30)
1535: attrValue[MaxMsgLength - 30] = EOS;
1.76 vatton 1536: HTMLSetBackgroundImage (context->doc, context->lastElement,
1537: STYLE_REPEAT, attrValue, FALSE);
1.48 vatton 1538: }
1539: else if (!strcmp (lastMappedAttr->XMLattribute, "bgcolor"))
1.76 vatton 1540: HTMLSetBackgroundColor (context->doc, context->lastElement,
1541: attrValue);
1.48 vatton 1542: else if (!strcmp (lastMappedAttr->XMLattribute, "text") ||
1543: !strcmp (lastMappedAttr->XMLattribute, "color"))
1544: HTMLSetForegroundColor (context->doc,
1545: context->lastElement, attrValue);
1546: }
1547: }
1.30 cvs 1548: }
1549:
1550: /*----------------------------------------------------------------------
1.16 cvs 1551: MapHTMLAttributeValue
1.2 cvs 1552: Search in the Attribute Value Mapping Table the entry for the attribute
1.66 vatton 1553: ThotAtt and its value attVal. Returns the corresponding Thot value.
1.1 cvs 1554: ----------------------------------------------------------------------*/
1.66 vatton 1555: void MapHTMLAttributeValue (char *attVal, AttributeType attrType, int *value)
1.1 cvs 1556: {
1.66 vatton 1557: MapXMLAttributeValue (XHTML_TYPE, attVal, attrType, value);
1.1 cvs 1558: }
Webmaster