ws-axis-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aj...@apache.org
Subject svn commit: r179743 [2/2] - in /webservices/axis/trunk/java/modules/samples/src/sample: ./ amazon/ amazon/amazonSimpleQueueService/ amazon/amazonSimpleQueueService/util/ google/ google/search/
Date Fri, 03 Jun 2005 08:12:50 GMT
Added: webservices/axis/trunk/java/modules/samples/src/sample/google/search/ClientUtil.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/src/sample/google/search/ClientUtil.java?rev=179743&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/samples/src/sample/google/search/ClientUtil.java (added)
+++ webservices/axis/trunk/java/modules/samples/src/sample/google/search/ClientUtil.java Fri
Jun  3 01:12:48 2005
@@ -0,0 +1,130 @@
+/*
+ * Copyright 2001-2004 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.
+ */
+
+package sample.google.search;
+
+import org.apache.axis.om.*;
+import org.apache.axis.soap.SOAPFactory;
+import org.apache.axis.soap.SOAPEnvelope;
+import org.apache.axis.context.ConfigurationContextFactory;
+import org.apache.axis.context.ConfigurationContext;
+import org.apache.axis.context.MessageContext;
+import org.apache.axis.engine.AxisFault;
+import org.apache.axis.deployment.DeploymentException;
+
+/**
+ * Builds the MessageContext as called by AsynchronousClient
+ * First build the request soap envilope
+ * then build a messageContext and soap envelope is attached to it
+ *
+ * @author Gayan Asanka  (gayan@opensource.lk)
+ */
+public class ClientUtil {
+
+    /** Soap request is included to this and pass it to sendMsg() in AsynchronousClient */
+    static MessageContext msgContext;
+
+    /**
+     * method getMessageContext
+     * @return msgContext
+     */
+    public static MessageContext getMessageContext() throws DeploymentException {
+        OMNamespace namespace,defNs;
+        OMElement operation,part1,part2,part3,part4,part5,part6,part7,part8,part9,part10;
+
+        String str_ST_index = Integer.toString(AsynchronousClient.StartIndex);
+
+        defNs = OMAbstractFactory.getSOAP11Factory().createOMNamespace("", "");
+        SOAPFactory omFactory = OMAbstractFactory.getSOAP11Factory();
+        SOAPEnvelope envelope = omFactory.getDefaultEnvelope();
+        namespace = envelope.declareNamespace(
+                "http://schemas.xmlsoap.org/soap/envelope/", "SOAP-ENV");
+        namespace = envelope.declareNamespace(
+                "http://schemas.xmlsoap.org/soap/encoding/", "SOAP-ENC");
+        namespace = envelope.declareNamespace(
+                "http://www.w3.org/1999/XMLSchema-instance/", "xsi");
+        namespace = envelope.declareNamespace("http://www.w3.org/1999/XMLSchema",
+                "xsd");
+
+        operation = omFactory.createOMElement("doGoogleSearch", "urn:GoogleSearch", "ns1");
+        envelope.getBody().addChild(operation);
+        operation.addAttribute("SOAP-ENV:encordingStyle",
+                "http://schemas.xmlsoap.org/soap/encoding/", null);
+
+        part1 = omFactory.createOMElement("key", defNs);
+        part1.addAttribute("xsi:type", "xsd:string", null);
+        part1.addChild(omFactory.createText(AsynchronousClient.key));
+        //a sample valid key "F0wt5EFQFHKxTs+rl3P+27o6D112BTWd"));
+
+        part2 = omFactory.createOMElement("q", defNs);
+        part2.addAttribute("xsi:type", "xsd:string", null);
+        part2.addChild(omFactory.createText(AsynchronousClient.search));
+
+        part3 = omFactory.createOMElement("start", defNs);
+        part3.addAttribute("xsi:type", "xsd:int", null);
+        part3.addChild(omFactory.createText(str_ST_index));
+
+        part4 = omFactory.createOMElement("maxResults", defNs);
+        part4.addAttribute("xsi:type", "xsd:int", null);
+        part4.addChild(omFactory.createText(AsynchronousClient.maxResults));
+
+        part5 = omFactory.createOMElement("filter", defNs);
+        part5.addAttribute("xsi:type", "xsd:boolean", null);
+        part5.addChild(omFactory.createText("true"));
+
+        part6 = omFactory.createOMElement("restrict", defNs);
+        part6.addAttribute("xsi:type", "xsd:string", null);
+
+        part7 = omFactory.createOMElement("safeSearch", defNs);
+        part7.addAttribute("xsi:type", "xsd:boolean", null);
+        part7.addChild(omFactory.createText("false"));
+
+        part8 = omFactory.createOMElement("lr", defNs);
+        part8.addAttribute("xsi:type", "xsd:string", null);
+
+        part9 = omFactory.createOMElement("ie", defNs);
+        part9.addAttribute("xsi:type", "xsd:string", null);
+        part9.addChild(omFactory.createText("latin1"));
+
+        part10 = omFactory.createOMElement("oe", defNs);
+        part10.addAttribute("xsi:type", "xsd:string", null);
+        part10.addChild(omFactory.createText("latin1"));
+
+        operation.addChild(part10);
+        operation.addChild(part9);
+        operation.addChild(part8);
+        operation.addChild(part7);
+        operation.addChild(part6);
+        operation.addChild(part5);
+        operation.addChild(part4);
+        operation.addChild(part3);
+        operation.addChild(part2);
+        operation.addChild(part1);
+
+        ConfigurationContextFactory fac = new ConfigurationContextFactory();
+        ConfigurationContext configContext = fac.buildClientEngineContext("doGoogleSearch");
+        try {
+            msgContext = new MessageContext(configContext);
+        } catch (AxisFault axisFault) {
+            axisFault.printStackTrace();
+        }
+        msgContext.setEnvelope(envelope);
+        return msgContext;
+    }
+}
+
+
+

Added: webservices/axis/trunk/java/modules/samples/src/sample/google/search/GUIHandler.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/src/sample/google/search/GUIHandler.java?rev=179743&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/samples/src/sample/google/search/GUIHandler.java (added)
+++ webservices/axis/trunk/java/modules/samples/src/sample/google/search/GUIHandler.java Fri
Jun  3 01:12:48 2005
@@ -0,0 +1,295 @@
+/*
+ * Copyright 2001-2004 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.
+ */
+
+package sample.google.search;
+
+import org.apache.axis.engine.AxisFault;
+
+import javax.swing.*;
+import java.awt.event.KeyListener;
+import java.awt.event.ActionListener;
+import java.awt.event.KeyEvent;
+import java.awt.event.ActionEvent;
+import java.awt.*;
+import java.io.*;
+
+/**
+ * Build and desplay the GUI
+ * implements both KeyListner and ActionListner
+ * KeyListner is used to detect space or Enter key at textField
+ * ActionListner is used for menu cammands
+ * Thread is run to isolate the GUI from internal actions
+ *
+ * @author Gayan Asanka  (gayan@opensource.lk)
+ */
+public class GUIHandler implements KeyListener, ActionListener, Runnable {
+
+    /**
+     * Results are desplayed here
+     */
+    private static JEditorPane text;
+
+    /**
+     * Query parameters typed here
+     */
+    private static JTextField textBox;
+
+    /**
+     * Buttons clicked to view more results and back
+     */
+    private static JButton next, back;
+
+    /**
+     * Menu commands to set the key and maximum no of results per page
+     */
+    private static JMenuItem mnuKey, mnuMaxResults;
+
+    /**
+     * Build the GUI using awt and swing components
+     */
+    public void buildFrame() {
+        JFrame frame;
+        SpringLayout layout;
+        JMenuBar menuBar;
+        JMenu setMenu;
+        Spring xSpring, ySpring, hSpring, wSpring;
+
+        frame = new JFrame("Google Search");
+        frame.setResizable(false);
+        layout = new SpringLayout();
+        Container pane = frame.getContentPane();
+        pane.setLayout(layout);
+
+        menuBar = new JMenuBar();
+        frame.setJMenuBar(menuBar);
+        setMenu = new JMenu("Set"); // Create Set menu
+        menuBar.add(setMenu);
+        setMenu.addActionListener(this);
+        mnuKey = new JMenuItem("Key");
+        mnuMaxResults = new JMenuItem("Result per page");
+
+        setMenu.add(mnuKey);
+        setMenu.add(mnuMaxResults);
+
+        mnuKey.addActionListener(this);
+        mnuMaxResults.addActionListener(this);
+
+        Toolkit theKit = frame.getToolkit(); // Get the window toolkit
+        Dimension wndSize = theKit.getScreenSize(); // Get screen size
+
+        // Set the position to screen center & size to half screen size
+        frame.setBounds(wndSize.width / 6, wndSize.height / 10, // Position
+                wndSize.width * 3 / 5, wndSize.height * 3 / 4); // Size
+        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+
+        next = new JButton("More Results");
+        back = new JButton("Previous Page");
+        back.setVisible(false);
+        text = new JEditorPane();
+        text.setEditable(false);
+        text.setContentType("text/html");
+        text.addHyperlinkListener(new LinkFollower());
+
+        JScrollPane scroll = new JScrollPane(text, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
+                JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+        pane.add(scroll);
+        pane.add(next);
+        pane.add(back);
+        next.addActionListener(this);
+        back.addActionListener(this);
+        textBox = new JTextField();
+        textBox.addKeyListener(this);
+
+        pane.add(textBox);
+
+        SpringLayout.Constraints textBoxConstraints = layout.getConstraints(textBox);
+        xSpring = Spring.constant(0); // Spring we’ll use for X
+        ySpring = Spring.constant(0); // Spring we’ll use for Y
+        wSpring = Spring.constant(frame.getBounds().width); // Spring we’ll use for width
+        hSpring = Spring.constant(30); // Strut we’ll use for height
+        textBoxConstraints.setWidth(wSpring); // Set component width constraint
+        textBoxConstraints.setHeight(hSpring);
+        textBoxConstraints.setX(xSpring); // Set the WEST edge constraint
+        textBoxConstraints.setY(ySpring);
+
+        SpringLayout.Constraints scrollConstraints = layout.getConstraints(scroll);
+        xSpring = Spring.constant(0); // Spring we’ll use for X
+        ySpring = Spring.constant(30); // Spring we’ll use for Y
+        wSpring = Spring.constant(frame.getBounds().width); // Spring we’ll use for width
+        hSpring = Spring.constant(450); // Strut we’ll use for height
+        scrollConstraints.setWidth(wSpring); // Set component width constraint
+        scrollConstraints.setHeight(hSpring);
+        scrollConstraints.setX(xSpring); // Set the WEST edge constraint
+        scrollConstraints.setY(ySpring); // Set the NORTH edge constraint
+
+        SpringLayout.Constraints backBtnConstraints = layout.getConstraints(back);
+        xSpring = Spring.constant(50); // Spring we’ll use for X
+        ySpring = Spring.constant(480); // Spring we’ll use for Y
+        wSpring = Spring.constant(200); // Spring we’ll use for width
+        hSpring = Spring.constant(30); // Strut we’ll use for height
+        backBtnConstraints.setWidth(wSpring); // Set component width constraint
+        backBtnConstraints.setHeight(hSpring);
+        backBtnConstraints.setX(xSpring); // Set the WEST edge constraint
+        backBtnConstraints.setY(ySpring);
+
+        SpringLayout.Constraints nextBtnConstraints = layout.getConstraints(next);
+        xSpring = Spring.constant(250); // Spring we’ll use for X
+        ySpring = Spring.constant(480); // Spring we’ll use for Y
+        wSpring = Spring.constant(200); // Spring we’ll use for width
+        hSpring = Spring.constant(30); // Strut we’ll use for height
+        nextBtnConstraints.setWidth(wSpring); // Set component width constraint
+        nextBtnConstraints.setHeight(hSpring);
+        nextBtnConstraints.setX(xSpring); // Set the WEST edge constraint
+        nextBtnConstraints.setY(ySpring);
+        frame.setVisible(true);
+    }
+
+    /**
+     * method showResults
+     * desplay results by ClientCallbackHandler
+     *
+     * @param results
+     */
+    protected static void showResults(String results) {
+        text.setText(results);
+    }
+
+    /**
+     * method setKey
+     * Get the key from user via an inputDialog and
+     * store it in the properties file
+     */
+    protected void setKey() {
+        File propertyFile;
+
+        AsynchronousClient.key = JOptionPane.showInputDialog(null, "Enter the license Key");
+        if (AsynchronousClient.key == null) {
+            setKey();
+        }
+        OutputStream propOut;
+        try {
+            String workingDir = System.getProperty("user.dir");
+            propertyFile =
+                    new File(
+                            workingDir + File.separator + "samples" + File.separator +
+                    "/key.properties");
+            propOut = new FileOutputStream(propertyFile);
+
+            AsynchronousClient.prop.setProperty("gglKey", AsynchronousClient.key);
+            AsynchronousClient.prop.store(propOut, "License Key");
+        } catch (FileNotFoundException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * method keyTyped
+     * fires when user typing in TextField textBox
+     * act when detects space and Enter key only
+     *
+     * @param e
+     */
+    public void keyTyped(KeyEvent e) {
+        System.out.println("inside");
+        int event = e.getKeyChar();
+
+        if (event == KeyEvent.VK_SPACE || event == KeyEvent.VK_ENTER) {
+            AsynchronousClient.search = textBox.getText().trim();
+            AsynchronousClient.search.trim();
+            System.out.println(textBox.getText());
+            if (!AsynchronousClient.prevSearch.equals(AsynchronousClient.search)) {
+                AsynchronousClient.doSearch = true;
+            }
+        }
+    }
+
+    public void keyPressed(KeyEvent e) {
+
+    }
+
+    public void keyReleased(KeyEvent s) {
+
+    }
+
+    /**
+     * method actionPerformed
+     * Detects menu click events and btn click events
+     * set flags
+     * @param e
+     */
+    public void actionPerformed(ActionEvent e) {
+        int i;
+
+        System.out.println("action is " + e.getSource());
+        if (e.getSource() == next) {
+            i = Integer.parseInt(AsynchronousClient.maxResults);
+            AsynchronousClient.StartIndex = AsynchronousClient.StartIndex + i;
+            back.setVisible(true);
+            AsynchronousClient.doSearch = true;
+        }
+        if (e.getSource() == back) {
+            if (AsynchronousClient.StartIndex != 0) {
+                i = Integer.parseInt(AsynchronousClient.maxResults);
+                AsynchronousClient.StartIndex = AsynchronousClient.StartIndex - i;
+                if (AsynchronousClient.StartIndex == 0) {
+                    back.setVisible(false);
+                }
+                AsynchronousClient.doSearch = true;
+            }
+        }
+        if (e.getSource() == mnuMaxResults) {
+            do {
+                System.out.println("come to the place");
+                AsynchronousClient.maxResults =
+                        JOptionPane.showInputDialog(null,
+                            "Enter the number of maximum results per page (Maximum allowed
is 10)");
+            } while (Integer.parseInt(AsynchronousClient.maxResults) > 10 ||
+                    Integer.parseInt(AsynchronousClient.maxResults) < 0);
+        }
+        if (e.getSource() == mnuKey) {
+            setKey();
+        }
+    }
+
+    /**
+     * method run
+     * check the flag doSearch
+     * if it's set, call sendMsg method
+     */
+    public void run() {
+        while (true) {
+            AsynchronousClient.search.toString().trim();
+            if (AsynchronousClient.doSearch == true) {
+                if (!AsynchronousClient.search.equals(AsynchronousClient.prevSearch)) {
+                    AsynchronousClient.StartIndex = 0;
+                }
+                try {
+                    AsynchronousClient.doSearch = false;
+                    AsynchronousClient.sendMsg();
+                } catch (AxisFault axisFault) {
+                    axisFault.printStackTrace();
+                }
+            }
+            try {
+                Thread.sleep(50);
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+}
\ No newline at end of file

Added: webservices/axis/trunk/java/modules/samples/src/sample/google/search/LinkFollower.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/src/sample/google/search/LinkFollower.java?rev=179743&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/samples/src/sample/google/search/LinkFollower.java
(added)
+++ webservices/axis/trunk/java/modules/samples/src/sample/google/search/LinkFollower.java
Fri Jun  3 01:12:48 2005
@@ -0,0 +1,148 @@
+/*
+ * Copyright 2001-2004 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.
+ */
+
+package sample.google.search;
+
+import javax.swing.*;
+import javax.swing.event.HyperlinkEvent;
+import javax.swing.event.HyperlinkListener;
+import java.awt.*;
+import java.io.IOException;
+
+/**
+ * class LinkFollower
+ * Listen to HyperLink actions and Open Simple web browser to open URLs
+ *
+ * @author Gayan Asanka  (gayan@opensource.lk)
+ */
+class LinkFollower implements HyperlinkListener, Runnable {
+
+
+    /**
+     * Flag to used by the thread, If set, thread opens a URL in the Simple Web Browser
+     */
+    protected static boolean showURL = false;
+
+    /**
+     * Used as the root of the Simple web Browser, only one instance is needed
+     */
+    private static JEditorPane jep;
+
+    /**
+     * Used for the Simple web Browser, only one instance is needed
+     */
+    private static JFrame f;
+    private static JPanel contentPane;
+    private static JScrollPane scrollPane;
+
+    /**
+     * Flag to prevent duplicating Building of the Simple web browser Window
+     */
+    private static boolean builded = false;
+
+    /**
+     * Keep the URL of the last Hyperlink click event
+     */
+    private static String currentURL;
+
+    /**
+     * Constructor
+     */
+    public LinkFollower() {
+
+    }
+
+    /**
+     * method hyperlinkUpdate
+     * The action is to show the page of the URL the user clicked on.
+     *
+     * @param evt the event. We only care when its type is ACTIVATED.
+     */
+    public void hyperlinkUpdate(HyperlinkEvent evt) {
+        if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
+
+            /** Window is not built yet, so build it */
+
+            if (builded == false) {
+                buildURLWindaw();
+            }
+            try {
+                currentURL = evt.getURL().toString();
+                System.out.println(currentURL);
+                //System.out.println("Going to " + currentURL);
+                showURL = true;
+
+            } catch (Exception e) {
+                System.out.println("ERROR: Trouble fetching url");
+            }
+        }
+    }
+
+    /**
+     * method setPage
+     * Open the URL in the simple web browser window by replacing the previous one
+     */
+    protected void setPage() {
+        jep.setEditable(false);
+        jep.addHyperlinkListener(new LinkFollower());
+        f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
+
+        contentPane.setLayout(new BorderLayout());
+        contentPane.setPreferredSize(new Dimension(400, 100));
+        contentPane.add(scrollPane, BorderLayout.CENTER);
+
+        f.pack();
+        f.setSize(640, 360);
+        f.setVisible(true);
+        try {
+            jep.setPage(currentURL);
+            //jep.setPage("http://www.google.com/");
+        } catch (IOException e) {
+            System.err.println(e);
+        }
+    }
+
+    /**
+     * method buildURLWindow
+     * Build the Simple Web Broser but not displayed
+     */
+    private void buildURLWindaw() {
+        builded = true;
+        jep = new JEditorPane();
+        f = new JFrame("Simple Web Browser");
+        contentPane = (JPanel) f.getContentPane();
+        scrollPane = new JScrollPane(jep);
+    }
+
+    /**
+     * method run
+     * check the showURL flag and if set, open the url in simple Web Browser
+     */
+    public void run() {
+        while (true) {
+            if (showURL == true) {
+                this.setPage();
+                showURL = false;
+            }
+            try {
+                Thread.sleep(100);
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+}
+

Added: webservices/axis/trunk/java/modules/samples/src/sample/google/search/key.properties
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/src/sample/google/search/key.properties?rev=179743&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/samples/src/sample/google/search/key.properties (added)
+++ webservices/axis/trunk/java/modules/samples/src/sample/google/search/key.properties Fri
Jun  3 01:12:48 2005
@@ -0,0 +1,3 @@
+#License Key
+#Wed Jun 01 15:28:16 LKT 2005
+Key=F0wt5EFQFHKxTs+rl3P+27o6D112BTWd



Mime
View raw message