Exemplo n.º 1
0
  public static boolean isPostBack() {
    ExternalContext ext = FacesUtils.extContext();
    boolean result = false;
    Map<String, Object> requestMap = ext.getRequestMap();
    Object value = requestMap.get(VIEW_STATE_KEY);
    if (!Strings.isEmpty(value)) {
      return true;
    }

    Map<String, String> params = ext.getRequestParameterMap();
    value = params.get(VIEW_STATE_KEY);
    if (!Strings.isEmpty(value)) {
      requestMap.put(VIEW_STATE_KEY, Boolean.TRUE);
      result = true;
    }
    return result;
  }
Exemplo n.º 2
0
 /**
  * Assert that the given argument String is not empty; that is, it must not be <code>null</code>
  * and not the empty String.
  *
  * <pre class="code">
  * Assert.notEmpty("id",id);
  * </pre>
  *
  * @param argumentName the name of argument to check
  * @param argumentValue the String value to check
  * @throws IllegalArgumentException if the value is <code>null</code> or empty
  */
 public static void notEmptyArgument(String argumentName, String argumentValue) {
   if (Strings.isEmpty(argumentValue)) {
     throw new IllegalArgumentException(
         Strings.format(
             "[Assertion failed] - the argument '{0}' is required, it must not be null or empty",
             argumentName));
   }
 }
Exemplo n.º 3
0
 public static long getDateValueFromDateDesc(String leadTime) {
   if (!Strings.isEmpty(leadTime)) {
     DateTime dateTime = new DateTime(DateTimeUtils.getDateFromDateDesc(leadTime));
     DateTime todayDateTime = new DateTime(0, 12, 31, 0, 0, 0, 0);
     return dateTime.getMillis() - todayDateTime.getMillis();
   }
   return 0;
 }
Exemplo n.º 4
0
 /**
  * 날자 형식의 String에 구분자를 넣어준다. (yyyy-MM-dd) Carendar를 사용하지 않기 위한 편법.
  *
  * @param 8자리 yyyyMMdd형식의 String
  */
 public static String toDate(String yyyyMMdd, String seperator) {
   if (Strings.isEmpty(yyyyMMdd)) return "";
   if (yyyyMMdd.length() == 8)
     return yyyyMMdd.substring(0, 4)
         + seperator
         + yyyyMMdd.substring(4, 6)
         + seperator
         + yyyyMMdd.substring(6, 8);
   else if (yyyyMMdd.length() == 6)
     return yyyyMMdd.substring(0, 4) + seperator + yyyyMMdd.substring(4, 6);
   else return yyyyMMdd;
 }
Exemplo n.º 5
0
 public String getSource(String mavenCoords, String className, String filePath)
     throws IOException {
   // the fileName could be just a name and extension so we may have to use the className to make a
   // fully qualified package
   String classNamePath = null;
   if (!Strings.isEmpty(className)) {
     classNamePath = className.replace('.', '/') + ".java";
   }
   if (Strings.isEmpty(filePath)) {
     filePath = classNamePath;
   } else {
     // we may have package in the className but not in the file name
     if (filePath.lastIndexOf('/') <= 0 && classNamePath != null) {
       int idx = classNamePath.lastIndexOf('/');
       if (idx > 0) {
         filePath = classNamePath.substring(0, idx) + ensureStartsWithSlash(filePath);
       }
     }
   }
   return getArtifactFile(mavenCoords, filePath, "sources");
 }
Exemplo n.º 6
0
  public static String getAjaxActionPath() {
    ViewHandler viewHandler = FacesUtils.context().getApplication().getViewHandler();
    String viewId = FacesUtils.context().getViewRoot().getViewId();

    String queryString = FacesUtils.getRequest().getQueryString();
    queryString = Strings.ifEmpty(queryString, "");
    if (Strings.isEmpty(queryString)) {
      queryString = "";
    } else {
      queryString = "?" + queryString;
    }
    return viewHandler.getActionURL(FacesUtils.context(), viewId) + queryString;
  }
Exemplo n.º 7
0
  public static void share(
      Activity activity, String title, String content, String chooserScreenName) {
    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_TEXT, content);
    sendIntent.putExtra(Intent.EXTRA_SUBJECT, title);

    sendIntent.setType("text/plain");

    if (Strings.isEmpty(chooserScreenName)) {
      activity.startActivity(sendIntent);
    } else {
      activity.startActivity(Intent.createChooser(sendIntent, chooserScreenName));
    }
  }
Exemplo n.º 8
0
 public static Date getDateFromDateDesc(String leadTime) {
   DateTime dateTime = new DateTime(0, 12, 31, 0, 0, 0, 0);
   if (!Strings.isEmpty(leadTime)) {
     String time = "0";
     if (leadTime.indexOf(".") > 0) {
       time = leadTime.substring(0, leadTime.indexOf("."));
     } else {
       time = leadTime.substring(0, leadTime.length() - 1);
     }
     int timeVal = Integer.parseInt(time);
     if (leadTime.indexOf(DAY) >= 0) {
       if (timeVal > 0) {
         dateTime = dateTime.plusDays(timeVal);
       } else {
         dateTime = dateTime.minusDays(Math.abs(timeVal));
       }
     } else if (leadTime.indexOf(WEEK) >= 0) {
       if (timeVal > 0) {
         dateTime = dateTime.plusWeeks(timeVal);
       } else {
         dateTime = dateTime.minusWeeks(Math.abs(timeVal));
       }
     } else if (leadTime.indexOf(MONTH) >= 0) {
       if (timeVal > 0) {
         dateTime = dateTime.plusMonths(timeVal);
       } else {
         dateTime = dateTime.minusMonths(Math.abs(timeVal));
       }
     } else if (leadTime.indexOf(QUARTER) >= 0) {
       if (timeVal > 0) {
         dateTime = dateTime.plusMonths(timeVal * 3);
       } else {
         dateTime = dateTime.minusMonths(Math.abs(timeVal * 3));
       }
     } else if (leadTime.indexOf(YEAR) >= 0) {
       if (timeVal > 0) {
         dateTime = dateTime.plusYears(timeVal);
       } else {
         dateTime = dateTime.minusYears(Math.abs(timeVal));
       }
     }
     return dateTime.toDate();
   }
   return dateTime.toDate();
 }
 public boolean check() {
   boolean success = !Strings.isEmpty(ramal);
   success &= !Strings.isEmpty(nomeEvento);
   success &= !Strings.isEmpty(nomeResponsavel);
   success &= dia > 0;
   success &= mes > 0 && mes <= 12;
   success &= ano > 0;
   success &= hora > 0;
   success &= minuto >= 0 && minuto <= 60;
   success &= duracao > 0;
   success &= !Strings.isEmpty(deprecante);
   success &= !Strings.isEmpty(deprecado);
   success &= !Strings.isEmpty(predio);
   success &= "Sim".equals(gravar) || "Não".equals(gravar);
   success &= !Strings.isEmpty(texto);
   return success;
 }
Exemplo n.º 10
0
  public static Date stringToDateWithZone(String isoDate) {
    DateTime dt = null;

    if (Strings.isEmpty(isoDate)) return null;

    try {
      dt = new DateTime(isoDate, DateTimeZone.forTimeZone(TimeZone.getDefault()));
    } catch (IllegalArgumentException e) {
      if (isoDate.indexOf(' ') > 0) isoDate = isoDate.replace(' ', 'T');
      try {
        dt = new DateTime(isoDate, DateTimeZone.forTimeZone(TimeZone.getDefault()));
      } catch (IllegalArgumentException ex) {
        log.error("parameter error");
      }
    }
    if (dt == null) return null;

    return dt.toDate();
  }
Exemplo n.º 11
0
 @Test
 public void isEmptyOnNotEmpty() {
   assert !Strings.isEmpty("X");
 }
Exemplo n.º 12
0
 public static String computeTime(String dateString, String val, String timeUnit) {
   DateTime date = new DateTime();
   int value = 0;
   boolean isLong = false;
   if (!Strings.isEmpty(val) && !Strings.isEmpty(dateString) && !Strings.isEmpty(timeUnit)) {
     if (dateString.substring(dateString.indexOf("T") + 1, dateString.length()).length() == 0) {
       dateString = dateString + DEFAULT_TIME_FORMAT;
     }
     date = new DateTime(dateString);
     if (val.indexOf(".") > 0) {
       val = val.substring(0, val.indexOf("."));
     }
     Long l = new Long(val);
     if ((l.longValue() < 0 && -l.longValue() > 32768)
         || (l.longValue() > 0 && l.longValue() > 32768)) {
       isLong = true;
     }
     if (!isLong) {
       value = Integer.parseInt(val);
     }
     if (!Strings.isEmpty(timeUnit)) {
       if (timeUnit.equals("d")) {
         if (!isLong) {
           if (value > 0) {
             date = date.plusDays(value);
           } else {
             date = date.minusDays(-value);
           }
         } else {
           if (l.longValue() < 0) {
             date = date.minus(-l.longValue() * 24 * 60 * 60 * 1000);
           } else {
             date = date.plus(l.longValue() * 24 * 60 * 60 * 1000);
           }
         }
       } else if (timeUnit.equals(HOUR)) {
         if (!isLong) {
           if (value > 0) {
             date = date.plusHours(value);
           } else {
             date = date.minusHours(-value);
           }
         } else {
           if (l.longValue() < 0) {
             date = date.minus(-l.longValue() * 60 * 60 * 1000);
           } else {
             date = date.plus(l.longValue() * 60 * 60 * 1000);
           }
         }
       } else if (timeUnit.equals(MIN)) {
         if (!isLong) {
           if (value > 0) {
             date = date.plusMinutes(value);
           } else {
             date = date.minusMinutes(-value);
           }
         } else {
           if (l.longValue() < 0) {
             date = date.minus(-l.longValue() * 60 * 1000);
           } else {
             date = date.plus(l.longValue() * 60 * 1000);
           }
         }
       } else if (timeUnit.equals(SEC)) {
         if (!isLong) {
           if (value > 0) {
             date = date.plusSeconds(value);
           } else {
             date = date.minusSeconds(-value);
           }
         } else {
           if (l.longValue() < 0) {
             date = date.minus(-l.longValue() * 1000);
           } else {
             date = date.plus(l.longValue() * 1000);
           }
         }
       }
     }
   }
   return FormatUtils.formatDateTimeToISO(date.toDate());
 }
Exemplo n.º 13
0
 @Test
 public void isEmptyOnNull() {
   assert Strings.isEmpty(null);
 }
Exemplo n.º 14
0
 public static String notEmpty(String text, String template, Object... args) {
   if (Strings.isEmpty(text)) {
     throw new IllegalArgumentException(Strings.format(template, args));
   }
   return text;
 }
Exemplo n.º 15
0
 @Test
 public void isEmptyOnEmpty() {
   assert Strings.isEmpty("");
 }
Exemplo n.º 16
0
 @Test
 public void isEmptyOnEmptyTrim() {
   assert Strings.isEmpty("  ", true);
 }
Exemplo n.º 17
0
 private static FilesException cannotCreateNewFile(String path, String reason, Exception cause) {
   String message = concat("Unable to create the new file ", quote(path));
   if (!Strings.isEmpty(reason)) message = concat(message, ": ", reason);
   if (cause != null) throw new FilesException(message, cause);
   throw new FilesException(message);
 }
Exemplo n.º 18
0
 @Test
 public void isEmptyOnNotEmptyTrim() {
   assert !Strings.isEmpty(" X ", true);
 }
Exemplo n.º 19
0
 /**
  * Assert that the given String is not empty; that is, it must not be <code>null</code> and not
  * the empty String.
  *
  * <pre class="code">
  * Assert.notEmpty(name, &quot;Name must not be empty&quot;);
  * </pre>
  *
  * @param text the String to check
  * @param message the exception message to use if the assertion fails
  * @see StringUtils#notEmpty
  */
 public static String notEmpty(String text, String message) {
   if (Strings.isEmpty(text)) {
     throw new IllegalArgumentException(message);
   }
   return text;
 }