Annotation of Amaya/amaya/templateUtils.c, revision 1.36
1.9 vatton 1: /*
2: *
1.18 vatton 3: * COPYRIGHT INRIA and W3C, 2006-2008
1.9 vatton 4: * Please first read the full copyright statement in file COPYRIGHT.
5: *
6: */
7:
1.3 quint 8: #include "templates.h"
1.14 kia 9: #include "Templatename.h"
10: #include "templates_f.h"
1.1 francesc 11:
1.21 kia 12: #include "AHTURLTools_f.h"
13: #include "HTMLsave_f.h"
14:
15:
1.19 kia 16: #include <stdarg.h>
17:
1.1 francesc 18: /*----------------------------------------------------------------------
1.30 kia 19: GetSchemaFromDocType: Returns the name of the schema corresponding to
1.1 francesc 20: a doc type.
21: ----------------------------------------------------------------------*/
1.24 kia 22: const char *GetSchemaFromDocType (DocumentType docType)
1.1 francesc 23: {
24: #ifdef TEMPLATES
25: switch (docType)
26: {
27: case docAnnot :
28: return "Annot";
29: case docBookmark :
30: return "Topics";
31: case docSVG :
32: return "SVG";
33: case docMath :
34: return "MathML";
35: case docXml :
36: return "XML";
37: default :
38: return "HTML";
39: }
40: #endif // TEMPLATES
41: return "HTML";
42: }
43:
1.5 kia 44: /*----------------------------------------------------------------------
1.30 kia 45: Set the value of a string attribute
1.5 kia 46: ----------------------------------------------------------------------*/
1.24 kia 47: void SetAttributeStringValue (Element el, int att, const char* value)
1.5 kia 48: {
49: #ifdef TEMPLATES
1.7 vatton 50: Document doc = TtaGetDocument(el);
51: AttributeType attType;
52: Attribute attribute;
1.5 kia 53:
1.10 kia 54: if (doc == 0 || !TtaGetDocumentAccessMode(doc))
1.9 vatton 55: return;
1.5 kia 56: attType.AttrSSchema = TtaGetElementType(el).ElSSchema;
57: attType.AttrTypeNum = att;
1.7 vatton 58: attribute = TtaGetAttribute(el, attType);
59: if (attribute == NULL)
60: {
61: attribute = TtaNewAttribute (attType);
62: TtaAttachAttribute(el, attribute, doc);
63: }
1.5 kia 64: TtaSetAttributeText(attribute, value, el, doc);
65: #endif /* TEMPLATES */
66: }
67:
1.11 kia 68: /*----------------------------------------------------------------------
69: Set the value of a string attribute and registering it in undo sequence.
70: ----------------------------------------------------------------------*/
71: void SetAttributeStringValueWithUndo (Element el, int att, char* value)
72: {
73: #ifdef TEMPLATES
74: Document doc = TtaGetDocument(el);
75: AttributeType attType;
76: Attribute attribute;
77:
78: if (doc == 0 || !TtaGetDocumentAccessMode(doc))
79: return;
80: attType.AttrSSchema = TtaGetElementType(el).ElSSchema;
81: attType.AttrTypeNum = att;
82: attribute = TtaGetAttribute(el, attType);
83: if (attribute == NULL)
84: {
85: attribute = TtaNewAttribute (attType);
86: TtaAttachAttribute(el, attribute, doc);
87: TtaRegisterAttributeCreate(attribute, el, doc);
88: }
89: TtaSetAttributeText(attribute, value, el, doc);
90: TtaRegisterAttributeReplace(attribute, el, doc);
91: #endif /* TEMPLATES */
92: }
93:
1.13 kia 94: /*----------------------------------------------------------------------
1.30 kia 95: Returns the value of a string attribute without copy it
1.13 kia 96: ----------------------------------------------------------------------*/
97: void GiveAttributeStringValueFromNum (Element el, int att, char* buff, int* sz)
98: {
99: #ifdef TEMPLATES
100: AttributeType attType;
101: Attribute attribute;
102: int size;
103:
104: attType.AttrSSchema = TtaGetElementType(el).ElSSchema;
105: attType.AttrTypeNum = att;
106: attribute = TtaGetAttribute(el, attType);
1.30 kia 107:
1.13 kia 108: size = TtaGetTextAttributeLength(attribute);
109: TtaGiveTextAttributeValue (attribute, buff, &size);
110: buff[size] = EOS;
111: if(sz)
112: *sz = size;
113: #endif /* TEMPLATES */
114: }
115:
116:
1.1 francesc 117:
118: /*----------------------------------------------------------------------
1.31 vatton 119: Returns the value of a string attribute or NULL
1.1 francesc 120: ----------------------------------------------------------------------*/
1.8 kia 121: char *GetAttributeStringValueFromNum (Element el, int att, int* sz)
1.1 francesc 122: {
123: #ifdef TEMPLATES
124: AttributeType attType;
1.12 vatton 125: Attribute attribute;
126: char *aux;
127: int size;
128:
1.1 francesc 129: attType.AttrSSchema = TtaGetElementType(el).ElSSchema;
130: attType.AttrTypeNum = att;
1.12 vatton 131: attribute = TtaGetAttribute(el, attType);
1.31 vatton 132: if (attribute == NULL)
133: return NULL;
1.30 kia 134:
1.31 vatton 135: size = TtaGetTextAttributeLength (attribute);
136: aux = (char*) TtaGetMemory (size+1);
1.1 francesc 137: TtaGiveTextAttributeValue (attribute, aux, &size);
1.12 vatton 138: aux[size] = EOS;
1.31 vatton 139: if (sz)
1.4 kia 140: *sz = size;
1.1 francesc 141: return aux;
142: #else
1.8 kia 143: return NULL;
1.1 francesc 144: #endif /* TEMPLATES */
145: }
1.2 francesc 146:
147: /*----------------------------------------------------------------------
1.30 kia 148: Returns the value of an int attribute
149: ----------------------------------------------------------------------*/
150: int GetAttributeIntValueFromNum (Element el, int att)
151: {
152: #ifdef TEMPLATES
153: AttributeType attType;
154: Attribute attribute;
155:
156: attType.AttrSSchema = TtaGetElementType(el).ElSSchema;
157: attType.AttrTypeNum = att;
158: attribute = TtaGetAttribute(el, attType);
159:
160: return TtaGetAttributeValue(attribute);
161: #else
162: return NULL;
163: #endif /* TEMPLATES */
164: }
165:
166: /*----------------------------------------------------------------------
167: Set the value of a int attribute and registering it in undo sequence if wanted
168: ----------------------------------------------------------------------*/
169: void SetAttributeIntValue (Element el, int att, int value, ThotBool undo)
170: {
171: #ifdef TEMPLATES
172: Document doc = TtaGetDocument(el);
173: AttributeType attType;
174: Attribute attribute;
175:
176: if (doc == 0 || !TtaGetDocumentAccessMode(doc))
177: return;
178: attType.AttrSSchema = TtaGetElementType(el).ElSSchema;
179: attType.AttrTypeNum = att;
180: attribute = TtaGetAttribute(el, attType);
181: if (attribute == NULL)
182: {
183: attribute = TtaNewAttribute (attType);
184: TtaAttachAttribute(el, attribute, doc);
185: if(undo)
186: TtaRegisterAttributeCreate(attribute, el, doc);
187: }
188: TtaSetAttributeValue(attribute, value, el, doc);
189: if(undo)
190: TtaRegisterAttributeReplace(attribute, el, doc);
191: #endif /* TEMPLATES */
192: }
193:
194:
195:
196:
197: /*----------------------------------------------------------------------
198: Returns the value of a string attribute
1.2 francesc 199: ----------------------------------------------------------------------*/
1.4 kia 200: char *GetAttributeStringValue (Element el, Attribute attribute, int* sz)
1.2 francesc 201: {
202: #ifdef TEMPLATES
203: int size = TtaGetTextAttributeLength(attribute);
204: char *aux = (char*) TtaGetMemory(size+1);
1.12 vatton 205:
1.2 francesc 206: TtaGiveTextAttributeValue (attribute, aux, &size);
1.12 vatton 207: aux[size] = EOS;
1.4 kia 208: if(sz)
209: *sz = size;
1.2 francesc 210: return aux;
211: #else
1.8 kia 212: return NULL;
1.2 francesc 213: #endif /* TEMPLATES */
214: }
1.6 kia 215:
1.31 vatton 216: /*----------------------------------------------------------------------
217: GetAncestorComponentName returns the name of the ancestor component
218: or NULL;
219: ----------------------------------------------------------------------*/
220: char *GetAncestorComponentName (Element *el)
221: {
222: #ifdef TEMPLATES
223: ElementType elType;
224: Element anc = NULL;
225: char *name;
226:
227: elType = TtaGetElementType (*el);
228: elType.ElTypeNum = Template_EL_component;
229: anc = TtaGetParent (*el);
230: anc = TtaGetExactTypedAncestor (anc, elType);
231: if (anc)
232: {
1.32 kia 233: name = GetAttributeStringValueFromNum (anc, Template_ATTR_name, NULL);
1.31 vatton 234: *el = anc;
235: return name;
236: }
1.32 kia 237: #endif /* TEMPLATES */
1.31 vatton 238: return NULL;
239: }
240:
1.6 kia 241:
242: /*----------------------------------------------------------------------
243: GetFirstEditableElement
244: Returns the first descendant element which is modifiable.
245: ----------------------------------------------------------------------*/
246: Element GetFirstEditableElement (Element el)
247: {
248: Element res = NULL;
249: Element current = TtaGetFirstChild(el);
1.30 kia 250:
1.6 kia 251: while(!res && current)
252: {
253: res = GetFirstEditableElement(current);
254: TtaNextSibling(¤t);
255: }
1.30 kia 256:
1.6 kia 257: if(!res && !TtaIsReadOnly(el))
258: res = el;
1.30 kia 259:
1.6 kia 260: return res;
261: }
1.14 kia 262:
263: /*----------------------------------------------------------------------
1.15 kia 264: TemplateCanInsertFirstChild
265: Test if an element can be inserted as child of another, bypassing xt.
266: ----------------------------------------------------------------------*/
267: ThotBool TemplateCanInsertFirstChild(ElementType elementType, Element parent, Document document)
268: {
269: #ifdef TEMPLATES
270: SSchema templateSSchema = TtaGetSSchema ("Template", document);
271: ElementType parType;
1.30 kia 272:
1.15 kia 273: while(parent)
274: {
275: parType = TtaGetElementType(parent);
276: if(parType.ElSSchema != templateSSchema)
277: break;
278: parent = TtaGetParent(parent);
279: }
280: if(!parent)
281: return FALSE;
282: #endif /* TEMPLATES */
283: return TtaCanInsertFirstChild(elementType, parent, document);
284: }
285:
286: /*----------------------------------------------------------------------
1.14 kia 287: ValidateTemplateAttrInMenu
288: Validate the status of an attribute according to xt::atribute rules.
289: ----------------------------------------------------------------------*/
290: ThotBool ValidateTemplateAttrInMenu (NotifyAttribute * event)
291: {
292: #ifdef TEMPLATES
293: Element elem;
294: Element parent;
295: ElementType elType;
296: AttributeType attrType;
297: Attribute attr;
298: char* attrName;
299: char buffer[MAX_LENGTH];
300: int sz;
301: int useAt, type;
1.30 kia 302:
1.14 kia 303: /* Prevent from showing attributes for template instance but not templates. */
1.33 vatton 304: if (IsTemplateInstanceDocument(event->document))
1.14 kia 305: {
306: /* Prevent if attribute's element is not a descendant of xt:use */
1.17 kia 307: /* Dont prevent if descendant of xt:bag. */
1.14 kia 308: parent = event->element;
309: elem = GetFirstTemplateParentElement(parent);
310: if(!elem)
311: return TRUE;
312: elType = TtaGetElementType(elem);
1.17 kia 313: if(elType.ElTypeNum==Template_EL_bag)
314: return FALSE;
1.14 kia 315: if(elType.ElTypeNum!=Template_EL_useSimple)
316: return TRUE;
317:
318: /* Search for the corresponding xt:attribute element*/
319: attrName = TtaGetAttributeName(event->attributeType);
320: attrType.AttrSSchema = TtaGetSSchema ("Template", event->document);
321: for(elem = TtaGetFirstChild(parent); elem; TtaNextSibling(&elem))
322: {
323: attrType.AttrTypeNum = Template_ATTR_ref_name;
324: elType = TtaGetElementType(elem);
325: if(elType.ElTypeNum==Template_EL_attribute &&
326: elType.ElSSchema==TtaGetSSchema ("Template", event->document))
327: {
328: attr = TtaGetAttribute(elem, attrType);
329: if(attr)
330: {
331: sz = MAX_LENGTH;
332: TtaGiveTextAttributeValue(attr, buffer, &sz);
333: if(!strcmp(buffer, attrName))
334: {
335: /* Process the attribute filtering */
336: /* Get 'useAt' attr value. */
337: attrType.AttrTypeNum = Template_ATTR_useAt;
338: attr = TtaGetAttribute(elem, attrType);
339: if(attr)
340: useAt = TtaGetAttributeValue(attr);
341: else
342: useAt = Template_ATTR_useAt_VAL_required;
1.30 kia 343: /* Get 'type' attr value. */
1.14 kia 344: attrType.AttrTypeNum = Template_ATTR_type;
345: attr = TtaGetAttribute(elem, attrType);
346: if(attr)
347: type = TtaGetAttributeValue(attr);
348: else
349: type = Template_ATTR_type_VAL_string;
350: event->restr.RestrType = (RestrictionContentType)type;
351: /* If attr is prohibited, dont show it.*/
352: if(useAt==Template_ATTR_useAt_VAL_prohibited)
1.16 kia 353: return TRUE;
1.14 kia 354: if(useAt==Template_ATTR_useAt_VAL_required)
355: {
356: /* Force the usage of this attribute.*/
357: event->restr.RestrFlags |= attr_mandatory;
358: }
359:
360: /* Get 'fixed' attr value. */
361: attrType.AttrTypeNum = Template_ATTR_fixed;
362: attr = TtaGetAttribute(elem, attrType);
363: if(attr)
364: {
365: sz = MAX_LENGTH;
366: TtaGiveTextAttributeValue(attr, buffer, &sz);
367: event->restr.RestrFlags |= attr_readonly;
368: event->restr.RestrDefVal = TtaStrdup(buffer);
369: return FALSE;
370: }
371:
372: /* Get 'default' attr value.*/
373: attrType.AttrTypeNum = Template_ATTR_defaultAt;
374: attr = TtaGetAttribute(elem, attrType);
375: if(attr)
376: {
377: sz = MAX_LENGTH;
378: TtaGiveTextAttributeValue(attr, buffer, &sz);
379: event->restr.RestrDefVal = TtaStrdup(buffer);
380: }
381:
382: /* Get 'values' attr value.*/
383: attrType.AttrTypeNum = Template_ATTR_values;
384: attr = TtaGetAttribute(elem, attrType);
385: if(attr)
386: {
387: sz = MAX_LENGTH;
388: TtaGiveTextAttributeValue(attr, buffer, &sz);
389: event->restr.RestrEnumVal = TtaStrdup(buffer);
390: event->restr.RestrFlags |= attr_enum;
391: }
392: return FALSE;
393: }
394: }
395: }
396: }
1.30 kia 397:
1.16 kia 398: return TRUE;
1.14 kia 399: }
400: else
401: #endif /* TEMPLATES */
402: return FALSE;
403: }
1.19 kia 404:
405: /*----------------------------------------------------------------------
1.20 kia 406: * Dump element path
407: ----------------------------------------------------------------------*/
408: void DumpElementSubPath(Element el, char* buffer)
409: {
1.36 ! vatton 410: #ifdef TEMPLATE_DEBUG
1.20 kia 411: Element parent = TtaGetParent(el);
412: if(parent==NULL)
413: strcpy(buffer, TtaGetElementTypeName(TtaGetElementType(el)));
414: else
415: {
416: DumpElementSubPath(parent, buffer);
417: strcat(buffer, "/");
418: strcat(buffer, TtaGetElementTypeName(TtaGetElementType(el)));
419: }
1.36 ! vatton 420: #endif /* TEMPLATE_DEBUG */
1.20 kia 421: }
422:
423: /*----------------------------------------------------------------------
424: * Dump element path
425: ----------------------------------------------------------------------*/
426: void DumpElementPath(Element el)
427: {
1.36 ! vatton 428: #ifdef TEMPLATE_DEBUG
1.20 kia 429: char buffer[MAX_LENGTH];
430: DumpElementSubPath(el, buffer);
431: printf("%s\n", buffer);
1.36 ! vatton 432: #endif /* TEMPLATE_DEBUG */
1.20 kia 433: }
434:
435:
436: /*----------------------------------------------------------------------
1.19 kia 437: * Dump template element
438: ----------------------------------------------------------------------*/
439: void DumpTemplateElement(Element el, Document doc)
440: {
1.36 ! vatton 441: #ifdef TEMPLATE_DEBUG
1.28 vatton 442: ElementType elType;
443: AttributeType attType;
444: Attribute att;
445: SSchema schema = TtaGetSSchema ("Template", doc);
446: char* str;
447: char buffer[MAX_LENGTH];
448: int len;
449: Language lang;
1.30 kia 450:
1.19 kia 451: if(el && doc)
452: {
453: elType = TtaGetElementType(el);
1.26 kia 454: printf("- %p %d ", elType.ElSSchema, elType.ElTypeNum);
455: printf(" %s", TtaGetSSchemaName(elType.ElSSchema));
456: printf(":%s", TtaGetElementTypeName(elType));
457: if(elType.ElTypeNum==1)
458: {
459: len = MAX_LENGTH-1;
460: TtaGiveTextContent(el, (unsigned char*)buffer, &len, &lang);
461: buffer[len] = EOS;
462: printf(" \"%s\"", buffer);
463: }
1.30 kia 464:
1.19 kia 465: if(elType.ElSSchema==schema)
466: {
467: switch(elType.ElTypeNum)
468: {
469: case Template_EL_head:
470: str = GetAttributeStringValueFromNum(el, Template_ATTR_version, NULL);
471: printf(" version=%s", str);
472: TtaFreeMemory(str);
473: str = GetAttributeStringValueFromNum(el, Template_ATTR_templateVersion, NULL);
474: printf(" templateVersion=%s", str);
1.30 kia 475: TtaFreeMemory(str);
1.19 kia 476: break;
477: case Template_EL_component:
478: str = GetAttributeStringValueFromNum(el, Template_ATTR_name, NULL);
479: printf(" name=%s", str);
480: TtaFreeMemory(str);
481: break;
482: case Template_EL_union:
483: str = GetAttributeStringValueFromNum(el, Template_ATTR_name, NULL);
484: printf(" name=%s", str);
485: TtaFreeMemory(str);
486: str = GetAttributeStringValueFromNum(el, Template_ATTR_includeAt, NULL);
487: printf(" include=%s", str);
488: TtaFreeMemory(str);
489: str = GetAttributeStringValueFromNum(el, Template_ATTR_exclude, NULL);
490: printf(" exclude=%s", str);
491: TtaFreeMemory(str);
492: break;
493: case Template_EL_import:
494: str = GetAttributeStringValueFromNum(el, Template_ATTR_src, NULL);
495: printf(" src=%s", str);
496: TtaFreeMemory(str);
497: break;
498: case Template_EL_repeat:
499: str = GetAttributeStringValueFromNum(el, Template_ATTR_title, NULL);
500: printf(" label=%s", str);
501: TtaFreeMemory(str);
502: str = GetAttributeStringValueFromNum(el, Template_ATTR_minOccurs, NULL);
503: printf(" minOccurs=%s", str);
504: TtaFreeMemory(str);
505: str = GetAttributeStringValueFromNum(el, Template_ATTR_maxOccurs, NULL);
506: printf(" maxOccurs=%s", str);
507: TtaFreeMemory(str);
508: break;
509: case Template_EL_useSimple:
510: case Template_EL_useEl:
511: str = GetAttributeStringValueFromNum(el, Template_ATTR_title, NULL);
512: printf(" label=%s", str);
513: TtaFreeMemory(str);
514: str = GetAttributeStringValueFromNum(el, Template_ATTR_types, NULL);
515: printf(" types=%s", str);
516: TtaFreeMemory(str);
1.28 vatton 517: attType.AttrSSchema = elType.ElSSchema;
518: attType.AttrTypeNum = Template_ATTR_option;
519: att = TtaGetAttribute (el, attType);
520: if (att)
521: printf(" option");
1.19 kia 522: break;
523: case Template_EL_bag:
524: str = GetAttributeStringValueFromNum(el, Template_ATTR_title, NULL);
525: printf(" label=%s", str);
526: TtaFreeMemory(str);
527: str = GetAttributeStringValueFromNum(el, Template_ATTR_types, NULL);
528: printf(" types=%s", str);
529: TtaFreeMemory(str);
530: break;
531: case Template_EL_attribute:
532: str = GetAttributeStringValueFromNum(el, Template_ATTR_ref_name, NULL);
533: printf(" name=%s", str);
534: TtaFreeMemory(str);
535: str = GetAttributeStringValueFromNum(el, Template_ATTR_type, NULL);
536: printf(" type=%s", str);
537: TtaFreeMemory(str);
538: str = GetAttributeStringValueFromNum(el, Template_ATTR_useAt, NULL);
539: printf(" use=%s", str);
540: TtaFreeMemory(str);
541: str = GetAttributeStringValueFromNum(el, Template_ATTR_defaultAt, NULL);
542: printf(" default=%s", str);
543: TtaFreeMemory(str);
544: str = GetAttributeStringValueFromNum(el, Template_ATTR_fixed, NULL);
545: printf(" fixed=%s", str);
546: TtaFreeMemory(str);
547: break;
548: }
549: }
550: }
1.36 ! vatton 551: #endif /* TEMPLATE_DEBUG */
1.19 kia 552: }
1.21 kia 553:
554: /*----------------------------------------------------------------------
1.25 kia 555: * Dump subtree
556: ----------------------------------------------------------------------*/
557: void DumpSubtree(Element el, Document doc, int off)
558: {
1.36 ! vatton 559: #ifdef TEMPLATE_DEBUG
1.25 kia 560: Element child = TtaGetFirstChild(el);
561: int i;
1.30 kia 562:
1.25 kia 563: for(i=0; i<off; i++)
564: printf(" ");
565: DumpTemplateElement(el, doc);
566: printf("\n");
567:
568: while(child)
569: {
570: DumpSubtree(child, doc, off+1);
571: TtaNextSibling(&child);
572: }
1.36 ! vatton 573: #endif /* TEMPLATE_DEBUG */
1.25 kia 574: }
575:
576: /*----------------------------------------------------------------------
1.34 vatton 577: Save an opened document to a specified path in order to open.
578: The parameter doc is the original doc to be saved
579: The parameter newdoc is the new document
580: The parameter newpath is the newdoc URI
581: Return the saved localFile (to be freed) or NULL
1.21 kia 582: ----------------------------------------------------------------------*/
1.34 vatton 583: char *SaveDocumentToNewDoc(Document doc, Document newdoc, char* newpath)
1.21 kia 584: {
585: ElementType elType;
586: Element root;
1.34 vatton 587: char *localFile = NULL, *s;
1.21 kia 588: ThotBool res = FALSE;
1.30 kia 589:
1.21 kia 590: localFile = GetLocalPath (newdoc, newpath);
1.22 kia 591: // update all links
1.24 kia 592: SetRelativeURLs (doc, newpath, NULL, FALSE, FALSE, FALSE);
1.22 kia 593: // prepare the new document view
594: TtaExtractName (newpath, DirectoryName, DocumentName);
1.21 kia 595:
1.22 kia 596: root = TtaGetRootElement(doc);
597: elType = TtaGetElementType (root);
598: // get the target document type
599: s = TtaGetSSchemaName (elType.ElSSchema);
600: if (strcmp (s, "HTML") == 0)
601: {
602: /* docType = docHTML; */
603: if (TtaGetDocumentProfile(doc) == L_Xhtml11 ||
604: TtaGetDocumentProfile(doc) == L_Basic)
605: res = TtaExportDocumentWithNewLineNumbers (doc, localFile, "HTMLT11", FALSE);
1.21 kia 606: else
1.22 kia 607: res = TtaExportDocumentWithNewLineNumbers (doc, localFile, "HTMLTX", FALSE);
608: }
609: else if (strcmp (s, "SVG") == 0)
610: /* docType = docSVG; */
611: res = TtaExportDocumentWithNewLineNumbers (doc, localFile, "SVGT", FALSE);
612: else if (strcmp (s, "MathML") == 0)
613: /* docType = docMath; */
614: res = TtaExportDocumentWithNewLineNumbers (doc, localFile, "MathMLT", FALSE);
615: else
616: /* docType = docXml; */
617: res = TtaExportDocumentWithNewLineNumbers (doc, localFile, NULL, FALSE);
1.34 vatton 618: if (res)
619: return localFile;
620: else
621: {
622: TtaFreeMemory (localFile);
623: return NULL;
624: }
1.21 kia 625: }
1.29 kia 626:
627: /*----------------------------------------------------------------------
628: * Retrieve the xt:head element.
629: ----------------------------------------------------------------------*/
1.35 vatton 630: Element TemplateFindHead (Document doc)
1.29 kia 631: {
632: #ifdef TEMPLATES
1.35 vatton 633: ElementType headType, elType;
634: Element head, root;
635:
1.29 kia 636: headType.ElSSchema = TtaGetSSchema ("Template", doc);
1.35 vatton 637: if (headType.ElSSchema == NULL)
638: return NULL;
639:
1.29 kia 640: headType.ElTypeNum = Template_EL_head;
1.35 vatton 641: root = TtaGetMainRoot (doc);
642: head = TtaSearchTypedElement (headType, SearchInTree, root);
643: if (head == NULL)
644: {
645: // create the template head
646: head = TtaNewElement (doc, headType);
647: elType = TtaGetElementType (root);
648: if (!strcmp (TtaGetSSchemaName (elType.ElSSchema), "HTML"))
649: {
650: elType.ElTypeNum = HTML_EL_HEAD;
651: root = TtaSearchTypedElement (elType, SearchInTree, root);
652: }
653: TtaInsertFirstChild (&head, root, doc);
654: SetAttributeStringValue (head, Template_ATTR_version, Template_Current_Version);
655: SetAttributeStringValue (head, Template_ATTR_templateVersion, "1.0");
656: }
657: return head;
1.29 kia 658: #else /* TEMPLATES */
659: return NULL;
660: #endif /* TEMPLATES */
661: }
662:
663:
Webmaster