Annotation of Amaya/amaya/templates.c, revision 1.12

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) */
1.11      cvs        32: static CHAR_T* script_URL;
1.1       cvs        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: {
1.10      cvs        49:   STRING    url;
1.1       cvs        50: 
1.10      cvs        51:   url = TtaGetEnvString ("TEMPLATE_URL");
                     52:   if (url)
                     53:     GetHTMLDocument (url, NULL, 0, 0, CE_ABSOLUTE, FALSE, NULL, NULL);
1.1       cvs        54: }
                     55: /*----------------------------------------------------------------------
                     56:    OpenTemplateDocument: Process the meta of a template document,
                     57:      changes the URL, try to save it and warn the user if it cannot be
                     58:      saved.
                     59:   ----------------------------------------------------------------------*/
                     60: #ifdef __STDC__
                     61: void               OpenTemplateDocument (Document doc)
                     62: #else  /* __STDC__ */
                     63: void               OpenTemplateDocument (doc)
                     64: Document doc;
                     65: #endif /* __STDC__ */
                     66: 
                     67: {
                     68:   ElementType         metaElType;
                     69:   Element             metaEl;
                     70:   Attribute           metaAttr;
                     71:   AttributeType       metaAttrType;
                     72:   ThotBool            found = FALSE;
                     73:   ThotBool            ok = FALSE;
                     74:   int                 length;
                     75:   CHAR_T              buffer[MAX_LENGTH];
                     76:   CHAR_T             *URLdir;
                     77:   CHAR_T             *URLname;
                     78: 
                     79:   metaElType.ElSSchema = TtaGetDocumentSSchema (doc);
                     80:   metaElType.ElTypeNum = HTML_EL_META;
                     81:   metaAttrType.AttrSSchema = TtaGetDocumentSSchema (doc);
                     82:   metaAttrType.AttrTypeNum = HTML_ATTR_meta_name;
                     83:   /* search the meta element */
                     84:   metaEl = TtaGetMainRoot (doc);
                     85:   do
                     86:     {
                     87:       metaEl = TtaSearchTypedElement (metaElType, SearchForward, metaEl);
                     88:       if (metaEl != NULL)
                     89:         {
                     90:           metaAttr = TtaGetAttribute (metaEl, metaAttrType); 
                     91:           if (metaAttr != NULL)
                     92:             {
                     93:               length = MAX_LENGTH - 1;
                     94:              TtaGiveTextAttributeValue (metaAttr, buffer, &length);
                     95:               found = !ustrcmp (buffer, META_TEMPLATE_NAME);
                     96:             }
                     97:         }
                     98:     }
                     99:   while (metaEl != NULL && !found);
                    100:   if (found)
                    101:     {
                    102:       /* get the url of the document */
                    103:       metaAttrType.AttrTypeNum = HTML_ATTR_meta_content; 
                    104:       metaAttr = TtaGetAttribute (metaEl, metaAttrType);
                    105:       if (metaAttr != NULL)
                    106:        {
                    107:          length = MAX_LENGTH - 1;
                    108:          TtaGiveTextAttributeValue (metaAttr, buffer, &length);
                    109:        }
                    110:       /* Delete the meta element */
                    111:       TtaDeleteTree (metaEl, doc);  
                    112:       /* try to save to the new url */
                    113: #ifdef WITH_PRELABLE_SAVE_POUR_VOIR      
                    114:       ok = SaveDocumentThroughNet (doc, 1, buffer, FALSE, TRUE, TRUE);
                    115: #else
                    116:       ok = TRUE;
                    117: #endif
                    118:       if (ok)
                    119:         {
                    120:           if (script_URL == NULL)
1.11      cvs       121:             script_URL = TtaWCSdup (DocumentURLs[doc]);
1.1       cvs       122:          TtaFreeMemory (DocumentURLs[doc]);
1.11      cvs       123:          DocumentURLs[doc] = TtaWCSdup (buffer);
1.1       cvs       124:           DocumentMeta[doc]->method = CE_TEMPLATE;
                    125:          TtaSetTextZone (doc, 1, 1, DocumentURLs[doc]);
                    126:          TtaSetDocumentUnmodified (doc);
                    127:           
                    128:        }
                    129:       else 
                    130:        {
                    131:          /* save failed : print warning message */
                    132:          
                    133:        }
                    134:        
                    135:       /* set the document name and dir */
                    136:       
                    137:       URLname = ustrrchr (buffer, URL_SEP);
1.5       cvs       138:       if (URLname)
                    139:        {
                    140:          URLname[0] = EOS;
                    141:          URLname++;
                    142:          URLdir = buffer;
                    143:          TtaSetDocumentDirectory (doc, URLdir);
1.9       cvs       144:          TtaSetDocumentName (doc, URLname);
1.5       cvs       145:          /* SetBrowserEditor(doc); */ 
                    146:        }
                    147:       else
                    148:        {
1.11      cvs       149:          TtaSetDocumentDirectory (doc, TEXT(""));
1.5       cvs       150:          TtaSetDocumentName (doc, buffer);
                    151:        }
1.9       cvs       152:       SetWindowTitle (doc, doc, 0);
1.1       cvs       153:     }
1.5       cvs       154:     
1.1       cvs       155: }
                    156:   
                    157: /*----------------------------------------------------------------------
                    158:   ReloadTemplateParams : restores the script URL and method into meta
                    159:   to reload a template
                    160:   ----------------------------------------------------------------------*/
                    161: #ifdef __STDC__    
1.11      cvs       162: void ReloadTemplateParams (CHAR_T* docURL, ClickEvent *method)
1.1       cvs       163: #else /* __STDC__ */
                    164: void ReloadTemplateParams (docURL, method)
1.11      cvs       165: CHAR_T* docURL;
1.1       cvs       166: ClickEvent *method;
                    167: #endif /* __STDC__ */
                    168: {
                    169:    *method = CE_FORM_GET;
1.5       cvs       170:    TtaFreeMemory (*docURL);
1.12    ! cvs       171:    *docURL = TtaWCSdup (script_URL); 
1.1       cvs       172: }

Webmaster