Ejemplo n.º 1
0
    private boolean verifyFile(File aFile, List theFileAttribList) {
      Iterator it = theFileAttribList.iterator();
      int theIndex = 0;
      String theMD5 = null;
      String theVal = null;
      long theSize;
      while (it.hasNext()) {
        try {
          theVal = (String) it.next();
          if (theIndex == 6) {
            theMD5 = MD5.getMD5(aFile);
            if (!theVal.equals(MD5.getMD5(aFile))) {
              return false;
            }
            break;
          }
          if (theIndex == 5) {
            theSize = aFile.length();
            if (theSize != Long.parseLong(theVal)) {
              return false;
            }
          }

        } catch (Exception E) {
          E.printStackTrace();
        }
        theIndex++;
      }
      return true;
    }
Ejemplo n.º 2
0
    private void downloadFile(String theFilename) {
      OutputStream outStream = null;
      InputStream is = null;
      try {
        myMessage.stateChanged("DOWNLOADLOCALBASE");
        String theFile =
            myProperties
                .getProperty("BASEURL")
                .substring(0, myProperties.getProperty("BASEURL").lastIndexOf("/"));

        theFile = theFile + "/" + (new URI((theFilename).replaceAll(" ", "%20")));
        URLConnection uCon = null;
        int size = 1024;
        URL Url;
        byte[] buf;
        int ByteRead, ByteWritten = 0;
        Url = new URL(theFile);
        String theLocalFilename = (String) myFileList.get(theFilename).get(2);
        long theFileSize = Long.parseLong((String) myFileList.get(theFilename).get(5));
        outStream =
            new BufferedOutputStream(
                new FileOutputStream(
                    myProperties.getProperty("LOCALBASEDIR")
                        + "\\"
                        + myFileList.get(theFilename).get(2)));

        uCon = Url.openConnection();
        is = uCon.getInputStream();
        buf = new byte[size];
        while ((ByteRead = is.read(buf)) != -1) {
          outStream.write(buf, 0, ByteRead);
          ByteWritten += ByteRead;
          myMessage.setProgress((int) getPercentage(ByteWritten, theFileSize));
          // System.out.println(ByteWritten);
        }
        myMessage.messageChanged("Downloaded Successfully.");
        myMessage.messageChanged(
            "File name:\""
                + theLocalFilename
                + "\"\nNo ofbytes :"
                + ByteWritten
                + "Filesize ="
                + theFileSize);
      } catch (Exception e) {
        e.printStackTrace();
      } finally {
        try {
          is.close();
          outStream.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
Ejemplo n.º 3
0
  /**
   * Searches for contact ids in history of recent messages.
   *
   * @param provider
   * @param after
   * @return
   */
  List<String> getRecentContactIDs(String provider, Date after) {
    List<String> res = new ArrayList<String>();

    try {
      History history = getHistory();

      if (history != null) {
        Iterator<HistoryRecord> recs = history.getReader().findLast(NUMBER_OF_MSGS_IN_HISTORY);
        SimpleDateFormat sdf = new SimpleDateFormat(HistoryService.DATE_FORMAT);

        while (recs.hasNext()) {
          HistoryRecord hr = recs.next();

          String contact = null;
          String recordProvider = null;
          Date timestamp = null;

          for (int i = 0; i < hr.getPropertyNames().length; i++) {
            String propName = hr.getPropertyNames()[i];

            if (propName.equals(STRUCTURE_NAMES[0])) recordProvider = hr.getPropertyValues()[i];
            else if (propName.equals(STRUCTURE_NAMES[1])) contact = hr.getPropertyValues()[i];
            else if (propName.equals(STRUCTURE_NAMES[2])) {
              try {
                timestamp = sdf.parse(hr.getPropertyValues()[i]);
              } catch (ParseException e) {
                timestamp = new Date(Long.parseLong(hr.getPropertyValues()[i]));
              }
            }
          }

          if (recordProvider == null || contact == null) continue;

          if (after != null && timestamp != null && timestamp.before(after)) continue;

          if (recordProvider.equals(provider)) res.add(contact);
        }
      }
    } catch (IOException ex) {
      logger.error("cannot create recent_messages history", ex);
    }

    return res;
  }
Ejemplo n.º 4
0
 private Object createObject(
     Node node, String name, String classPackage, String type, String value, boolean setProperty) {
   Bean parentBean = null;
   if (beansStack.size() > 0) parentBean = (Bean) beansStack.peek();
   Object object = null;
   // param is either an XSD type or a bean,
   // check if it can be converted to an XSD type
   XSDatatype dt = null;
   try {
     dt = DatatypeFactory.getTypeByName(type);
   } catch (DatatypeException dte) {
     // the type is not a valid XSD data type
   }
   // convert null value to default
   if ((dt != null) && (value == null)) {
     Class objType = dt.getJavaObjectType();
     if (objType == String.class) value = "";
     else if ((objType == java.math.BigInteger.class)
         || (objType == Long.class)
         || (objType == Integer.class)
         || (objType == Short.class)
         || (objType == Byte.class)) value = "0";
     else if ((objType == java.math.BigDecimal.class)
         || (objType == Double.class)
         || (objType == Float.class)) value = "0.0";
     else if (objType == Boolean.class) value = "false";
     else if (objType == java.util.Date.class) value = DateUtils.getCurrentDate();
     else if (objType == java.util.Calendar.class) value = DateUtils.getCurrentDateTime();
   }
   //  check whether the type was converted to an XSD datatype
   if ((dt != null) && dt.isValid(value, null)) {
     // create and return an XSD Java object (e.g. String, Integer, Boolean, etc)
     object = dt.createJavaObject(value, null);
     if (object instanceof java.util.Calendar) {
       // check that the object is truly a Calendar
       // because DatatypeFactory converts xsd:date
       // types to GregorianCalendar instead of Date.
       if (type.equals("date")) {
         java.text.DateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd");
         try {
           object = df.parse(value);
         } catch (java.text.ParseException pe) {
           object = new java.util.Date();
         }
       }
     }
   } else {
     // Create a bean object
     if (topLevelBean == null) topLevelBean = parentBean;
     object = pushBeanOnStack(classPackage, type);
     // Check fields to see if this property is the 'value' for the object
     Field[] fields = object.getClass().getDeclaredFields();
     for (int i = 0; i < fields.length; i++) {
       if (fields[i].isAnnotationPresent(ObjectXmlAsValue.class)) {
         try {
           StringBuffer fieldName = new StringBuffer(fields[i].getName());
           char c = fieldName.charAt(0);
           if (c >= 'a' && c <= 'z') {
             c += 'A' - 'a';
           }
           fieldName.setCharAt(0, c);
           fieldName.insert(0, "set");
           Method method =
               object
                   .getClass()
                   .getMethod(fieldName.toString(), new Class[] {fields[i].getType()});
           method.invoke(object, value);
           break;
         } catch (Exception e) {
           System.err.println(e.getMessage());
         }
       }
     }
     NamedNodeMap nodeAttrs = node.getAttributes();
     // iterate attributes and set field values for property attributes
     for (int i = 0; i < nodeAttrs.getLength(); i++) {
       String nodePrefix = nodeAttrs.item(i).getPrefix();
       if (nodePrefix.equals(nsPrefix)) {
         String nodeName = nodeAttrs.item(i).getLocalName();
         String nodeValue = nodeAttrs.item(i).getNodeValue();
         try {
           Field field = object.getClass().getDeclaredField(nodeName);
           if (field.isAnnotationPresent(ObjectXmlAsAttribute.class)) {
             StringBuffer fieldName = new StringBuffer(field.getName());
             char c = fieldName.charAt(0);
             if (c >= 'a' && c <= 'z') {
               c += 'A' - 'a';
             }
             fieldName.setCharAt(0, c);
             fieldName.insert(0, "set");
             Method method =
                 object.getClass().getMethod(fieldName.toString(), new Class[] {field.getType()});
             if (field.getType() == String.class) method.invoke(object, nodeValue);
             else if (field.getType() == Boolean.TYPE)
               method.invoke(object, StringUtils.strToBool(nodeValue, "true"));
             else if (field.getType() == Byte.TYPE)
               method.invoke(object, Byte.valueOf(nodeValue).byteValue());
             else if (field.getType() == Character.TYPE)
               method.invoke(object, Character.valueOf(nodeValue.charAt(0)));
             else if (field.getType() == Double.TYPE)
               method.invoke(object, Double.valueOf(nodeValue).doubleValue());
             else if (field.getType() == Float.TYPE)
               method.invoke(object, Float.valueOf(nodeValue).floatValue());
             else if (field.getType() == Integer.TYPE)
               method.invoke(object, Integer.valueOf(nodeValue).intValue());
             else if (field.getType() == Long.TYPE)
               method.invoke(object, Long.valueOf(nodeValue).longValue());
             else if (field.getType() == Short.TYPE)
               method.invoke(object, Short.valueOf(nodeValue).shortValue());
           }
         } catch (Exception e) {
           System.err.println(e.getMessage());
         }
       }
     }
   }
   if ((parentBean != null) && (setProperty)) {
     parentBean.setProperty(name, object);
   }
   return object;
 }
Ejemplo n.º 5
0
 /** setAsText for long calls Long.valueOf(). * */
 public void setAsText(String val) throws IllegalArgumentException {
   setValue(Long.valueOf(val));
 }
Ejemplo n.º 6
0
    private boolean getStatus(long theFileSize) {
      URL theURL = null;
      ;
      try {
        theURL = new URL(myProperties.getProperty("BASEURL"));
      } catch (MalformedURLException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }
      ;

      String data = "";
      boolean theStatus = false;
      try {
        data =
            URLEncoder.encode("filelocation", "UTF-8")
                + "="
                + URLEncoder.encode(myProperties.getProperty("REMOTEBASEDIR"), "UTF-8");
        data +=
            "&"
                + URLEncoder.encode("fileprocess", "UTF-8")
                + "="
                + URLEncoder.encode("STATUS", "UTF-8");
        data +=
            "&"
                + URLEncoder.encode("filename", "UTF-8")
                + "="
                + URLEncoder.encode(myProperties.getProperty("REMOTEDOWNLOADFILENAME"), "UTF-8");

        URLConnection conn = theURL.openConnection();
        conn.setDoOutput(true);
        OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
        wr.write(data);
        wr.flush();
        // Get the response
        BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line2;
        CSV theParser = new CSV('|');
        while (((line2 = rd.readLine()) != null) && !isCancelled()) {
          List list = theParser.parse(line2);
          System.out.println((String) list.get(0));
          if (((String) list.get(0)).equals(" Process running")) {
            theStatus = true;
            myMessage.messageChanged(
                (int) getPercentage(Long.parseLong((String) list.get(1)), theFileSize),
                "Process Running downloaded " + (String) list.get(1) + " bytes");
          }
          if (((String) list.get(0)).equals(" Process stopped")) {
            theStatus = false;
            myMessage.messageChanged(
                (int) getPercentage(Long.parseLong((String) list.get(1)), theFileSize),
                "Process Stopped File size =  " + (String) list.get(1) + " bytes");
          }
        }
        rd.close();

      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      System.out.println("theStatus =" + theStatus);
      return theStatus;
    }