Exemplo n.º 1
0
 public void doEnd(Token t)
 {
     StackElem pred = Pop();
     if (pred.predFlag)
     {
         if (Count > 0)
         {
             accumulator.Add(new Triple(NS(pred.id.TokenText), Peek().guid, pred.guid, true));
         }
         else
         {
             throw new Exception("Problem parsing: expecting overriding resource for: " + t.TokenText);
         }
     }
 }
 public void doEnd(Token t) { }
 public void doBegin(Token t) { }
        public void doValueProperty(Token t, Token iprop) 
        {
            if (mComponentToken == null)
                return;

            switch (mComponentToken.TokenText)
            {
                case "Vevent":

                    if (mAccountEvent == null || mIdToken == null || mSchedule == null)
                        throw new Exception(string.Format(
                            "Unexpected {0}", t.TokenText));

                    switch (mIdToken.TokenText)
                    {
                        case "dtstart":
                            mSchedule.StartDateTime = mAccountEvent.StartDateTime = DateTime.Parse(
                                Token.ParseDateTime(t.TokenText)).Add(-UtcOffset);
                            mSchedule.EndDateTime = mAccountEvent.EndDateTime = mAccountEvent.StartDateTime.AddHours(1);
                            break;
                        case "dtend":
                            mSchedule.EndDateTime = mAccountEvent.EndDateTime = DateTime.Parse(
                                Token.ParseDateTime(t.TokenText)).Add(-UtcOffset);
                            break;
                    }

                    break;            
            }
        
            // Console.WriteLine(mIdToken.TokenText  + ": "  + t.TokenText);
        }
        public void doRest(Token t, Token id) 
        {
            if (mComponentToken == null)
                return;

            switch (mComponentToken.TokenText)
            {
                case "Vevent":
                    
                    if (mAccountEvent == null)
                        throw new Exception(string.Format(
                            "Unexpected {0}", id.TokenText));

                    switch (id.TokenText)
                    {
                        case "summary":
                            mAccountEvent.Name = t.TokenText;
                            break;
                        case "description":
                            mAccountEvent.Description = t.TokenText;
                            break;
                        case "url":
                            mAccountEvent.Website = t.TokenText;
                            break;
                    }

                    break;

                case "Vvenue":

                    if (mAccountEvent == null || mPlace == null)
                        throw new Exception(string.Format(
                            "Unexpected {0}", id.TokenText));

                    switch (id.TokenText)
                    {
                        case "name":
                            mPlace.Name = mAccountEvent.PlaceName = t.TokenText;
                            break;
                        case "address":
                            mPlace.Street = t.TokenText;
                            break;
                        case "city":
                            mPlace.City = mAccountEvent.PlaceCity = t.TokenText;
                            break;
                        case "region":
                            mPlace.State = mAccountEvent.PlaceState = t.TokenText;
                            break;
                        case "country":
                            mPlace.Country = mAccountEvent.PlaceCountry = t.TokenText;
                            break;
                        case "postalcode":
                            mPlace.Zip = t.TokenText;
                            break;
                    }

                    break;
            }

            // Console.WriteLine("\t" + id.TokenText + "=>" + t.TokenText);
        } 
 public void doSymbolic(Token t) { }
 public void doURIResource(Token t) { }
Exemplo n.º 8
0
 public void doURIResource(Token t)
 {
     StackElem elem = Pop();
     accumulator.Add(new Triple(NS(elem.id.TokenText), Peek().guid, NS(t.TokenText), true));
 }
Exemplo n.º 9
0
 public void doMailto(Token t)
 {
     StackElem elem = Pop();
     elem.guid = NewGuid();
     accumulator.Add(new Triple(NS(elem.id.TokenText), Peek().guid, elem.guid, true));
     accumulator.Add(new Triple(NS("calAddress"), elem.guid, NS(t.TokenText), true));
     Push(elem);
 }
Exemplo n.º 10
0
 public void doID(Token t)
 {
     StackElem elem = new StackElem(t, null, false);  // the rest of the methods will fill in this properly
     Push(elem);
 }
Exemplo n.º 11
0
 public void doSymbolic(Token t)
 {
     //TODO: url encoding
     StackElem elem = Pop();
     accumulator.Add(new Triple(NS(elem.id.TokenText), Peek().guid, NS(Token.CamelCase(t.TokenText.ToLower())), true));
 }
Exemplo n.º 12
0
 public void doBegin(Token t)
 {
     // this indicates the beginning of a property describing the resource on the top of the stack
     Push(new StackElem(t, null, true));
 }
Exemplo n.º 13
0
        public void doComponentBegin(Token t)
        {
            // beginning of a rdfType for this stmt - ie. it's a new resource
            string guid = NewGuid();
            StackElem elem = new StackElem(t, guid, false);

            if (Count > 0 && Peek().predFlag)
            {
                StackElem top = Peek();
                top.guid = guid;
            }
            Push(elem);

            accumulator.Add(new Triple(RDF("type"), guid, NS(t.TokenText), true));
        }
Exemplo n.º 14
0
 public void doResourceBegin(Token t)
 {
     Push(new StackElem(t, NewGuid(), true));
 }
Exemplo n.º 15
0
 public void doEndComponent() 
 {
     // Console.WriteLine(mComponentToken.TokenText);
     mComponentToken = null;
 }
Exemplo n.º 16
0
        public void doValueProperty(Token t, Token iprop)
        {
            StackElem elem = Pop();
            elem.guid = NewGuid();
            accumulator.Add(new Triple(NS(elem.id.TokenText), Peek().guid, elem.guid, true));

            if (iprop != null)
            {
                string tag = NS(Token.CamelCase(iprop.TokenText.ToLower()));
                string lprop = Token.CamelCase(iprop.TokenText.ToLower());
                string lobj;
                if (lprop == "date")
                {
                    lobj = Token.ParseDate(t.TokenText);
                }
                else
                {
                    lobj = Token.CamelCase(t.TokenText.ToLower());
                }
                accumulator.Add(new Triple(tag, elem.guid, lobj, false));
            }
            else
            {
                accumulator.Add(new Triple(NS("dateTime"), elem.guid, Token.ParseDateTime(t.TokenText), false));
            }
            Push(elem);
        }
Exemplo n.º 17
0
 public void doID(Token t)
 {
     mIdToken = t;
 }
Exemplo n.º 18
0
 public void doIprop(Token t, Token iprop)
 {
     StackElem elem = Pop();
     accumulator.Add(new Triple(NS(elem.id.TokenText), Peek().guid, NS(iprop.TokenText), true));
 }
Exemplo n.º 19
0
 public void doResource(Token t) { } 
Exemplo n.º 20
0
 public void doRest(Token t, Token id)
 {
     StackElem elem = Pop();
     accumulator.Add(new Triple(NS(elem.id.TokenText), Peek().guid, t.TokenText, false));
 }
Exemplo n.º 21
0
 public void doMailto(Token t) { }
Exemplo n.º 22
0
 public void doAttribute(Token key, Token val)
 {
     string actual;
     if (key.TokenText == "until")
     {
         actual = Token.ParseDateTime(val.TokenText);
     }
     else
     {
         actual = val.TokenText;
     }
     accumulator.Add(new Triple(NS(key.TokenText), Peek().guid, actual, false));
 }
Exemplo n.º 23
0
 public void doIprop(Token t, Token iprop) { }
Exemplo n.º 24
0
 public StackElem(Token _id, string _guid, bool _predFlag)
 {
     id = _id;
     guid = _guid;
     predFlag = _predFlag;
 }
Exemplo n.º 25
0
 public void doAttribute(Token key, Token val) { }
Exemplo n.º 26
0
        /// <summary>
        /// Alternate entry point for starting the parser.
        /// </summary>
        /// <param name="emitHandT">Indicates if the emitter should be told to emit headers
        /// and trailers before and after emitting the iCalendar body</param>
        public void Parse(bool emitHandT)
        {
            buff = new StringBuilder();
            stack = new Stack();
            linenumber = 0;
            attributes = new Stack();  // a stack of key-value pairs (implemented as a stack of DitionaryEntry)

            if (emitHandT)
            {
                emitter.doIntro();
            }

            // each time through the loop will get a single (maybe folded) line
            while (true)
            {
                // check for termination condition
                if (scanner.isEOF())
                {
                    // end of file - do cleanup and go
                    break;
                }

                // empty the attribute stack and the iprop value...
                attributes.Clear();
                iprop = null;
                id = null;

                //FIXME: linenumber doesn't really keep track of actual line numbers because
                //       it is not aware of folded lines...
                linenumber++;

                //DEBUG: emit line number
                //emitter.emit( linenumber + ". " );

                if (!parseID())
                {
                    continue;
                }

                // we now have to parse a set of attributes (semi-colon separated) or
                // a value (delimited by a colon)
                Token sep = scanner.GetNextToken(ScannerState.ParseSimple);
                if (sep == null || sep.TokenVal == TokenValue.Error)
                {
                    // some kind of error - skip rest of line and continue
                    reportError(scanner, " expecting : or ; after id - found nothing.");
                    continue;
                }
                else if (sep.TokenVal == TokenValue.SemiColon)
                {
                    if (!parseAttributes(scanner))
                    {
                        continue;
                    }

                    // now we have to parse the value
                    sep = scanner.GetNextToken(ScannerState.ParseSimple);
                    if (!parseValue())
                    {
                        continue;
                    }
                }
                else if (sep.TokenVal == TokenValue.Colon)
                {
                    if (!parseValue())
                    {
                        continue;
                    }
                }
                else
                {
                    reportError(scanner, "expecting : or ; after id - found: " + sep.TokenText);
                    continue;
                }

                // now sploosh out the attributes (if any) and finish the ID tag
                while (attributes.Count > 0)
                {
                    DictionaryEntry entry = (DictionaryEntry)attributes.Pop();
                    Token key = (Token)entry.Key;
                    Token val = (Token)entry.Value;
                    emitter.doAttribute(key, val);
                }

                emitter.doEnd(id);
            }

            if (emitHandT)
            {
                emitter.doOutro();
            }
        }
Exemplo n.º 27
0
 public void doResourceBegin(Token t) { }
Exemplo n.º 28
0
        /// <summary>
        /// Parse the first field (ID) of the line.  Returns a boolean on weather or not the
        /// method sucesfully recognized an ID.  If not, the method insures that the scanner
        /// will start at the beginning of a new line.
        /// </summary>
        /// <returns></returns>
        protected virtual bool parseID()
        {
            Token t;  // re-usable token variable
            id = scanner.GetNextToken(ScannerState.ParseID);
            if (id == null || id.TokenVal == TokenValue.Error)
            {
                // some kind of error - skip rest of line and continue
                reportError(scanner, "expecting ID - found nothing.");
                return false;
            }

            switch (id.TokenVal)
            {
                case TokenValue.Tbegin:
                    t = scanner.GetNextToken(ScannerState.ParseSimple);
                    if (t == null || t.isError() || t.TokenVal != TokenValue.Colon)
                    {
                        if (t == null)
                            reportError(scanner, " expecting : - found nothing.");
                        else
                            reportError(scanner, " expecting : - found " + t.TokenText);
                        return false;
                    }

                    t = scanner.GetNextToken(ScannerState.ParseID);
                    if (t == null || t.isError() || (!t.isBeginEndValue() && !t.isResourceProperty()))
                    {
                        if (t == null)
                            reportError(scanner, " expecting a valid beginend value - found nothing.");
                        else
                            reportError(scanner, " expecting a valid beginend value - found " + t.TokenText);
                        return false;
                    }

                    // check for the different types of begin tags
                    if (t.isResourceProperty())
                    {
                        emitter.doResourceBegin(t);
                    }
                    else if (t.isComponent())
                    {
                        emitter.doComponent();
                        emitter.doComponentBegin(t);
                    }
                    else if (t.TokenVal == TokenValue.Tvcalendar)
                    {
                        emitter.doComponentBegin(t);
                    }
                    else
                    {
                        emitter.doBegin(t);
                    }
                    stack.Push(t);  // to match up to the corresponding end value
                    //scanner.ConsumeToEOL();
                    return false;

                case TokenValue.Tend:
                    t = scanner.GetNextToken(ScannerState.ParseSimple);
                    if (t == null || t.isError() || t.TokenVal != TokenValue.Colon)
                    {
                        if (t == null)
                            reportError(scanner, " expecting : - found nothing.");
                        else
                            reportError(scanner, " expecting : - found " + t.TokenText);
                        return false;
                    }

                    t = scanner.GetNextToken(ScannerState.ParseID);
                    if (t == null || t.isError() || (!t.isBeginEndValue() && !t.isResourceProperty()))
                    {
                        if (t == null)
                            reportError(scanner, " expecting a valid beginend value - found nothing.");
                        else
                            reportError(scanner, " expecting a valid beginend value - found " + t.TokenText);
                        return false;
                    }

                    // the end is easier - ignore the last one...  
                    if (stack.Count != 0)
                    {
                        emitter.doEnd(t);
                        if (t.isComponent())
                        {
                            emitter.doEndComponent();
                        }
                        stack.Pop();
                    }
                    else
                    {
                        reportError(scanner, "stack stuff is weird - probably illformed .ics file - parsing " + id.TokenText);
                    }
                    //scanner.ConsumeToEOL();
                    return false;

                case TokenValue.Trrule:
                    emitter.doResourceBegin(id);
                    break;

                default:
                    emitter.doID(id);
                    break;
            }
            return true;
        }
Exemplo n.º 29
0
 public void doComponentBegin(Token t)
 {
     mComponentToken = t;
     // Console.WriteLine(t.TokenText);
 }
Exemplo n.º 30
0
 public bool MoveNext()
 {
     current = scanner.GetNextToken();
     return current != null;
 }