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

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

Webmaster