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

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

Webmaster