diff --git a/calendar/modules/parser/ical/Makefile b/calendar/modules/parser/ical/Makefile new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/parser/ical/inc/Makefile b/calendar/modules/parser/ical/inc/Makefile new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/parser/ical/inc/manifest.mn b/calendar/modules/parser/ical/inc/manifest.mn new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/parser/ical/inc/nsCalICalendarContentSink.h b/calendar/modules/parser/ical/inc/nsCalICalendarContentSink.h new file mode 100644 index 00000000000..d8bbd390c24 --- /dev/null +++ b/calendar/modules/parser/ical/inc/nsCalICalendarContentSink.h @@ -0,0 +1,78 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * 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. + */ + +#ifndef NS_CALICALENDARCONTENTSINK +#define NS_CALICALENDARCONTENTSINK + +#include "nsIParserNode.h" +#include "nsIContentSink.h" +#include "nsString.h" +#include "nsxpfcCIID.h" +#include "nsIVector.h" +#include "nsIIterator.h" +#include "nsIStack.h" +#include "nsCalICalendarDTD.h" +#include "nsICalICalendarParserObject.h" +#include "nsICalICalendarContentSink.h" +//#include "nsCalICalendarParserCIID.h" + +class nsCalICalendarContentSink : public nsICalICalendarContentSink, + public nsIContentSink +{ +public: + + NS_DECL_ISUPPORTS + + nsCalICalendarContentSink(); + virtual ~nsCalICalendarContentSink(); + + //nsICalICalendarContentSink + NS_IMETHOD Init(); + NS_IMETHOD SetViewerContainer(nsIWebViewerContainer * aViewerContainer); + + //nsIContentSink + NS_IMETHOD OpenContainer(const nsIParserNode& aNode); + NS_IMETHOD CloseContainer(const nsIParserNode& aNode); + NS_IMETHOD AddLeaf(const nsIParserNode& aNode); + NS_IMETHOD WillBuildModel(void); + NS_IMETHOD DidBuildModel(PRInt32 aQualityLevel); + NS_IMETHOD WillInterrupt(void); + NS_IMETHOD WillResume(void); + +private: + NS_IMETHOD CIDFromTag(eCalICalendarTags tag, nsCID &aClass); + NS_IMETHOD ConsumeAttributes(const nsIParserNode& aNode, nsICalICalendarParserObject& aObject); + NS_IMETHOD AddToHierarchy(nsICalICalendarParserObject& aObject, PRBool aPush); + +public: + NS_IMETHOD_(PRBool) IsContainer(const nsIParserNode& aNode); + + +private: + nsIWebViewerContainer * mViewerContainer ; + nsIStack * mXPFCStack; + nsIVector * mOrphanMenuList; + nsIVector * mContainerList ; + PRUint32 mState; + +}; + + +#endif + + diff --git a/calendar/modules/parser/ical/inc/nsCalICalendarDTD.h b/calendar/modules/parser/ical/inc/nsCalICalendarDTD.h new file mode 100644 index 00000000000..24fd1e282e5 --- /dev/null +++ b/calendar/modules/parser/ical/inc/nsCalICalendarDTD.h @@ -0,0 +1,142 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * 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. + */ + +#ifndef NS_CALICALENDARDTD__ +#define NS_CALICALENDARDTD__ + +#include "nscalexport.h" +#include "CNavDTD.h" +#include "nscalstrings.h" +#include "nsxpfc.h" +#include "nsIDTD.h" +#include "nsISupports.h" +#include "nsIParser.h" +#include "nsCalICalendarTags.h" +#include "nsCalICalendarTokens.h" +#include "nscalicalendarpars.h" +#include "nsVoidArray.h" +#include "nsDeque.h" +//#include "nsCalICalendarParserCIID.h" +//#include "nsCalICalendarStrings.h" // todo: + +class nsIHTMLContentSink; +class nsIDTDDebug; +class nsIParserNode; +class nsCParserNode; +class CITokenHandler; +class nsParser; +class nsDTDContext; +class nsTagStack; +class CScanner; +/* +enum eCalICalendarComponents +{ + eCalICalendarComponents_vcalendar = 0, + eCalICalendarComponents_vevent, + eCalICalendarComponents_vtodo, + eCalICalendarComponents_vjournal, + eCalICalendarComponents_vfreebusy, + eCalICalendarComponents_valarm, + eCalICalendarComponents_vtimezone +}; + +enum eCalICalendarProperties +{ + eCalICalendarProperties_attach = 0, + // todo: finish +}; +*/ + +class nsCalICalendarDTD : public nsIDTD { + +public: + + NS_DECL_ISUPPORTS + + nsCalICalendarDTD(); + virtual ~nsCalICalendarDTD(); + + //nsIDID + virtual PRBool CanParse(nsString& aContentType, PRInt32 aVersion); + virtual eAutoDetectResult AutoDetectContentType(nsString& aBuffer,nsString& aType); + NS_IMETHOD HandleToken(CToken* aToken); + virtual nsresult CreateNewInstance(nsIDTD** aInstancePtrResult); + + nsresult HandleBeginToken(CToken* aToken); + nsresult HandleEndToken(CToken* aToken); + nsresult HandleAttributeToken(CToken* aToken); + nsresult HandlePropertyValueToken(CToken* aToken); + + + //more nsIDID + virtual void SetParser(nsIParser* aParser); + virtual nsIContentSink* SetContentSink(nsIContentSink* aSink); + NS_IMETHOD WillBuildModel(nsString& aFilename,PRBool aNotifySink); + NS_IMETHOD DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink); + NS_IMETHOD ConsumeToken(CToken*& aToken); + NS_IMETHOD WillResumeParse(void); + NS_IMETHOD WillInterruptParse(void); + virtual PRBool CanContain(PRInt32 aParent,PRInt32 aChild) const; + virtual PRBool IsContainer(PRInt32 aTag) const; + virtual PRBool Verify(nsString& aURLRef); + virtual nsITokenRecycler* GetTokenRecycler(void); + + /*nsresult ConsumeBeginTag(PRUnichar aChar,CScanner& aScanner,CToken*& aToken); + nsresult ConsumeEndTag(PRUnichar aChar,CScanner& aScanner,CToken*& aToken); + */ + nsresult ConsumeNewline(PRUnichar aChar,CScanner& aScanner,CToken*& aToken); + nsresult ConsumeWhitespace(PRUnichar aChar,CScanner& aScanner,CToken*& aToken); + nsresult ConsumePropertyLine(PRUnichar aChar,CScanner& aScanner,CToken*& aToken); + nsresult ConsumePropertyNameAndAttributes(PRUnichar aChar,CScanner& aScanner,CToken*& aToken); + nsresult ConsumePropertyValue(PRUnichar aChar,CScanner& aScanner,CToken*& aToken); + + nsresult ConsumeAttributes(PRUnichar aChar, CScanner& aScanner, + CCalICalendarBeginToken* aToken); +private: + //NS_IMETHOD_(eCalICalendarTags) ComponentTypeFromObject(const nsIParserNode& aNode); + +protected: + PRInt32 CollectPropertyValue(nsCParserNode& aNode, PRInt32 aCount); + PRInt32 CollectAttributes(nsCParserNode& aNode, PRInt32 aCount); + + nsParser* mParser; + nsIContentSink* mSink; + //CITokenHandler* mTokenHandlers[eToken_last]; + //nsDTDContext* mContext; + nsDeque mTokenDeque; + nsString mFilename; + nsIDTDDebug* mDTDDebug; + PRInt32 mLineNumber; + eParseMode mParseMode; +}; + +extern NS_CALICALENDARPARS nsresult NS_NewICAL_DTD(nsIDTD** aInstancePtrResult); + +#endif + + + + + + + + + + + + diff --git a/calendar/modules/parser/ical/inc/nsCalICalendarParserCIID.h b/calendar/modules/parser/ical/inc/nsCalICalendarParserCIID.h new file mode 100644 index 00000000000..8abf3870c17 --- /dev/null +++ b/calendar/modules/parser/ical/inc/nsCalICalendarParserCIID.h @@ -0,0 +1,49 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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. + */ + +#ifndef nsCalParserCIID_h__ +#define nsCalParserCIID_h__ + +#include "nsISupports.h" +#include "nsIFactory.h" +#include "nsRepository.h" + +// 4d17a720-5a4d-11d2-9432-006008268c31 +/* +#define NS_ICALICALENDAR_DTD_IID \ +{ 0x4d17a720, 0x5a4d, 0x11d2, \ + {0x94, 0x32, 0x00, 0x60, 0x08, 0x26, 0x8c, 0x31} } + +// 7b944f60-5a4d-11d2-9432-006008268c31 +#define NS_CALICALENDARCONTENTSINK_IID \ +{ 0x7b944f60, 0x5a4d, 0x11d2, \ + {0x94, 0x32, 0x00, 0x60, 0x08, 0x26, 0x8c, 0x31} } +*/ +//6758a720-6522-11d2-943c-006008268c31 +#define NS_CALICALENDARPARSER_NODE_IID \ +{ 0x6758a720, 0x6522, 0x11d2 \ + {0x94, 0x3c, 0x00, 0x60, 0x08, 0x26, 0x8c, 0x31} } +#endif + + + + + + + + diff --git a/calendar/modules/parser/ical/inc/nsCalICalendarParserNode.h b/calendar/modules/parser/ical/inc/nsCalICalendarParserNode.h new file mode 100644 index 00000000000..77f562996fe --- /dev/null +++ b/calendar/modules/parser/ical/inc/nsCalICalendarParserNode.h @@ -0,0 +1,165 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * 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. + */ + +#ifndef NS_CALICALENDARPARSERNODE__ +#define NS_CALICALENDARPARSERNODE__ + +#include "nsIParserNode.h" +#include "nsCalICalendarTokens.h" +#include "nsString.h" +#include "nsParserCIID.h" +#include "nsCalParserCIID.h" + + +class nsCalICalendarCParserNode : public nsIParserNode { + enum {eMaxAttr=20}; + + public: + + NS_DECL_ISUPPORTS + + /** + * Default constructor + * @update gess5/11/98 + * @param aToken is the token this node "refers" to + */ + nsCalICalendarCParserNode(CCalICalendarToken* aToken=nsnull,PRInt32 aLineNumber=1); + + /** + * Destructor + * @update gess5/11/98 + */ + virtual ~nsCalICalendarCParserNode(); + + /** + * Init + * @update gess5/11/98 + */ + virtual nsresult Init(CCalICalendarToken* aToken=nsnull,PRInt32 aLineNumber=1); + + /** + * Retrieve the name of the node + * @update gess5/11/98 + * @return string containing node name + */ + virtual const nsString& GetName() const; + + /** + * Retrieve the text from the given node + * @update gess5/11/98 + * @return string containing node text + */ + virtual const nsString& GetText() const; + + /** + * Retrieve skipped context from node + * @update gess5/11/98 + * @return string containing skipped content + */ + virtual const nsString& GetSkippedContent() const; + + /** + * Retrieve the type of the parser node. + * @update gess5/11/98 + * @return node type. + */ + virtual PRInt32 GetNodeType() const; + + /** + * Retrieve token type of parser node + * @update gess5/11/98 + * @return token type + */ + virtual PRInt32 GetTokenType() const; + + //*************************************** + //methods for accessing key/value pairs + //*************************************** + + /** + * Retrieve the number of attributes in this node. + * @update gess5/11/98 + * @return count of attributes (may be 0) + */ + virtual PRInt32 GetAttributeCount(PRBool askToken=PR_FALSE) const; + + /** + * Retrieve the key (of key/value pair) at given index + * @update gess5/11/98 + * @param anIndex is the index of the key you want + * @return string containing key. + */ + virtual const nsString& GetKeyAt(PRInt32 anIndex) const; + + /** + * Retrieve the value (of key/value pair) at given index + * @update gess5/11/98 + * @param anIndex is the index of the value you want + * @return string containing value. + */ + virtual const nsString& GetValueAt(PRInt32 anIndex) const; + + /** + * NOTE: When the node is an entity, this will translate the entity + * to it's unicode value, and store it in aString. + * @update gess5/11/98 + * @param aString will contain the resulting unicode string value + * @return int (unicode char or unicode index from table) + */ + + virtual PRInt32 TranslateToUnicodeStr(nsString& aString) const; + + /** + * + * @update gess5/11/98 + * @param + * @return + */ + virtual void AddAttribute(CCalICalendarToken* aToken); + + /** + * + * @update gess5/11/98 + * @param + * @return + */ + virtual void SetSkippedContent(CCalICalendarToken* aToken); + + /** + * This getter retrieves the line number from the input source where + * the token occured. Lines are interpreted as occuring between \n characters. + * @update gess7/24/98 + * @return int containing the line number the token was found on + */ + virtual PRInt32 GetSourceLineNumber(void) const; + + protected: + PRInt32 mAttributeCount; + PRInt32 mLineNumber; + CCalICalendarToken* mToken; + CCalICalendarToken* mAttributes[eMaxAttr]; // XXX Ack! This needs to be dynamic! + CCalICalendarToken* mSkippedContent; + // nsAutoString mName; + + static const nsAutoString mEmptyString; + +}; + +#endif + + diff --git a/calendar/modules/parser/ical/inc/nsCalICalendarTags.h b/calendar/modules/parser/ical/inc/nsCalICalendarTags.h new file mode 100644 index 00000000000..d9e48260086 --- /dev/null +++ b/calendar/modules/parser/ical/inc/nsCalICalendarTags.h @@ -0,0 +1,69 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are Copyright (C) 1998 + * Netscape Communications Corporation. All Rights Reserved. + */ + +/* Do not edit - generated by gentags.pl */ +#ifndef nsCalICalendarTags_h___ +#define nsCalICalendarTags_h___ +#include "nscalicalendarpars.h" +enum nsCalICalendarTag { + /* this enum must be first and must be zero */ + eCalICalendarTag_unknown=0, + + /* begin tag enums */ + eCalICalendarTag_action=1, eCalICalendarTag_attach=2, + eCalICalendarTag_attendee=3, eCalICalendarTag_begin=4, + eCalICalendarTag_calscale=5, eCalICalendarTag_categories=6, + eCalICalendarTag_class=7, eCalICalendarTag_comment=8, + eCalICalendarTag_completed=9, eCalICalendarTag_contact=10, + eCalICalendarTag_created=11, eCalICalendarTag_daylight=12, + eCalICalendarTag_description=13, eCalICalendarTag_dtend=14, + eCalICalendarTag_dtstart=15, eCalICalendarTag_due=16, + eCalICalendarTag_duration=17, eCalICalendarTag_end=18, + eCalICalendarTag_exdate=19, eCalICalendarTag_exrule=20, + eCalICalendarTag_freebusy=21, eCalICalendarTag_geo=22, + eCalICalendarTag_last_modified=23, eCalICalendarTag_location=24, + eCalICalendarTag_method=25, eCalICalendarTag_organizer=26, + eCalICalendarTag_percent_complete=27, eCalICalendarTag_priority=28, + eCalICalendarTag_prodid=29, eCalICalendarTag_rdate=30, + eCalICalendarTag_recurrence_id=31, eCalICalendarTag_related_to=32, + eCalICalendarTag_repeat=33, eCalICalendarTag_request_status=34, + eCalICalendarTag_resources=35, eCalICalendarTag_rrule=36, + eCalICalendarTag_sequence=37, eCalICalendarTag_standard=38, + eCalICalendarTag_status=39, eCalICalendarTag_summary=40, + eCalICalendarTag_transp=41, eCalICalendarTag_trigger=42, + eCalICalendarTag_tzid=43, eCalICalendarTag_tzname=44, + eCalICalendarTag_tzoffsetfrom=45, eCalICalendarTag_tzoffsetto=46, + eCalICalendarTag_tzurl=47, eCalICalendarTag_uid=48, + eCalICalendarTag_url=49, eCalICalendarTag_valarm=50, + eCalICalendarTag_vcalendar=51, eCalICalendarTag_version=52, + eCalICalendarTag_vevent=53, eCalICalendarTag_vfreebusy=54, + eCalICalendarTag_vjournal=55, eCalICalendarTag_vtimezone=56, + eCalICalendarTag_vtodo=57, + + /* The remaining enums are not for tags */ + eCalICalendarTag_text=58, eCalICalendarTag_whitespace=59, + eCalICalendarTag_newline=60, eCalICalendarTag_entity=61, + eCalICalendarTag_userdefined=62 +}; +#define NS_CALICALENDAR_TAG_MAX 57 + +extern NS_CALICALENDARPARS nsCalICalendarTag NS_CalICalendarTagToEnum(const char* aTag); +extern NS_CALICALENDARPARS const char* NS_CalICalendarEnumToTag(nsCalICalendarTag aEnum); + +#endif /* nsCalICalendarTags_h___ */ diff --git a/calendar/modules/parser/ical/inc/nsCalICalendarTokens.h b/calendar/modules/parser/ical/inc/nsCalICalendarTokens.h new file mode 100644 index 00000000000..92ed306a631 --- /dev/null +++ b/calendar/modules/parser/ical/inc/nsCalICalendarTokens.h @@ -0,0 +1,174 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * 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. + */ + +#ifndef CALICALENDARTOKENS_H_ +#define CALICALENDARTOKENS_H_ + +#include "nsToken.h" +#include "nsCalICalendarTags.h" +#include + +const PRUint32 kSemiColon = ';'; +const PRUint32 kColon = ':'; +const PRUint32 kNewline = '\n'; +const PRUint32 kCarriageReturn = '\r'; +class CScanner; +class CToken; + +enum eCalICalendarTokenTypes { + eCalICalendarToken_unknown = 0, + eCalICalendarToken_begin=1, + eCalICalendarToken_end, + eCalICalendarToken_whitespace, + eCalICalendarToken_newline, + eCalICalendarToken_text, + eCalICalendarToken_attribute, + eCalICalendarToken_propertyvalue, + eCalICalendarToken_propertyname, + eCalICalendarToken_identifier, + eCalICalendarToken_last // make sure this stays the last token... +}; + +#define eCalICalendarTags nsCalICalendarTag + +PRInt32 CalICalendarConsumeQuotedString(PRUnichar aChar,nsString& aString,CScanner& aScanner); +PRInt32 CalICalendarConsumeAttributeText(PRUnichar aChar,nsString& aString,CScanner& aScanner); +const char * CalICalendarGetTagName(PRInt32 aTag); + +class CCalICalendarToken: public CToken { +public: + + CCalICalendarToken(eCalICalendarTags aTag); + CCalICalendarToken(const nsString& aString,eCalICalendarTags aTag=eCalICalendarTag_unknown); + virtual void SetStringValue(const char* name); + +protected: +}; + +class CCalICalendarIdentifierToken: public CCalICalendarToken { +public: + CCalICalendarIdentifierToken(eCalICalendarTags aTag); + CCalICalendarIdentifierToken(const nsString& aString,eCalICalendarTags aTag=eCalICalendarTag_unknown); + + virtual nsresult Consume(PRUnichar aChar,CScanner& aScanner); + virtual PRInt32 GetTypeID(void); + virtual const char* GetClassName(void); + virtual PRInt32 GetTokenType(void); + virtual void DebugDumpSource(ostream& out); +}; + +class CCalICalendarPropertyValueToken: public CCalICalendarToken { +public: + CCalICalendarPropertyValueToken(); + CCalICalendarPropertyValueToken(eCalICalendarTags aTag); + CCalICalendarPropertyValueToken(const nsString& aString,eCalICalendarTags aTag=eCalICalendarTag_unknown); + + virtual nsresult Consume(PRUnichar aChar,CScanner& aScanner); + virtual PRInt32 GetTypeID(void); + virtual const char* GetClassName(void); + virtual PRInt32 GetTokenType(void); + virtual void DebugDumpSource(ostream& out); +}; + +class CCalICalendarBeginToken: public CCalICalendarToken { +public: + + CCalICalendarBeginToken(eCalICalendarTags aTag); + CCalICalendarBeginToken(nsString& aName, eCalICalendarTags aTag=eCalICalendarTag_unknown); + virtual nsresult Consume(PRUnichar aChar,CScanner& aScanner); + virtual PRInt32 GetTypeID(void); + virtual const char* GetClassName(void); + virtual PRInt32 GetTokenType(void); + + PRBool IsAttributed(void); + void SetAttributed(PRBool aValue); + PRBool IsEmpty(void); + void SetEmpty(PRBool aValue); + virtual void DebugDumpSource(ostream& out); + virtual void Reinitialize(PRInt32 aTag, const nsString& aString); + +protected: + PRBool mAttributed; + PRBool mEmpty; +}; + +class CCalICalendarEndToken: public CCalICalendarToken { +public: + CCalICalendarEndToken(eCalICalendarTags aTag); + CCalICalendarEndToken(const nsString& aString); + virtual nsresult Consume(PRUnichar aChar,CScanner& aScanner); + virtual PRInt32 GetTypeID(void); + virtual const char* GetClassName(void); + virtual PRInt32 GetTokenType(void); + virtual void DebugDumpSource(ostream& out); +}; + +class CCalICalendarWhitespaceToken: public CCalICalendarToken { +public: + CCalICalendarWhitespaceToken(); + CCalICalendarWhitespaceToken(const nsString& aString); + virtual nsresult Consume(PRUnichar aChar,CScanner& aScanner); + virtual const char* GetClassName(void); + virtual PRInt32 GetTokenType(void); +}; + +class CCalICalendarTextToken: public CCalICalendarToken { +public: + CCalICalendarTextToken(); + CCalICalendarTextToken(const nsString& aString); + virtual nsresult Consume(PRUnichar aChar,CScanner& aScanner); + virtual const char* GetClassName(void); + virtual PRInt32 GetTokenType(void); +}; + +class CCalICalendarAttributeToken: public CCalICalendarToken { + public: + CCalICalendarAttributeToken(); + CCalICalendarAttributeToken(const nsString& aString); + CCalICalendarAttributeToken(const nsString& aKey, const nsString& aString); + virtual nsresult Consume(PRUnichar aChar,CScanner& aScanner); + virtual const char* GetClassName(void); + virtual PRInt32 GetTokenType(void); + virtual nsString& GetKey(void) {return mTextKey;} + virtual void DebugDumpToken(ostream& out); + virtual void DebugDumpSource(ostream& out); + PRBool mLastAttribute; + virtual void Reinitialize(PRInt32 aTag, const nsString& aString); + + protected: + nsString mTextKey; +}; + +class CCalICalendarNewlineToken: public CCalICalendarToken { + public: + CCalICalendarNewlineToken(); + CCalICalendarNewlineToken(const nsString& aString); + virtual nsresult Consume(PRUnichar aChar,CScanner& aScanner); + virtual const char* GetClassName(void); + virtual PRInt32 GetTokenType(void); + virtual nsString& GetStringValueXXX(void); +}; + +#endif + + + + + + + diff --git a/calendar/modules/parser/ical/inc/nscalicalendarpars.h b/calendar/modules/parser/ical/inc/nscalicalendarpars.h new file mode 100644 index 00000000000..55f41a01f09 --- /dev/null +++ b/calendar/modules/parser/ical/inc/nscalicalendarpars.h @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * 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. + */ + +/** + * MODULE NOTES: + * @update gess 4/1/98 + */ + +#ifndef nscalicalendarpars_h___ +#define nscalicalendarpars_h___ + +#include "nscore.h" + +#ifdef _IMPL_NS_CALICALENDARPARS +#define NS_CALICALENDARPARS NS_EXPORT +#else +#define NS_CALICALENDARPARS NS_IMPORT +#endif + +#if defined(XP_MAC) + #define CLASS_EXPORT_CALICALENDARPARS NS_CALICALENDARPARS class +#else + #define CLASS_EXPORT_CALICALENDARPARS class NS_CALICALENDARPARS +#endif + +#endif /* nscalicalendarpars_h___ */ + + + + + + + + + diff --git a/calendar/modules/parser/ical/manifest.mn b/calendar/modules/parser/ical/manifest.mn new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/parser/ical/public/Makefile b/calendar/modules/parser/ical/public/Makefile new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/parser/ical/public/manifest.mn b/calendar/modules/parser/ical/public/manifest.mn new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/parser/ical/public/nsICalICalendarContentSink.h b/calendar/modules/parser/ical/public/nsICalICalendarContentSink.h new file mode 100644 index 00000000000..37ea0e8d0d5 --- /dev/null +++ b/calendar/modules/parser/ical/public/nsICalICalendarContentSink.h @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * 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. + */ + +#ifndef nsICalICalendarContentSink_h___ +#define nsICalICalendarContentSink_h___ + +#include "nsISupports.h" +#include "nsIWebViewerContainer.h" + +// e2549d00-5a4d-11d2-9432-006008268c31 +#define NS_ICALICALENDAR_CONTENT_SINK_IID \ +{ 0xe2549d00, 0x5a4d, 0x11d2, \ +{ 0x94, 0x32, 0x00, 0x60, 0x08, 0x26, 0x8c, 0x31 } } + +class nsICalICalendarContentSink : public nsISupports +{ + +public: + + NS_IMETHOD Init() = 0 ; + NS_IMETHOD SetViewerContainer(nsIWebViewerContainer * aViewerContainer) = 0; + +}; + +#endif /* nsICalICalendarContentSink_h___ */ + diff --git a/calendar/modules/parser/ical/public/nsICalICalendarParserObject.h b/calendar/modules/parser/ical/public/nsICalICalendarParserObject.h new file mode 100644 index 00000000000..2695795d642 --- /dev/null +++ b/calendar/modules/parser/ical/public/nsICalICalendarParserObject.h @@ -0,0 +1,40 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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. + */ + +#ifndef nsICalICalendarParserObject_h___ +#define nsICalICalendarParserObject_h___ + +#include "nsISupports.h" +#include "nsString.h" + +// 316a1830-5a4e-11d2-9432-006008268c31 +#define NS_ICALICALENDAR_PARSER_OBJECT_IID \ +{ 0x316a1830, 0x5a43, 0x11d2, \ +{ 0x94, 0x32, 0x00, 0x60, 0x08, 0x26, 0x8c, 0x31 } } + +class nsICalICalendarParserObject : public nsISupports +{ + +public: + + NS_IMETHOD Init() = 0; + NS_IMETHOD SetParameter(nsString& aKey, nsString& aValue) = 0; + +}; + +#endif /* nsICalICalendarParserObject_h___ */ diff --git a/calendar/modules/parser/ical/src/Makefile b/calendar/modules/parser/ical/src/Makefile new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/parser/ical/src/config.mk b/calendar/modules/parser/ical/src/config.mk new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/parser/ical/src/manifest.mn b/calendar/modules/parser/ical/src/manifest.mn new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/parser/ical/src/nsCalICalendarContentSink.cpp b/calendar/modules/parser/ical/src/nsCalICalendarContentSink.cpp new file mode 100644 index 00000000000..96f9d1be6b4 --- /dev/null +++ b/calendar/modules/parser/ical/src/nsCalICalendarContentSink.cpp @@ -0,0 +1,294 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * 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. + */ + +#include "nsCalICalendarContentSink.h" +#include "nscalcoreicalCIID.h" +//#include "nsCalICalendarTokens.h" +//#include "nsCalICalendarDTD.h" +//#include "nsCalICalendarParserCIID.h" +//#include "nsICalICalendarParserObject.h" +//#include "nsICalendarShell.h" +//#include "nsCalParserCIID.h" +//#include "nsxpfcCIID.h" + +// +//#include "vevent.h" +//#include "nscal.h" +//#include "vtodo.h" +//#include "vfrbsy.h" +//#include "vtimezne.h" +//#include "valarm.h" +// + +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +static NS_DEFINE_IID(kIContentSinkIID, NS_ICONTENT_SINK_IID); +static NS_DEFINE_IID(kICalICalendarContentSinkIID, NS_ICALICALENDAR_CONTENT_SINK_IID); +static NS_DEFINE_IID(kICalICalendarParserObjectIID, NS_ICALICALENDAR_PARSER_OBJECT_IID); + +static NS_DEFINE_IID(kCCalICalendarVCalendarCID, NS_CALICALENDARVCALENDAR_CID); +static NS_DEFINE_IID(kCCalICalendarVEventCID, NS_CALICALENDARVEVENT_CID); +static NS_DEFINE_IID(kCCalICalendarVTodoCID, NS_CALICALENDARVTODO_CID); +static NS_DEFINE_IID(kCCalICalendarVJournalCID, NS_CALICALENDARVJOURNAL_CID); +static NS_DEFINE_IID(kCCalICalendarVFreebusyCID, NS_CALICALENDARVFREEBUSY_CID); +static NS_DEFINE_IID(kCCalICalendarVTimeZoneCID, NS_CALICALENDARVTIMEZONE_CID); +static NS_DEFINE_IID(kCCalICalendarVAlarmCID, NS_CALICALENDARVALARM_CID); + +nsCalICalendarContentSink::nsCalICalendarContentSink() { +} + +nsCalICalendarContentSink::~nsCalICalendarContentSink() { +} + +NS_IMETHODIMP nsCalICalendarContentSink::Init() { + return NS_OK; +} + +nsresult nsCalICalendarContentSink::QueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + if (NULL == aInstancePtr) { + return NS_ERROR_NULL_POINTER; + } + if (aIID.Equals(kISupportsIID)) { + *aInstancePtr = (nsIContentSink*)(this); + } + else if (aIID.Equals(kIContentSinkIID)) { + *aInstancePtr = (nsIContentSink*)(this); + } + else if (aIID.Equals(kICalICalendarContentSinkIID)) { + *aInstancePtr = (nsICalICalendarContentSink*)(this); + } + else { + *aInstancePtr=0; + return NS_NOINTERFACE; + } + NS_ADDREF_THIS(); + return NS_OK; +} + +NS_IMPL_ADDREF(nsCalICalendarContentSink); +NS_IMPL_RELEASE(nsCalICalendarContentSink); + +nsresult nsCalICalendarContentSink::SetViewerContainer(nsIWebViewerContainer * aViewerContainer) +{ + mViewerContainer = aViewerContainer; + return NS_OK; +} + +NS_IMETHODIMP nsCalICalendarContentSink::OpenContainer(const nsIParserNode& aNode) +{ + nsICalICalendarParserObject * object = nsnull; + eCalICalendarTags tag = (eCalICalendarTags) aNode.GetNodeType(); + nsresult res; + nsCID aclass; + + nsString tex = aNode.GetText(); + res = CIDFromTag(tag, aclass); + + if (NS_OK != res) + return res; + + res = nsRepository::CreateInstance(aclass, nsnull, kICalICalendarParserObjectIID, + (void **) &object); + + if (NS_OK != res) + return res; + + AddToHierarchy(*object, PR_TRUE); + object->Init(); + ConsumeAttributes(aNode,*object); + // todo: finish + return NS_OK; +} + +NS_IMETHODIMP nsCalICalendarContentSink::CloseContainer(const nsIParserNode& aNode) +{ + nsISupports * container = (nsISupports *)mXPFCStack->Pop(); + + // todo: finish + + NS_IF_RELEASE(container); + return NS_OK; +} + +NS_IMETHODIMP nsCalICalendarContentSink::AddLeaf(const nsIParserNode& aNode) +{ + nsICalICalendarParserObject * object = nsnull; + eCalICalendarTags tag = (eCalICalendarTags) aNode.GetNodeType(); + nsresult res; + nsCID aclass; + + nsString text = aNode.GetText(); + res = CIDFromTag(tag, aclass); + res = nsRepository::CreateInstance(aclass, + nsnull, + kICalICalendarParserObjectIID, + (void **)&object); + if (NS_OK != res) + return res; + + AddToHierarchy(*object, PR_FALSE); + + object->Init(); + + ConsumeAttributes(aNode, *object); + + //ConsumePropertyValues(aNode, *object); + + return NS_OK; +} + +NS_IMETHODIMP nsCalICalendarContentSink::WillBuildModel(void) +{ + return NS_OK; +} + +NS_IMETHODIMP nsCalICalendarContentSink::DidBuildModel(PRInt32 aQualityLevel) +{ + return NS_OK; +} + +NS_IMETHODIMP nsCalICalendarContentSink::WillInterrupt(void) +{ + return NS_OK; +} + +NS_IMETHODIMP nsCalICalendarContentSink::WillResume(void) +{ + return NS_OK; +} + + +/* + * Find the CID from the XML Tag Object + */ + +NS_IMETHODIMP nsCalICalendarContentSink::CIDFromTag(eCalICalendarTags tag, nsCID &aClass) +{ + switch(tag) + { + case eCalICalendarTag_vcalendar: + aClass = kCCalICalendarVCalendarCID; + break; + + case eCalICalendarTag_vevent: + aClass = kCCalICalendarVEventCID; + break; + + case eCalICalendarTag_vtodo: + aClass = kCCalICalendarVTodoCID; + break; + + case eCalICalendarTag_vjournal: + aClass = kCCalICalendarVJournalCID; + break; + + case eCalICalendarTag_vfreebusy: + aClass = kCCalICalendarVFreebusyCID; + break; + + case eCalICalendarTag_vtimezone: + aClass = kCCalICalendarVTimeZoneCID; + break; + + case eCalICalendarTag_valarm: + aClass = kCCalICalendarVAlarmCID; + break; + + default: + return (NS_ERROR_UNEXPECTED); + break; + } + + + return NS_OK; +} + +NS_IMETHODIMP nsCalICalendarContentSink::ConsumeAttributes(const nsIParserNode& aNode, + nsICalICalendarParserObject& aObject) +{ + PRInt32 i = 0; + nsString key,value; + nsString scontainer; + //PRBool container; + + for (i = 0; i < aNode.GetAttributeCount(); i++) { + key = aNode.GetKeyAt(i); + value = aNode.GetValueAt(i); + + key.StripChars("\""); + value.StripChars("\""); + + aObject.SetParameter(key,value); + } + + eCalICalendarTags tag = (eCalICalendarTags) aNode.GetNodeType(); + + // todo: finish + + return NS_OK; +} + +/* +NS_IMETHODIMP nsCalICalendarContentSink::ConsumePropertyValues(const nsIParserNode& aNode, + nsICalICalendarParserObject& aObject) +{ + PRInt32 i = 0; + nsString key,value; + nsString scontainer; + //PRBool container; + + for (i = 0; i < aNode.GetAttributeCount(); i++) { + key = aNode.GetKeyAt(i); + value = aNode.GetValueAt(i); + + key.StripChars("\""); + value.StripChars("\""); + + aObject.SetParameter(key,value); + } + + eCalICalendarTags tag = (eCalICalendarTags) aNode.GetNodeType(); + + // todo: finish + + return NS_OK; +} +*/ + +NS_IMETHODIMP nsCalICalendarContentSink::AddToHierarchy(nsICalICalendarParserObject& aObject, + PRBool aPush) +{ + return NS_OK; +} + +PRBool nsCalICalendarContentSink::IsContainer(const nsIParserNode& aNode) +{ + PRInt32 i = 0; + nsString key; + PRBool container = PR_FALSE; + + for (i = 0; i < aNode.GetAttributeCount(); i++) { + + key = aNode.GetKeyAt(i); + key.StripChars("\""); + + // todo: finish + } + + return container; +} diff --git a/calendar/modules/parser/ical/src/nsCalICalendarDTD.bak b/calendar/modules/parser/ical/src/nsCalICalendarDTD.bak new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/parser/ical/src/nsCalICalendarDTD.cpp b/calendar/modules/parser/ical/src/nsCalICalendarDTD.cpp new file mode 100644 index 00000000000..3dde591c350 --- /dev/null +++ b/calendar/modules/parser/ical/src/nsCalICalendarDTD.cpp @@ -0,0 +1,854 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * 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. + */ + +#include "nscalexport.h" +#include "nsCalXMLDTD.h" +#include "nsCalParserCIID.h" +#include "nsxpfcCIID.h" +#include "nsCalICalendarDTD.h" +#include "nsToken.h" +#include "nsScanner.h" +#include "nsParser.h" // ? +#include "nsParserNode.h" // ? +#include "nsIParserNode.h" // ? +#include "nsCalICalendarContentSink.h" +#include "nsCalICalendarTokens.h" // todo: +#include "nsCalICalendarParserCIID.h" +#include "nsParserCIID.h" +#include "nsCRT.h" // ? + +//#include "nsCalICalendarStrings.h" + +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID); +static NS_DEFINE_IID(kClassIID, NS_ICALICALENDAR_DTD_IID); +static NS_DEFINE_IID(kBaseClassIID, NS_ICALICALENDAR_DTD_IID); + +static NS_DEFINE_IID(kCParserNodeCID, NS_PARSER_NODE_IID); +static NS_DEFINE_IID(kCParserNodeIID, NS_IPARSER_NODE_IID); + +static const char* kNullToken = "Error: Null token given"; +static const char* kCalICalendarTextHeader = "BEGIN:VCALENDAR"; +static const char* kCalICalendarTextContentType = "text/calendar"; +static nsAutoString gCalEmpty; + +static eCalICalendarTags gCalNonContainers[]={ + eCalICalendarTag_action, eCalICalendarTag_attach, + eCalICalendarTag_attendee, eCalICalendarTag_calscale, + eCalICalendarTag_categories, eCalICalendarTag_class, + eCalICalendarTag_comment, eCalICalendarTag_completed, + eCalICalendarTag_contact, eCalICalendarTag_created, + eCalICalendarTag_description, + eCalICalendarTag_dtend, eCalICalendarTag_dtstart, + eCalICalendarTag_due, eCalICalendarTag_duration, + eCalICalendarTag_exdate, eCalICalendarTag_exrule, + eCalICalendarTag_freebusy, eCalICalendarTag_geo, + eCalICalendarTag_last_modified, eCalICalendarTag_location, + eCalICalendarTag_method, eCalICalendarTag_organizer, + eCalICalendarTag_percent_complete, eCalICalendarTag_priority, + eCalICalendarTag_prodid, eCalICalendarTag_rdate, + eCalICalendarTag_recurrence_id, eCalICalendarTag_related_to, + eCalICalendarTag_repeat, eCalICalendarTag_request_status, + eCalICalendarTag_resources, eCalICalendarTag_rrule, + eCalICalendarTag_sequence, + eCalICalendarTag_status, eCalICalendarTag_summary, + eCalICalendarTag_transp, eCalICalendarTag_trigger, + eCalICalendarTag_tzid, eCalICalendarTag_tzname, + eCalICalendarTag_tzoffsetfrom, eCalICalendarTag_tzoffsetto, + eCalICalendarTag_tzurl, eCalICalendarTag_uid, + eCalICalendarTag_url, + eCalICalendarTag_version, +}; + +struct nsCalICalendarTagEntry { + char mName[32]; + eCalICalendarTags fTagID; +}; + +nsCalICalendarTagEntry gCalICalendarTagTable[] = +{ + {"vcalendar", eCalICalendarTag_vcalendar}, + {"vevent", eCalICalendarTag_vevent}, + {"vtodo", eCalICalendarTag_vtodo}, + {"vjournal", eCalICalendarTag_vjournal}, + {"vfreebusy", eCalICalendarTag_vfreebusy}, + {"valarm", eCalICalendarTag_valarm}, + {"vtimezone", eCalICalendarTag_vtimezone} +}; + +eCalICalendarTags DetermineCalICalendarComponentType(const nsString& aString) +{ + PRInt32 result=-1; + PRInt32 cnt=sizeof(gCalICalendarTagTable)/sizeof(nsCalICalendarTagEntry); + PRInt32 low=0; + PRInt32 high=cnt-1; + PRInt32 middle=0; + + while(low<=high){ + middle=(PRInt32)(low+high)/2; + //result=aString.Compare(gCalICalendarTagTable[middle].mName, nsCRT::strlen(gXPFCXMLTagTable[middle].mName), PR_TRUE); + result=aString.Compare(gCalICalendarTagTable[middle].mName, PR_TRUE); + if (result==0) + return gCalICalendarTagTable[middle].fTagID; + if (result<0) + high=middle-1; + else low=middle+1; + } + return eCalICalendarTag_userdefined; +} + +PRInt32 CalICalendarDispatchTokenHandler(CToken* aToken,nsIDTD* aDTD) { + PRInt32 result=0; + eCalICalendarTokenTypes theType = (eCalICalendarTokenTypes)aToken->GetTokenType(); + nsCalICalendarDTD* theDTD=(nsCalICalendarDTD*)aDTD; + + nsString& name = aToken->GetStringValueXXX(); + eCalICalendarTags type = DetermineCalICalendarComponentType(name); + + if (type != eCalICalendarTag_userdefined) + aToken->SetTypeID(type); + + if (aDTD) { + switch(theType) { + case eCalICalendarToken_begin: + result=theDTD->HandleBeginToken(aToken); break; + case eCalICalendarToken_end: + result=theDTD->HandleEndToken(aToken); break; + case eCalICalendarToken_attribute: + result=theDTD->HandleAttributeToken(aToken); break; + case eCalICalendarToken_propertyvalue: + result=theDTD->HandlePropertyValueToken(aToken); break; + default: + result=0; + }//switch + }//if + return result; +} + + +/* token deallocator */ +class nsCalTokenDeallocator: public nsDequeFunctor { +public: + virtual void* operator()(void* anObject) { + CToken* aToken = (CToken*)anObject; + delete aToken; + return 0; + } +}; +static nsCalTokenDeallocator gCalTokenKiller; + +/* token recycler, cuts down number of tokens that get created during the run of system */ +class nsCalTokenRecycler: public nsITokenRecycler { +public: + nsCalTokenRecycler(); + virtual ~nsCalTokenRecycler(); + virtual void RecycleToken(CToken* aToken); + virtual CToken* CreateTokenOfType(eCalICalendarTokenTypes aType,eCalICalendarTags aTag, + const nsString& aString); + +protected: + nsDeque* mTokenCache[eCalICalendarToken_last-1]; +}; + +nsCalTokenRecycler::nsCalTokenRecycler() : nsITokenRecycler() { + int i=0; + for (i=0;iGetTokenType(); + mTokenCache[theType-1]->Push(aToken); + } +} + +CToken * nsCalTokenRecycler::CreateTokenOfType(eCalICalendarTokenTypes aType, + eCalICalendarTags aTag, + const nsString& aString) +{ + CToken* result=(CToken*)mTokenCache[aType-1]->Pop(); + + if(result) { + result->Reinitialize(aTag,aString); + } + else { + switch(aType) { + //todo: finish + case eCalICalendarToken_begin: result=new CCalICalendarBeginToken(aTag); break; + case eCalICalendarToken_end: result=new CCalICalendarEndToken(aTag); break; + case eCalICalendarToken_propertyname: result=new CCalICalendarIdentifierToken(aTag); break; + case eCalICalendarToken_attribute: result=new CCalICalendarAttributeToken(); break; + case eCalICalendarToken_propertyvalue: result=new CCalICalendarPropertyValueToken(); break; + default: + break; + } + } + return result; +} + +nsCalTokenRecycler gCalTokenRecycler; + +struct nsCalICalendarComponentEntry { + char mName[32]; + eCalICalendarTags fTagID; +}; + + +nsresult nsCalICalendarDTD::QueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + if (NULL == aInstancePtr) { + return NS_ERROR_NULL_POINTER; + } + + if (aIID.Equals(kISupportsIID)) { //do IUnknown... + *aInstancePtr = (nsIDTD*)(this); + } + else if (aIID.Equals(kIDTDIID)) { //do IParser base class... + *aInstancePtr = (nsIDTD*)(this); + } + else if (aIID.Equals(kClassIID)) { //do this class... + *aInstancePtr = (nsCalICalendarDTD*)(this); + } + else { + *aInstancePtr=0; + return NS_NOINTERFACE; + } + ((nsISupports*) *aInstancePtr)->AddRef(); + return NS_OK; +} + +NS_CALICALENDARPARS nsresult NS_NewICAL_DTD(nsIDTD** aInstancePtrResult) +{ + nsCalICalendarDTD * it = new nsCalICalendarDTD(); + + if (it == 0) { + return NS_ERROR_OUT_OF_MEMORY; + } + + return it->QueryInterface(kClassIID, (void **) aInstancePtrResult); +} + +NS_IMPL_ADDREF(nsCalICalendarDTD) +NS_IMPL_RELEASE(nsCalICalendarDTD) + +nsCalICalendarDTD::nsCalICalendarDTD() : nsIDTD() , mTokenDeque(gCalTokenKiller) +{ + NS_INIT_REFCNT(); + mParser=0; +} + +nsCalICalendarDTD::~nsCalICalendarDTD(){ +} + +PRBool nsCalICalendarDTD::CanParse(nsString& aContentType, PRInt32 aVersion) +{ + if (aContentType == kCalICalendarTextContentType) + return PR_TRUE; + + return PR_FALSE; +} + +eAutoDetectResult nsCalICalendarDTD::AutoDetectContentType(nsString& aBuffer,nsString& aType) +{ + if (aType == kCalICalendarTextContentType || aBuffer.Find(kCalICalendarTextHeader) != -1) + { + aType = kCalICalendarTextContentType; + return eValidDetect; + } + return eUnknownDetect; +} + +nsresult nsCalICalendarDTD::HandleToken(CToken* aToken) +{ + nsresult result=NS_OK; + + if(aToken) { + + CCalICalendarToken* theToken= (CCalICalendarToken*)(aToken); + eCalICalendarTokenTypes theType=eCalICalendarTokenTypes(theToken->GetTokenType()); + + result=CalICalendarDispatchTokenHandler(theToken,this); + } + return result; +} + +nsresult nsCalICalendarDTD::CreateNewInstance(nsIDTD** aInstancePtrResult) +{ + /* + static NS_DEFINE_IID(kCCalCalICalendarDTD, NS_ICALICALENDAR_DTD_IID); + + nsresult result = nsRepository::CreateInstance(kCCalCalICalendarDTD, + nsnull, + kIDTDIID, + (void**) aInstancePtrResult); + + return (result); + */ + return NS_NewICAL_DTD(aInstancePtrResult); +} + +nsresult nsCalICalendarDTD::HandleAttributeToken(CToken* aToken) { + NS_PRECONDITION(0 != aToken,kNullToken); + NS_ERROR("attribute encountered -- this shouldn't happen!"); + + return NS_OK; +} + +nsresult nsCalICalendarDTD::HandlePropertyValueToken(CToken* aToken) { + + /* + todo: handle "Content-type" stuff here + */ + /* + XXX: this is bad hack. I really shouldn't be handling MIME. + Someone else should parse all the MIME. + This DTD should really know how to parse iCal. + I should really NS_ERROR if this is called. + */ + + return NS_OK; +} + +nsresult nsCalICalendarDTD::HandleBeginToken(CToken* aToken) +{ + CCalICalendarBeginToken * st = (CCalICalendarBeginToken*)aToken; + eCalICalendarTags tokenTagType = (eCalICalendarTags) st->GetTypeID(); + nsCParserNode * attrNode = nsnull; + + //Begin by gathering up attributes... + static NS_DEFINE_IID(kCParserNodeCID, NS_PARSER_NODE_IID); + static NS_DEFINE_IID(kCParserNodeIID, NS_IPARSER_NODE_IID); + + nsresult result = nsRepository::CreateInstance(kCParserNodeCID, nsnull, kCParserNodeIID,(void**) &attrNode); + + if (NS_OK != result) + return result; + + attrNode->Init((CCalICalendarToken*)aToken,mLineNumber); + + PRInt16 attrCount=aToken->GetAttributeCount(); + result=(0==attrCount) ? NS_OK : CollectAttributes(*attrNode,attrCount); + + // now set skipped content to property value token + /* todo: finish + if (tokenTagType == eCalICalendarTag_begin) { + tokenTagType = ComponentTypeFromObject(*attrNode); + st->SetTypeID(tokenTagType); + } + */ + if(NS_OK==result) { + + switch(tokenTagType) { + case eCalICalendarTag_vcalendar: + case eCalICalendarTag_vevent: + case eCalICalendarTag_vtodo: + case eCalICalendarTag_vjournal: + case eCalICalendarTag_vfreebusy: + case eCalICalendarTag_valarm: + case eCalICalendarTag_vtimezone: + { + mSink->OpenContainer(*attrNode); + } + break; + + case eCalICalendarTag_action: + case eCalICalendarTag_attach: + case eCalICalendarTag_attendee: + case eCalICalendarTag_calscale: + case eCalICalendarTag_categories: + case eCalICalendarTag_class: + case eCalICalendarTag_comment: + case eCalICalendarTag_completed: + case eCalICalendarTag_contact: + case eCalICalendarTag_created: + case eCalICalendarTag_description: + case eCalICalendarTag_dtend: + case eCalICalendarTag_dtstart: + case eCalICalendarTag_due: + case eCalICalendarTag_duration: + case eCalICalendarTag_exdate: + case eCalICalendarTag_exrule: + case eCalICalendarTag_freebusy: + case eCalICalendarTag_geo: + case eCalICalendarTag_last_modified: + case eCalICalendarTag_location: + case eCalICalendarTag_method: + case eCalICalendarTag_organizer: + case eCalICalendarTag_percent_complete: + case eCalICalendarTag_priority: + case eCalICalendarTag_prodid: + case eCalICalendarTag_rdate: + case eCalICalendarTag_rrule: + case eCalICalendarTag_recurrence_id: + case eCalICalendarTag_related_to: + case eCalICalendarTag_repeat: + case eCalICalendarTag_request_status: + case eCalICalendarTag_resources: + case eCalICalendarTag_sequence: + case eCalICalendarTag_status: + case eCalICalendarTag_summary: + case eCalICalendarTag_transp: + case eCalICalendarTag_trigger: + case eCalICalendarTag_tzid: + case eCalICalendarTag_tzname: + case eCalICalendarTag_tzoffsetfrom: + case eCalICalendarTag_tzoffsetto: + case eCalICalendarTag_tzurl: + case eCalICalendarTag_uid: + case eCalICalendarTag_url: + case eCalICalendarTag_version: + { + // todo: finish + /* + if (((nsCalICalendarContentSink *)mSink)->IsContainer(*attrNode) == PR_TRUE) + st->SetTypeID(eCalICalendarTag_property); + */ + result = CollectPropertyValue(*attrNode,attrCount); + mSink->AddLeaf(*attrNode); + } + break; + + default: + break; + } + } + + NS_RELEASE(attrNode); + + if(eCalICalendarTag_newline==tokenTagType) + mLineNumber++; + + return result; +} + +PRInt32 nsCalICalendarDTD::CollectPropertyValue(nsCParserNode& aNode,PRInt32 aCount) { + + CToken* theToken=mParser->PeekToken(); + if(theToken) { + eCalICalendarTokenTypes theType=eCalICalendarTokenTypes(theToken->GetTokenType()); + if(eCalICalendarToken_propertyvalue==theType){ + mParser->PopToken(); //pop it for real... + aNode.SetSkippedContent(theToken); + } + else return kInterrupted; + } + return kNoError; +} + +PRInt32 nsCalICalendarDTD::CollectAttributes(nsCParserNode& aNode,PRInt32 aCount) { + int attr=0; + for(attr=0;attrPeekToken(); + if(theToken) { + eCalICalendarTokenTypes theType=eCalICalendarTokenTypes(theToken->GetTokenType()); + if(eCalICalendarToken_attribute==theType){ + mParser->PopToken(); //pop it for real... + aNode.AddAttribute(theToken); + } + } + else return kInterrupted; + } + return kNoError; +} + +nsresult nsCalICalendarDTD::HandleEndToken(CToken* aToken) +{ + nsresult result=NS_OK; + CCalICalendarEndToken* et = (CCalICalendarEndToken *)(aToken); + eCalICalendarTags tokenTagType=(eCalICalendarTags)et->GetTypeID(); + nsCParserNode * attrNode = nsnull; + + static NS_DEFINE_IID(kCParserNodeCID, NS_PARSER_NODE_IID); + static NS_DEFINE_IID(kCParserNodeIID, NS_IPARSER_NODE_IID); + + result = nsRepository::CreateInstance(kCParserNodeCID, nsnull, kCParserNodeIID, (void**)&attrNode); + + if (NS_OK != result) + return result; + + attrNode->Init((CCalICalendarToken *)aToken, mLineNumber); + + /* todo: finish + if (tokenTagType == eCalICalendarTag_object) { + tokenTagType = ComponentTypeFromObject(*attrNode); + et->SetTypeID(tokenTagType); + } + */ + switch(tokenTagType) { + + case eCalICalendarTag_vcalendar: + case eCalICalendarTag_vevent: + case eCalICalendarTag_vtodo: + case eCalICalendarTag_vjournal: + case eCalICalendarTag_vfreebusy: + case eCalICalendarTag_valarm: + case eCalICalendarTag_vtimezone: + { + mSink->CloseContainer(*attrNode); + } + break; + + case eCalICalendarTag_attach: + case eCalICalendarTag_attendee: + case eCalICalendarTag_calscale: + case eCalICalendarTag_categories: + case eCalICalendarTag_class: + case eCalICalendarTag_comment: + case eCalICalendarTag_completed: + case eCalICalendarTag_contact: + case eCalICalendarTag_created: + case eCalICalendarTag_description: + case eCalICalendarTag_dtend: + case eCalICalendarTag_dtstart: + case eCalICalendarTag_due: + case eCalICalendarTag_duration: + case eCalICalendarTag_exdate: + case eCalICalendarTag_exrule: + case eCalICalendarTag_freebusy: + case eCalICalendarTag_geo: + case eCalICalendarTag_last_modified: + case eCalICalendarTag_location: + case eCalICalendarTag_method: + case eCalICalendarTag_organizer: + case eCalICalendarTag_percent_complete: + case eCalICalendarTag_priority: + case eCalICalendarTag_prodid: + case eCalICalendarTag_rdate: + case eCalICalendarTag_rrule: + case eCalICalendarTag_recurrence_id: + case eCalICalendarTag_related_to: + case eCalICalendarTag_repeat: + case eCalICalendarTag_request_status: + case eCalICalendarTag_resources: + case eCalICalendarTag_sequence: + case eCalICalendarTag_status: + case eCalICalendarTag_summary: + case eCalICalendarTag_transp: + case eCalICalendarTag_trigger: + case eCalICalendarTag_tzid: + case eCalICalendarTag_tzname: + case eCalICalendarTag_tzoffsetfrom: + case eCalICalendarTag_tzoffsetto: + case eCalICalendarTag_tzurl: + case eCalICalendarTag_uid: + case eCalICalendarTag_url: + case eCalICalendarTag_version: + break; + default: + break; + } + + NS_RELEASE(attrNode); + + return result; +} + +/* +eCalICalendarTags nsCalICalendarDTD::ComponentTypeFromObject(const nsIParserNode& aNode) +{ + PRInt32 i = 0; + + for (i = 0; i < aNode.GetAttributeCount(); i++) { + + nsString key = aNode.GetKeyAt(i); + key.StripChars("\""); + if (key.EqualsIgnoreCase(XPFC_STRING_CLASS)) { + nsString value = aNode.GetValueAt(i); + + value.StripChars("\""); + + if (value.EqualsIgnoreCase("attach")) + return (eCalICalendarTag_attach); + // todo: finish + } + } + return (eCalICalendarTag_unknown); +} +*/ + +NS_IMETHODIMP nsCalICalendarDTD::WillBuildModel(nsString& aFilename,PRInt32 aLevel) { + nsresult result=NS_OK; +/* + mFilename=aFilename; + + if((aNotifySink) && (mSink)) { + mLineNumber=1; + result = mSink->WillBuildModel(); + } + */ + return result; +} + +NS_IMETHODIMP nsCalICalendarDTD::DidBuildModel(PRInt32 anErrorCode,PRInt32 aLevel){ + nsresult result=NS_OK; + return result; +} + +void nsCalICalendarDTD::SetParser(nsIParser* aParser) { + mParser=(nsParser*)aParser; + if (mParser) + mParseMode = aParser->GetParseMode(); +} + +nsIContentSink* nsCalICalendarDTD::SetContentSink(nsIContentSink* aSink) { + nsIContentSink* old=mSink; + mSink= aSink; + return old; +} + +// todo: consume token + +nsresult nsCalICalendarDTD::WillResumeParse(void){ + nsresult result = NS_OK; + if(mSink) { + result = mSink->WillResume(); + } + return result; +} + +nsresult nsCalICalendarDTD::WillInterruptParse(void){ + nsresult result = NS_OK; + if(mSink) { + result = mSink->WillResume(); + } + return result; +} + +PRBool nsCalICalendarDTD::Verify(nsString& aURLRef){ + PRBool result=PR_TRUE; + return result; +} + +PRBool nsCalICalendarDTD::IsContainer(PRInt32 aTag) const{ + PRBool result=PR_FALSE; + return result; +} + +PRBool nsCalICalendarDTD::CanContain(PRInt32 aParent,PRInt32 aChild) const{ + PRBool result=PR_FALSE; + return result; +} + +nsITokenRecycler* nsCalICalendarDTD::GetTokenRecycler(void){ + return 0; +} + +nsresult nsCalICalendarDTD::ConsumeToken(CToken*& aToken){ + aToken = 0; + if(mTokenDeque.GetSize()>0) + { + aToken=(CToken*)mTokenDeque.Pop(); + return NS_OK; + } + CScanner* theScanner=mParser->GetScanner(); + + PRUnichar aChar; + nsresult result=theScanner->GetChar(aChar); + switch(result) { + case kEOF: + break; + + case kInterrupted: + theScanner->RewindToMark(); + break; + + case NS_OK: + default: + switch(aChar) { + case kNotFound: + break; + + case kCR: case kLF: + result=ConsumeNewline(aChar,*theScanner,aToken); + break; + default: + if (!nsString::IsSpace(aChar)) { + result=ConsumePropertyLine(aChar,*theScanner,aToken); + break; + } + result=ConsumeWhitespace(aChar,*theScanner,aToken); + break; + } //switch + } + //if(NS_OK==result) + // result=theScanner->Eof(); + return result; +} + +nsresult +nsCalICalendarDTD::ConsumePropertyValue(PRUnichar aChar, CScanner& aScanner, + CToken*&aToken) +{ + PRInt32 theDequeSize=mTokenDeque.GetSize(); + nsresult result=NS_OK; + + CCalICalendarPropertyValueToken* theToken= (CCalICalendarPropertyValueToken*) + gCalTokenRecycler.CreateTokenOfType(eCalICalendarToken_propertyvalue, + eCalICalendarTag_unknown, gCalEmpty); + + //aToken=gCalTokenRecycler.CreateTokenOfType(eCalICalendarToken_propertyvalue, + // eCalICalendarTag_unknown, gCalEmpty); + if(theToken) { + result=theToken->Consume(aChar,aScanner);// parse property value (need to handle multiline) + //todo: also handle base64 and quoted-printable + if (NS_OK!=result) { + delete theToken; + aToken=0; + } + else + { + mTokenDeque.Push(theToken); + } + } + return result; +} + +nsresult +nsCalICalendarDTD::ConsumePropertyLine(PRUnichar aChar,CScanner& aScanner,CToken*& aToken) +{ + nsresult result = NS_OK; + result = ConsumePropertyNameAndAttributes(aChar, aScanner, aToken); + if ((0 != aToken) && (NS_OK == result)) + { + if (eCalICalendarTag_begin != aToken->GetTypeID() && eCalICalendarTag_end != aToken->GetTypeID()) + { + result = ConsumePropertyValue(aChar, aScanner, aToken); + if(NS_OK!=result) { + delete aToken; + aToken=0; + } + }//if (eCalICalendarTag_begin ...) + } + return result; +} + +nsresult +nsCalICalendarDTD::ConsumePropertyNameAndAttributes(PRUnichar aChar, CScanner& aScanner, + CToken*& aToken) +{ + PRInt32 theDequeSize=mTokenDeque.GetSize(); + nsresult result=NS_OK; + + aToken=gCalTokenRecycler.CreateTokenOfType(eCalICalendarToken_begin, + eCalICalendarTag_unknown, gCalEmpty); + + if(aToken) { + // eats BEGIN, but not BEGIN: or BEGIN; + result=aToken->Consume(aChar,aScanner); //tell new token to finish consuming text... + + if (eCalICalendarTag_begin != aToken->GetTypeID() && eCalICalendarTag_end != aToken->GetTypeID()) + { + + if (NS_OK==result) { + if (((CCalICalendarBeginToken*)aToken)->IsAttributed()) { + result=ConsumeAttributes(aChar,aScanner,(CCalICalendarBeginToken*)aToken); + } + if (NS_OK!=result) { + while(mTokenDeque.GetSize()>theDequeSize) { + delete mTokenDeque.PopBack(); + } + } + } //if + } //if + }// if (eCalICalendar_begin ...) + return result; +} + +nsresult +nsCalICalendarDTD::ConsumeWhitespace(PRUnichar aChar, + CScanner& aScanner, + CToken*& aToken) { + aToken=gCalTokenRecycler.CreateTokenOfType(eCalICalendarToken_whitespace, + eCalICalendarTag_whitespace, + gCalEmpty); + nsresult result=NS_OK; + if (aToken) { + result=aToken->Consume(aChar, aScanner); + } + return kNoError; +} + +nsresult +nsCalICalendarDTD::ConsumeNewline(PRUnichar aChar, + CScanner& aScanner, + CToken*& aToken) { + aToken=gCalTokenRecycler.CreateTokenOfType(eCalICalendarToken_newline, + eCalICalendarTag_newline, + gCalEmpty); + nsresult result=NS_OK; + if (aToken) { + result=aToken->Consume(aChar, aScanner); + } + return kNoError; +} + +nsresult +nsCalICalendarDTD::ConsumeAttributes(PRUnichar aChar, + CScanner& aScanner, + CCalICalendarBeginToken* aToken) { + PRBool done=PR_FALSE; + nsresult result=NS_OK; + PRInt16 theAttrCount=0; + + while((!done) && (result==NS_OK)) { + CCalICalendarAttributeToken* theToken= (CCalICalendarAttributeToken*) + gCalTokenRecycler.CreateTokenOfType(eCalICalendarToken_attribute, + eCalICalendarTag_unknown,gCalEmpty); + if(theToken){ + // first eat leading semicolon + result=aScanner.Peek(aChar); + if(aChar=kSemiColon) + aScanner.GetChar(aChar); + + result=theToken->Consume(aChar,aScanner); //tell new token to finish consuming text... + + if (NS_OK==result){ + theAttrCount++; + mTokenDeque.Push(theToken); + }//if + else delete theToken; //we can't keep it.. + }//if + if (NS_OK==result){ + result=aScanner.Peek(aChar); + if(aChar==kColon) { + aScanner.GetChar(aChar); + done=PR_TRUE; + }//if + }//if + }//while + aToken->SetAttributeCount(theAttrCount); + return result; +} + + + + + + + + diff --git a/calendar/modules/parser/ical/src/nsCalICalendarParserNode.cpp b/calendar/modules/parser/ical/src/nsCalICalendarParserNode.cpp new file mode 100644 index 00000000000..5e20555f425 --- /dev/null +++ b/calendar/modules/parser/ical/src/nsCalICalendarParserNode.cpp @@ -0,0 +1,277 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * 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. + */ + + +#include "nsCalICalendarParserNode.h" +#include "string.h" +#include "nsCalICalendarTokens.h" +#include "nscalicalendarpars.h" + +const nsAutoString nsCalICalendarCParserNode::mEmptyString(""); + +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +static NS_DEFINE_IID(kClassIID, NS_CALICALENDARPARSER_NODE_IID); +static NS_DEFINE_IID(kIParserNodeIID, NS_IPARSER_NODE_IID); + +/** + * Default constructor + * + * @update gess 3/25/98 + * @param aToken -- token to init internal token + * @return + */ +nsCalICalendarCParserNode::nsCalICalendarCParserNode(CCalICalendarToken* aToken,PRInt32 aLineNumber): nsIParserNode() { + NS_INIT_REFCNT(); + mAttributeCount=0; + mLineNumber=aLineNumber; + mToken=aToken; + memset(mAttributes,0,sizeof(mAttributes)); + mSkippedContent=nsnull; +} + + +/** + * default destructor + * + * @update gess 3/25/98 + * @param + * @return + */ +nsCalICalendarCParserNode::~nsCalICalendarCParserNode() { +} + +NS_IMPL_ADDREF(nsCalICalendarCParserNode) +NS_IMPL_RELEASE(nsCalICalendarCParserNode) + +/** + * Init + * + * @update gess 3/25/98 + * @param + * @return + */ + +nsresult nsCalICalendarCParserNode::Init(CCalICalendarToken* aToken,PRInt32 aLineNumber) +{ + mLineNumber=aLineNumber; + mToken=aToken; + return NS_OK; +} + +/** + * This method gets called as part of our COM-like interfaces. + * Its purpose is to create an interface to parser object + * of some type. + * + * @update gess 3/25/98 + * @param nsIID id of object to discover + * @param aInstancePtr ptr to newly discovered interface + * @return NS_xxx result code + */ +nsresult nsCalICalendarCParserNode::QueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + if (NULL == aInstancePtr) { + return NS_ERROR_NULL_POINTER; + } + + if(aIID.Equals(kISupportsIID)) { //do IUnknown... + *aInstancePtr = (nsIParserNode*)(this); + } + else if(aIID.Equals(kIParserNodeIID)) { //do IParser base class... + *aInstancePtr = (nsIParserNode*)(this); + } + else if(aIID.Equals(kClassIID)) { //do this class... + *aInstancePtr = (nsCalICalendarCParserNode*)(this); + } + else { + *aInstancePtr=0; + return NS_NOINTERFACE; + } + NS_ADDREF_THIS(); + return NS_OK; +} + + +/** + * Causes the given attribute to be added to internal + * mAttributes list, and mAttributeCount to be incremented. + * + * @update gess 3/25/98 + * @param aToken -- token to be added to attr list + * @return + */ +void nsCalICalendarCParserNode::AddAttribute(CCalICalendarToken* aToken) { + NS_PRECONDITION(mAttributeCountGetTokenType(), "not a skipped content token"); + mSkippedContent = aToken; + } +} + + +/** + * Gets the name of this node. Currently unused. + * + * @update gess 3/25/98 + * @param + * @return string ref containing node name + */ +const nsString& nsCalICalendarCParserNode::GetName() const { + return mEmptyString; + // return mName; +} + + +/** + * Get text value of this node, which translates into + * getting the text value of the underlying token + * + * @update gess 3/25/98 + * @param + * @return string ref of text from internal token + */ +const nsString& nsCalICalendarCParserNode::GetText() const { + return mToken->GetStringValueXXX(); +} + +/** + * Get text value of this node, which translates into + * getting the text value of the underlying token + * + * @update gess 3/25/98 + * @param + * @return string ref of text from internal token + */ +const nsString& nsCalICalendarCParserNode::GetSkippedContent() const { + if (nsnull != mSkippedContent) { + return ((CCalICalendarPropertyValueToken*)mSkippedContent)->GetStringValueXXX(); + } + return mEmptyString; +} + +/** + * Get node type, meaning, get the tag type of the + * underlying token + * + * @update gess 3/25/98 + * @param + * @return int value that represents tag type + */ +PRInt32 nsCalICalendarCParserNode::GetNodeType(void) const{ + return mToken->GetTypeID(); +} + + +/** + * Gets the token type, which corresponds to a value from + * eHTMLTokens_xxx. + * + * @update gess 3/25/98 + * @param + * @return + */ +PRInt32 nsCalICalendarCParserNode::GetTokenType(void) const{ + return mToken->GetTokenType(); +} + + +/** + * Retrieve the number of attributes on this node + * + * @update gess 3/25/98 + * @param + * @return int -- representing attribute count + */ +PRInt32 nsCalICalendarCParserNode::GetAttributeCount(PRBool askToken) const{ + if(PR_TRUE==askToken) + return mToken->GetAttributeCount(); + return mAttributeCount; +} + +/** + * Retrieve the string rep of the attribute key at the + * given index. + * + * @update gess 3/25/98 + * @param anIndex-- offset of attribute to retrieve + * @return string rep of given attribute text key + */ +const nsString& nsCalICalendarCParserNode::GetKeyAt(PRInt32 anIndex) const { + if(anIndexGetKey(); + } + return mEmptyString; +} + + +/** + * Retrieve the string rep of the attribute at given offset + * + * @update gess 3/25/98 + * @param anIndex-- offset of attribute to retrieve + * @return string rep of given attribute text value + */ +const nsString& nsCalICalendarCParserNode::GetValueAt(PRInt32 anIndex) const { + NS_PRECONDITION(anIndexGetStringValueXXX(); + } + return mEmptyString; +} + +PRInt32 nsCalICalendarCParserNode::TranslateToUnicodeStr(nsString& aString) const +{ + /* + if (eCalICalendarToken_entity == mToken->GetTokenType()) { + return ((CEntityToken*)mToken)->TranslateToUnicodeStr(aString); + } + */ + return -1; +} + + +/** + * This getter retrieves the line number from the input source where + * the token occured. Lines are interpreted as occuring between \n characters. + * @update gess7/24/98 + * @return int containing the line number the token was found on + */ +PRInt32 nsCalICalendarCParserNode::GetSourceLineNumber(void) const { + return mLineNumber; +} + diff --git a/calendar/modules/parser/ical/src/nsCalICalendarTags.cpp b/calendar/modules/parser/ical/src/nsCalICalendarTags.cpp new file mode 100644 index 00000000000..6ec0eb04091 --- /dev/null +++ b/calendar/modules/parser/ical/src/nsCalICalendarTags.cpp @@ -0,0 +1,93 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are Copyright (C) 1998 + * Netscape Communications Corporation. All Rights Reserved. + */ + +/* Do not edit - generated by gentags.pl */ +#include "nsCRT.h" +#include "nsCalICalendarTags.h" + +static char* tagTable[] = { + "ACTION", "ATTACH", "ATTENDEE", "BEGIN", "CALSCALE", "CATEGORIES", "CLASS", + "COMMENT", "COMPLETED", "CONTACT", "CREATED", "DAYLIGHT", "DESCRIPTION", + "DTEND", "DTSTART", "DUE", "DURATION", "END", "EXDATE", "EXRULE", + "FREEBUSY", "GEO", "LAST-MODIFIED", "LOCATION", "METHOD", "ORGANIZER", + "PERCENT-COMPLETE", "PRIORITY", "PRODID", "RDATE", "RECURRENCE-ID", + "RELATED-TO", "REPEAT", "REQUEST-STATUS", "RESOURCES", "RRULE", "SEQUENCE", + "STANDARD", "STATUS", "SUMMARY", "TRANSP", "TRIGGER", "TZID", "TZNAME", + "TZOFFSETFROM", "TZOFFSETTO", "TZURL", "UID", "URL", "VALARM", "VCALENDAR", + "VERSION", "VEVENT", "VFREEBUSY", "VJOURNAL", "VTIMEZONE", "VTODO" +}; + +nsCalICalendarTag NS_CalICalendarTagToEnum(const char* aTag) { + int low = 0; + int high = NS_CALICALENDAR_TAG_MAX - 1; + while (low <= high) { + int middle = (low + high) >> 1; + int result = nsCRT::strcasecmp(aTag, tagTable[middle]); + if (result == 0) + return (nsCalICalendarTag) (middle + 1); + if (result < 0) + high = middle - 1; + else + low = middle + 1; + } + return eCalICalendarTag_userdefined; +} + +const char* NS_CalICalendarEnumToTag(nsCalICalendarTag aTagID) { + if ((int(aTagID) <= 0) || (int(aTagID) > NS_CALICALENDAR_TAG_MAX)) { + return 0; + } + return tagTable[int(aTagID) - 1]; +} + +#ifdef NS_DEBUG +#include + +class nsCalICalendarTestTagTable { +public: + nsCalICalendarTestTagTable() { + const char *tag; + nsCalICalendarTag id; + + // Make sure we can find everything we are supposed to + for (int i = 0; i < NS_CALICALENDAR_TAG_MAX; i++) { + tag = tagTable[i]; + id = NS_CalICalendarTagToEnum(tag); + NS_ASSERTION(id != eCalICalendarTag_userdefined, "can't find tag id"); + const char* check = NS_CalICalendarEnumToTag(id); + NS_ASSERTION(check == tag, "can't map id back to tag"); + } + + // Make sure we don't find things that aren't there + id = NS_CalICalendarTagToEnum("@"); + NS_ASSERTION(id == eCalICalendarTag_userdefined, "found @"); + id = NS_CalICalendarTagToEnum("zzzzz"); + NS_ASSERTION(id == eCalICalendarTag_userdefined, "found zzzzz"); + + tag = NS_CalICalendarEnumToTag((nsCalICalendarTag) 0); + NS_ASSERTION(0 == tag, "found enum 0"); + tag = NS_CalICalendarEnumToTag((nsCalICalendarTag) -1); + NS_ASSERTION(0 == tag, "found enum -1"); + tag = NS_CalICalendarEnumToTag((nsCalICalendarTag) (NS_CALICALENDAR_TAG_MAX + 1)); + NS_ASSERTION(0 == tag, "found past max enum"); + } +}; +nsCalICalendarTestTagTable validateTagTable; +#endif + diff --git a/calendar/modules/parser/ical/src/nsCalICalendarTokens.cpp b/calendar/modules/parser/ical/src/nsCalICalendarTokens.cpp new file mode 100644 index 00000000000..7e720720d29 --- /dev/null +++ b/calendar/modules/parser/ical/src/nsCalICalendarTokens.cpp @@ -0,0 +1,621 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * 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 theg + * 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. + */ + +#include +#include +#include +#include "nsScanner.h" +#include "nsToken.h" +#include "nsCalICalendarTokens.h" +#include "nsParserTypes.h" +#include "prtypes.h" +#include "nsDebug.h" +#include "nsCalICalendarTags.h" +//#include "nsCalICalendarEntities.h" // todo: if necessary +#include "nsCRT.h" + +static nsString gIdentChars("-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"); +static nsString gNewLine("\n\r"); +static nsAutoString gDigits("0123456789"); +static nsAutoString gWhitespace("\b\t "); +static nsAutoString gDelimeters("\n\r:;"); +static const char* gUserdefined = "userdefined"; +static const char* gEmpty = ""; + +const PRInt32 kMAXNAMELEN=10; + +CCalICalendarToken::CCalICalendarToken(const nsString& aName, eCalICalendarTags aTag) : CToken(aName) { + mTypeID=aTag; +} + +CCalICalendarToken::CCalICalendarToken(eCalICalendarTags aTag) : CToken(aTag) { +} + +void CCalICalendarToken::SetStringValue(const char* name){ + if(name) { + mTextValue=name; + mTypeID = NS_CalICalendarTagToEnum(name); + } +} + +CCalICalendarIdentifierToken::CCalICalendarIdentifierToken(eCalICalendarTags aTag) + : CCalICalendarToken(aTag) { +} + +CCalICalendarIdentifierToken::CCalICalendarIdentifierToken(const nsString& aString, + eCalICalendarTags aTag) + : CCalICalendarToken(aString, aTag) { +} + + +nsresult CCalICalendarIdentifierToken::Consume(PRUnichar aChar, CScanner& aScanner) +{ + mTextValue=aChar; + + nsresult result=aScanner.ReadUntil(mTextValue,gIdentChars,PR_FALSE,PR_FALSE); + if (NS_OK==result) { + mTextValue.StripChars("\r"); + } + return result; +} + + +PRInt32 CCalICalendarIdentifierToken::GetTypeID(){ + if(eCalICalendarTag_unknown==mTypeID) { + nsAutoString tmp(mTextValue); + tmp.ToUpperCase(); + char cbuf[20]; + tmp.ToCString(cbuf, sizeof(cbuf)); + mTypeID = NS_CalICalendarTagToEnum(cbuf); + } + return mTypeID; +} + +const char* CCalICalendarIdentifierToken::GetClassName(void) { + return "identifier"; +} + +PRInt32 CCalICalendarIdentifierToken::GetTokenType(void) { + return eCalICalendarToken_identifier; +} + +void CCalICalendarIdentifierToken::DebugDumpSource(ostream& out) { + char buffer[200]; + mTextValue.ToCString(buffer,sizeof(buffer)-1); + out << "<" << buffer; +} + +CCalICalendarPropertyValueToken::CCalICalendarPropertyValueToken() + : CCalICalendarToken(eCalICalendarTag_unknown) { +} + +CCalICalendarPropertyValueToken::CCalICalendarPropertyValueToken(eCalICalendarTags aTag) + : CCalICalendarToken(aTag) { +} + +CCalICalendarPropertyValueToken::CCalICalendarPropertyValueToken(const nsString& aString, + eCalICalendarTags aTag) + : CCalICalendarToken(aString, aTag) { +} + + +nsresult CCalICalendarPropertyValueToken::Consume(PRUnichar aChar, CScanner& aScanner) +{ + //mTextValue=aChar; + PRUnichar nextChar; + PRBool done = PR_FALSE; + nsString cString; + + nsresult result=aScanner.ReadUntil(mTextValue,gNewLine,PR_TRUE,PR_FALSE); + + /* Consume the next line if starts with a space */ + while (!done) + { + + /* Consume the '\r\n'. Also handles UNIX where '\r' is line end */ + aScanner.GetChar(nextChar); // eat next '\r'; + + // if next char is '\n' eat it also + result = aScanner.Peek(nextChar); + if (kNewline == nextChar) + aScanner.GetChar(nextChar); + + // handle multi-line property values + result = aScanner.Peek(nextChar); + if (kSpace==nextChar) + { + aScanner.GetChar(nextChar); // eat space + cString = ""; + result = aScanner.ReadUntil(cString,gNewLine,PR_TRUE,PR_FALSE); + if (NS_OK == result) + { + mTextValue.Append(cString); + } + else { + // XXX: todo: handle error here. + } + } + else + { + done = PR_TRUE; + } + } + if (NS_OK==result) { + mTextValue.StripChars("\r"); + } + return result; +} + + +PRInt32 CCalICalendarPropertyValueToken::GetTypeID(){ + if(eCalICalendarTag_unknown==mTypeID) { + nsAutoString tmp(mTextValue); + tmp.ToUpperCase(); + char cbuf[20]; + tmp.ToCString(cbuf, sizeof(cbuf)); + mTypeID = NS_CalICalendarTagToEnum(cbuf); + } + return mTypeID; +} + +const char* CCalICalendarPropertyValueToken::GetClassName(void) { + return "propertyValue"; +} + +PRInt32 CCalICalendarPropertyValueToken::GetTokenType(void) { + return eCalICalendarToken_propertyvalue; +} + +void CCalICalendarPropertyValueToken::DebugDumpSource(ostream& out) { + char buffer[200]; + mTextValue.ToCString(buffer,sizeof(buffer)-1); + out << "<" << buffer; +} + +CCalICalendarBeginToken::CCalICalendarBeginToken(eCalICalendarTags aTag) : + CCalICalendarToken(aTag) { + mAttributed=PR_FALSE; + mEmpty=PR_FALSE; +} + +CCalICalendarBeginToken::CCalICalendarBeginToken(nsString& aString, + eCalICalendarTags aTag) : + CCalICalendarToken(aString,aTag) { + mAttributed=PR_FALSE; + mEmpty=PR_FALSE; +} + +void CCalICalendarBeginToken::Reinitialize(PRInt32 aTag, const nsString& aString){ + CToken::Reinitialize(aTag,aString); + mAttributed=PR_FALSE; + mEmpty=PR_FALSE; +} + + +PRInt32 CCalICalendarBeginToken::GetTypeID(){ + if(eCalICalendarTag_unknown==mTypeID) { + nsAutoString tmp(mTextValue); + tmp.ToUpperCase(); + char cbuf[20]; + tmp.ToCString(cbuf, sizeof(cbuf)); + mTypeID = NS_CalICalendarTagToEnum(cbuf); + } + return mTypeID; +} + +const char* CCalICalendarBeginToken::GetClassName(void) { + return "begin"; +} + +PRInt32 CCalICalendarBeginToken::GetTokenType(void) { + return eCalICalendarToken_begin; +} + +void CCalICalendarBeginToken::SetAttributed(PRBool aValue) { + mAttributed=aValue; +} + +PRBool CCalICalendarBeginToken::IsAttributed(void) { + return mAttributed; +} + +void CCalICalendarBeginToken::SetEmpty(PRBool aValue) { + mEmpty=aValue; +} + +PRBool CCalICalendarBeginToken::IsEmpty(void) { + return mEmpty; +} + +//todo: this needs to be modified more +nsresult CCalICalendarBeginToken::Consume(PRUnichar aChar, CScanner& aScanner) { + + //if you're here, we've need to consume the BEGIN: char, and are + //ready to Consume the rest of the open tag identifier. + //Stop consuming as soon as you see a space or a '\r\n'. + //NOTE: We don't Consume the tag attributes here, nor do we eat the "\r\n" + /* + nsresult result=NS_OK; + aScanner.GetChar(aChar); + mTextValue="BEGIN:"; + if(kMinus==aChar) { + mTextValue+="-"; + */ + + mTextValue=aChar; + nsresult result=aScanner.ReadWhile(mTextValue,gIdentChars,PR_TRUE,PR_FALSE); + char buffer[300]; + mTextValue.ToCString(buffer,sizeof(buffer)-1); + mTypeID = NS_CalICalendarTagToEnum(buffer); + + //Good. Now, let's skip whitespace after the identifier, + //and see if the next char is ">". If so, we have a complete + //tag without attributes. + if(NS_OK==result) { + result=aScanner.SkipWhitespace(); + if(NS_OK==result) { + result=aScanner.GetChar(aChar); + if(NS_OK==result) { + if(kSemiColon==aChar) { //look for ';' + //push that char back, since we apparently have attributes... + aScanner.PutBack(aChar); + mAttributed=PR_TRUE; + } //if + } //if + }//if + } + + // skip "BEGIN" or "END", reset mTextValue to VCALENDAR,VEVENT,etc.. + if (mTypeID == eCalICalendarTag_begin || mTypeID == eCalICalendarTag_end) + { + result = aScanner.SkipWhitespace(); + if (NS_OK == result) + { + mTextValue=""; + result = aScanner.ReadWhile(mTextValue,gIdentChars,PR_TRUE,PR_FALSE); + } + } + + return result; +}; + +void CCalICalendarBeginToken::DebugDumpSource(ostream& out) { + char buffer[200]; + mTextValue.ToCString(buffer,sizeof(buffer)-1); + out << "BEGIN:" << buffer; + if(!mAttributed) + out << "\r\n"; +} + +CCalICalendarEndToken::CCalICalendarEndToken(eCalICalendarTags aTag) : CCalICalendarToken(aTag) { +} + +CCalICalendarEndToken::CCalICalendarEndToken(const nsString& aName) : CCalICalendarToken(aName) { +} + +// todo: revisit +nsresult CCalICalendarEndToken::Consume(PRUnichar aChar, CScanner& aScanner) { + + //if you're here, we've already Consumed the "END:" chars, and are + //ready to Consume the rest of the open tag identifier. + //Stop consuming as soon as you see a space or a '\r\n'. + //NOTE: We don't Consume the tag attributes here, nor do we eat the ">" + + mTextValue=""; + nsresult result=aScanner.ReadUntil(mTextValue,kGreaterThan,PR_FALSE); + + char buffer[300]; + mTextValue.ToCString(buffer,sizeof(buffer)-1); + mTypeID= NS_CalICalendarTagToEnum(buffer); + + if(NS_OK==result) + result=aScanner.GetChar(aChar); //eat the closing '>; + return result; +} + +PRInt32 CCalICalendarEndToken::GetTypeID(){ + if (eCalICalendarTag_unknown==mTypeID) { + nsAutoString tmp(mTextValue); + tmp.ToUpperCase(); + char cbuf[200]; + tmp.ToCString(cbuf, sizeof(cbuf)); + mTypeID = NS_CalICalendarTagToEnum(cbuf); + } + return mTypeID; +} + +const char* CCalICalendarEndToken::GetClassName(void) { + return "/end"; +} + +PRInt32 CCalICalendarEndToken::GetTokenType(void) { + return eCalICalendarToken_end; +} + +void CCalICalendarEndToken::DebugDumpSource(ostream& out) { + char buffer[200]; + mTextValue.ToCString(buffer,sizeof(buffer)-1); + out << "END:" << buffer << "\r\n"; +} + +CCalICalendarTextToken::CCalICalendarTextToken() : + CCalICalendarToken(eCalICalendarTag_text) { +} + +CCalICalendarTextToken::CCalICalendarTextToken(const nsString& aName) : + CCalICalendarToken(aName) { + mTypeID=eCalICalendarTag_text; +} + +const char* CCalICalendarTextToken::GetClassName(void) { + return "text"; +} + +PRInt32 CCalICalendarTextToken::GetTokenType(void) { + return eCalICalendarToken_text; +} + +//todo: revisit +nsresult CCalICalendarTextToken::Consume(PRUnichar aChar, CScanner& aScanner) { + static nsAutoString terminals("&<\r"); + nsresult result=NS_OK; + PRBool done=PR_FALSE; + + while((NS_OK==result) && (!done)) { + result=aScanner.ReadUntil(mTextValue,terminals,PR_FALSE,PR_FALSE); + if(NS_OK==result) { + result=aScanner.Peek(aChar); + if(kCR==aChar) { + result=aScanner.GetChar(aChar); //strip off the \r + result=aScanner.Peek(aChar); //then see what's next. + switch(aChar) { + case kCR: + result=aScanner.GetChar(aChar); //strip off the \r + mTextValue.Append("\n\n"); + break; + case kNewLine: + //which means we saw \r\n, which becomes \n + result=aScanner.GetChar(aChar); //strip off the \n + //now fall through on purpose... + default: + mTextValue.Append("\n"); + break; + } + } + else done=PR_TRUE; + } + } + return result; +} + +CCalICalendarNewlineToken::CCalICalendarNewlineToken() : CCalICalendarToken(eCalICalendarTag_newline) { +} + +CCalICalendarNewlineToken::CCalICalendarNewlineToken(const nsString& aName) : CCalICalendarToken(aName) { + mTypeID=eCalICalendarTag_newline; +} + +const char* CCalICalendarNewlineToken::GetClassName(void) { + return "CRLF"; +} + +PRInt32 CCalICalendarNewlineToken::GetTokenType(void) { + return eCalICalendarToken_newline; +} + +nsString& CCalICalendarNewlineToken::GetStringValueXXX(void) { + static nsAutoString theStr("\n"); + return theStr; +} + +nsresult CCalICalendarNewlineToken::Consume(PRUnichar aChar, CScanner& aScanner) { + mTextValue=aChar; + + //we already read the \r or \n, let's see what's next! + PRUnichar nextChar; + nsresult result=aScanner.Peek(nextChar); + + if(NS_OK==result) { + switch(aChar) { + case kNewLine: + if(kCR==nextChar) { + result=aScanner.GetChar(nextChar); + mTextValue+=nextChar; + } + break; + case kCR: + if(kNewLine==nextChar) { + result=aScanner.GetChar(nextChar); + mTextValue+=nextChar; + } + break; + default: + break; + } + } + return result; +} + +CCalICalendarAttributeToken::CCalICalendarAttributeToken() : CCalICalendarToken(eCalICalendarTag_unknown) { +} + +CCalICalendarAttributeToken::CCalICalendarAttributeToken(const nsString& aName) : + CCalICalendarToken(aName), + mTextKey() { + mLastAttribute=PR_FALSE; +} + +CCalICalendarAttributeToken::CCalICalendarAttributeToken(const nsString& aKey, + const nsString& aName) : + CCalICalendarToken(aName) { + mTextKey = aKey; + mLastAttribute=PR_FALSE; +} + +void CCalICalendarAttributeToken::Reinitialize(PRInt32 aTag, const nsString& aString){ + CCalICalendarToken::Reinitialize(aTag,aString); + mTextKey.Truncate(); + mLastAttribute=PR_FALSE; +} + +const char* CCalICalendarAttributeToken::GetClassName(void) { + return "attr"; +} + +PRInt32 CCalICalendarAttributeToken::GetTokenType(void) { + return eCalICalendarToken_attribute; +} + +void CCalICalendarAttributeToken::DebugDumpToken(ostream& out) { + char buffer[200]; + mTextKey.ToCString(buffer,sizeof(buffer)-1); + out << "[" << GetClassName() << "] " << buffer << "="; + mTextValue.ToCString(buffer,sizeof(buffer)-1); + out << buffer << ": " << mTypeID << endl; +} + +PRInt32 CalICalendarConsumeQuotedString(PRUnichar aChar,nsString& aString,CScanner& aScanner){ + PRInt32 result=kNotFound; + switch(aChar) { + case kQuote: + result=aScanner.ReadUntil(aString,kQuote,PR_TRUE); + break; + case kApostrophe: + result=aScanner.ReadUntil(aString,kApostrophe,PR_TRUE); + break; + default: + break; + } + PRUnichar ch=aString.Last(); + if(ch!=aChar) + aString+=aChar; + return result; +} + +// todo: revisit +PRInt32 CalICalendarConsumeAttributeValueText(PRUnichar,nsString& aString,CScanner& aScanner){ + + PRInt32 result=kNotFound; + static nsAutoString terminals(":;"); + + result=aScanner.ReadUntil(aString,terminals,PR_FALSE,PR_FALSE); + return result; +} + +PRInt32 ConsumeAttributeValueText(PRUnichar,nsString& aString,CScanner& aScanner) { + PRInt32 result=kNotFound; + static nsAutoString terminals(":;"); + result=aScanner.ReadUntil(aString,terminals,PR_FALSE,PR_FALSE); + return result; +} + +// todo: revisit +nsresult CCalICalendarAttributeToken::Consume(PRUnichar aChar, CScanner& aScanner) { + + aScanner.SkipWhitespace(); //skip leading whitespace + nsresult result=aScanner.Peek(aChar); + if(NS_OK==result) { + static nsAutoString terminals("\b\t\n\r \"="); + result=aScanner.ReadUntil(mTextKey,terminals,PR_TRUE,PR_FALSE); + + //now it's time to Consume the (optional) value... + if(NS_OK == (result=aScanner.SkipWhitespace())) { + //Skip ahead until you find an equal sign or a '>'... + if(NS_OK == (result=aScanner.Peek(aChar))) { + if(kEqual==aChar){ + result=aScanner.GetChar(aChar); //skip the equal sign... + if(NS_OK==result) { + result=aScanner.SkipWhitespace(); //now skip any intervening whitespace + if(NS_OK==result) { + result=aScanner.GetChar(aChar); //and grab the next char. + if(NS_OK==result) { + if((kQuote==aChar) || (kApostrophe==aChar)) { + mTextValue=aChar; + result=CalICalendarConsumeQuotedString(aChar,mTextValue,aScanner); + } + else { + mTextValue=aChar; //it's an alphanum attribute... + result=ConsumeAttributeValueText(aChar,mTextValue,aScanner); + } + }//if + if(NS_OK==result) + result=aScanner.SkipWhitespace(); + }//if + }//if + }//if + }//if +// }if + } + if(NS_OK==result) { + result=aScanner.Peek(aChar); + mLastAttribute= PRBool((kColon==aChar) || (kEOF==result)); + } + } + return result; +} + +void CCalICalendarAttributeToken::DebugDumpSource(ostream& out) { + char buffer[200]; + mTextKey.ToCString(buffer,sizeof(buffer)-1); + out << " " << buffer; + if(mTextValue.Length()){ + mTextValue.ToCString(buffer,sizeof(buffer)-1); + out << "=" << buffer; + } + if(mLastAttribute) + out<<">"; +} + +CCalICalendarWhitespaceToken::CCalICalendarWhitespaceToken() : + CCalICalendarToken(eCalICalendarTag_whitespace) { +} + +CCalICalendarWhitespaceToken::CCalICalendarWhitespaceToken(const nsString& aName) : + CCalICalendarToken(aName) { + mTypeID=eCalICalendarTag_whitespace; +} + +const char* CCalICalendarWhitespaceToken::GetClassName(void) { + return "ws"; +} + +PRInt32 CCalICalendarWhitespaceToken::GetTokenType(void) { + return eCalICalendarToken_whitespace; +} + +nsresult CCalICalendarWhitespaceToken::Consume(PRUnichar aChar, CScanner& aScanner) { + + mTextValue=aChar; + + nsresult result=aScanner.ReadWhile(mTextValue,gWhitespace,PR_FALSE,PR_FALSE); + if(NS_OK==result) { + mTextValue.StripChars("\r"); + } + return result; +} + +const char* CalICalendarGetTagName(PRInt32 aTag) { + const char* result = NS_CalICalendarEnumToTag((nsCalICalendarTag) aTag); + if (0 == result) { + if(aTag>=eCalICalendarTag_userdefined) + result = gUserdefined; + else result= gEmpty; + } + return result; +} + diff --git a/calendar/modules/parser/ical/tools/gentags.pl b/calendar/modules/parser/ical/tools/gentags.pl new file mode 100644 index 00000000000..e8ee240a953 --- /dev/null +++ b/calendar/modules/parser/ical/tools/gentags.pl @@ -0,0 +1,274 @@ +#! /usr/local/bin/perl + +# The contents of this file are subject to the Netscape Public License +# Version 1.0 (the "License"); you may not use this file except in +# compliance with the License. You may obtain a copy of the License at +# http://www.mozilla.org/NPL/ +# +# Software distributed under the License is distributed on an "AS IS" +# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +# the License for the specific language governing rights and limitations +# under the License. +# +# The Original Code is Mozilla Communicator client code. +# +# The Initial Developer of the Original Code is Netscape Communications +# Corporation. Portions created by Netscape are Copyright (C) 1998 +# Netscape Communications Corporation. All Rights Reserved. + +###################################################################### + +# Table of tag names; it doesn't have to be sorted because code +# below will do it. However, for the sake of ease of additions, keep +# it sorted so that its easy to tell where to add a new tag and that +# the tag hasn't already been added. +$i = 0; +$tags[$i++] = "action"; +$tags[$i++] = "attach"; +$tags[$i++] = "attendee"; +$tags[$i++] = "begin"; +$tags[$i++] = "calscale"; +$tags[$i++] = "categories"; +$tags[$i++] = "class"; +$tags[$i++] = "comment"; +$tags[$i++] = "completed"; +$tags[$i++] = "contact"; +$tags[$i++] = "created"; +$tags[$i++] = "daylight"; +$tags[$i++] = "description"; +$tags[$i++] = "dtend"; +$tags[$i++] = "dtstart"; +$tags[$i++] = "due"; +$tags[$i++] = "duration"; +$tags[$i++] = "end"; +$tags[$i++] = "exdate"; +$tags[$i++] = "exrule"; +$tags[$i++] = "freebusy"; +$tags[$i++] = "geo"; +$tags[$i++] = "last_modified"; +$tags[$i++] = "location"; +$tags[$i++] = "method"; +$tags[$i++] = "organizer"; +$tags[$i++] = "percent_complete"; +$tags[$i++] = "priority"; +$tags[$i++] = "prodid"; +$tags[$i++] = "rdate"; +$tags[$i++] = "rrule"; +$tags[$i++] = "recurrence_id"; +$tags[$i++] = "related_to"; +$tags[$i++] = "repeat"; +$tags[$i++] = "request_status"; +$tags[$i++] = "resources"; +$tags[$i++] = "sequence"; +$tags[$i++] = "standard"; +$tags[$i++] = "status"; +$tags[$i++] = "summary"; +$tags[$i++] = "transp"; +$tags[$i++] = "trigger"; +$tags[$i++] = "tzid"; +$tags[$i++] = "tzname"; +$tags[$i++] = "tzoffsetfrom"; +$tags[$i++] = "tzoffsetto"; +$tags[$i++] = "tzurl"; +$tags[$i++] = "uid"; +$tags[$i++] = "url"; +$tags[$i++] = "valarm"; +$tags[$i++] = "vcalendar"; +$tags[$i++] = "version"; +$tags[$i++] = "vevent"; +$tags[$i++] = "vfreebusy"; +$tags[$i++] = "vjournal"; +$tags[$i++] = "vtimezone"; +$tags[$i++] = "vtodo"; + +###################################################################### + +# These are not tags; rather they are extra values to place into the +# tag enumeration after the normal tags. These do not need to be sorted +# and they do not go into the tag table, just into the tag enumeration. +$extra = 0; +$extra_tags[$extra++] = "text"; +$extra_tags[$extra++] = "whitespace"; +$extra_tags[$extra++] = "newline"; +$extra_tags[$extra++] = "entity"; +$extra_tags[$extra++] = "userdefined"; + +###################################################################### + +# Sort the tag table before using it +@tags = sort @tags; + +$copyright = "/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the \"License\"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an \"AS IS\" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are Copyright (C) 1998 + * Netscape Communications Corporation. All Rights Reserved. + */ + +/* Do not edit - generated by gentags.pl */ +"; + +###################################################################### + +$file_base = @ARGV[0]; + +# Generate the header file first +open(HEADER_FILE, ">$file_base.h"); + +# Print out copyright and do not edit notice +print HEADER_FILE $copyright; +print HEADER_FILE "#ifndef " . $file_base . "_h___\n"; +print HEADER_FILE "#define " . $file_base . "_h___\n"; +print HEADER_FILE "#include \"nscalicalendarpars.h\"\n"; + +# Print out enum's for the tag symbols +print HEADER_FILE "enum nsCalICalendarTag {\n"; +print HEADER_FILE " /* this enum must be first and must be zero */\n"; +print HEADER_FILE " eCalICalendarTag_unknown=0,\n\n"; +print HEADER_FILE " /* begin tag enums */\n "; +$width = 2; +print HEADER_FILE $str; +for ($j = 0; $j < $i; $j++) { + $lower = $tags[$j]; + $lower =~ tr/A-Z/a-z/; + $str = "eCalICalendarTag_" . $lower . "=" . ($j + 1); + $str = $str . ", "; + $len = length($str); + if ($width + $len > 78) { + print HEADER_FILE "\n "; + $width = 2; + } + print HEADER_FILE $str; + $width = $width + $len; +} +print HEADER_FILE "\n\n /* The remaining enums are not for tags */\n "; + +# Print out extra enum's that are not in the tag table +$width = 2; +for ($k = 0; $k < $extra; $k++) { + $lower = $extra_tags[$k]; + $lower =~ tr/A-Z/a-z/; + $str = "eCalICalendarTag_" . $lower . "=" . ($j + $k + 1); + if ($k < $extra - 1) { + $str = $str . ", "; + } + $len = length($str); + if ($width + $len > 78) { + print HEADER_FILE "\n "; + $width = 2; + } + print HEADER_FILE $str; + $width = $width + $len; +} + +print HEADER_FILE "\n};\n#define NS_CALICALENDAR_TAG_MAX " . $j . "\n\n"; +print HEADER_FILE "extern NS_CALICALENDARPARS nsCalICalendarTag NS_CalICalendarTagToEnum(const char* aTag);\n"; +print HEADER_FILE "extern NS_CALICALENDARPARS const char* NS_CalICalendarEnumToTag(nsCalICalendarTag aEnum);\n\n"; +print HEADER_FILE "#endif /* " . $file_base . "_h___ */\n"; +close(HEADER_FILE); + +###################################################################### + +# Generate the source file +open(CPP_FILE, ">$file_base.cpp"); +print CPP_FILE $copyright; +print CPP_FILE "#include \"nsCRT.h\"\n"; +print CPP_FILE "#include \"$file_base.h\"\n\n"; + +# Print out table of tag names +print CPP_FILE "static char* tagTable[] = {\n "; +$width = 2; +for ($j = 0; $j < $i; $j++) { + $upper = $tags[$j]; + $upper =~ tr/a-z/A-Z/; + $upper =~ s/_/-/; + $str = "\"" . $upper . "\""; + if ($j < $i - 1) { + $str = $str . ", "; + } + $len = length($str); + if ($width + $len > 78) { + print CPP_FILE "\n "; + $width = 2; + } + print CPP_FILE $str; + $width = $width + $len; +} +print CPP_FILE "\n};\n"; + +# Finally, dump out the search routine that takes a char* and finds it +# in the table. +print CPP_FILE " +nsCalICalendarTag NS_CalICalendarTagToEnum(const char* aTag) { + int low = 0; + int high = NS_CALICALENDAR_TAG_MAX - 1; + while (low <= high) { + int middle = (low + high) >> 1; + int result = nsCRT::strcasecmp(aTag, tagTable[middle]); + if (result == 0) + return (nsCalICalendarTag) (middle + 1); + if (result < 0) + high = middle - 1; + else + low = middle + 1; + } + return eCalICalendarTag_userdefined; +} + +const char* NS_CalICalendarEnumToTag(nsCalICalendarTag aTagID) { + if ((int(aTagID) <= 0) || (int(aTagID) > NS_CALICALENDAR_TAG_MAX)) { + return 0; + } + return tagTable[int(aTagID) - 1]; +} + +#ifdef NS_DEBUG +#include + +class nsCalICalendarTestTagTable { +public: + nsCalICalendarTestTagTable() { + const char *tag; + nsCalICalendarTag id; + + // Make sure we can find everything we are supposed to + for (int i = 0; i < NS_CALICALENDAR_TAG_MAX; i++) { + tag = tagTable[i]; + id = NS_CalICalendarTagToEnum(tag); + NS_ASSERTION(id != eCalICalendarTag_userdefined, \"can't find tag id\"); + const char* check = NS_CalICalendarEnumToTag(id); + NS_ASSERTION(check == tag, \"can't map id back to tag\"); + } + + // Make sure we don't find things that aren't there + id = NS_CalICalendarTagToEnum(\"@\"); + NS_ASSERTION(id == eCalICalendarTag_userdefined, \"found @\"); + id = NS_CalICalendarTagToEnum(\"zzzzz\"); + NS_ASSERTION(id == eCalICalendarTag_userdefined, \"found zzzzz\"); + + tag = NS_CalICalendarEnumToTag((nsCalICalendarTag) 0); + NS_ASSERTION(0 == tag, \"found enum 0\"); + tag = NS_CalICalendarEnumToTag((nsCalICalendarTag) -1); + NS_ASSERTION(0 == tag, \"found enum -1\"); + tag = NS_CalICalendarEnumToTag((nsCalICalendarTag) (NS_CALICALENDAR_TAG_MAX + 1)); + NS_ASSERTION(0 == tag, \"found past max enum\"); + } +}; +nsCalICalendarTestTagTable validateTagTable; +#endif + +"; + +close(CPP_FILE);