Exemplo n.º 1
0
        public void TestParse()
        {
            var jParser = CreateJavaParser(modelFile);
            var sParser = CreateSharpParser(modelFile);

            var sentences = new[] {
                "Let all your things have their places; let each part of your business have its time.",
                "It has become appallingly obvious that our technology has exceeded our humanity.",
                "The real problem is not whether machines think but whether men do.",
                "The worst form of inequality is to try to make unequal things equal.",
                "People won't have time for you if you are always angry or complaining.",
                "To keep the body in good health is a duty... otherwise we shall not be able to keep our mind strong and clear.",
                "You, yourself, as much as anybody in the entire universe, deserve your love and affection."
            };


            foreach (var sentence in sentences)
            {
                var jParses = opennlp.tools.cmdline.parser.ParserTool.parseLine(sentence, jParser, 1);
                var sParses = ParserTool.ParseLine(sentence, sParser, 1);

                var jsb = new java.lang.StringBuffer();

                jParses[0].show(jsb);

                Assert.That(sParses[0].ToString(), Is.EqualTo(jsb.ToString()));
            }
        }
Exemplo n.º 2
0
        //[Test]
        public void TestParse()
        {
            // This test can't be done becouse a bug in the OpenNLP IKVM version
            // https://issues.apache.org/jira/browse/OPENNLP-727

            //const string sentence = "The quick brown fox jumps over the lazy dog .";

            const string sentence = "How much fruit do animals eat ?";

            var jParser = CreateJavaParser(modelFile);
            var sParser = CreateSharpParser(modelFile);

            var jParses = opennlp.tools.cmdline.parser.ParserTool.parseLine(sentence, jParser, 1);
            var sParses = ParserTool.ParseLine(sentence, sParser, 1);

            var jsb = new java.lang.StringBuffer();

            jParses[0].show(jsb);

            Assert.AreEqual("(TOP (SBAR (WHADJP (WRB How)) (S (NP (JJ much) (NN fruit)) (VP (VBP do) (S (NP (NNS animals)) (VP (VB eat))))) (. ?)))",
                            jsb.toString());

            Assert.AreEqual("(TOP (SBAR (WHADJP (WRB How)) (S (NP (JJ much) (NN fruit)) (VP (VBP do) (S (NP (NNS animals)) (VP (VB eat))))) (. ?)))",
                            sParses[0].ToString());

            Assert.NotNull(sParses);

            //CheckParseChild(jParses, sParses);
        }
Exemplo n.º 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);
 }
Exemplo n.º 4
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);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Constructs a new
 /// <code>StringWriter</code>
 /// which has a
 /// <see cref="java.lang.StringBuffer">java.lang.StringBuffer</see>
 /// allocated with a size of
 /// <code>initialSize</code>
 /// characters. The
 /// <code>StringBuffer</code>
 /// is also the
 /// <code>lock</code>
 /// used to synchronize access to this
 /// writer.
 /// </summary>
 /// <param name="initialSize">the intial size of the target string buffer.</param>
 public StringWriter(int initialSize)
 {
     if (initialSize < 0)
     {
         throw new System.ArgumentException();
     }
     buf   = new java.lang.StringBuffer(initialSize);
     @lock = buf;
 }
Exemplo n.º 6
0
		/// <summary>
		/// Constructs a new
		/// <code>StringWriter</code>
		/// which has a
		/// <see cref="java.lang.StringBuffer">java.lang.StringBuffer</see>
		/// allocated with a size of
		/// <code>initialSize</code>
		/// characters. The
		/// <code>StringBuffer</code>
		/// is also the
		/// <code>lock</code>
		/// used to synchronize access to this
		/// writer.
		/// </summary>
		/// <param name="initialSize">the intial size of the target string buffer.</param>
		public StringWriter(int initialSize)
		{
			if (initialSize < 0)
			{
				throw new System.ArgumentException();
			}
			buf = new java.lang.StringBuffer(initialSize);
			@lock = buf;
		}
Exemplo n.º 7
0
 /// <summary>
 /// Replaces all occurrences of this matcher's pattern in the input with a
 /// given string.
 /// </summary>
 /// <remarks>
 /// Replaces all occurrences of this matcher's pattern in the input with a
 /// given string.
 /// </remarks>
 /// <param name="replacement">the replacement text.</param>
 /// <returns>the modified input string.</returns>
 public string replaceAll(string replacement)
 {
     reset();
     java.lang.StringBuffer buffer = new java.lang.StringBuffer(input.Length);
     while (find())
     {
         appendReplacement(buffer, replacement);
     }
     return(appendTail(buffer).ToString());
 }
Exemplo n.º 8
0
 public global::java.util.regex.Matcher appendReplacement(java.lang.StringBuffer arg0, java.lang.String arg1)
 {
     global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv;
     if (!IsClrObject)
     {
         return(global::MonoJavaBridge.JavaBridge.WrapJavaObject(@__env.CallObjectMethod(this.JvmHandle, global::java.util.regex.Matcher._appendReplacement15768, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg1))) as java.util.regex.Matcher);
     }
     else
     {
         return(global::MonoJavaBridge.JavaBridge.WrapJavaObject(@__env.CallNonVirtualObjectMethod(this.JvmHandle, global::java.util.regex.Matcher.staticClass, global::java.util.regex.Matcher._appendReplacement15768, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg1))) as java.util.regex.Matcher);
     }
 }
Exemplo n.º 9
0
 /// <summary>
 /// Appends the contents of the specified
 /// <code>StringBuffer</code>
 /// . If the
 /// StringBuffer is
 /// <code>null</code>
 /// , then the string
 /// <code>"null"</code>
 /// is
 /// appended.
 /// </summary>
 /// <param name="sb">
 /// the
 /// <code>StringBuffer</code>
 /// to append.
 /// </param>
 /// <returns>this builder.</returns>
 public java.lang.StringBuilder append(java.lang.StringBuffer sb)
 {
     if (sb == null)
     {
         appendNull();
     }
     else
     {
         append0(sb.getValue(), 0, sb.Length);
     }
     return(this);
 }
Exemplo n.º 10
0
 public override global::java.lang.StringBuffer format(java.lang.Object arg0, java.lang.StringBuffer arg1, java.text.FieldPosition arg2)
 {
     global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv;
     if (!IsClrObject)
     {
         return(global::MonoJavaBridge.JavaBridge.WrapJavaObject(@__env.CallObjectMethod(this.JvmHandle, global::java.text.NumberFormat._format15126, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg1), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg2))) as java.lang.StringBuffer);
     }
     else
     {
         return(global::MonoJavaBridge.JavaBridge.WrapJavaObject(@__env.CallNonVirtualObjectMethod(this.JvmHandle, global::java.text.NumberFormat.staticClass, global::java.text.NumberFormat._format15126, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg1), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg2))) as java.lang.StringBuffer);
     }
 }
Exemplo n.º 11
0
 public new global::java.lang.StringBuilder append(java.lang.StringBuffer arg0)
 {
     global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv;
     if (!IsClrObject)
     {
         return(global::MonoJavaBridge.JavaBridge.WrapJavaObject(@__env.CallObjectMethod(this.JvmHandle, global::java.lang.StringBuilder._append13291, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0))) as java.lang.StringBuilder);
     }
     else
     {
         return(global::MonoJavaBridge.JavaBridge.WrapJavaObject(@__env.CallNonVirtualObjectMethod(this.JvmHandle, global::java.lang.StringBuilder.staticClass, global::java.lang.StringBuilder._append13291, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0))) as java.lang.StringBuilder);
     }
 }
Exemplo n.º 12
0
        public string FormatNumber(double number, string pattern)
        {
            java.text.DecimalFormat frm = new java.text.DecimalFormat("", javaFormat);

            frm.applyLocalizedPattern(pattern);

            //TODO: the next 4 string could be replaced by just
            //return frm.format (number);
            //I don't want to do that before release
            java.lang.StringBuffer  buffer = new java.lang.StringBuffer();
            java.text.FieldPosition fld    = new java.text.FieldPosition(0);

            frm.format(number, buffer, fld);
            return(buffer.ToString());
        }
Exemplo n.º 13
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);
            }
        }
Exemplo n.º 14
0
 public abstract global::java.lang.StringBuffer format(long arg0, java.lang.StringBuffer arg1, java.text.FieldPosition arg2);
Exemplo n.º 15
0
        public void TestParse() {


            var jParser = CreateJavaParser(modelFile);
            var sParser = CreateSharpParser(modelFile);


            var sentences = new[] {
                "Let all your things have their places; let each part of your business have its time.",
                "It has become appallingly obvious that our technology has exceeded our humanity.",
                "The real problem is not whether machines think but whether men do.",  
                "The worst form of inequality is to try to make unequal things equal.",
                "People won't have time for you if you are always angry or complaining.",
                "To keep the body in good health is a duty... otherwise we shall not be able to keep our mind strong and clear.",
                "You, yourself, as much as anybody in the entire universe, deserve your love and affection."
            };


            foreach (var sentence in sentences) {

                var jParses = opennlp.tools.cmdline.parser.ParserTool.parseLine(sentence, jParser, 1);
                var sParses = ParserTool.ParseLine(sentence, sParser, 1);

                var jsb = new java.lang.StringBuffer();

                jParses[0].show(jsb);

                Assert.AreEqual(jsb.toString(), sParses[0].ToString());

                jParses[0].show(jsb);
            }
        }
Exemplo n.º 16
0
 public sealed override java.lang.StringBuffer format(object @object, java.lang.StringBuffer
                                                      buffer, java.text.FieldPosition field)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 17
0
 public abstract java.lang.StringBuffer format(System.DateTime date, java.lang.StringBuffer
                                               buffer, java.text.FieldPosition field);
Exemplo n.º 18
0
		/// <summary>
		/// Constructs a new
		/// <code>StringWriter</code>
		/// which has a
		/// <see cref="java.lang.StringBuffer">java.lang.StringBuffer</see>
		/// allocated with the default size of 16 characters. The
		/// <code>StringBuffer</code>
		/// is also the
		/// <code>lock</code>
		/// used to synchronize access to this
		/// writer.
		/// </summary>
		public StringWriter()
		{
			buf = new java.lang.StringBuffer(16);
			@lock = buf;
		}
Exemplo n.º 19
0
 private void appendNumber(java.lang.StringBuffer buffer, int count, int value)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 20
0
 private void appendNumericTimeZone(java.lang.StringBuffer buffer, bool generalTimeZone
                                    )
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 21
0
 internal static bool upToWithQuotes(string @string, java.text.ParsePosition position
                                     , java.lang.StringBuffer buffer, char stop, char start)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 22
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());
                }
            }
        }
		public string FormatNumber (double number, string pattern)
		{
			java.text.DecimalFormat frm = new java.text.DecimalFormat("", javaFormat);

			frm.applyLocalizedPattern (pattern);

			//TODO: the next 4 string could be replaced by just 
			//return frm.format (number);
			//I don't want to do that before release
			java.lang.StringBuffer buffer= new java.lang.StringBuffer ();
			java.text.FieldPosition fld = new java.text.FieldPosition (0);

			frm.format (number, buffer, fld);
			return buffer.ToString();
		}
Exemplo n.º 24
0
 /// <summary>
 /// Constructs a new
 /// <code>StringWriter</code>
 /// which has a
 /// <see cref="java.lang.StringBuffer">java.lang.StringBuffer</see>
 /// allocated with the default size of 16 characters. The
 /// <code>StringBuffer</code>
 /// is also the
 /// <code>lock</code>
 /// used to synchronize access to this
 /// writer.
 /// </summary>
 public StringWriter()
 {
     buf   = new java.lang.StringBuffer(16);
     @lock = buf;
 }
Exemplo n.º 25
0
 public override java.lang.StringBuffer format(System.DateTime date, java.lang.StringBuffer
                                               buffer, java.text.FieldPosition fieldPos)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 26
0
 private java.lang.StringBuffer formatImpl(System.DateTime date, java.lang.StringBuffer
                                           buffer, java.text.FieldPosition field, java.util.List <java.text.FieldPosition>
                                           fields)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 27
0
		/// <summary>
		/// Replaces all occurrences of this matcher's pattern in the input with a
		/// given string.
		/// </summary>
		/// <remarks>
		/// Replaces all occurrences of this matcher's pattern in the input with a
		/// given string.
		/// </remarks>
		/// <param name="replacement">the replacement text.</param>
		/// <returns>the modified input string.</returns>
		public string replaceAll(string replacement)
		{
			reset();
			java.lang.StringBuffer buffer = new java.lang.StringBuffer(input.Length);
			while (find())
			{
				appendReplacement(buffer, replacement);
			}
			return appendTail(buffer).ToString();
		}
Exemplo n.º 28
0
 private void append(java.lang.StringBuffer buffer, java.text.FieldPosition position
                     , java.util.List <java.text.FieldPosition> fields, char format_1, int count)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 29
0
 private void appendMonth(java.lang.StringBuffer buffer, int count, string[] longs
                          , string[] shorts)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 30
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());
            }
        }
Exemplo n.º 31
0
 public abstract java.lang.StringBuffer format(object @object, java.lang.StringBuffer
                                               buffer, java.text.FieldPosition field);