@Override
 public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
     throws SAXException {
   if ("message".equals(qName)) {
     entry = new EntryImpl();
     for (int i = 0; i < atts.getLength(); i++) {
       if ("time".equals(atts.getQName(i))) {
         try {
           entry.setTime(EmpathyParser.TIME_FORMAT.parse(atts.getValue(i)));
         } catch (ParseException ex) {
           LOG.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
         }
       }
       if ("name".equals(atts.getQName(i))) {
         entry.setName(atts.getValue(i));
       }
       if ("type".equals(atts.getQName(i))) {
         entry.setType(atts.getValue(i));
       }
       if ("id".equals(atts.getQName(i))) {
         entry.setId(atts.getValue(i));
       }
     }
   }
 }
Ejemplo n.º 2
0
 @Override
 public int compare(IValue v1, IValue v2) {
   try {
     Date d1 = dateFormat.parse(v1.toString());
     Date d2 = dateFormat.parse(v2.toString());
     return d1.compareTo(d2);
   } catch (ParseException ex) {
     throw new ChaseException("Unable to parse float value " + ex.getLocalizedMessage());
   }
 }
 /** Parse a given String into a Date. */
 @SuppressLint("SimpleDateFormat")
 public static Date stringToDate(String rawDate) {
   DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
   Date date = null;
   try {
     date = dateFormat.parse(rawDate);
   } catch (ParseException e) {
     Log.e(TAG, "stringToDate: " + e.getClass() + ": " + e.getLocalizedMessage());
   }
   return date;
 }
Ejemplo n.º 4
0
 /**
  * @see
  *     org.argouml.uml.diagram.ui.FigNodeModelElement#textEdited(org.tigris.gef.presentation.FigText)
  */
 protected void textEdited(FigText ft) throws PropertyVetoException {
   super.textEdited(ft);
   Object classifier = getOwner();
   if (classifier == null) {
     return;
   }
   int i = new Vector(getAttributesFig().getFigs()).indexOf(ft);
   if (i != -1) {
     highlightedFigText = (CompartmentFigText) ft;
     highlightedFigText.setHighlighted(true);
     try {
       Object attribute = highlightedFigText.getOwner();
       ParserDisplay.SINGLETON.parseAttributeFig(
           classifier, attribute, highlightedFigText.getText().trim());
       ProjectBrowser.getInstance().getStatusBar().showStatus("");
     } catch (ParseException pe) {
       String msg = "statusmsg.bar.error.parsing.attribute";
       Object[] args = {pe.getLocalizedMessage(), new Integer(pe.getErrorOffset())};
       ProjectBrowser.getInstance().getStatusBar().showStatus(Translator.messageFormat(msg, args));
     }
     return;
   }
   i = new Vector(getOperationsFig().getFigs()).indexOf(ft);
   if (i != -1) {
     highlightedFigText = (CompartmentFigText) ft;
     highlightedFigText.setHighlighted(true);
     try {
       Object operation = highlightedFigText.getOwner();
       ParserDisplay.SINGLETON.parseOperationFig(
           classifier, operation, highlightedFigText.getText().trim());
       ProjectBrowser.getInstance().getStatusBar().showStatus("");
     } catch (ParseException pe) {
       String msg = "statusmsg.bar.error.parsing.operation";
       Object[] args = {pe.getLocalizedMessage(), new Integer(pe.getErrorOffset())};
       ProjectBrowser.getInstance().getStatusBar().showStatus(Translator.messageFormat(msg, args));
     }
     return;
   }
 }
 /*
  * @see org.argouml.uml.notation.NotationProvider#parse(java.lang.Object, java.lang.String)
  */
 public void parse(Object modelElement, String text) {
   try {
     parseStateBody(modelElement, text);
   } catch (ParseException pe) {
     String msg = "statusmsg.bar.error.parsing.statebody";
     Object[] args = {
       pe.getLocalizedMessage(), Integer.valueOf(pe.getErrorOffset()),
     };
     ArgoEventPump.fireEvent(
         new ArgoHelpEvent(
             ArgoEventTypes.HELP_CHANGED, this, Translator.messageFormat(msg, args)));
   }
 }
Ejemplo n.º 6
0
 @SeekBarProgressChange(resName = "seekBar")
 void onSeekBarChanged(int progress) {
   if (mCursor != null) {
     if (progress < mCursor.getCount()) {
       mCursor.moveToPosition(progress);
       taskText.setTextTitle(mCursor.getString(1));
       taskText.setTextRest(mCursor.getString(2));
       try {
         timestamp.setText(timeFormatter.format(dbTimeParser.parse(mCursor.getString(3))));
       } catch (ParseException e) {
         Log.d("nononsenseapps time", e.getLocalizedMessage());
       }
     }
   }
 }
 @Override
 public void parse(Object modelElement, String text) {
   try {
     parseEnumerationLiteralFig(
         Model.getFacade().getEnumeration(modelElement), modelElement, text);
   } catch (ParseException pe) {
     String msg = "statusmsg.bar.error.parsing.enumeration-literal";
     Object[] args = {
       pe.getLocalizedMessage(), Integer.valueOf(pe.getErrorOffset()),
     };
     ArgoEventPump.fireEvent(
         new ArgoHelpEvent(
             ArgoEventTypes.HELP_CHANGED, this, Translator.messageFormat(msg, args)));
   }
 }
 @Override
 public Date deserialize(JsonElement element, Type type, JsonDeserializationContext arg2)
     throws JsonParseException {
   try {
     if (element == null || TextUtils.isEmpty(element.getAsString())) {
       return new Date();
     } else {
       String dateString = element.getAsString();
       if (dateString.length() > 19) {
         dateString = dateString.substring(0, 19);
       }
       return df.parse(dateString);
     }
   } catch (ParseException e) {
     Log.e("DateTypeAdapter", e.getLocalizedMessage());
     return new Date();
   }
 }
Ejemplo n.º 9
0
 private void extractVersion(String linha) {
   Pattern p =
       Pattern.compile("(1000 OK:) +(.*) (Version:) +((\\d+)\\.(\\d+)\\.(\\d+)) +\\((.+)\\)");
   Matcher m = p.matcher(linha);
   if (m.find()) {
     this.setDirectorName(m.group(2));
     this.setDirectorMajorVersion(Integer.parseInt(m.group(5)));
     this.setDirectorMinorVersion(Integer.parseInt(m.group(6)));
     this.setDirectorRevisionVersion(Integer.parseInt(m.group(7)));
     SimpleDateFormat sdf = new SimpleDateFormat("dd MMMM yyyy", Locale.US);
     try {
       this.setDirectorRelease(sdf.parse(m.group(8)));
     } catch (ParseException ex) {
       this.logger.error(ex.getLocalizedMessage());
       this.setDirectorRelease(new Date());
     }
   }
 }
Ejemplo n.º 10
0
  private NewsItem parseInfo(Element item) {

    NewsItem tempItem = new NewsItem();

    tempItem.setTitle(item.getElementsByTagName("title").item(0).getTextContent());
    tempItem.setLink(item.getElementsByTagName("link").item(0).getTextContent());

    try {
      tempItem.setPubDate(
          new SimpleDateFormat("EEE, dd MMM yyyy HH:mm z")
              .parse(
                  item.getElementsByTagName("pubDate")
                      .item(0)
                      .getTextContent()
                      .replaceAll("\\p{Cntrl}", "")));
    } catch (ParseException e) {
      System.out.println("NewsFeed: parseInfo Error parsing date-> " + e.getLocalizedMessage());
      e.printStackTrace();
    }

    String tmpDesc = item.getElementsByTagName("description").item(0).getTextContent();
    int imgStartIndex = tmpDesc.indexOf("<img");
    System.out.println("Start of img tag: " + imgStartIndex);

    if (imgStartIndex != -1) {

      int imgStopIndex = tmpDesc.indexOf("/>", imgStartIndex);
      System.out.println("Sto of img tag: " + imgStopIndex);
      String imageTag = tmpDesc.substring(imgStartIndex + 5, imgStopIndex - 1);
      tmpDesc = tmpDesc.substring(imgStopIndex + 2);
      imgStartIndex = imageTag.indexOf("src=\"");
      imgStopIndex = imageTag.indexOf("\" ", imgStartIndex);
      String imageSrc = imageTag.substring(imgStartIndex + 5, imgStopIndex);
      System.out.println("Image Link: " + imageSrc);
      tempItem.setImage(imageSrc);
    }

    tempItem.setDescription(tmpDesc);

    return tempItem;
  }
Ejemplo n.º 11
0
  public Map<String, Object> disconnectEvent(String inode, String startDateStr, String endDateStr)
      throws DotRuntimeException, PortalException, SystemException, DotDataException,
          DotSecurityException, java.text.ParseException {

    WebContext ctx = WebContextFactory.get();
    HttpServletRequest request = ctx.getHttpServletRequest();

    // Retrieving the current user
    User user = userAPI.getLoggedInUser(request);
    boolean respectFrontendRoles = true;

    Map<String, Object> eventMap = new HashMap<String, Object>();
    List<String> disconnectEventErrors = new ArrayList<String>();

    String inodeStr = (InodeUtils.isSet(inode) ? inode : "");
    Contentlet contentlet = new Contentlet();
    if (InodeUtils.isSet(inodeStr)) {
      contentlet = contAPI.find(inodeStr, user, false);
    }
    if (InodeUtils.isSet(contentlet.getInode())) {
      Event ev = null;
      try {
        ev = eventAPI.find(contentlet.getIdentifier(), false, user, respectFrontendRoles);
      } catch (Exception e) {
        disconnectEventErrors.add(e.getLocalizedMessage());
      } finally {
        if (disconnectEventErrors.size() > 0) {
          eventMap.put("disconnectEventErrors", disconnectEventErrors);
        }
      }

      if (ev != null) {
        Date startDate = null;
        Date endDate = null;

        try {
          if (UtilMethods.isSet(startDateStr)) {
            String date = dateFormat.format(dateFormat2.parse(startDateStr));
            startDate = dateFormat.parse(date);
          }
          if (UtilMethods.isSet(endDateStr)) {
            String date = dateFormat.format(dateFormat2.parse(endDateStr));
            endDate = dateFormat.parse(date);
          }

        } catch (java.text.ParseException pe) {
          disconnectEventErrors.add(pe.getLocalizedMessage());
        } finally {
          if (disconnectEventErrors.size() > 0) {
            eventMap.put("disconnectEventErrors", disconnectEventErrors);
          }
        }

        if (startDate != null && endDate != null) {
          Calendar originalStartDate = Calendar.getInstance();
          Calendar originalEndDate = Calendar.getInstance();
          Calendar newStartDate = Calendar.getInstance();
          Calendar newEndDate = Calendar.getInstance();
          originalStartDate.setTime(ev.getStartDate());
          originalEndDate.setTime(ev.getEndDate());
          newStartDate.setTime(startDate);
          newEndDate.setTime(endDate);

          originalStartDate.set(Calendar.YEAR, newStartDate.get(Calendar.YEAR));
          originalStartDate.set(Calendar.MONTH, newStartDate.get(Calendar.MONTH));
          originalStartDate.set(Calendar.DAY_OF_MONTH, newStartDate.get(Calendar.DAY_OF_MONTH));

          originalEndDate.set(Calendar.YEAR, newEndDate.get(Calendar.YEAR));
          originalEndDate.set(Calendar.MONTH, newEndDate.get(Calendar.MONTH));
          originalEndDate.set(Calendar.DAY_OF_MONTH, newEndDate.get(Calendar.DAY_OF_MONTH));

          Event newEvent = null;

          try {
            boolean autoCom = false;
            try {
              autoCom = DbConnectionFactory.getConnection().getAutoCommit();
            } catch (Exception e) {
              throw new DotDataException(e.getMessage());
            }
            if (autoCom) {
              HibernateUtil.startTransaction();
            }
            newEvent =
                eventAPI.disconnectEvent(
                    ev, user, originalStartDate.getTime(), originalEndDate.getTime());
            eventMap = newEvent.getMap();
            // Loading categories
            List<Map<String, Object>> categoryMaps = new ArrayList<Map<String, Object>>();
            List<Category> eventCategories =
                categoryAPI.getParents(newEvent, user, respectFrontendRoles);
            for (Category cat : eventCategories) {
              categoryMaps.add(cat.getMap());
            }
            eventMap.put("categories", categoryMaps);
            eventMap.put("rating", RatingAPI.getAverageRating(newEvent.getIdentifier()));
            eventMap.put("votes", RatingAPI.getRatingVotesNumber(newEvent.getIdentifier()));
            eventMap.put(
                "hasReadPermission",
                perAPI.doesUserHavePermission(
                    newEvent, PermissionAPI.PERMISSION_READ, user, respectFrontendRoles));
            eventMap.put(
                "hasWritePermission",
                perAPI.doesUserHavePermission(
                    newEvent, PermissionAPI.PERMISSION_WRITE, user, respectFrontendRoles));
            eventMap.put(
                "hasPublishPermission",
                perAPI.doesUserHavePermission(
                    newEvent, PermissionAPI.PERMISSION_PUBLISH, user, respectFrontendRoles));
            eventMap.put(
                "readPermission",
                perAPI.doesUserHavePermission(
                    newEvent, PermissionAPI.PERMISSION_READ, user, respectFrontendRoles));
            eventMap.put(
                "writePermission",
                perAPI.doesUserHavePermission(
                    newEvent, PermissionAPI.PERMISSION_WRITE, user, respectFrontendRoles));
            eventMap.put(
                "publishPermission",
                perAPI.doesUserHavePermission(
                    newEvent, PermissionAPI.PERMISSION_PUBLISH, user, respectFrontendRoles));
            eventMap.put("isDisconnected", UtilMethods.isSet(newEvent.getDisconnectedFrom()));
            CommentsWebAPI cAPI = new CommentsWebAPI();
            cAPI.setUser(user);
            cAPI.setRespectFrontendRoles(respectFrontendRoles);
            eventMap.put("commentsCount", cAPI.getCommentsCount(newEvent.getInode()));
            HibernateUtil.commitTransaction();
          } catch (Exception e) {
            HibernateUtil.rollbackTransaction();
            disconnectEventErrors.add(e.getLocalizedMessage());
          } finally {
            if (disconnectEventErrors.size() > 0) {
              eventMap.put("disconnectEventErrors", disconnectEventErrors);
            }
          }
        }
      }
    }

    return eventMap;
  }