Android Open Source - android_sdk X M Lfunctions






From Project

Back to project page android_sdk.

License

The source code is released under:

GNU Lesser General Public License

If you think the Android project android_sdk 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

/**
 * Copyright (c) Adroit HealthTech Pvt Ltd, All Rights Reserved.
 *///from   w  w w.  ja  va2  s  .  com
package com.qubecell.xmlparser;

import java.io.IOException;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;

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

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;


public class XMLfunctions {

  public final static Document XMLfromString(String xml){
    
    Document doc = null;
    
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        try {
          
      DocumentBuilder db = dbf.newDocumentBuilder();
      InputSource is = new InputSource();
          is.setCharacterStream(new StringReader(xml));
          
          doc = db.parse(is);          
    } catch (ParserConfigurationException e) {
      System.out.println("XML parse error: " + e.getMessage());
      return null;
    } catch (SAXException e) {
      System.out.println("Wrong XML file structure: " + e.getMessage());
            return null;
    } catch (IOException e) {
      System.out.println("I/O exeption: " + e.getMessage());
      return null;
    }
           
        return doc;
        
  }
  
  /** Returns element value
    * @param elem element (it is XML tag)
    * @return Element value otherwise empty String
    */
   public final static String getElementValue( Node elem ) {
       Node kid;
       if( elem != null){
           if (elem.hasChildNodes()){
               for( kid = elem.getFirstChild(); kid != null; kid = kid.getNextSibling() ){
                   if( kid.getNodeType() == Node.TEXT_NODE  ){
                       return kid.getNodeValue();
                   }
               }
           }
       }
       return "";
   }
     
   public static String getXML(){   
      String line = null;

      try {
        
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost("http://p-xr.com/xml");

        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        line = EntityUtils.toString(httpEntity);
        
      } catch (UnsupportedEncodingException e) {
        line = "<results status=\"error\"><msg>Can't connect to server</msg></results>";
      } catch (MalformedURLException e) {
        line = "<results status=\"error\"><msg>Can't connect to server</msg></results>";
      } catch (IOException e) {
        line = "<results status=\"error\"><msg>Can't connect to server</msg></results>";
      }

      return line;
  }
   
  public static int numResults(Document doc){    
    Node results = doc.getDocumentElement();
    int res = -1;
    
    try{
      res = Integer.valueOf(results.getAttributes().getNamedItem("count").getNodeValue());
    }catch(Exception e ){
      res = -1;
    }
    return res;
  }

  public static String getValue(Element e, String str) {  
    
    NodeList n = e.getElementsByTagName(str);
    return XMLfunctions.getElementValue(n.item(0));
    
  }
}




Java Source Code List

com.qubecell.beans.BaseBean.java
com.qubecell.beans.CheckStatusRespBean.java
com.qubecell.beans.EventChargeRespBean.java
com.qubecell.beans.MsisdnRespBean.java
com.qubecell.beans.OperatorDetails.java
com.qubecell.beans.OperatorsRespBean.java
com.qubecell.beans.ResponseBaseBean.java
com.qubecell.beans.SendOTPRespBean.java
com.qubecell.beans.ValidateOTPRespBean.java
com.qubecell.constants.ApplicationActivities.java
com.qubecell.constants.CheckstatusServerRespCode.java
com.qubecell.constants.ConstantStrings.java
com.qubecell.constants.EventChargeServerRespCode.java
com.qubecell.constants.HttpConstant.java
com.qubecell.constants.IntentConstant.java
com.qubecell.constants.MerchantData.java
com.qubecell.constants.MessageResponseCode.java
com.qubecell.constants.MobileOperators.java
com.qubecell.constants.MsisdnServerRespCode.java
com.qubecell.constants.NetworkResponseCode.java
com.qubecell.constants.NetworkResponse.java
com.qubecell.constants.NetworkURL.java
com.qubecell.constants.PaymentResult.java
com.qubecell.constants.ProductIds.java
com.qubecell.constants.QubecellResult.java
com.qubecell.constants.SendOTPServerRespCode.java
com.qubecell.constants.ServerCommand.java
com.qubecell.constants.ThemeConfigurationVariables.java
com.qubecell.constants.ValidateOTPServerRespCode.java
com.qubecell.constants.WidgetsTagName.java
com.qubecell.elogger.ELogger.java
com.qubecell.network.AsyncClient.java
com.qubecell.network.NetworkController.java
com.qubecell.receivers.SMSReceiver.java
com.qubecell.smsmgr.QubecellSMSManager.java
com.qubecell.ui.BaseActivity.java
com.qubecell.ui.QubecellActivity.java
com.qubecell.ui.ResultActivity.java
com.qubecell.ui.SelectOperatorActivity.java
com.qubecell.ui.ValidateOTPActivity.java
com.qubecell.utility.CommonUtility.java
com.qubecell.utility.ImageBase64.java
com.qubecell.xmlparser.XMLParser.java
com.qubecell.xmlparser.XMLfunctions.java
com.qubecelltestapp.ui.MerchantActivity.java