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

1.1       cvs         1: /*
                      2:  *
1.24      vatton      3:  *  COPYRIGHT INRIA and W3C, 1996-2004
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.3       cvs        28: #include "init_f.h"
                     29: 
                     30: 
1.1       cvs        31: /*----------------------------------------------------------------------
                     32:    NewTemplate: Opens a template form on the remote template server
                     33:   ----------------------------------------------------------------------*/
1.18      cvs        34: void NewTemplate (Document doc, View view)
1.1       cvs        35: {
1.25    ! vatton     36:   char       *url;
1.1       cvs        37: 
1.10      cvs        38:   url = TtaGetEnvString ("TEMPLATE_URL");
1.25    ! vatton     39:   if (url && TtaCheckDirectory (url))
        !            40:     {
        !            41:       /*TtaNewScrollPopup (BaseDialog + xxx, TtaGetViewFrame (doc, 1),
        !            42:                         NULL, nbitems, FormBuf, NULL, multipleOptions, 'L');
        !            43:       InitOpenDocForm (doc, view, "New.html",
        !            44:       "xxx", docHTML);*/
        !            45:       /*GetAmayaDoc (url, NULL, 0, 0, CE_ABSOLUTE, FALSE, NULL, NULL);*/
        !            46:     }
1.1       cvs        47: }
1.25    ! vatton     48: 
1.1       cvs        49: /*----------------------------------------------------------------------
                     50:    OpenTemplateDocument: Process the meta of a template document,
                     51:      changes the URL, try to save it and warn the user if it cannot be
                     52:      saved.
                     53:   ----------------------------------------------------------------------*/
1.18      cvs        54: void OpenTemplateDocument (Document doc)
1.1       cvs        55: {
                     56:   ElementType         metaElType;
                     57:   Element             metaEl;
                     58:   Attribute           metaAttr;
                     59:   AttributeType       metaAttrType;
                     60:   ThotBool            found = FALSE;
                     61:   int                 length;
1.24      vatton     62:   char               *utf8path, *path;
                     63:   char               *URLdir, *URLname;
1.1       cvs        64: 
                     65:   metaElType.ElSSchema = TtaGetDocumentSSchema (doc);
                     66:   metaElType.ElTypeNum = HTML_EL_META;
                     67:   metaAttrType.AttrSSchema = TtaGetDocumentSSchema (doc);
                     68:   metaAttrType.AttrTypeNum = HTML_ATTR_meta_name;
                     69:   /* search the meta element */
                     70:   metaEl = TtaGetMainRoot (doc);
1.24      vatton     71:   path = NULL;
1.1       cvs        72:   do
                     73:     {
                     74:       metaEl = TtaSearchTypedElement (metaElType, SearchForward, metaEl);
                     75:       if (metaEl != NULL)
                     76:         {
                     77:           metaAttr = TtaGetAttribute (metaEl, metaAttrType); 
                     78:           if (metaAttr != NULL)
                     79:             {
1.24      vatton     80:              length = TtaGetTextAttributeLength (metaAttr) + 1;
                     81:              utf8path = (char *) TtaGetMemory (length);
                     82:              TtaGiveTextAttributeValue (metaAttr, utf8path, &length);
                     83:              path = (char *)TtaConvertMbsToByte ((unsigned char *)utf8path,
                     84:                                                  TtaGetDefaultCharset ());
                     85:              TtaFreeMemory (utf8path);
                     86:               found = !strcmp (path, META_TEMPLATE_NAME);
1.1       cvs        87:             }
                     88:         }
                     89:     }
1.24      vatton     90:   while (metaEl && !found);
                     91: 
1.1       cvs        92:   if (found)
                     93:     {
                     94:       /* get the url of the document */
                     95:       metaAttrType.AttrTypeNum = HTML_ATTR_meta_content; 
                     96:       metaAttr = TtaGetAttribute (metaEl, metaAttrType);
                     97:       if (metaAttr != NULL)
                     98:        {
1.24      vatton     99:          length = TtaGetTextAttributeLength (metaAttr) + 1;
                    100:          utf8path = (char *) TtaGetMemory (length);
                    101:          TtaGiveTextAttributeValue (metaAttr, utf8path, &length);
                    102:          path = (char *)TtaConvertMbsToByte ((unsigned char *)utf8path,
                    103:                                              TtaGetDefaultCharset ());
                    104:          TtaFreeMemory (utf8path);
1.1       cvs       105:        }
1.24      vatton    106: 
1.1       cvs       107:       /* Delete the meta element */
                    108:       TtaDeleteTree (metaEl, doc);  
1.24      vatton    109:       if (script_URL == NULL)
                    110:        script_URL = TtaStrdup (DocumentURLs[doc]);
                    111:       TtaFreeMemory (DocumentURLs[doc]);
                    112:       DocumentURLs[doc] = TtaStrdup (path);
                    113:       DocumentMeta[doc]->method = CE_TEMPLATE;
                    114:       AddURLInCombobox (DocumentURLs[doc], NULL, TRUE);
                    115:       TtaSetTextZone (doc, 1, URL_list);
                    116:       TtaSetDocumentUnmodified (doc);
                    117:       
1.1       cvs       118:       /* set the document name and dir */
1.24      vatton    119:       URLname = strrchr (path, URL_SEP);
1.5       cvs       120:       if (URLname)
                    121:        {
                    122:          URLname[0] = EOS;
                    123:          URLname++;
1.24      vatton    124:          URLdir = path;
1.5       cvs       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.24      vatton    132:          TtaSetDocumentName (doc, path);
1.5       cvs       133:        }
1.9       cvs       134:       SetWindowTitle (doc, doc, 0);
1.1       cvs       135:     }
1.24      vatton    136:   TtaFreeMemory (path);
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