Android Open Source - foodroid Update






From Project

Back to project page foodroid.

License

The source code is released under:

GNU General Public License

If you think the Android project foodroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.wmc.ReservationClient;
//from   ww w.  j  a va2s . co m
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.StringReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

import android.content.Context;

public class Update 
{
  private List<Branch> branchs=new ArrayList<Branch>();
  private List<Comment> comments=new ArrayList<Comment>();
  private List<Food> foods=new ArrayList<Food>();
  String Server;
  String[] items;
  
  public Update(Context context)
  {
      Server = context.getString(R.string.Server);
      
  }
  
  public void updatePictures(Context context)
  {
    try
    {
      String urlImage = "http://" + Server +
        "/RestaurantReservation/" + "picture/1.jpg";
        URL ulrn = new URL(urlImage);
        HttpURLConnection con = (HttpURLConnection)ulrn.openConnection();
        InputStream in = con.getInputStream();
        String fullPath = "/data/data/com.wmc.ReservationClient/";
        OutputStream out = new FileOutputStream(fullPath + "/" + "picture/1.jpg");
        byte[] buffer = new byte[1024];
        int length;
        while ((length = in.read(buffer)) != -1)
        {
          out.write(buffer, 0, length);
        }
        in.close();
        in = null;
        out.flush();
        out.close();
        out = null;  
    }
    catch(Exception ex)
    {
      
    }
        
  }
  
  public void UpdateBranche() throws Exception 
  {
        HttpClient client=new DefaultHttpClient();
        HttpGet getMethod=new HttpGet(
            "http://" + Server + "/RestaurantReservation/resources/branchlist/*");
        ResponseHandler<String> responseHandler=new BasicResponseHandler();
    try
    {
      String responseBody=client.execute(getMethod, responseHandler);
      responseBody = responseBody.replace("&lt;", "<").replace("&gt;", ">").replace("&amp;", "&");

      getWebServiceBranchs(responseBody);
      
      items = new String[branchs.size()];
      for(int i = 0; i< branchs.size(); i++)
        items[i] = branchs.get(i).name;
    } 
    catch (ClientProtocolException e) 
    {
      e.printStackTrace();
    } 
    catch (IOException e) 
    {
      e.printStackTrace();
    }    
  }
  
  void getWebServiceBranchs(String raw) throws Exception 
  {
    branchs.clear();
    
    String value = "";
    DocumentBuilder builder=DocumentBuilderFactory
        .newInstance()
        .newDocumentBuilder();
    Document doc=builder.parse(new InputSource(new StringReader(raw)));
    NodeList IDs=doc.getElementsByTagName("ID");
    
    for (int i=0;i<IDs.getLength();i++) 
    {
      Element id=(Element)IDs.item(i);
      Branch branch=new Branch();
      branchs.add(branch);
      value = "";
      for(int j=0;j<id.getChildNodes().getLength();j++)
        value += id.getChildNodes().item(j).getNodeValue();
      branch.id = value;
    }
    
    NodeList names=doc.getElementsByTagName("Name");
    
    for (int i=0;i<names.getLength();i++) 
    {
      Element name=(Element)names.item(i);
      Branch branch=branchs.get(i);
      value = "";
      for(int j=0;j<name.getChildNodes().getLength();j++)
        value += name.getChildNodes().item(j).getNodeValue();
      branch.name = value;
    }
    
    NodeList pictures=doc.getElementsByTagName("Picture");
    
    for (int i=0;i<pictures.getLength();i++) 
    {
      Element picture=(Element)pictures.item(i);
      Branch branch=branchs.get(i);
      value = "";
      for(int j=0;j<picture.getChildNodes().getLength();j++)
        value += picture.getChildNodes().item(j).getNodeValue();
      branch.picture = value;
    }
    
    NodeList tels=doc.getElementsByTagName("Tel");
    
    for (int i=0;i<tels.getLength();i++) 
    {
      Element tel=(Element)tels.item(i);
      Branch branch=branchs.get(i);
      value = "";
      for(int j=0;j<tel.getChildNodes().getLength();j++)
        value += tel.getChildNodes().item(j).getNodeValue();
      branch.tel = value;
    }
    
    NodeList addresses=doc.getElementsByTagName("Address");
    
    for (int i=0;i<addresses.getLength();i++) 
    {
      Element address=(Element)addresses.item(i);
      Branch branch=branchs.get(i);
      value = "";
      for(int j=0;j<address.getChildNodes().getLength();j++)
        value += address.getChildNodes().item(j).getNodeValue();
      branch.address = value;
    }
  }
  
  void UpdateComment() throws Exception
  {    
    HttpClient client=new DefaultHttpClient();
        HttpGet getMethod=new HttpGet(
            "http://" + Server + "/RestaurantReservation/resources/commentlist/" + "1"/*branchID*/);
        ResponseHandler<String> responseHandler=new BasicResponseHandler();
    try 
    {
      String responseBody=client.execute(getMethod, responseHandler);
      responseBody = responseBody.replace("&lt;", "<").replace("&gt;", ">").replace("&amp;", "&");

      getWebServiceComment(responseBody);
      
      String[] commentItems = new String[comments.size()];
      for(int i = 0; i< comments.size(); i++)
        commentItems[i] = comments.get(i).message;
    
    }
    catch (ClientProtocolException e) 
    {
      e.printStackTrace();
    } 
    catch (IOException e) 
    {
      e.printStackTrace();
    }
  }
  
  void getWebServiceComment(String raw) throws Exception 
  {
    comments.clear();
    
    String value = "";
    DocumentBuilder builder=DocumentBuilderFactory
        .newInstance()
        .newDocumentBuilder();
    Document doc=builder.parse(new InputSource(new StringReader(raw)));
    NodeList IDs=doc.getElementsByTagName("BranchID");
    
    for (int i=0;i<IDs.getLength();i++) 
    {
      Element id=(Element)IDs.item(i);
      Comment comment =new Comment();
      comments.add(comment);
      value = "";
      for(int j=0;j<id.getChildNodes().getLength();j++)
        value += id.getChildNodes().item(j).getNodeValue();
      comment.id = value;
    }
    
    NodeList messages=doc.getElementsByTagName("message");
    
    for (int i=0;i<messages.getLength();i++) 
    {
      Element message=(Element)messages.item(i);
      Comment comment =comments.get(i);
      value = "";
      for(int j=0;j<message.getChildNodes().getLength();j++)
        value += message.getChildNodes().item(j).getNodeValue();
      comment.message = value;
    }
    
    NodeList rates=doc.getElementsByTagName("rate");
    
    for (int i=0;i<rates.getLength();i++) 
    {
      Element rate=(Element)rates.item(i);
      Comment comment=comments.get(i);
      value = "";
      for(int j=0;j<rate.getChildNodes().getLength();j++)
        value += rate.getChildNodes().item(j).getNodeValue();
      comment.rate = value;
    }
  }
  
  void UpdateFood() throws Exception
  {
    HttpClient client=new DefaultHttpClient();
        HttpGet getMethod=new HttpGet(
            "http://" + Server + "/RestaurantReservation/resources/foodlist/" + "1"/*branchID*/);
        ResponseHandler<String> responseHandler=new BasicResponseHandler();
    try 
    {
      String responseBody=client.execute(getMethod, responseHandler);
      responseBody = responseBody.replace("&lt;", "<").replace("&gt;", ">").replace("&amp;", "&");

      getWebServiceFood(responseBody);
      
      String[] foodItems = new String[foods.size()];
      for(int i = 0; i< foods.size(); i++)
        foodItems[i] = foods.get(i).Name;
    
    }
    catch (ClientProtocolException e) 
    {
      e.printStackTrace();
    } 
    catch (IOException e) 
    {
      e.printStackTrace();
    }
  }
  
  
  void getWebServiceFood(String raw) throws Exception 
  {
    foods.clear();
    
    String value = "";
    DocumentBuilder builder=DocumentBuilderFactory
        .newInstance()
        .newDocumentBuilder();
    Document doc=builder.parse(new InputSource(new StringReader(raw)));
    NodeList IDs=doc.getElementsByTagName("BranchID");
    
    for (int i=0;i<IDs.getLength();i++) 
    {
      Element id=(Element)IDs.item(i);
      Food food=new Food();
      foods.add(food);
      value = "";
      for(int j=0;j<id.getChildNodes().getLength();j++)
        value += id.getChildNodes().item(j).getNodeValue();
      food.BranchID = value;
    }
    
    NodeList names=doc.getElementsByTagName("Name");
    
    for (int i=0;i<names.getLength();i++) 
    {
      Element name=(Element)names.item(i);
      Food food=foods.get(i);
      value = "";
      for(int j=0;j<name.getChildNodes().getLength();j++)
        value += name.getChildNodes().item(j).getNodeValue();
      food.Name = value;
    }
    
    NodeList prices=doc.getElementsByTagName("Price");
    
    for (int i=0;i<prices.getLength();i++) 
    {
      Element price=(Element)prices.item(i);
      Food food=foods.get(i);
      value = "";
      for(int j=0;j<price.getChildNodes().getLength();j++)
        value += price.getChildNodes().item(j).getNodeValue();
      food.Price = value;
    }
    
    NodeList pictures=doc.getElementsByTagName("Picture");
    
    for (int i=0;i<pictures.getLength();i++) 
    {
      Element picture=(Element)pictures.item(i);
      Food food=foods.get(i);
      value = "";
      for(int j=0;j<picture.getChildNodes().getLength();j++)
        value += picture.getChildNodes().item(j).getNodeValue();
      food.Picture = value;
    }
  }
  
  
  
}




Java Source Code List

com.adp.ADPWsSample.java
com.adp.BalanceResult.java
com.adp.ChangePasswordResponse.java
com.adp.ChangePassword.java
com.adp.GetBalanceResponse.java
com.adp.GetBalance.java
com.adp.GetStatusResponse.java
com.adp.GetStatus.java
com.adp.IncomingMessage.java
com.adp.JaxRpcMessagingServiceServiceLocator.java
com.adp.JaxRpcMessagingServiceService.java
com.adp.JaxRpcMessagingService.java
com.adp.MessageObject.java
com.adp.MessagingServiceSoapBindingStub.java
com.adp.MultiAddressMessageObject.java
com.adp.OutgoingMessage.java
com.adp.ReceiveResponse.java
com.adp.ReceiveResult.java
com.adp.Receive.java
com.adp.ReportResponse.java
com.adp.ReportResult.java
com.adp.Report.java
com.adp.Result.java
com.adp.SendMultipleResponse.java
com.adp.SendMultiple.java
com.adp.SendResponse.java
com.adp.SendResult.java
com.adp.Send.java
com.adp.StatusReportResponse.java
com.adp.StatusReportResult.java
com.adp.StatusReportType0.java
com.adp.StatusReport.java
com.sba.util.DateFields.java
com.sba.util.PersianCalendar.java
com.wmc.Registration.BranchlistResource.java
com.wmc.Registration.CommentListBean.java
com.wmc.Registration.CommentResource.java
com.wmc.Registration.CommentlistResource.java
com.wmc.Registration.FoodListResource.java
com.wmc.Registration.LoginResource.java
com.wmc.Registration.OrderBean.java
com.wmc.Registration.OrderListBean.java
com.wmc.Registration.OrderResource.java
com.wmc.Registration.RegisterResource.java
com.wmc.Registration.ReserveListBean.java
com.wmc.Registration.Settings.java
com.wmc.ReservationClient.Account.java
com.wmc.ReservationClient.BranchList.java
com.wmc.ReservationClient.BranchPage.java
com.wmc.ReservationClient.Branch.java
com.wmc.ReservationClient.Comment.java
com.wmc.ReservationClient.DatabaseHelper.java
com.wmc.ReservationClient.Favorite.java
com.wmc.ReservationClient.FoodList.java
com.wmc.ReservationClient.FoodPage.java
com.wmc.ReservationClient.Food.java
com.wmc.ReservationClient.Login.java
com.wmc.ReservationClient.Main.java
com.wmc.ReservationClient.OrderList.java
com.wmc.ReservationClient.Order.java
com.wmc.ReservationClient.Search.java
com.wmc.ReservationClient.SmsMessageReceiver.java
com.wmc.ReservationClient.Table.java
com.wmc.ReservationClient.Update.java
com.wmc.ReservationClient.Utility.java
smsserver.CommentSMS.java
smsserver.LoginSMS.java
smsserver.OrderSMS.java
smsserver.Settings.java
smsserver.SmsServer.java