Annotation of Amaya/amaya/templates.c, revision 1.9
1.1 cvs 1: /*
2: *
3: * COPYRIGHT MIT and INRIA, 1996.
4: * Please first read the full copyright statement in file COPYRIGHT.
5: *
6: */
7:
8: /*
9: * Amaya browser functions called form Thot and declared in HTML.A.
10: * These functions concern links and other HTML general features.
11: *
12: * Authors: L. Bonameau, S. Bonhomme (INRIA) - HTML templates
13: *
14: */
15:
16: /* Included headerfiles */
17: #define THOT_EXPORT extern
18: #include "amaya.h"
19: #include "css.h"
20:
21: #include "document.h"
22: #include "view.h"
23:
24:
25: /* content of the attr name of the meta tag defining the doc's destination URL */
1.4 cvs 26: #if defined(_I18N_) || defined(__JIS__)
27: # define META_TEMPLATE_NAME L"AMAYA_TEMPLATE"
28: #else /* defined(_I18N_) || defined(__JIS__) */
29: # define META_TEMPLATE_NAME "AMAYA_TEMPLATE"
30: #endif /* defined(_I18N_) || defined(__JIS__) */
1.1 cvs 31: /* URL of the script providing templates (for reload) */
32: static STRING script_URL;
33:
1.3 cvs 34: #include "init_f.h"
35:
36:
1.1 cvs 37: /*----------------------------------------------------------------------
38: NewTemplate: Opens a template form on the remote template server
39: ----------------------------------------------------------------------*/
40: #ifdef __STDC__
41: void NewTemplate (Document doc, View view)
42: #else /* __STDC__ */
43: void NewTemplate (doc, view)
44: Document doc;
45: View view;
46: #endif /* __STDC__ */
47:
48: {
49: STRING URLform;
1.6 cvs 50: // Document templateSelect;
1.1 cvs 51:
1.8 cvs 52: URLform = TtaGetEnvString ("TEMPLATE_URL");
1.1 cvs 53: if (URLform != NULL)
54: {
1.5 cvs 55: /* templateSelect = GetHTMLDocument (URLform, NULL, 0, 0, CE_ABSOLUTE, FALSE, NULL, NULL);*/
56: doc = GetHTMLDocument (URLform, NULL, 0, 0, CE_ABSOLUTE, FALSE, NULL, NULL);
57: /* SetBrowserEditor(doc); */
1.1 cvs 58: }
59: }
60: /*----------------------------------------------------------------------
61: OpenTemplateDocument: Process the meta of a template document,
62: changes the URL, try to save it and warn the user if it cannot be
63: saved.
64: ----------------------------------------------------------------------*/
65: #ifdef __STDC__
66: void OpenTemplateDocument (Document doc)
67: #else /* __STDC__ */
68: void OpenTemplateDocument (doc)
69: Document doc;
70: #endif /* __STDC__ */
71:
72: {
73: ElementType metaElType;
74: Element metaEl;
75: Attribute metaAttr;
76: AttributeType metaAttrType;
77: ThotBool found = FALSE;
78: ThotBool ok = FALSE;
79: int length;
80: CHAR_T buffer[MAX_LENGTH];
81: CHAR_T *URLdir;
82: CHAR_T *URLname;
83:
84: metaElType.ElSSchema = TtaGetDocumentSSchema (doc);
85: metaElType.ElTypeNum = HTML_EL_META;
86: metaAttrType.AttrSSchema = TtaGetDocumentSSchema (doc);
87: metaAttrType.AttrTypeNum = HTML_ATTR_meta_name;
88: /* search the meta element */
89: metaEl = TtaGetMainRoot (doc);
90: do
91: {
92: metaEl = TtaSearchTypedElement (metaElType, SearchForward, metaEl);
93: if (metaEl != NULL)
94: {
95: metaAttr = TtaGetAttribute (metaEl, metaAttrType);
96: if (metaAttr != NULL)
97: {
98: length = MAX_LENGTH - 1;
99: TtaGiveTextAttributeValue (metaAttr, buffer, &length);
100: found = !ustrcmp (buffer, META_TEMPLATE_NAME);
101: }
102: }
103: }
104: while (metaEl != NULL && !found);
105: if (found)
106: {
107: /* get the url of the document */
108: metaAttrType.AttrTypeNum = HTML_ATTR_meta_content;
109: metaAttr = TtaGetAttribute (metaEl, metaAttrType);
110: if (metaAttr != NULL)
111: {
112: length = MAX_LENGTH - 1;
113: TtaGiveTextAttributeValue (metaAttr, buffer, &length);
114: }
115: /* Delete the meta element */
116: TtaDeleteTree (metaEl, doc);
117: /* try to save to the new url */
118: #ifdef WITH_PRELABLE_SAVE_POUR_VOIR
119: ok = SaveDocumentThroughNet (doc, 1, buffer, FALSE, TRUE, TRUE);
120: #else
121: ok = TRUE;
122: #endif
123: if (ok)
124: {
125: if (script_URL == NULL)
126: script_URL = TtaStrdup (DocumentURLs[doc]);
127: TtaFreeMemory (DocumentURLs[doc]);
128: DocumentURLs[doc] = TtaStrdup (buffer);
129: DocumentMeta[doc]->method = CE_TEMPLATE;
130: TtaSetTextZone (doc, 1, 1, DocumentURLs[doc]);
131: TtaSetDocumentUnmodified (doc);
132:
133: }
134: else
135: {
136: /* save failed : print warning message */
137:
138: }
139:
140: /* set the document name and dir */
141:
142: URLname = ustrrchr (buffer, URL_SEP);
1.5 cvs 143: if (URLname)
144: {
145: URLname[0] = EOS;
146: URLname++;
147: URLdir = buffer;
148: TtaSetDocumentDirectory (doc, URLdir);
1.9 ! cvs 149: TtaSetDocumentName (doc, URLname);
1.5 cvs 150: /* SetBrowserEditor(doc); */
151: }
152: else
153: {
154: TtaSetDocumentDirectory (doc, "");
155: TtaSetDocumentName (doc, buffer);
156: }
1.9 ! cvs 157: SetWindowTitle (doc, doc, 0);
1.1 cvs 158: }
1.5 cvs 159:
1.1 cvs 160: }
161:
162: /*----------------------------------------------------------------------
163: ReloadTemplateParams : restores the script URL and method into meta
164: to reload a template
165: ----------------------------------------------------------------------*/
166: #ifdef __STDC__
1.5 cvs 167: void ReloadTemplateParams (STRING *docURL, ClickEvent *method)
1.1 cvs 168: #else /* __STDC__ */
169: void ReloadTemplateParams (docURL, method)
1.5 cvs 170: STRING *docURL;
1.1 cvs 171: ClickEvent *method;
172: #endif /* __STDC__ */
173: {
174: *method = CE_FORM_GET;
1.5 cvs 175: TtaFreeMemory (*docURL);
176: *docURL = TtaStrdup (script_URL);
1.1 cvs 177: }
Webmaster