Ejemplo n.º 1
0
 /**
  * @param parent Only for i18n needed.
  * @param startTime Start time or null.
  * @param stopTime Stop time or null.
  * @return The weeks of year range for the given start an stop time.
  */
 public static String getCalendarWeeks(
     final MarkupContainer parent, final Date startTime, final Date stopTime) {
   int fromWeek = -1;
   int toWeek = -1;
   if (startTime != null) {
     fromWeek = DateHelper.getWeekOfYear(startTime);
   }
   if (stopTime != null) {
     toWeek = DateHelper.getWeekOfYear(stopTime);
   }
   if (fromWeek < 0 && toWeek < 0) {
     return "";
   }
   final StringBuffer buf = new StringBuffer();
   buf.append(parent.getString("calendar.weekOfYearShortLabel")).append(" ");
   if (fromWeek >= 0) {
     buf.append(StringHelper.format2DigitNumber(fromWeek));
     if (toWeek == -1) {
       buf.append("-");
     } else if (toWeek != fromWeek) {
       buf.append("-").append(StringHelper.format2DigitNumber(toWeek));
     }
   } else {
     buf.append("-").append(StringHelper.format2DigitNumber(toWeek));
   }
   return buf.toString();
 }
 public String objectToString(final Object object) {
   if (object == null || object instanceof String == false) {
     return "";
   }
   final String number = (String) object;
   return number
       + '|'
       + StringHelper.removeNonDigits(number)
       + '|'
       + NumberHelper.extractPhonenumber(number);
 }
Ejemplo n.º 3
0
 /**
  * For field-sets with multiple fields this method generates a multi label, such as
  * "label1/label2", e. g. "zip code/city".
  *
  * @param label
  * @return
  */
 public static String createMultipleFieldsetLabel(final String... labels) {
   return StringHelper.listToString("/", labels);
 }
 private void callNow() {
   if (StringUtils.isBlank(ConfigXml.getInstance().getTelephoneSystemUrl()) == true) {
     log.error("Telephone system url not configured. Phone calls not supported.");
     return;
   }
   log.info(
       "User initiates direct call from phone with id '"
           + form.getMyCurrentPhoneId()
           + "' to destination numer: "
           + StringHelper.hideStringEnding(form.getPhoneNumber(), 'x', 3));
   result = null;
   final StringBuffer buf = new StringBuffer();
   buf.append(form.getPhoneNumber()).append(SEPARATOR);
   final AddressDO address = form.getAddress();
   if (address != null
       && StringHelper.isIn(
               form.getPhoneNumber(),
               extractPhonenumber(address.getBusinessPhone()),
               extractPhonenumber(address.getMobilePhone()),
               extractPhonenumber(address.getPrivatePhone()),
               extractPhonenumber(address.getPrivateMobilePhone()))
           == true) {
     buf.append(address.getFirstName()).append(" ").append(address.getName());
     if (form.getPhoneNumber().equals(extractPhonenumber(address.getMobilePhone())) == true) {
       buf.append(", ").append(getString("address.phoneType.mobile"));
     } else if (form.getPhoneNumber().equals(extractPhonenumber(address.getPrivatePhone()))
         == true) {
       buf.append(", ").append(getString("address.phoneType.private"));
     }
     buf.append(" #").append(address.getId());
   } else {
     buf.append("???");
   }
   final HttpClient client = new HttpClient();
   String url = ConfigXml.getInstance().getTelephoneSystemUrl();
   url = StringUtils.replaceOnce(url, "#source", form.getMyCurrentPhoneId());
   url = StringUtils.replaceOnce(url, "#target", form.getPhoneNumber());
   final String urlProtected = StringHelper.hideStringEnding(url, 'x', 3);
   final GetMethod method = new GetMethod(url);
   String errorKey = null;
   try {
     form.lastSuccessfulPhoneCall = new Date();
     client.executeMethod(method);
     final String resultStatus = method.getResponseBodyAsString();
     if ("0".equals(resultStatus) == true) {
       result =
           DateTimeFormatter.instance().getFormattedDateTime(new Date())
               + ": "
               + getString("address.phoneCall.result.successful");
       form.getRecentSearchTermsQueue().append(buf.toString());
     } else if ("2".equals(resultStatus) == true) {
       errorKey = "address.phoneCall.result.wrongSourceNumber";
     } else if ("3".equals(resultStatus) == true) {
       errorKey = "address.phoneCall.result.wrongDestinationNumber";
     } else {
       errorKey = "address.phoneCall.result.callingError";
     }
   } catch (final HttpException ex) {
     result = "Call failed. Please contact administrator.";
     log.fatal(result + ": " + urlProtected);
     throw new RuntimeException(ex);
   } catch (final IOException ex) {
     result = "Call failed. Please contact administrator.";
     log.fatal(result + ": " + urlProtected);
     throw new RuntimeException(ex);
   }
   if (errorKey != null) {
     form.addError(errorKey);
   }
 }