Annotation of Amaya/amaya/templates.c, revision 1.26
1.1 cvs 1: /*
2: *
1.24 vatton 3: * COPYRIGHT INRIA and W3C, 1996-2004
1.1 cvs 4: * Please first read the full copyright statement in file COPYRIGHT.
5: *
6: */
1.14 cvs 7:
1.1 cvs 8: /*
9: * Amaya browser functions called form Thot and declared in HTML.A.
10: * These functions concern links and other HTML general features.
11: *
1.15 cvs 12: * Authors: I. Vatton, L. Bonameau, S. Bonhomme (INRIA)
1.1 cvs 13: *
14: */
15:
16: /* Included headerfiles */
17: #define THOT_EXPORT extern
18: #include "amaya.h"
19: #include "css.h"
20: #include "document.h"
21: #include "view.h"
22:
23:
24: /* content of the attr name of the meta tag defining the doc's destination URL */
1.18 cvs 25: #define META_TEMPLATE_NAME "AMAYA_TEMPLATE"
1.1 cvs 26: /* URL of the script providing templates (for reload) */
1.18 cvs 27: static char *script_URL;
1.3 cvs 28: #include "init_f.h"
29:
30:
1.1 cvs 31: /*----------------------------------------------------------------------
32: NewTemplate: Opens a template form on the remote template server
33: ----------------------------------------------------------------------*/
1.18 cvs 34: void NewTemplate (Document doc, View view)
1.1 cvs 35: {
1.25 vatton 36: char *url;
1.1 cvs 37:
1.10 cvs 38: url = TtaGetEnvString ("TEMPLATE_URL");
1.25 vatton 39: if (url && TtaCheckDirectory (url))
40: {
41: /*TtaNewScrollPopup (BaseDialog + xxx, TtaGetViewFrame (doc, 1),
42: NULL, nbitems, FormBuf, NULL, multipleOptions, 'L');
43: InitOpenDocForm (doc, view, "New.html",
44: "xxx", docHTML);*/
45: /*GetAmayaDoc (url, NULL, 0, 0, CE_ABSOLUTE, FALSE, NULL, NULL);*/
46: }
1.1 cvs 47: }
1.25 vatton 48:
1.1 cvs 49: /*----------------------------------------------------------------------
50: OpenTemplateDocument: Process the meta of a template document,
51: changes the URL, try to save it and warn the user if it cannot be
52: saved.
53: ----------------------------------------------------------------------*/
1.18 cvs 54: void OpenTemplateDocument (Document doc)
1.1 cvs 55: {
56: ElementType metaElType;
57: Element metaEl;
58: Attribute metaAttr;
59: AttributeType metaAttrType;
60: ThotBool found = FALSE;
61: int length;
1.24 vatton 62: char *utf8path, *path;
63: char *URLdir, *URLname;
1.1 cvs 64:
65: metaElType.ElSSchema = TtaGetDocumentSSchema (doc);
66: metaElType.ElTypeNum = HTML_EL_META;
67: metaAttrType.AttrSSchema = TtaGetDocumentSSchema (doc);
68: metaAttrType.AttrTypeNum = HTML_ATTR_meta_name;
69: /* search the meta element */
70: metaEl = TtaGetMainRoot (doc);
1.24 vatton 71: path = NULL;
1.1 cvs 72: do
73: {
74: metaEl = TtaSearchTypedElement (metaElType, SearchForward, metaEl);
75: if (metaEl != NULL)
76: {
77: metaAttr = TtaGetAttribute (metaEl, metaAttrType);
78: if (metaAttr != NULL)
79: {
1.24 vatton 80: length = TtaGetTextAttributeLength (metaAttr) + 1;
81: utf8path = (char *) TtaGetMemory (length);
82: TtaGiveTextAttributeValue (metaAttr, utf8path, &length);
83: path = (char *)TtaConvertMbsToByte ((unsigned char *)utf8path,
84: TtaGetDefaultCharset ());
85: TtaFreeMemory (utf8path);
86: found = !strcmp (path, META_TEMPLATE_NAME);
1.26 ! cvs 87: /* free previous path if necessary */
! 88: TtaFreeMemory (path);
! 89: path = NULL;
1.1 cvs 90: }
91: }
92: }
1.24 vatton 93: while (metaEl && !found);
94:
1.1 cvs 95: if (found)
96: {
97: /* get the url of the document */
98: metaAttrType.AttrTypeNum = HTML_ATTR_meta_content;
99: metaAttr = TtaGetAttribute (metaEl, metaAttrType);
100: if (metaAttr != NULL)
101: {
1.24 vatton 102: length = TtaGetTextAttributeLength (metaAttr) + 1;
103: utf8path = (char *) TtaGetMemory (length);
104: TtaGiveTextAttributeValue (metaAttr, utf8path, &length);
105: path = (char *)TtaConvertMbsToByte ((unsigned char *)utf8path,
106: TtaGetDefaultCharset ());
107: TtaFreeMemory (utf8path);
1.1 cvs 108: }
1.24 vatton 109:
1.1 cvs 110: /* Delete the meta element */
111: TtaDeleteTree (metaEl, doc);
1.24 vatton 112: if (script_URL == NULL)
113: script_URL = TtaStrdup (DocumentURLs[doc]);
114: TtaFreeMemory (DocumentURLs[doc]);
115: DocumentURLs[doc] = TtaStrdup (path);
116: DocumentMeta[doc]->method = CE_TEMPLATE;
117: AddURLInCombobox (DocumentURLs[doc], NULL, TRUE);
118: TtaSetTextZone (doc, 1, URL_list);
119: TtaSetDocumentUnmodified (doc);
120:
1.1 cvs 121: /* set the document name and dir */
1.24 vatton 122: URLname = strrchr (path, URL_SEP);
1.5 cvs 123: if (URLname)
124: {
125: URLname[0] = EOS;
126: URLname++;
1.24 vatton 127: URLdir = path;
1.5 cvs 128: TtaSetDocumentDirectory (doc, URLdir);
1.9 cvs 129: TtaSetDocumentName (doc, URLname);
1.5 cvs 130: /* SetBrowserEditor(doc); */
131: }
132: else
133: {
1.16 cvs 134: TtaSetDocumentDirectory (doc, "");
1.24 vatton 135: TtaSetDocumentName (doc, path);
1.5 cvs 136: }
1.9 cvs 137: SetWindowTitle (doc, doc, 0);
1.1 cvs 138: }
1.24 vatton 139: TtaFreeMemory (path);
1.1 cvs 140: }
141:
142: /*----------------------------------------------------------------------
143: ReloadTemplateParams : restores the script URL and method into meta
144: to reload a template
145: ----------------------------------------------------------------------*/
1.18 cvs 146: void ReloadTemplateParams (char **docURL, ClickEvent *method)
1.1 cvs 147: {
148: *method = CE_FORM_GET;
1.5 cvs 149: TtaFreeMemory (*docURL);
1.17 cvs 150: *docURL = TtaStrdup (script_URL);
1.1 cvs 151: }
Webmaster