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

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

Webmaster