Annotation of Amaya/amaya/templates.c, revision 1.22
1.1 cvs 1: /*
2: *
1.22 ! vatton 3: * COPYRIGHT INRIA and W3C, 1996-2003
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.1 cvs 28:
1.3 cvs 29: #include "init_f.h"
30:
31:
1.1 cvs 32: /*----------------------------------------------------------------------
33: NewTemplate: Opens a template form on the remote template server
34: ----------------------------------------------------------------------*/
1.18 cvs 35: void NewTemplate (Document doc, View view)
1.1 cvs 36: {
1.18 cvs 37: char *url;
1.1 cvs 38:
1.10 cvs 39: url = TtaGetEnvString ("TEMPLATE_URL");
40: if (url)
1.19 vatton 41: GetAmayaDoc (url, NULL, 0, 0, CE_ABSOLUTE, FALSE, NULL, NULL,
42: TtaGetDefaultCharset ());
1.1 cvs 43: }
44: /*----------------------------------------------------------------------
45: OpenTemplateDocument: Process the meta of a template document,
46: changes the URL, try to save it and warn the user if it cannot be
47: saved.
48: ----------------------------------------------------------------------*/
1.18 cvs 49: void OpenTemplateDocument (Document doc)
1.1 cvs 50: {
51: ElementType metaElType;
52: Element metaEl;
53: Attribute metaAttr;
54: AttributeType metaAttrType;
55: ThotBool found = FALSE;
56: ThotBool ok = FALSE;
57: int length;
1.17 cvs 58: char buffer[MAX_LENGTH];
59: char *URLdir;
60: char *URLname;
1.1 cvs 61:
62: metaElType.ElSSchema = TtaGetDocumentSSchema (doc);
63: metaElType.ElTypeNum = HTML_EL_META;
64: metaAttrType.AttrSSchema = TtaGetDocumentSSchema (doc);
65: metaAttrType.AttrTypeNum = HTML_ATTR_meta_name;
66: /* search the meta element */
67: metaEl = TtaGetMainRoot (doc);
68: do
69: {
70: metaEl = TtaSearchTypedElement (metaElType, SearchForward, metaEl);
71: if (metaEl != NULL)
72: {
73: metaAttr = TtaGetAttribute (metaEl, metaAttrType);
74: if (metaAttr != NULL)
75: {
76: length = MAX_LENGTH - 1;
77: TtaGiveTextAttributeValue (metaAttr, buffer, &length);
1.17 cvs 78: found = !strcmp (buffer, META_TEMPLATE_NAME);
1.1 cvs 79: }
80: }
81: }
82: while (metaEl != NULL && !found);
83: if (found)
84: {
85: /* get the url of the document */
86: metaAttrType.AttrTypeNum = HTML_ATTR_meta_content;
87: metaAttr = TtaGetAttribute (metaEl, metaAttrType);
88: if (metaAttr != NULL)
89: {
90: length = MAX_LENGTH - 1;
91: TtaGiveTextAttributeValue (metaAttr, buffer, &length);
92: }
93: /* Delete the meta element */
94: TtaDeleteTree (metaEl, doc);
95: /* try to save to the new url */
96: #ifdef WITH_PRELABLE_SAVE_POUR_VOIR
97: ok = SaveDocumentThroughNet (doc, 1, buffer, FALSE, TRUE, TRUE);
98: #else
99: ok = TRUE;
100: #endif
101: if (ok)
102: {
103: if (script_URL == NULL)
1.17 cvs 104: script_URL = TtaStrdup (DocumentURLs[doc]);
1.1 cvs 105: TtaFreeMemory (DocumentURLs[doc]);
1.17 cvs 106: DocumentURLs[doc] = TtaStrdup (buffer);
1.1 cvs 107: DocumentMeta[doc]->method = CE_TEMPLATE;
1.21 vatton 108: AddURLInCombobox (DocumentURLs[doc], TRUE);
109: TtaSetTextZone (doc, 1, URL_list);
1.1 cvs 110: TtaSetDocumentUnmodified (doc);
111:
112: }
113: else
114: {
115: /* save failed : print warning message */
116:
117: }
118:
119: /* set the document name and dir */
120:
1.17 cvs 121: URLname = strrchr (buffer, URL_SEP);
1.5 cvs 122: if (URLname)
123: {
124: URLname[0] = EOS;
125: URLname++;
126: URLdir = buffer;
127: TtaSetDocumentDirectory (doc, URLdir);
1.9 cvs 128: TtaSetDocumentName (doc, URLname);
1.5 cvs 129: /* SetBrowserEditor(doc); */
130: }
131: else
132: {
1.16 cvs 133: TtaSetDocumentDirectory (doc, "");
1.5 cvs 134: TtaSetDocumentName (doc, buffer);
135: }
1.9 cvs 136: SetWindowTitle (doc, doc, 0);
1.1 cvs 137: }
1.5 cvs 138:
1.1 cvs 139: }
140:
141: /*----------------------------------------------------------------------
142: ReloadTemplateParams : restores the script URL and method into meta
143: to reload a template
144: ----------------------------------------------------------------------*/
1.18 cvs 145: void ReloadTemplateParams (char **docURL, ClickEvent *method)
1.1 cvs 146: {
147: *method = CE_FORM_GET;
1.5 cvs 148: TtaFreeMemory (*docURL);
1.17 cvs 149: *docURL = TtaStrdup (script_URL);
1.1 cvs 150: }
Webmaster