[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mirae-dev
Subject:    svn commit: r225340 -
From:       ias () apache ! org
Date:       2005-07-26 16:18:26
Message-ID: 20050726161826.91808.qmail () minotaur ! apache ! org
[Download RAW message or body]

Author: ias
Date: Tue Jul 26 09:18:24 2005
New Revision: 225340

URL: http://svn.apache.org/viewcvs?rev=225340&view=rev
Log:
Initial drop of StAX ME sample.

Added:
    webservices/mirae/trunk/samples/stax/memo/MemoViewer.java

Added: webservices/mirae/trunk/samples/stax/memo/MemoViewer.java
URL: http://svn.apache.org/viewcvs/webservices/mirae/trunk/samples/stax/memo/MemoViewer.java?rev=225340&view=auto
 ==============================================================================
--- webservices/mirae/trunk/samples/stax/memo/MemoViewer.java (added)
+++ webservices/mirae/trunk/samples/stax/memo/MemoViewer.java Tue Jul 26 09:18:24 \
2005 @@ -0,0 +1,118 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.microedition.io.Connector;
+import javax.microedition.io.StreamConnection;
+import javax.microedition.lcdui.Command;
+import javax.microedition.lcdui.CommandListener;
+import javax.microedition.lcdui.Display;
+import javax.microedition.lcdui.Displayable;
+import javax.microedition.lcdui.TextBox;
+import javax.microedition.lcdui.TextField;
+import javax.microedition.midlet.MIDlet;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+public class MemoViewer extends MIDlet implements CommandListener {
+
+    private static final String MEMO_URL = "http://www.iasandcb.pe.kr/memo.xml";
+
+    private static final Command CMD_EXIT = new Command("Exit", Command.EXIT, 1);
+
+    private static final Command CMD_VIEW = new Command("View", Command.ITEM, 1);
+
+    private Display display;
+
+    private XMLInputFactory factory;
+
+    private TextBox memoBox;
+
+    public MemoViewer() {
+        memoBox = new TextBox("Memo Viewer", "Disconnected", 100, TextField.ANY);
+        factory = XMLInputFactory.newInstance();
+        // factory = new StAXInputFactory();
+    }
+
+    protected void startApp() {
+        display = Display.getDisplay(this);
+        memoBox.addCommand(CMD_EXIT);
+        memoBox.addCommand(CMD_VIEW);
+        memoBox.setCommandListener(this);
+        display.setCurrent(memoBox);
+    }
+
+    public void commandAction(Command c, Displayable d) {
+
+        if (c == CMD_EXIT) {
+            destroyApp(false);
+            notifyDestroyed();
+        } else if (c == CMD_VIEW) {
+            StreamConnection con = null;
+            InputStream in = null;
+            try {
+                con = (StreamConnection) Connector.open(MEMO_URL);
+                in = con.openInputStream();
+                XMLStreamReader reader = factory.createXMLStreamReader(in);
+                if (reader.next() != XMLStreamConstants.START_ELEMENT) {
+                    reader.nextTag();
+                }
+                reader.require(XMLStreamConstants.START_ELEMENT, null, "memo");
+                reader.nextTag();
+                reader.require(XMLStreamConstants.START_ELEMENT, null,
+                        "subject");
+                memoBox.setTitle(reader.getElementText());
+                reader.require(XMLStreamConstants.END_ELEMENT, null, "subject");
+                reader.nextTag();
+                reader.require(XMLStreamConstants.START_ELEMENT, null,
+                        "content");
+                memoBox.setString(reader.getElementText());
+                reader.require(XMLStreamConstants.END_ELEMENT, null, "content");
+                reader.nextTag();
+                reader.require(XMLStreamConstants.END_ELEMENT, null, "memo");
+                reader.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            } catch (XMLStreamException e) {
+                e.printStackTrace();
+            } finally {
+                if (in != null) {
+                    try {
+                        in.close();
+                    } catch (IOException e) {
+                    }
+                }
+                if (con != null) {
+                    try {
+                        con.close();
+                    } catch (IOException e) {
+                    }
+                }
+            }
+        }
+    }
+
+    protected void destroyApp(boolean unconditional) {
+    }
+
+    protected void pauseApp() {
+    }
+
+}
\ No newline at end of file


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic