コード例 #1
0
 public void setVisibilityPeriod(Period period) {
   if (period.isBeginNotDefined()) {
     setBeginDate(null);
     setBeginHour(null);
   } else {
     setBeginDate(period.getBeginDate());
     setBeginHour(DateUtil.formatTime(period.getBeginDate()));
   }
   if (period.isEndNotDefined()) {
     setEndDate(null);
     setEndHour(null);
   } else {
     setEndDate(period.getEndDate());
     setEndHour(DateUtil.formatTime(period.getEndDate()));
   }
 }
コード例 #2
0
 @XmlElement
 public String getPublishTime() {
   return DateUtil.formatTime(getDate());
 }
コード例 #3
0
  /**
   * Prints the HTML value of the field. The displayed value must be updatable by the end user. The
   * value format may be adapted to a local language. The fieldName must be used to name the html
   * form input. Never throws an Exception but log a silvertrace and writes an empty string when :
   *
   * <UL>
   *   <LI>the field type is not a managed type.
   * </UL>
   *
   * @param out
   * @param field
   * @param template
   * @param pageContext
   * @throws FormException
   */
  @Override
  public void display(
      PrintWriter out, TextField field, FieldTemplate template, PagesContext pageContext)
      throws FormException {
    String value = "";
    String html = "";

    String fieldName = template.getFieldName();
    SilverTrace.info(
        "form", "TimeFieldDisplayer.display", "root.MSG_GEN_PARAM_VALUE", "fieldName=" + fieldName);
    Map<String, String> parameters = template.getParameters(pageContext.getLanguage());
    if (field == null) {
      return;
    }
    if (!field.getTypeName().equals(TextField.TYPE)) {
      SilverTrace.info(
          "form", "TimeFieldDisplayer.display", "form.INFO_NOT_CORRECT_TYPE", TextField.TYPE);
    }

    String defaultParam = (parameters.containsKey("default") ? parameters.get("default") : "");
    String defaultValue = "";
    if ("now".equalsIgnoreCase(defaultParam) && !pageContext.isIgnoreDefaultValues()) {
      defaultValue = DateUtil.formatTime(new Date());
    }
    value = (!field.isNull() ? field.getValue(pageContext.getLanguage()) : defaultValue);
    if (pageContext.isBlankFieldsUse()) {
      value = "";
    }

    if (template.isReadOnly() && !template.isHidden()) {
      html = value;
    } else {
      input inputField = new input();
      inputField.setName(template.getFieldName());
      inputField.setID(template.getFieldName());
      inputField.setValue(EncodeHelper.javaStringToHtmlString(value));
      inputField.setType(template.isHidden() ? input.hidden : input.text);
      inputField.setMaxlength("5");
      inputField.setSize("10");
      if (template.isDisabled()) {
        inputField.setDisabled(true);
      } else if (template.isReadOnly()) {
        inputField.setReadOnly(true);
      }

      img image = null;
      if (template.isMandatory()
          && !template.isDisabled()
          && !template.isReadOnly()
          && !template.isHidden()
          && pageContext.useMandatory()) {
        image = new img();
        image.setSrc(Util.getIcon("mandatoryField"));
        image.setWidth(5);
        image.setHeight(5);
        image.setBorder(0);
      }

      // print field
      if (image != null) {
        ElementContainer container = new ElementContainer();
        container.addElement(inputField);
        container.addElement("&nbsp;");
        container.addElement(image);
        out.println(container.toString());
      } else {
        out.println(inputField.toString());
      }
    }
    out.println(html);
  }
コード例 #4
0
 /** Test of insertRow method, of class PublicationDAO. */
 @Test
 public void testInsertRow() throws Exception {
   IDatabaseConnection connection = getConnection();
   try {
     Connection con = connection.getConnection();
     PublicationPK pk = new PublicationPK("500", "kmelia36");
     Calendar now = Calendar.getInstance();
     now.set(Calendar.SECOND, 0);
     now.set(Calendar.MILLISECOND, 0);
     now.set(Calendar.MINUTE, 0);
     now.set(Calendar.HOUR_OF_DAY, 0);
     Calendar beginDate = RandomGenerator.getCalendarAfter(now);
     Calendar endDate = RandomGenerator.getCalendarAfter(beginDate);
     String name = RandomGenerator.getRandomString();
     String description = RandomGenerator.getRandomString();
     String creatorId = "" + RandomGenerator.getRandomInt();
     int importance = RandomGenerator.getRandomInt(5);
     String version = RandomGenerator.getRandomString();
     String contenu = RandomGenerator.getRandomString();
     StringBuilder buffer = new StringBuilder();
     int nbKeywords = RandomGenerator.getRandomInt(5) + 2;
     for (int i = 0; i < nbKeywords; i++) {
       buffer.append(RandomGenerator.getRandomString());
       if (i < (nbKeywords - 1)) {
         buffer.append(' ');
       }
     }
     String keywords = buffer.toString();
     PublicationDetail detail =
         new PublicationDetail(
             pk,
             name,
             description,
             now.getTime(),
             beginDate.getTime(),
             endDate.getTime(),
             creatorId,
             importance,
             version,
             keywords,
             contenu);
     detail.setBeginHour(DateUtil.formatTime(beginDate));
     detail.setEndHour(DateUtil.formatTime(endDate));
     PublicationDAO.insertRow(con, detail);
     PublicationDetail result = PublicationDAO.loadRow(con, pk);
     detail.setUpdateDate(now.getTime());
     detail.setUpdaterId(creatorId);
     detail.setInfoId("0");
     assertEquals(detail.getPK(), result.getPK());
     assertEquals(detail.getAuthor(), result.getAuthor());
     assertEquals(detail.getBeginDate(), result.getBeginDate());
     assertEquals(detail.getBeginHour(), result.getBeginHour());
     assertEquals(detail.getContent(), result.getContent());
     assertEquals(detail.getCreationDate(), result.getCreationDate());
     assertEquals(detail.getUpdateDate(), result.getCreationDate());
     assertEquals(detail.getCreatorId(), result.getCreatorId());
     assertEquals(detail.getDescription(), result.getDescription());
     assertEquals(detail.getEndDate(), result.getEndDate());
     assertEquals(detail.getEndHour(), result.getEndHour());
     assertEquals(detail.getImportance(), result.getImportance());
     assertEquals(detail.getInfoId(), result.getInfoId());
     assertEquals(detail.getInstanceId(), result.getInstanceId());
     assertEquals(detail.getKeywords(), result.getKeywords());
     assertEquals(detail.getName(), result.getName());
     assertEquals(detail.getStatus(), result.getStatus());
     assertEquals(detail.getTitle(), result.getTitle());
   } finally {
     connection.close();
   }
 }
コード例 #5
0
 /** Test of storeRow method, of class PublicationDAO. */
 @Test
 public void testStoreRow() throws Exception {
   IDatabaseConnection connection = getConnection();
   try {
     Connection con = connection.getConnection();
     PublicationPK pk = new PublicationPK("100", "kmelia200");
     PublicationDetail detail = PublicationDAO.loadRow(con, pk);
     assertEquals(pk, detail.getPK());
     assertEquals("Homer Simpson", detail.getAuthor());
     assertEquals("2009/10/18", DateUtil.formatDate(detail.getBeginDate()));
     assertEquals("00:00", detail.getBeginHour());
     assertEquals("Contenu de la publication 1", detail.getContent());
     assertEquals("2008/11/18", DateUtil.formatDate(detail.getCreationDate()));
     assertEquals("100", detail.getCreatorId());
     assertEquals("Première publication de test", detail.getDescription());
     assertEquals("2020/12/18", DateUtil.formatDate(detail.getEndDate()));
     assertEquals("23:59", detail.getEndHour());
     assertEquals(1, detail.getImportance());
     assertEquals("0", detail.getInfoId());
     assertEquals("kmelia200", detail.getInstanceId());
     assertEquals("test", detail.getKeywords());
     assertEquals("Publication 1", detail.getName());
     assertEquals("Valid", detail.getStatus());
     assertEquals("300", detail.getValidatorId());
     assertEquals("Publication 1", detail.getTitle());
     Calendar now = Calendar.getInstance();
     now.set(Calendar.SECOND, 0);
     now.set(Calendar.MILLISECOND, 0);
     now.set(Calendar.MINUTE, 0);
     now.set(Calendar.HOUR_OF_DAY, 0);
     Calendar beginDate = RandomGenerator.getCalendarAfter(now);
     Calendar endDate = RandomGenerator.getCalendarAfter(beginDate);
     String name = RandomGenerator.getRandomString();
     String description = RandomGenerator.getRandomString();
     String creatorId = "" + RandomGenerator.getRandomInt();
     int importance = RandomGenerator.getRandomInt(5);
     String version = RandomGenerator.getRandomString();
     String contenu = RandomGenerator.getRandomString();
     StringBuilder buffer = new StringBuilder();
     int nbKeywords = RandomGenerator.getRandomInt(5) + 2;
     for (int i = 0; i < nbKeywords; i++) {
       buffer.append(RandomGenerator.getRandomString());
       if (i < (nbKeywords - 1)) {
         buffer.append(' ');
       }
     }
     String keywords = buffer.toString();
     detail.setName(name);
     detail.setDescription(description);
     detail.setCreationDate(now.getTime());
     detail.setBeginDateAndHour(beginDate.getTime());
     detail.setEndDateAndHour(endDate.getTime());
     detail.setCreatorId(creatorId);
     detail.setImportance(importance);
     detail.setVersion(version);
     detail.setKeywords(keywords);
     detail.setContent(contenu);
     detail.setBeginHour(DateUtil.formatTime(beginDate));
     detail.setEndHour(DateUtil.formatTime(endDate));
     PublicationDAO.storeRow(con, detail);
     PublicationDetail result = PublicationDAO.loadRow(con, pk);
     detail.setUpdateDate(now.getTime());
     detail.setUpdaterId(creatorId);
     detail.setInfoId("0");
     assertEquals(detail.getPK(), result.getPK());
     assertEquals(detail.getAuthor(), result.getAuthor());
     assertEquals(detail.getBeginDate(), result.getBeginDate());
     assertEquals(detail.getBeginHour(), result.getBeginHour());
     assertEquals(detail.getContent(), result.getContent());
     assertEquals(detail.getCreationDate(), result.getCreationDate());
     assertEquals(detail.getUpdateDate(), result.getCreationDate());
     assertEquals(detail.getCreatorId(), result.getCreatorId());
     assertEquals(detail.getDescription(), result.getDescription());
     assertEquals(detail.getEndDate(), result.getEndDate());
     assertEquals(detail.getEndHour(), result.getEndHour());
     assertEquals(detail.getImportance(), result.getImportance());
     assertEquals(detail.getInfoId(), result.getInfoId());
     assertEquals(detail.getInstanceId(), result.getInstanceId());
     assertEquals(detail.getKeywords(), result.getKeywords());
     assertEquals(detail.getName(), result.getName());
     assertEquals(detail.getStatus(), result.getStatus());
     assertEquals(detail.getTitle(), result.getTitle());
   } finally {
     connection.close();
   }
 }