Ejemplo n.º 1
0
 /**
  * Parse the given {@code timeZoneString} value into a {@link TimeZone}.
  *
  * @param timeZoneString the time zone String, following {@link TimeZone#getTimeZone(String)} but
  *     throwing {@link IllegalArgumentException} in case of an invalid time zone specification
  * @return a corresponding {@link TimeZone} instance
  * @throws IllegalArgumentException in case of an invalid time zone specification
  */
 public static TimeZone parseTimeZoneString(String timeZoneString) {
   TimeZone timeZone = TimeZone.getTimeZone(timeZoneString);
   if ("GMT".equals(timeZone.getID()) && !timeZoneString.startsWith("GMT")) {
     // We don't want that GMT fallback...
     throw new IllegalArgumentException(
         "Invalid time zone specification '" + timeZoneString + "'");
   }
   return timeZone;
 }
 private void setTimeZone(String line) throws JBookTraderException {
   String timeZone = line.substring(line.indexOf('=') + 1);
   TimeZone tz = TimeZone.getTimeZone(timeZone);
   if (!tz.getID().equals(timeZone)) {
     String msg =
         "The specified time zone " + "\"" + timeZone + "\"" + " does not exist." + LINE_SEP;
     msg += "Examples of valid time zones: " + " America/New_York, Europe/London, Asia/Singapore.";
     throw new JBookTraderException(msg);
   }
   sdf = new SimpleDateFormat("MMddyyHHmmss");
   // Enforce strict interpretation of date and time formats
   sdf.setLenient(false);
   sdf.setTimeZone(tz);
 }
Ejemplo n.º 3
0
  private void writeTimeZone(MarkupWriter writer) {
    if (timeZone == TimeZoneVisibility.NONE) return;

    TimeZone tz = timeZoneTracker.getClientTimeZone();

    writer.element("span", "class", "tx-datefield-timezone");

    switch (timeZone) {
      case DISPLAY:
        writer.write(" ");
        writer.write(tz.getDisplayName(locale));
        break;

      case SELECT:
        writer.element("select", "name", getControlName() + "$timezone");

        for (TimeZone option :
            F.flow(TimeZone.getAvailableIDs()).map(ID_TO_TIME_ZONE).sort(timeZoneComparator)) {
          writer.element("option", "value", option.getID());

          if (tz.equals(option)) writer.attributes("selected", "selected");

          int offset = option.getRawOffset() / (1000 * 60 * 60);

          writer.write(String.format("UTC%+03d %s", offset, option.getID()));

          writer.end();
        }

        writer.end();

      default:
        break;
    }

    writer.end();
  }
Ejemplo n.º 4
0
  /**
   * Converts this <code>Date</code> object to a <code>String</code> of the form:
   *
   * <blockquote>
   *
   * <pre>
   * dow mon dd hh:mm:ss zzz yyyy</pre>
   *
   * </blockquote>
   *
   * where:
   *
   * <ul>
   *   <li><tt>dow</tt> is the day of the week (<tt>Sun, Mon, Tue, Wed, Thu, Fri, Sat</tt>).
   *   <li><tt>mon</tt> is the month (<tt>Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov,
   *       Dec</tt>).
   *   <li><tt>dd</tt> is the day of the month (<tt>01</tt> through <tt>31</tt>), as two decimal
   *       digits.
   *   <li><tt>hh</tt> is the hour of the day (<tt>00</tt> through <tt>23</tt>), as two decimal
   *       digits.
   *   <li><tt>mm</tt> is the minute within the hour (<tt>00</tt> through <tt>59</tt>), as two
   *       decimal digits.
   *   <li><tt>ss</tt> is the second within the minute (<tt>00</tt> through <tt>61</tt>, as two
   *       decimal digits.
   *   <li><tt>zzz</tt> is the time zone (and may reflect daylight savings time). If time zone
   *       information is not available, then <tt>zzz</tt> is empty - that is, it consists of no
   *       characters at all.
   *   <li><tt>yyyy</tt> is the year, as four decimal digits.
   * </ul>
   *
   * @return a string representation of this date.
   */
  public static String toString(Calendar calendar) {
    // Printing in the absence of a Calendar
    // implementation class is not supported
    if (calendar == null) {
      return "Thu Jan 01 00:00:00 UTC 1970";
    }

    int dow = calendar.get(Calendar.DAY_OF_WEEK);
    int month = calendar.get(Calendar.MONTH);
    int day = calendar.get(Calendar.DAY_OF_MONTH);
    int hour_of_day = calendar.get(Calendar.HOUR_OF_DAY);
    int minute = calendar.get(Calendar.MINUTE);
    int seconds = calendar.get(Calendar.SECOND);
    int year = calendar.get(Calendar.YEAR);

    String yr = Integer.toString(year);

    TimeZone zone = calendar.getTimeZone();
    String zoneID = zone.getID();
    if (zoneID == null) zoneID = "";

    // The total size of the string buffer
    // 3+1+3+1+2+1+2+1+2+1+2+1+zoneID.length+1+yr.length
    //  = 21 + zoneID.length + yr.length
    StringBuffer sb = new StringBuffer(25 + zoneID.length() + yr.length());

    sb.append(days[dow - 1]).append(' ');
    sb.append(months[month]).append(' ');
    appendTwoDigits(sb, day).append(' ');
    appendTwoDigits(sb, hour_of_day).append(':');
    appendTwoDigits(sb, minute).append(':');
    appendTwoDigits(sb, seconds).append(' ');
    if (zoneID.length() > 0) sb.append(zoneID).append(' ');
    appendFourDigits(sb, year);

    return sb.toString();
  }
Ejemplo n.º 5
0
    public ConfigBuilder(InputStream configXml) {
      try {
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        dbFactory.setNamespaceAware(true);
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        doc = dBuilder.parse(configXml);
        doc.getDocumentElement().normalize();

        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema =
            factory.newSchema(
                new StreamSource(
                    Thread.currentThread()
                        .getContextClassLoader()
                        .getResourceAsStream("jen8583.xsd")));

        Validator validator = schema.newValidator();
        validator.validate(new DOMSource(doc));
      } catch (Exception e) {
        throw new ConfigException(e.getMessage(), e);
      }

      Element defaults = (Element) doc.getElementsByTagName(ELEMENT_DEFAULTS).item(0);

      for (Element e : getSubElements(defaults)) {
        switch (e.getTagName()) {
          case ELEMENT_VAR:
            defaultLengthEncoding =
                Encoding.valueOf(getMandatoryAttribute(e, ATTR_LENGTH_ENCODING));
            LOG.info("Default length encoding: {}", defaultLengthEncoding);
            break;
          case ELEMENT_TLV:
            defaultTlvTagEncoding = Encoding.valueOf(getMandatoryAttribute(e, ATTR_TAG_ENCODING));
            LOG.info("Default tlv tag encoding: {}", defaultTlvTagEncoding);
            defaultTlvLengthEncoding =
                Encoding.valueOf(getMandatoryAttribute(e, ATTR_LENGTH_ENCODING));
            LOG.info("Default tlv length encoding: {}", defaultTlvLengthEncoding);
            break;
          case ELEMENT_ALPHA:
            defaultTrim = Boolean.valueOf(getMandatoryAttribute(e, ATTR_TRIM));
            LOG.info("Default trim: {}", defaultTrim);
            String stringJustify = getMandatoryAttribute(e, ATTR_JUSTIFIED);
            switch (stringJustify) {
              case ATTR_CONST_LEFT:
                defaultLeftJustified = true;
                break;
              case ATTR_CONST_RIGHT:
                defaultLeftJustified = false;
                break;
              default:
                throw new ConfigException(format("Invalid value for justified: %s", stringJustify));
            }
            LOG.info(
                "Default {} justified", defaultLeftJustified ? ATTR_CONST_LEFT : ATTR_CONST_RIGHT);
            break;
          case ELEMENT_NUMERIC:
            defaultNumericEncoding = Encoding.valueOf(getMandatoryAttribute(e, ATTR_ENCODING));
            LOG.info("Default numeric encoding: {}", defaultNumericEncoding);
            break;
          case ELEMENT_DATE:
            defaultDateEncoding = Encoding.valueOf(getMandatoryAttribute(e, ATTR_ENCODING));
            LOG.info("Default date encoding: {}", defaultDateEncoding);
            String tzDefault = getMandatoryAttribute(e, ATTR_TIMEZONE);
            defaultTimeZone =
                ATTR_CONST_SYSTEM.equals(tzDefault)
                    ? TimeZone.getDefault()
                    : ZoneInfo.getTimeZone(tzDefault);
            LOG.info("Default timezone: {}", defaultTimeZone.getID());
            break;
          case ELEMENT_ORDINALITY:
            defaultMandatory = Boolean.valueOf(getMandatoryAttribute(e, ATTR_MANDATORY));
            LOG.info("Default mandatory: {}", defaultMandatory);
            defaultFailFast = Boolean.valueOf(getMandatoryAttribute(e, ATTR_FAIL_FAST));
            LOG.info("Default fail-fast: {}", defaultFailFast);
            break;
        }
      }
    }
Ejemplo n.º 6
0
  public void go(SystemEnvironment sysEnv) throws SDMSException {
    try {
      obj.resolve(sysEnv);
    } catch (final NotFoundException nfe) {

    }
    final Long seId = obj.seId;

    final Vector mappedPath = new Vector(obj.path);
    final String mappedName = (String) mappedPath.remove(mappedPath.size() - 1);

    final SDMSSchedule parent = SDMSScheduleTable.getSchedule(sysEnv, mappedPath);
    final Long parentId = parent.getId(sysEnv);

    if (SDMSScheduleTable.idx_parentId_name.containsKey(
        sysEnv, new SDMSKey(parentId, mappedName))) {
      if (replace) {
        final AlterSchedule as = new AlterSchedule(obj, with, Boolean.FALSE);
        as.setEnv(env);
        as.go(sysEnv);
        result = as.result;
        return;
      }

      throw new DuplicateKeyException(
          new SDMSMessage(
              sysEnv,
              "04207251651",
              "Object with name $1 already exists within $2",
              mappedName,
              SDMSScheduleTable.getObject(sysEnv, parentId).pathString(sysEnv)));
    }

    final Long ivalId;
    final String intervalName = (String) with.get(ParseStr.S_INTERVAL);
    if (intervalName == null) ivalId = null;
    else {
      final SDMSInterval ival =
          SDMSIntervalTable.idx_name_getUnique(sysEnv, IntervalUtil.mapIdName(intervalName, seId));
      ivalId = ival.getId(sysEnv);
    }

    final Long uId = env.uid();
    final SDMSUser u = SDMSUserTable.getObject(sysEnv, uId);
    final Long gId;
    if (!with.containsKey(ParseStr.S_GROUP)) {
      gId = u.getDefaultGId(sysEnv);
    } else {
      final String gName = (String) with.get(ParseStr.S_GROUP);
      gId =
          SDMSGroupTable.idx_name_deleteVersion_getUnique(sysEnv, new SDMSKey(gName, new Long(0)))
              .getId(sysEnv);
      if (!SDMSMemberTable.idx_gId_uId.containsKey(sysEnv, new SDMSKey(gId, uId))
          && !SDMSMemberTable.idx_gId_uId.containsKey(
              sysEnv, new SDMSKey(SDMSObject.adminGId, uId))) {
        throw new CommonErrorException(
            new SDMSMessage(
                sysEnv,
                "03401151027",
                "User $1 does not belong to Group $2",
                u.getName(sysEnv),
                gName));
      }
    }

    Long inheritPrivs;
    if (with.containsKey(ParseStr.S_INHERIT)) {
      inheritPrivs = (Long) with.get(ParseStr.S_INHERIT);
      if (inheritPrivs == null) inheritPrivs = new Long(0);
    } else inheritPrivs = null;

    long lpriv = (inheritPrivs == null ? parent.getPrivilegeMask() : inheritPrivs.longValue());
    if ((parent.getPrivilegeMask() & lpriv) != lpriv) {
      throw new CommonErrorException(new SDMSMessage(sysEnv, "03202061327", "Incompatible grant"));
    }

    inheritPrivs = new Long(lpriv);

    if (!with.containsKey(ParseStr.S_ACTIVE)) active = Boolean.TRUE;
    else active = (Boolean) with.get(ParseStr.S_ACTIVE);

    String tz;
    String warning = "";
    if (with.containsKey(ParseStr.S_TIME)) {
      tz = (String) with.get(ParseStr.S_TIME);
      TimeZone tmp = TimeZone.getTimeZone(tz);
      if (!tz.equals(tmp.getID())) {
        throw new CommonErrorException(
            new SDMSMessage(sysEnv, "03207031503", "Time Zone " + tz + " unknown"));
      }
    } else {
      TimeZone tmp = TimeZone.getDefault();
      tz = tmp.getID();
    }

    SDMSScheduleTable.table.create(
        sysEnv, mappedName, gId, ivalId, parentId, tz, seId, active, inheritPrivs);

    result.setFeedback(new SDMSMessage(sysEnv, "04207251652", "Schedule created"));
  }
Ejemplo n.º 7
0
 /** Set value in millis. */
 public void set(long millis, TimeZone timeZone) {
   this.millis = millis;
   this.timeZone = timeZone;
   this.bits0 = bits1 = 0;
   if (timeZone != null) tz = timeZone.getID();
 }