/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
A data source that reads the 4.x "bookmarks.html" file and
constructs an in-memory data source.
TO DO
1) Write the modified bookmarks file back to disk.
*/
#include "nsIRDFDataSource.h"
#include "nsIRDFNode.h"
#include "nsIRDFService.h"
#include "nsIServiceManager.h"
#include "nsRDFCID.h"
#include "nsString.h"
#include "nsVoidArray.h"
#include "prio.h"
#include "rdf.h"
#include "rdfutil.h"
////////////////////////////////////////////////////////////////////////
static NS_DEFINE_IID(kIRDFDataSourceIID, NS_IRDFDATASOURCE_IID);
static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static const char kURINC_BookmarksRoot[] = "NC:BookmarksRoot"; // XXX?
#define NC_NAMESPACE_URI "http://home.netscape.com/NC-rdf#"
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, child);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, BookmarkAddDate);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Description);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Folder);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Name);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, PersonalToolbarFolderCategory);
#define WEB_NAMESPACE_URI "http://home.netscape.com/WEB-rdf#"
DEFINE_RDF_VOCAB(WEB_NAMESPACE_URI, WEB, LastVisitDate);
DEFINE_RDF_VOCAB(WEB_NAMESPACE_URI, WEB, LastModifiedDate);
#define RDF_NAMESPACE_URI "http://www.w3.org/TR/WD-rdf-syntax#"
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, instanceOf);
static const char kPersonalToolbar[] = "Personal Toolbar";
////////////////////////////////////////////////////////////////////////
/**
* The bookmark parser knows how to read bookmarks.html and convert it
* into an RDF graph.
*/
class BookmarkParser {
protected:
static const char* kBRString;
static const char* kCloseDLString;
static const char* kDDString;
static const char* kOpenAnchorString;
static const char* kOpenDLString;
static const char* kOpenH3String;
static const char* kOpenTitleString;
static const char* kSeparatorString;
enum BookmarkParserState {
eBookmarkParserState_Initial,
eBookmarkParserState_InTitle,
eBookmarkParserState_InH3,
eBookmarkParserState_InItemTitle,
eBookmarkParserState_InItemDescription
};
nsIRDFService* mRDFService;
nsIRDFDataSource* mDataSource;
nsVoidArray mStack;
nsIRDFResource* mLastItem;
nsAutoString mLine;
PRInt32 mCounter;
nsAutoString mFolderDate;
BookmarkParserState mState;
void Tokenize(const char* buf, PRInt32 size);
void NextToken(void);
void DoStateTransition(void);
void CreateBookmark(void);
nsresult AssertTime(nsIRDFResource* subject,
const nsString& predicateURI,
const nsString& time);
public:
BookmarkParser(void);
~BookmarkParser();
nsresult Parse(PRFileDesc* file, nsIRDFDataSource* dataSource);
};
const char* BookmarkParser::kBRString = "
";
const char* BookmarkParser::kCloseDLString = "";
const char* BookmarkParser::kDDString = "
\n", (name) ? name:"");
}
while ((next = RDF_NextValue(c)) != nsnull) {
url = resourceID(next);
if (containerp(next) && (!startsWith("ftp:",url)) && (!startsWith("file:",url))
&& (!startsWith("IMAP:", url)) && (!startsWith("nes:", url))
&& (!startsWith("mail:", url)) && (!startsWith("cache:", url))
&& (!startsWith("ldap:", url))) {
for (loop=0; loop \n", nsnull);
HT_WriteOutAsBookmarks1(rdf, fp, next, top, indent+1);
for (loop=0; loop \n", nsnull);
}
else if (isSeparator(next)) {
for (loop=0; loop", (date) ? date:"");
if (date) freeMem(date);
name = RDF_GetResourceName(rdf, next);
ht_rjcprintf(fp, "%s
\n", name);
for (loop=0; loop