home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / modules / rdf / src / columns.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  5.9 KB  |  239 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. /* 
  20.    This file synthesizes default columns for a given node.
  21.    For more information on this file, contact rjc or guha 
  22.    For more information on RDF, look at the RDF section of www.mozilla.org
  23. */
  24.  
  25. #include "columns.h"
  26.  
  27.  
  28.  
  29. RDF_Cursor
  30. ColumnsGetSlotValues (RDFT rdf, RDF_Resource u, RDF_Resource s,
  31.         RDF_ValueType type,  PRBool inversep, PRBool tv)
  32. {
  33.     RDF_Cursor        c;
  34.  
  35.     if (!containerp(u) || (s != gNavCenter->RDF_Column) || (inversep) ||
  36.         (!tv) || (type != RDF_RESOURCE_TYPE)) 
  37.     {
  38.         return(NULL);
  39.     }
  40.     if ((c = (RDF_Cursor)getMem(sizeof(struct RDF_CursorStruct))) != NULL)
  41.     {
  42.         c->u = u;
  43.         c->value = NULL;
  44.         c->count = 0;
  45.     }
  46.     return(c);
  47. }
  48.  
  49.  
  50.  
  51. void *
  52. ColumnsGetSlotValue(RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type,
  53.         PRBool inversep, PRBool tv)
  54. {
  55.     void            *val = NULL;
  56.  
  57.     if (u == NULL)    return(NULL);
  58.  
  59.     if ((s == gCoreVocab->RDF_name) && (type == RDF_STRING_TYPE)
  60.         && (!inversep) && (tv))
  61.     {
  62.         /* XXX localization */
  63.         if (u == gCoreVocab->RDF_name)            val = copyString("Name");
  64.         else if (u == gWebData->RDF_URL)        val = copyString("URL");
  65.         else if (u == gWebData->RDF_description)    val = copyString("Description");
  66.         else if (u == gWebData->RDF_firstVisitDate)    val = copyString("First Visit");
  67.         else if (u == gWebData->RDF_lastVisitDate)    val = copyString("Last Visit");
  68.         else if (u == gWebData->RDF_numAccesses)    val = copyString("Accesses");
  69.         else if (u == gWebData->RDF_creationDate)    val = copyString("Created");
  70.         else if (u == gWebData->RDF_lastModifiedDate)    val = copyString("Modified");
  71.         else if (u == gWebData->RDF_size)        val = copyString("Size");
  72.         else if (u == gNavCenter->RDF_bookmarkAddDate)    val = copyString("Added");
  73.         else val = copyString(resourceID(u));
  74.     }
  75.     else if ((s == gNavCenter->RDF_ColumnDataType) &&
  76.         (type == RDF_INT_TYPE) && (!inversep) && (tv))
  77.     {
  78.         if (u == gNavCenter->RDF_bookmarkAddDate ||
  79.             u == gWebData->RDF_lastVisitDate ||
  80.             u == gWebData->RDF_lastModifiedDate)
  81.         {
  82.             val = (void *)HT_COLUMN_DATE_STRING;
  83.         }
  84.         else if (u == gWebData->RDF_firstVisitDate)
  85.         {
  86.             val = (void *)HT_COLUMN_DATE_INT;
  87.         }
  88.         else if (u == gWebData->RDF_size ||
  89.              u == gWebData->RDF_numAccesses)
  90.         {
  91.             val = (void *)HT_COLUMN_INT;
  92.         }
  93.         else
  94.         {
  95.             /* default to string... XXX wrong thing to do */
  96.             val = (void *)HT_COLUMN_STRING;
  97.         }
  98.     }
  99.     else if ((s == gNavCenter->RDF_ColumnWidth) &&
  100.         (type == RDF_INT_TYPE) && (!inversep) && (tv))
  101.     {
  102.         if (u == gCoreVocab->RDF_name)        val = (void *)128L;
  103.         else if (u == gWebData->RDF_URL)    val = (void *)200L;
  104.         else                    val = (void *)80;
  105.     }
  106.     return(val);
  107. }
  108.  
  109.  
  110.  
  111. void *
  112. ColumnsNextValue (RDFT rdf, RDF_Cursor c)
  113. {
  114.     void            *arc = NULL;
  115.  
  116.     XP_ASSERT(c != NULL);
  117.     if (c == NULL)        return(NULL);
  118.  
  119.     switch( resourceType(c->u) )
  120.     {
  121.         case    RDF_RT:
  122.         if ((c->u == gNavCenter->RDF_Sitemaps) || (c->u == gNavCenter->RDF_Mail))
  123.         {
  124.             switch(c->count)
  125.             {
  126.                 case    0:    arc = gCoreVocab->RDF_name;        break;
  127.                 case    1:    arc = gWebData->RDF_URL;        break;
  128.             }
  129.         }
  130.         else
  131.         {
  132.             switch(c->count)
  133.             {
  134.                 case    0:    arc = gCoreVocab->RDF_name;        break;
  135.                 case    1:    arc = gWebData->RDF_URL;        break;
  136.                 case    2:    arc = gWebData->RDF_description;    break;
  137.                 case    3:    arc = gNavCenter->RDF_bookmarkAddDate;    break;
  138.                 case    4:    arc = gWebData->RDF_lastVisitDate;    break;
  139.                 case    5:    arc = gWebData->RDF_lastModifiedDate;    break;
  140.             }
  141.         }
  142.         break;
  143.  
  144.         case    HISTORY_RT:
  145.         switch(c->count)
  146.         {
  147.             case    0:    arc = gCoreVocab->RDF_name;        break;
  148.             case    1:    arc = gWebData->RDF_URL;        break;
  149.             case    2:    arc = gWebData->RDF_firstVisitDate;    break;
  150.             case    3:    arc = gWebData->RDF_lastVisitDate;    break;
  151.             case    4:    arc = NULL;                break;
  152.             case    5:    arc = gWebData->RDF_numAccesses;    break;
  153.         }
  154.         break;
  155.  
  156.         case    FTP_RT:
  157.         case    ES_RT:
  158.         switch(c->count)
  159.         {
  160.             case    0:    arc = gCoreVocab->RDF_name;        break;
  161.             case    1:    arc = gWebData->RDF_URL;        break;
  162.         }
  163.         break;
  164.  
  165.         case    LFS_RT:
  166.         switch(c->count)
  167.         {
  168.             case    0:    arc = gCoreVocab->RDF_name;        break;
  169.             case    1:    arc = gWebData->RDF_URL;        break;
  170.             case    2:    arc = gWebData->RDF_size;        break;
  171. #ifdef    NSPR20
  172.             case    3:    arc = gWebData->RDF_creationDate;    break;
  173. #endif
  174.             case    4:    arc = gWebData->RDF_lastModifiedDate;    break;
  175.         }
  176.         break;
  177.  
  178.         case    LDAP_RT:
  179.         switch(c->count)
  180.         {
  181.             case    0:    arc = gCoreVocab->RDF_name;        break;
  182.         }
  183.         break;
  184.  
  185.         case    PM_RT:
  186.         case    IM_RT:
  187.         switch(c->count)
  188.         {
  189.             case    0:    arc = gCoreVocab->RDF_name;        break;
  190.             case    1:    arc = gWebData->RDF_URL;        break;
  191.         }
  192.         break;
  193.  
  194.         default:
  195.         switch(c->count)
  196.         {
  197.             case    0:    arc = gCoreVocab->RDF_name;        break;
  198.         }
  199.         break;
  200.     }
  201.     ++(c->count);
  202.     return(arc);
  203. }
  204.  
  205.  
  206.  
  207. RDF_Error
  208. ColumnsDisposeCursor (RDFT rdf, RDF_Cursor c)
  209. {
  210.     if (c != NULL)
  211.     {
  212.         freeMem(c);
  213.     } 
  214.     return(0);
  215. }
  216.  
  217.  
  218.  
  219. RDFT
  220. MakeColumnStore (char* url)
  221. {
  222.     RDFT        ntr = NULL;
  223.  
  224.     if (strstr(url, "rdf:columns"))
  225.     {
  226.         if ((ntr = (RDFT)getMem(sizeof(struct RDF_TranslatorStruct))) != NULL)
  227.         {
  228.             ntr->getSlotValues = ColumnsGetSlotValues;
  229.             ntr->getSlotValue = ColumnsGetSlotValue;
  230.             ntr->nextValue = ColumnsNextValue;
  231.             ntr->disposeCursor = ColumnsDisposeCursor;
  232.             ntr->url = copyString(url);
  233.         }
  234.            
  235.     }
  236.     
  237.     return(ntr);
  238. }
  239.