Beispiel #1
0
 public override void write(char[] chars, int offset, int count)
 {
     java.util.Arrays.checkOffsetAndCount(chars.Length, offset, count);
     if (count == 0)
     {
         return;
     }
     buf.append(chars, offset, count);
 }
Beispiel #2
0
 /// <summary>
 /// Appends the (unmatched) remainder of the input to the given
 /// <see cref="java.lang.StringBuffer">java.lang.StringBuffer</see>
 /// . The method can be used in conjunction with
 /// <see cref="find()">find()</see>
 /// and
 /// <see cref="appendReplacement(java.lang.StringBuffer, string)">appendReplacement(java.lang.StringBuffer, string)
 ///     </see>
 /// to
 /// walk through the input and replace all matches of the
 /// <code>Pattern</code>
 /// with something else.
 /// </summary>
 /// <param name="buffer">
 /// the
 /// <code>StringBuffer</code>
 /// to append to.
 /// </param>
 /// <returns>
 /// the
 /// <code>StringBuffer</code>
 /// .
 /// </returns>
 /// <exception cref="System.InvalidOperationException">if no successful match has been made.
 ///     </exception>
 public java.lang.StringBuffer appendTail(java.lang.StringBuffer buffer)
 {
     if (appendPos < _regionEnd)
     {
         buffer.append(Sharpen.StringHelper.Substring(input, appendPos, _regionEnd));
     }
     return(buffer);
 }
Beispiel #3
0
 /// <summary>
 /// Appends a literal part of the input plus a replacement for the current
 /// match to a given
 /// <see cref="java.lang.StringBuffer">java.lang.StringBuffer</see>
 /// . The literal part is exactly the
 /// part of the input between the previous match and the current match. The
 /// method can be used in conjunction with
 /// <see cref="find()">find()</see>
 /// and
 /// <see cref="appendTail(java.lang.StringBuffer)">appendTail(java.lang.StringBuffer)
 ///     </see>
 /// to walk through the input and replace
 /// all occurrences of the
 /// <code>Pattern</code>
 /// with something else.
 /// </summary>
 /// <param name="buffer">
 /// the
 /// <code>StringBuffer</code>
 /// to append to.
 /// </param>
 /// <param name="replacement">the replacement text.</param>
 /// <returns>
 /// the
 /// <code>Matcher</code>
 /// itself.
 /// </returns>
 /// <exception cref="System.InvalidOperationException">if no successful match has been made.
 ///     </exception>
 public java.util.regex.Matcher appendReplacement(java.lang.StringBuffer buffer, string
                                                  replacement)
 {
     buffer.append(Sharpen.StringHelper.Substring(input, appendPos, start()));
     appendEvaluated(buffer, replacement);
     appendPos = end();
     return(this);
 }
Beispiel #4
0
        /// <summary>Internal helper method to append a given string to a given string buffer.
        ///     </summary>
        /// <remarks>
        /// Internal helper method to append a given string to a given string buffer.
        /// If the string contains any references to groups, these are replaced by
        /// the corresponding group's contents.
        /// </remarks>
        /// <param name="buffer">the string buffer.</param>
        /// <param name="s">the string to append.</param>
        private void appendEvaluated(java.lang.StringBuffer buffer, string s)
        {
            bool escape = false;
            bool dollar = false;

            {
                for (int i = 0; i < s.Length; i++)
                {
                    char c = s[i];
                    if (c == '\\' && !escape)
                    {
                        escape = true;
                    }
                    else
                    {
                        if (c == '$' && !escape)
                        {
                            dollar = true;
                        }
                        else
                        {
                            if (c >= '0' && c <= '9' && dollar)
                            {
                                buffer.append(group(c - '0'));
                                dollar = false;
                            }
                            else
                            {
                                buffer.append(c);
                                dollar = false;
                                escape = false;
                            }
                        }
                    }
                }
            }
            // This seemingly stupid piece of code reproduces a JDK bug.
            if (escape)
            {
                throw Sharpen.Util.IndexOutOfRangeCtor(s.Length);
            }
        }
Beispiel #5
0
        /**
         * Processes messages associated with a Conversation.
         * Processes <em>only</em> messages of type:
         * <ul>
         *   <li>STARTED_LIVESESSION&#8212;lists details of in-coming and out-going calls</li>
         *   <li>POSTED_VOICE_MESSAGE&#8212;lists details of in-coming and out-going voicemails</li>
         *   <li>REQUESTED_AUTH&#8212;lists Contact authorization requests</li>
         *   <li>GRANTED_AUTH&#8212;lists Contacts granted authorization</li>
         * </ul>
         *
         * @param mySession
         *	Populated session object
         * @param myMessages
         *	Array of message strings to process.
         *
         * @since 1.0
         */
        static void doRenderHistory(MySession mySession, Message[] myMessages)
        {
            ParsePosition s_pos;
            ParsePosition e_pos;

            int msgTimeStamp;
            Date dateTimeStamp;
            DateFormat dateFmt = DateFormat.getDateTimeInstance();

            String author;
            String bodyXml;
            int bodyXmlLength;

            /*
             *         myXmlStrMgr.setVerboseDebug(true);
             */

            int msgCount = myMessages.Length;
            Message currMsg;
            Message.Type currMsgType;
            MySession.myConsole.printf("%d ...%n", msgCount);
            for (int i = 0; i < msgCount; i++)
            {
                currMsg = myMessages[i];
                currMsgType = currMsg.getType();

                if (currMsgType == Message.Type.STARTED_LIVE_SESSION)
                {
                    MySession.myConsole.printf("%nProcessing message of type %s%n", currMsgType.toString());
                    // Message.Property.P_AUTHOR tells who initiated the call.
                    author = currMsg.getAuthor();

                    // For duration we unfortunately have to parse the XML
                    // The duration we're interested in is
                    // <part identity="&me">%n...<duration>x</duration>...
                    //
                    // Real implementation should use a proper XML-parser here!
                    java.lang.StringBuffer partTag = new java.lang.StringBuffer("<part identity=\"");
                    partTag.append(mySession.myAccountName + "\">");
                    s_pos = myXmlStrMgr.getXmlSubStrPos(currMsg.getBodyXml(),
                                                        partTag.toString(), ZERO_POS);
                    if (s_pos == null)
                    {
                        MySession.myConsole.printf("%s: Could not find \"%s\" in xmlDoc%n%s%n%nSkipping...%n%n",
                                MY_CLASS_TAG, partTag.toString(),
                                currMsg.getBodyXml());
                        break;
                    }

                    int duration =
                        myXmlStrMgr.getXmlValueNum(currMsg.getBodyXml(),
                                                    "<duration>", s_pos);

                    // Ditto for counting how many parts the body has...
                    int num_parts = 0;
                    s_pos.setIndex(0);
                    do
                    {
                        e_pos = myXmlStrMgr.getXmlSubStrPos(currMsg.getBodyXml(),
                                                            "<part ", s_pos);
                        if (e_pos != null)
                        {
                            num_parts++;
                            s_pos.setIndex(e_pos.getIndex());
                        }
                    }
                    while (e_pos != null);

                    // Get timestamp -- it's in seconds, and the Date constructor needs milliseconds!
                    msgTimeStamp = currMsg.getTimestamp();
                    dateTimeStamp = new Date((msgTimeStamp * 1000L));
                    MySession.myConsole.printf("[%s] ", dateFmt.format(dateTimeStamp));
                    // Last part is to fetch message reason
                    String reason = currMsg.getReason();

                    if (author.Equals(mySession.myAccountName))
                    {
                        // I initiated the call
                        MySession.myConsole.println("outgoing call to ");
                    }
                    else
                    {
                        // Somebody else called me
                        MySession.myConsole.println("incoming call from ");
                    }

                    // List identities
                    doListIdentities(currMsg);

                    if (duration >= 0)
                    {
                        MySession.myConsole.printf("duration %d seconds", duration);
                    }
                    else if (num_parts > 1)
                    {
                        if (reason.Equals("manual"))
                        {
                            MySession.myConsole.printf("refused");
                        }
                        else
                        {
                            MySession.myConsole.printf("failed (%s)", reason);
                        }
                    }
                    else
                    {
                        MySession.myConsole.printf("missed");
                    }

                    MySession.myConsole.printf(" (%d parts).%n", num_parts);
                }
                else if (currMsgType == Message.Type.POSTED_VOICE_MESSAGE)
                {
                    MySession.myConsole.printf("%nProcessing message of type %s%n", currMsgType.toString());
                    author = currMsg.getAuthor();
                    // XML parsing again...
                    bodyXml = currMsg.getBodyXml();
                    bodyXmlLength = myXmlStrMgr.getXmlValueNum(bodyXml, "<length>", ZERO_POS);
                    // Get timestamp -- it's in seconds, and the Date constructor needs milliseconds!
                    msgTimeStamp = currMsg.getTimestamp();
                    dateTimeStamp = new Date((msgTimeStamp * 1000L));
                    MySession.myConsole.printf("[%s] ", dateFmt.format(dateTimeStamp));
                    if (author.Equals(mySession.myAccountName))
                    {
                        // I initiated the call
                        MySession.myConsole.println("Sent voicemail to ");
                    }
                    else
                    {
                        // Somebody else called me
                        MySession.myConsole.println("Got voicemail from ");
                    }
                    // List identities
                    doListIdentities(currMsg);
                    MySession.myConsole.printf("duration %d%n", bodyXmlLength);
                }
                else if (currMsgType == Message.Type.REQUESTED_AUTH)
                {
                    MySession.myConsole.printf("%nProcessing message of type %s%n", currMsgType.toString());
                    // Please note that REQUESTED_AUTH is not used to request authorization
                    // ALERT is used for that. REQUESTED_AUTH is used only for history
                    author = currMsg.getAuthor();
                    // Get timestamp -- it's in seconds, and the Date constructor needs milliseconds!
                    msgTimeStamp = currMsg.getTimestamp();
                    dateTimeStamp = new Date((msgTimeStamp * 1000L));
                    MySession.myConsole.printf("[%s] ", dateFmt.format(dateTimeStamp));
                    MySession.myConsole.printf("Authorization request from %s to ", author);
                    // List identities
                    doListIdentities(currMsg);
                    MySession.myConsole.println("");
                }
                else if (currMsgType == Message.Type.GRANTED_AUTH)
                {
                    MySession.myConsole.printf("%nProcessing message of type %s%n", currMsgType.toString());
                    author = currMsg.getAuthor();
                    // Get timestamp -- it's in seconds, and the Date constructor needs milliseconds!
                    msgTimeStamp = currMsg.getTimestamp();
                    dateTimeStamp = new Date((msgTimeStamp * 1000L));
                    MySession.myConsole.printf("[%s] ", dateFmt.format(dateTimeStamp));
                    MySession.myConsole.printf("%s granted authorization to ", author);
                    // List identities
                    doListIdentities(currMsg);
                    MySession.myConsole.println("");
                }

                else
                    MySession.myConsole.printf("%nIgnoring message of type %s%n", currMsgType.toString());
            }
        }
Beispiel #6
0
        /**
         * Processes messages associated with a Conversation.
         * Processes <em>only</em> messages of type:
         * <ul>
         *   <li>STARTED_LIVESESSION&#8212;lists details of in-coming and out-going calls</li>
         *   <li>POSTED_VOICE_MESSAGE&#8212;lists details of in-coming and out-going voicemails</li>
         *   <li>REQUESTED_AUTH&#8212;lists Contact authorization requests</li>
         *   <li>GRANTED_AUTH&#8212;lists Contacts granted authorization</li>
         * </ul>
         *
         * @param mySession
         *	Populated session object
         * @param myMessages
         *	Array of message strings to process.
         *
         * @since 1.0
         */
        static void doRenderHistory(MySession mySession, Message[] myMessages)
        {
            ParsePosition s_pos;
            ParsePosition e_pos;

            int        msgTimeStamp;
            Date       dateTimeStamp;
            DateFormat dateFmt = DateFormat.getDateTimeInstance();

            String author;
            String bodyXml;
            int    bodyXmlLength;

            /*
             *         myXmlStrMgr.setVerboseDebug(true);
             */

            int     msgCount = myMessages.Length;
            Message currMsg;

            Message.Type currMsgType;
            MySession.myConsole.printf("%d ...%n", msgCount);
            for (int i = 0; i < msgCount; i++)
            {
                currMsg     = myMessages[i];
                currMsgType = currMsg.getType();

                if (currMsgType == Message.Type.STARTED_LIVE_SESSION)
                {
                    MySession.myConsole.printf("%nProcessing message of type %s%n", currMsgType.toString());
                    // Message.Property.P_AUTHOR tells who initiated the call.
                    author = currMsg.getAuthor();

                    // For duration we unfortunately have to parse the XML
                    // The duration we're interested in is
                    // <part identity="&me">%n...<duration>x</duration>...
                    //
                    // Real implementation should use a proper XML-parser here!
                    java.lang.StringBuffer partTag = new java.lang.StringBuffer("<part identity=\"");
                    partTag.append(mySession.myAccountName + "\">");
                    s_pos = myXmlStrMgr.getXmlSubStrPos(currMsg.getBodyXml(),
                                                        partTag.toString(), ZERO_POS);
                    if (s_pos == null)
                    {
                        MySession.myConsole.printf("%s: Could not find \"%s\" in xmlDoc%n%s%n%nSkipping...%n%n",
                                                   MY_CLASS_TAG, partTag.toString(),
                                                   currMsg.getBodyXml());
                        break;
                    }

                    int duration =
                        myXmlStrMgr.getXmlValueNum(currMsg.getBodyXml(),
                                                   "<duration>", s_pos);

                    // Ditto for counting how many parts the body has...
                    int num_parts = 0;
                    s_pos.setIndex(0);
                    do
                    {
                        e_pos = myXmlStrMgr.getXmlSubStrPos(currMsg.getBodyXml(),
                                                            "<part ", s_pos);
                        if (e_pos != null)
                        {
                            num_parts++;
                            s_pos.setIndex(e_pos.getIndex());
                        }
                    }while (e_pos != null);

                    // Get timestamp -- it's in seconds, and the Date constructor needs milliseconds!
                    msgTimeStamp  = currMsg.getTimestamp();
                    dateTimeStamp = new Date((msgTimeStamp * 1000L));
                    MySession.myConsole.printf("[%s] ", dateFmt.format(dateTimeStamp));
                    // Last part is to fetch message reason
                    String reason = currMsg.getReason();

                    if (author.Equals(mySession.myAccountName))
                    {
                        // I initiated the call
                        MySession.myConsole.println("outgoing call to ");
                    }
                    else
                    {
                        // Somebody else called me
                        MySession.myConsole.println("incoming call from ");
                    }

                    // List identities
                    doListIdentities(currMsg);

                    if (duration >= 0)
                    {
                        MySession.myConsole.printf("duration %d seconds", duration);
                    }
                    else if (num_parts > 1)
                    {
                        if (reason.Equals("manual"))
                        {
                            MySession.myConsole.printf("refused");
                        }
                        else
                        {
                            MySession.myConsole.printf("failed (%s)", reason);
                        }
                    }
                    else
                    {
                        MySession.myConsole.printf("missed");
                    }

                    MySession.myConsole.printf(" (%d parts).%n", num_parts);
                }
                else if (currMsgType == Message.Type.POSTED_VOICE_MESSAGE)
                {
                    MySession.myConsole.printf("%nProcessing message of type %s%n", currMsgType.toString());
                    author = currMsg.getAuthor();
                    // XML parsing again...
                    bodyXml       = currMsg.getBodyXml();
                    bodyXmlLength = myXmlStrMgr.getXmlValueNum(bodyXml, "<length>", ZERO_POS);
                    // Get timestamp -- it's in seconds, and the Date constructor needs milliseconds!
                    msgTimeStamp  = currMsg.getTimestamp();
                    dateTimeStamp = new Date((msgTimeStamp * 1000L));
                    MySession.myConsole.printf("[%s] ", dateFmt.format(dateTimeStamp));
                    if (author.Equals(mySession.myAccountName))
                    {
                        // I initiated the call
                        MySession.myConsole.println("Sent voicemail to ");
                    }
                    else
                    {
                        // Somebody else called me
                        MySession.myConsole.println("Got voicemail from ");
                    }
                    // List identities
                    doListIdentities(currMsg);
                    MySession.myConsole.printf("duration %d%n", bodyXmlLength);
                }
                else if (currMsgType == Message.Type.REQUESTED_AUTH)
                {
                    MySession.myConsole.printf("%nProcessing message of type %s%n", currMsgType.toString());
                    // Please note that REQUESTED_AUTH is not used to request authorization
                    // ALERT is used for that. REQUESTED_AUTH is used only for history
                    author = currMsg.getAuthor();
                    // Get timestamp -- it's in seconds, and the Date constructor needs milliseconds!
                    msgTimeStamp  = currMsg.getTimestamp();
                    dateTimeStamp = new Date((msgTimeStamp * 1000L));
                    MySession.myConsole.printf("[%s] ", dateFmt.format(dateTimeStamp));
                    MySession.myConsole.printf("Authorization request from %s to ", author);
                    // List identities
                    doListIdentities(currMsg);
                    MySession.myConsole.println("");
                }
                else if (currMsgType == Message.Type.GRANTED_AUTH)
                {
                    MySession.myConsole.printf("%nProcessing message of type %s%n", currMsgType.toString());
                    author = currMsg.getAuthor();
                    // Get timestamp -- it's in seconds, and the Date constructor needs milliseconds!
                    msgTimeStamp  = currMsg.getTimestamp();
                    dateTimeStamp = new Date((msgTimeStamp * 1000L));
                    MySession.myConsole.printf("[%s] ", dateFmt.format(dateTimeStamp));
                    MySession.myConsole.printf("%s granted authorization to ", author);
                    // List identities
                    doListIdentities(currMsg);
                    MySession.myConsole.println("");
                }

                else
                {
                    MySession.myConsole.printf("%nIgnoring message of type %s%n", currMsgType.toString());
                }
            }
        }