/**
   * Reads the resources available for processing based on the path parameters.
   *
   * <p>
   *
   * @return the resources available for processing based on the path parameters.
   */
  @SuppressWarnings("unchecked")
  private List<CmsResource> getResources() {

    List<CmsResource> result = new LinkedList<CmsResource>();
    CmsObject cms = this.getCms();
    CmsResourceFilter filter = CmsResourceFilter.ALL;
    try {
      for (String path : this.m_paths) {
        List<CmsResource> resources = cms.readResources(path, filter, true);
        // filter out any resource that is no XML content:
        for (CmsResource resource : resources) {
          if (resource.isFile()) {
            if (CmsResourceTypeXmlContent.isXmlContent(resource)) {
              result.add(resource);
            } else if (CmsResourceTypeXmlPage.isXmlPage(resource)) {
              result.add(resource);
            }
          }
        }
      }
    } catch (CmsException e) {
      LOG.error(Messages.get().getBundle().key(Messages.LOG_ERR_LANGUAGECOPY_READRESOURCES_0), e);
      result = Collections.emptyList();
    }

    return result;
  }
  /**
   * Creates the history clear Thread.
   *
   * <p>
   *
   * @param cms the current OpenCms context object
   * @param historyClear the settings to clear the history
   */
  public CmsHistoryClearThread(CmsObject cms, CmsHistoryClear historyClear) {

    super(
        cms,
        Messages.get()
            .getBundle()
            .key(
                Messages.GUI_HISTORY_CLEAR_THREAD_NAME_1,
                cms.getRequestContext().getCurrentProject().getName()));
    m_historyClear = historyClear;
    initHtmlReport(cms.getRequestContext().getLocale());
  }
Exemplo n.º 3
0
  /**
   * Sends the given message to the given addresses.
   *
   * <p>
   *
   * @param cms the cms context
   * @throws Exception if something goes wrong
   */
  public void sendEmail(CmsObject cms) throws Exception {

    // create a plain text email
    CmsSimpleMail theMail = new CmsSimpleMail();
    theMail.setCharset(cms.getRequestContext().getEncoding());
    theMail.setFrom(cms.getRequestContext().getCurrentUser().getEmail(), getFrom());
    theMail.setTo(createInternetAddresses(getTo()));
    if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getCc())) {
      theMail.setCc(createInternetAddresses(getCc()));
    }
    theMail.setSubject("[" + OpenCms.getSystemInfo().getServerName() + "] " + getSubject());
    theMail.setMsg(getMsg());
    // send the mail
    theMail.send();
  }
  /**
   * Returns the resource for the given item.
   *
   * <p>
   *
   * @param cms the cms object
   * @param item the item
   * @return the resource
   */
  public CmsResource getResource(CmsObject cms, CmsListItem item) {

    CmsResource res = m_resCache.get(item.getId());
    if (res == null) {
      CmsUUID id = new CmsUUID(item.getId());
      if (!id.isNullUUID()) {
        try {
          res = cms.readResource(id, CmsResourceFilter.ALL);
          m_resCache.put(item.getId(), res);
        } catch (CmsException e) {
          // should never happen
          if (LOG.isErrorEnabled()) {
            LOG.error(e.getLocalizedMessage(), e);
          }
        }
      }
    }
    return res;
  }
  /**
   * Tests incremental index updates with the new content blob feature.
   *
   * <p>
   *
   * @throws Exception in case the test fails
   */
  public void testIncrementalIndexUpdate() throws Exception {

    CmsObject cms = getCmsObject();
    echo("Testing search incremental index update - new content blob feature");

    // create test folder
    cms.createResource("/test/", CmsResourceTypeFolder.RESOURCE_TYPE_ID, null, null);
    cms.unlockResource("/test/");

    String fileName = "/test/master.pdf";

    // create master resource
    importTestResource(
        cms,
        "org/opencms/search/extractors/test1.pdf",
        fileName,
        CmsResourceTypeBinary.getStaticTypeId(),
        Collections.EMPTY_LIST);

    // create 5 siblings
    for (int i = 0; i < 5; i++) {
      cms.createSibling(fileName, "/test/sibling" + i + ".pdf", null);
    }

    // publish the project and update the search index
    I_CmsReport report = new CmsShellReport(cms.getRequestContext().getLocale());
    OpenCms.getPublishManager().publishProject(cms, report);
    OpenCms.getPublishManager().waitWhileRunning();

    cms.lockResource(fileName);
    cms.writePropertyObject(
        fileName, new CmsProperty(CmsPropertyDefinition.PROPERTY_TITLE, "Title of the PDF", null));

    // publish the project and update the search index
    report = new CmsShellReport(cms.getRequestContext().getLocale());
    OpenCms.getPublishManager().publishProject(cms, report);
    OpenCms.getPublishManager().waitWhileRunning();
  }
Exemplo n.º 6
0
  /**
   * Returns the editor widget to use depending on the current users settings, current browser and
   * installed editors.
   *
   * <p>
   *
   * @param cms the current CmsObject
   * @param widgetDialog the dialog where the widget is used on
   * @return the editor widget to use depending on the current users settings, current browser and
   *     installed editors
   */
  private I_CmsWidget getEditorWidget(CmsObject cms, I_CmsWidgetDialog widgetDialog) {

    if (m_editorWidget == null) {
      // get HTML widget to use from editor manager
      String widgetClassName =
          OpenCms.getWorkplaceManager()
              .getWorkplaceEditorManager()
              .getWidgetEditor(cms.getRequestContext(), widgetDialog.getUserAgent());
      boolean foundWidget = true;
      if (CmsStringUtil.isEmpty(widgetClassName)) {
        // no installed widget found, use default text area to edit HTML value
        widgetClassName = CmsTextareaWidget.class.getName();
        foundWidget = false;
      }
      try {
        if (foundWidget) {
          // get widget instance and set the widget configuration
          Class widgetClass = Class.forName(widgetClassName);
          A_CmsHtmlWidget editorWidget = (A_CmsHtmlWidget) widgetClass.newInstance();
          editorWidget.setHtmlWidgetOption(getHtmlWidgetOption());
          m_editorWidget = editorWidget;
        } else {
          // set the text area to display 15 rows for editing
          Class widgetClass = Class.forName(widgetClassName);
          I_CmsWidget editorWidget = (I_CmsWidget) widgetClass.newInstance();
          editorWidget.setConfiguration("15");
          m_editorWidget = editorWidget;
        }
      } catch (Exception e) {
        // failed to create widget instance
        LOG.error(
            Messages.get()
                .container(Messages.LOG_CREATE_HTMLWIDGET_INSTANCE_FAILED_1, widgetClassName)
                .key());
      }
    }
    return m_editorWidget;
  }
  /**
   * Returns a String which holds the selected categories for the result page of the new documents
   * query.
   *
   * <p>
   *
   * @param cms the CmsObject
   * @param request the HttpServletRequest
   * @param messageAll the localized message String used when all categories were selected
   * @return String with comma separated selected categories or localized "all" message
   */
  public static String getCategories(CmsObject cms, HttpServletRequest request, String messageAll) {

    StringBuffer retValue = new StringBuffer(128);

    // get the current user's HHTP session
    // HttpSession session =
    // ((HttpServletRequest)cms.getRequestContext().getRequest().getOriginalRequest()).getSession();
    HttpSession session = request.getSession();

    // get the required parameters
    String paramAll = (String) session.getAttribute(C_DOCUMENT_SEARCH_PARAM_ALL);

    if ("true".equals(paramAll)) {
      return messageAll;
    } else {
      List<String> categories =
          getCategoryList((String) session.getAttribute(C_DOCUMENT_SEARCH_PARAM_CATEGORYLIST));
      Iterator<String> i = categories.iterator();
      while (i.hasNext()) {
        String path = i.next();
        try {
          retValue.append(
              cms.readPropertyObject(path, CmsCategory.CATEGORY_TITLE, false).getValue());
        } catch (CmsException e) {
          // noop
        }
        if (i.hasNext()) {
          retValue.append(", ");
        }
      }

      // clear objects to release memory
      categories = null;
      i = null;
    }
    return retValue.toString();
  }
  /**
   * @see org.opencms.workplace.explorer.menu.I_CmsMenuItemRule#matches(org.opencms.file.CmsObject,
   *     CmsResourceUtil[])
   */
  public boolean matches(CmsObject cms, CmsResourceUtil[] resourceUtil) {

    return cms.getRequestContext().getCurrentProject().isOnlineProject();
  }
Exemplo n.º 9
0
  public String buildHtml() {
    StringBuffer html = new StringBuffer(512);
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
    HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
    CmsJspActionElement cms = new CmsJspActionElement(pageContext, request, response);
    CmsJspXmlContentBean cmsx = new CmsJspXmlContentBean(pageContext, request, response);
    Locale locale = cms.getRequestContext().getLocale();
    String folderpath1 = "";
    String folderpath2 = "";
    int mwidth = 0;
    int iwidth = 0;
    int fwidth = 0;
    int twidth = 0;
    int fs = 0;
    int zf = 0;
    boolean have = false;
    try {
      String cssfile = cms.getRequestContext().removeSiteRoot(getCssFile());
      String linkpath = cms.getRequestContext().removeSiteRoot(getLinkFile());
      CmsObject obj = cms.getCmsObject();
      CmsFile config = obj.readFile(cssfile, CmsResourceFilter.IGNORE_EXPIRATION);
      CmsXmlContent configuration = CmsXmlContentFactory.unmarshal(obj, config);
      String mainwidth = configuration.getStringValue(obj, "main.width", locale);
      String imgwidth = configuration.getStringValue(obj, "img.width", locale);
      String trmargin = configuration.getStringValue(obj, "tr.margin", locale);
      String fontsize = configuration.getStringValue(obj, "font.size", locale);

      String imguprowbgimage = configuration.getStringValue(obj, "img.uprow.bgimage", locale);
      String imgdownrowbgimage = configuration.getStringValue(obj, "img.downrow.bgimage", locale);
      List lt = new ArrayList();

      I_CmsXmlContentContainer container;

      container = cmsx.contentload("singleFile", linkpath, true);

      while (container.hasMoreResources()) {

        I_CmsXmlContentContainer container1 = cmsx.contentloop(container, "ProgramLink");

        for (int number = 0; container1.hasMoreResources() && number < 2; number++) {

          if (number == 0) {
            folderpath1 = cmsx.contentshow(container1, "ProgramLink");
          } else {
            folderpath2 = cmsx.contentshow(container1, "ProgramLink");
          }
        }
      }

      String fileName = config.getName();
      if (CmsStringUtil.isEmpty(getCssIndicator())) {
        html.append("<style type=\"text/css\">\n");
        html.append("<!--");
        html.append(buildCSS(cms, cssfile));
        html.append("-->");
        html.append("</style>\n");
      }
      if (CmsStringUtil.isNotEmpty(getCssIndicator())
          && A_LanghuaTag.CSS_INDICATOR_NOSTYLE.equals(getCssIndicator())) {

        html.append(buildCSS(cms, cssfile));
      }
      if (CmsStringUtil.isEmpty(getCssIndicator())
          || A_LanghuaTag.CSS_INDICATOR_CUSTOMIZED.equals(getCssIndicator())) {
        html.append("<div align=\"center\">\n");
        html.append("<div class=\"content" + fileName + "\">\n");
        html.append("<div class=\"img" + fileName + "\">");
        html.append("</div>");
        if (CmsStringUtil.isNotEmpty(mainwidth) && CmsStringUtil.isNotEmpty(imgwidth)) {
          mwidth = Integer.parseInt(mainwidth);
          iwidth = Integer.parseInt(imgwidth);
          fwidth = mwidth - iwidth;
        }
        if (CmsStringUtil.isNotEmpty(trmargin)) {
          twidth = Integer.parseInt(trmargin);
        }
        if (CmsStringUtil.isNotEmpty(fontsize)) {
          fs = Integer.parseInt(fontsize);
        }
        if (CmsStringUtil.isEmpty(imguprowbgimage)) {
          html.append("<div class=\"uprow" + fileName + "\" >");
        } else {
          String uprowuri = cms.link(imguprowbgimage);
          html.append(
              "<div class=\"uprow" + fileName + "\" style=\"background:url(" + uprowuri + ");\">");
        }
        if (CmsStringUtil.isNotEmpty(folderpath1)) {

          List<CmsJspNavElement> list =
              new CmsJspNavBuilder(cms.getCmsObject()).getNavigationForFolder(folderpath1);
          for (int j = 0; j < list.size(); j++) {
            CmsJspNavElement nav = (CmsJspNavElement) list.get(j);
            String ntitle = nav.getNavText();
            String npath = cms.link(nav.getResourceName());
            int nl = ntitle.length();
            nl = nl * fs;
            zf = zf + twidth + nl;
            if (zf > fwidth && (fwidth != 0)) {
              have = true;
            }
            if (have) {
              TitleFont titfont = new TitleFont();
              titfont.setTitlefont(ntitle);
              titfont.setPath(npath);
              lt.add(titfont);

            } else {
              html.append("<div class=\"tr" + fileName + "\">");
              html.append("<a href=\"" + npath + "\"  class=\"uplink" + fileName + "\">");
              html.append(ntitle);
              html.append("</a>");
              html.append("</div>");
            }
          }
        }

        I_CmsXmlContentContainer container0;

        container0 = cmsx.contentload("singleFile", linkpath, true);

        while (container0.hasMoreResources()) {

          I_CmsXmlContentContainer container1 = cmsx.contentloop(container0, "SuperLink");

          while (container1.hasMoreResources()) {
            String description = cmsx.contentshow(container1, "Description");
            String uri = cmsx.contentshow(container1, "SuperLink");
            uri = cms.getRequestContext().removeSiteRoot(uri);
            String id = cmsx.contentshow(container1, "ID");
            if ("1".equals(id)) {
              html.append("<div class=\"tr" + fileName + "\">");
              html.append("<a href=\"" + uri + "\" class=\"uplink" + fileName + "\">\n");
              html.append(description);
              html.append("</a>\n");
              html.append("</div>");
            }
          }
        }
        html.append("</div>");
        if (CmsStringUtil.isEmpty(imgdownrowbgimage)) {
          html.append("<div class=\"downrow" + fileName + "\" >");
        } else {
          String downrowuri = cms.link(imgdownrowbgimage);
          html.append(
              "<div class=\"downrow"
                  + fileName
                  + "\" style=\"background:url("
                  + downrowuri
                  + ");\">");
        }
        ListIterator iterator = lt.listIterator();
        if (have) {
          while (iterator.hasNext()) {
            TitleFont titfont = new TitleFont();
            titfont = (TitleFont) iterator.next();

            html.append("<div class=\"tr" + fileName + "\">");
            html.append(
                "<a href=\"" + titfont.getPath() + "\"  class=\"downlink" + fileName + "\">");
            html.append(titfont.getTitlefont());
            html.append("</a>");
            html.append("</div>");
          }
        }
        if (CmsStringUtil.isNotEmpty(folderpath2)) {
          List<CmsJspNavElement> list =
              new CmsJspNavBuilder(cms.getCmsObject()).getNavigationForFolder(folderpath2);
          for (int j = 0; j < list.size(); j++) {
            CmsJspNavElement nav = (CmsJspNavElement) list.get(j);
            html.append("<div class=\"tr" + fileName + "\">");
            html.append(
                "<a href=\""
                    + cms.link(nav.getResourceName())
                    + "\"  class=\"downlink"
                    + fileName
                    + "\">");
            html.append(nav.getNavText());
            html.append("</a>");
            html.append("</div>");
          }
        }
        I_CmsXmlContentContainer container3;

        container3 = cmsx.contentload("singleFile", linkpath, true);

        while (container3.hasMoreResources()) {

          I_CmsXmlContentContainer container1 = cmsx.contentloop(container3, "SuperLink");

          while (container1.hasMoreResources()) {
            String description = cmsx.contentshow(container1, "Description");
            String uri = cmsx.contentshow(container1, "SuperLink");
            String id = cmsx.contentshow(container1, "ID");
            if ("2".equals(id)) {
              html.append("<div class=\"tr" + fileName + "\">");
              html.append("<a href=\"" + uri + "\" class=\"downlink" + fileName + "\">\n");
              html.append(description);
              html.append("</a>\n");
              html.append("</div>");
            }
          }
        }

        html.append("</div>");
        html.append("</div>");

        html.append("</div>");
      }
    } catch (Exception e1) {

      if (LOG.isDebugEnabled()) {
        LOG.debug(e1);
      }
    }

    return html.toString();
  }
  /**
   * Calculates the date to use for comparison of this resource based on the given date identifiers.
   *
   * <p>
   *
   * @param cms the current OpenCms user context
   * @param resource the resource to create the key for
   * @param dateIdentifiers the date identifiers to use for selecting the date
   * @param defaultValue the default value to use in case no value can be calculated
   * @return the calculated date
   * @see CmsDateResourceComparator for a description about how the date identifieres are used
   */
  public static long calculateDate(
      CmsObject cms, CmsResource resource, List<String> dateIdentifiers, long defaultValue) {

    long result = 0;
    List<CmsProperty> properties = null;
    for (int i = 0, size = dateIdentifiers.size(); i < size; i++) {
      // check all configured comparisons
      String date = dateIdentifiers.get(i);
      int pos = DATE_ATTRIBUTES_LIST.indexOf(date);
      switch (pos) {
        case 0: // "dateCreated"
          result = resource.getDateCreated();
          break;
        case 1: // "dateLastModified"
          result = resource.getDateLastModified();
          break;
        case 2: // "dateContent"
          if (resource.isFile()) {
            // date content makes no sense for folders
            result = resource.getDateContent();
          }
          break;
        case 3: // "dateReleased"
          long dr = resource.getDateReleased();
          if (dr != CmsResource.DATE_RELEASED_DEFAULT) {
            // default release date must be ignored
            result = dr;
          }
          break;
        case 4: // "dateExpired"
          long de = resource.getDateExpired();
          if (de != CmsResource.DATE_EXPIRED_DEFAULT) {
            // default expiration date must be ignored
            result = de;
          }
          break;
        default:
          // of this is not an attribute, assume this is a property
          if (properties == null) {
            // we may not have to read the properties since the user may only use attributes,
            // so use lazy initializing here
            try {
              properties = cms.readPropertyObjects(resource, false);
            } catch (CmsException e) {
              // use empty list in case of an error, to avoid further re-read tries
              properties = Collections.emptyList();
            }
          }
          String propValue = CmsProperty.get(date, properties).getValue();
          if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(propValue)) {
            try {
              result = Long.parseLong(propValue.trim());
            } catch (NumberFormatException e) {
              // maybe we have better luck with the next property
            }
          }
          break;
      }
      if (result != 0) {
        // if a date value has been found, terminate the loop
        break;
      }
    }
    if (result == 0) {
      // if nothing else was found, use default
      result = defaultValue;
    }
    return result;
  }
Exemplo n.º 11
0
  /**
   * Creates a list of new resources of the specified folder and filters the unwanted resources.
   *
   * <p>If the parameter categoryFolders is an empty list, all new resources are returned, otherwise
   * only those resources which are in a subfolder specified by the list.
   *
   * <p>
   *
   * @param cms the CmsObject
   * @param startFolder the root folder
   * @param startDate the start date in milliseconds
   * @param endDate the end date in milliseconds
   * @param selectedCategories list with selected categories/folders
   * @param openedCategories list with opened categories/folders
   * @return list of new resources
   */
  private static List<CmsResource> getNewResourceList(
      CmsObject cms,
      String startFolder,
      long startDate,
      long endDate,
      List<String> selectedCategories,
      List<String> openedCategories) {

    List<CmsResource> searchResult = null;
    List<CmsResource> foundResources = null;
    Set<CmsUUID> addedResources = null;

    if (LOG.isDebugEnabled()) {

      StringBuffer buf = new StringBuffer();
      for (int i = 0, n = selectedCategories.size(); i < n; i++) {
        buf.append(selectedCategories.get(i));

        if (i < (n - 1)) {
          buf.append(", ");
        }
      }

      LOG.debug("################ INPUT VALUES FOR NEW DOCUMENTS SEARCH");
      LOG.debug("startDate : " + startDate + " " + new java.util.Date(startDate).toString());
      LOG.debug("endDate : " + endDate + " " + new java.util.Date(endDate).toString());
      LOG.debug("startFolder : " + startFolder);
      LOG.debug("categories : " + buf.toString());
    }

    try {

      // get all resources in the site root which are in the time range
      CmsResourceFilter filter = CmsResourceFilter.IGNORE_EXPIRATION;
      filter = filter.addRequireLastModifiedAfter(startDate);
      filter = filter.addRequireLastModifiedBefore(endDate);
      foundResources = cms.readResources(startFolder, filter);
    } catch (CmsException e) {

      if (LOG.isErrorEnabled()) {
        LOG.error(
            "Error reading resources in time range "
                + new java.util.Date(startDate).toString()
                + " - "
                + new java.util.Date(endDate).toString()
                + " below folder "
                + startFolder,
            e);
      }
      foundResources = Collections.emptyList();
    }

    if (selectedCategories.size() == 0) {

      // return all found resources with filtered links
      searchResult = filterLinkedResources(foundResources);
    } else {

      addedResources = new HashSet<CmsUUID>();
      searchResult = new ArrayList<CmsResource>();
      long currentTime = System.currentTimeMillis();

      for (int i = 0, n = foundResources.size(); i < n; i++) {

        // analyze each resource if it has to be included in the search result

        CmsResource resource = foundResources.get(i);

        // filter those documents that are folders or outside the release and expire window
        if (resource.isFolder()
            || (resource.getDateReleased() > currentTime)
            || (resource.getDateExpired() < currentTime)) {
          // skip folders and resources outside time range
          continue;
        }

        String resourceName = cms.getRequestContext().removeSiteRoot(resource.getRootPath());
        String parentFolder = CmsResource.getParentFolder(resourceName);
        boolean addToResult = false;

        if (!selectedCategories.contains(parentFolder) && openedCategories.contains(parentFolder)) {

          // skip resources that are inside an opened, but un-selected category/folder
          continue;
        }

        // check if the parent folder of the resource is one of the selected categories/folders
        addToResult = selectedCategories.contains(parentFolder);

        if (!addToResult) {

          // check if the resource is inside a collapsed sub-tree
          // of a selected category

          int openedCategoryCount = 0;

          while (!"/".equals(parentFolder)) {

            if (openedCategories.contains(parentFolder)) {
              openedCategoryCount++;
            }

            if (selectedCategories.contains(parentFolder) && (openedCategoryCount == 0)) {

              // we found a selected parent category,
              // and it's sub-tree is collapsed
              addToResult = true;
              break;
            }

            parentFolder = CmsResource.getParentFolder(parentFolder);
          }
        }

        if (!addToResult) {

          // continue with the next resource
          continue;
        }

        if (CmsDocumentFactory.isIgnoredDocument(resourceName, true)) {
          // this resource is ignored, skip it before checking the resource id
          continue;
        }

        // check if the resource is a sibling that has already been added to the search result
        CmsUUID resourceId = resource.getResourceId();
        if (!addedResources.contains(resourceId)) {

          // add resource to the result
          addedResources.add(resourceId);
          searchResult.add(resource);
        }
      }
    }

    return searchResult;
  }
  /**
   * @see org.opencms.module.I_CmsModuleAction#initialize(CmsObject cmsObject,
   *     CmsConfigurationManager cmsConfigurationManager, CmsModule cmsModule)
   */
  public void initialize(
      CmsObject cmsObject, CmsConfigurationManager cmsConfigurationManager, CmsModule cmsModule) {
    boolean isTransmitMaiJobThere = false;
    boolean isDeletionJobThere = false;
    TreeMap map = new TreeMap();
    CmsContextInfo context = new CmsContextInfo(cmsObject.getRequestContext());

    CmsScheduleManager scheduleManager = OpenCms.getScheduleManager();
    List jobs = scheduleManager.getJobs();
    Iterator jobsIter = jobs.iterator();
    while (jobsIter.hasNext()) {
      CmsScheduledJobInfo jobInfo = ((CmsScheduledJobInfo) jobsIter.next());
      log.debug("The name of the ScheduledClass is : " + jobInfo.getClassName());
      log.debug("The name of the ScheduledJob is : " + jobInfo.getJobName());
      if (jobInfo.getClassName().equals(CLASSNAME_TRANSMIT_MAIL)) {
        isTransmitMaiJobThere = true;
      }
      if (jobInfo.getClassName().equals(CLASSNAME_DELETION_JOB)) {
        isDeletionJobThere = true;
      }
    }
    // check if the necessary jobs are there or not
    if (!isDeletionJobThere) {
      try {
        // create a new schedule job at the opencms system to delete greeting cards from archive
        // after a specified time
        CmsScheduledJobInfo scheduleDeletionJob =
            new CmsScheduledJobInfo(
                null,
                JOBNAME_DELETION_JOB,
                CLASSNAME_DELETION_JOB,
                context,
                CRONEXPRESSION_DELETION_JOB,
                false,
                true,
                map);
        // add the new job to the schedule manager
        scheduleManager.scheduleJob(cmsObject, scheduleDeletionJob);
      } catch (CmsRoleViolationException ex) {
        log.error("Exception scheduling job", ex);
      } catch (CmsSchedulerException ex) {
        log.error("Exception scheduling job", ex);
      }
    }
    if (!isTransmitMaiJobThere) {
      try {
        // create a new schedule job at the opencms system to transmit mails at the specified
        // timestamp
        CmsScheduledJobInfo newScheduleJob =
            new CmsScheduledJobInfo(
                null,
                JOBNAME_TRANSMIT_MAIL,
                CLASSNAME_TRANSMIT_MAIL,
                context,
                CRONEXPRESSION_TRANSMIT_MAIL,
                false,
                true,
                map);
        // add the new job to the schedule manager
        scheduleManager.scheduleJob(cmsObject, newScheduleJob);
      } catch (CmsRoleViolationException ex) {
        log.error("Exception scheduling job", ex);
      } catch (CmsSchedulerException ex) {
        log.error("Exception scheduling job", ex);
      }
    }
  }
Exemplo n.º 13
0
  public String buildHtml() {
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
    HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
    CmsJspActionElement cms = new CmsJspActionElement(pageContext, request, response);
    StringBuffer html = new StringBuffer(512);
    String fileName = null;
    boolean showWeekday = true;
    try {
      if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getCssFile())) {
        String cssfile = cms.getRequestContext().removeSiteRoot(getCssFile());
        CmsObject cmso = cms.getCmsObject();
        Locale locale = cms.getRequestContext().getLocale();
        CmsFile configFile = cmso.readFile(cssfile, CmsResourceFilter.IGNORE_EXPIRATION);
        CmsXmlContent configuration = CmsXmlContentFactory.unmarshal(cmso, configFile);
        showWeekday =
            Boolean.parseBoolean(configuration.getStringValue(cmso, "showweekday", locale));
        fileName = configFile.getName();
        html.append("<style type=\"text/css\">\n");
        html.append("<!--");
        html.append(buildCSS(cms, cssfile));
        html.append("-->");
        html.append("</style>\n");
      }
      html.append(
          "<div"
              + (CmsStringUtil.isEmpty(fileName) ? "" : (" class=\"topTime" + fileName + "\""))
              + ">\n");
      html.append("<SCRIPT language=\"JavaScript\">\n");
      html.append("dayObj=new Date();\n");
      html.append("monthStr=dayObj.getMonth()+1;\n");
      html.append("year=dayObj.getFullYear();\n");
      html.append(
          "document.write(year+\""
              + cms.label(Messages.YEAR)
              + "\"+monthStr+\""
              + cms.label(Messages.MONTH)
              + "\"+dayObj.getDate()+\""
              + cms.label(Messages.DAY)
              + "\"+\" \"); \n");
      if (showWeekday) {
        html.append("document.write(\"&nbsp;\");\n");
        html.append(
            "if(dayObj.getDay()==1) document.write(\"" + cms.label(Messages.XQYI) + "\");\n");
        html.append(
            "if(dayObj.getDay()==2) document.write(\"" + cms.label(Messages.XQER) + "\");\n");
        html.append(
            "if(dayObj.getDay()==3) document.write(\"" + cms.label(Messages.XQSAN) + "\");\n");
        html.append(
            "if(dayObj.getDay()==4) document.write(\"" + cms.label(Messages.XQSI) + "\");\n");
        html.append(
            "if(dayObj.getDay()==5) document.write(\"" + cms.label(Messages.XQWU) + "\");\n");
        html.append(
            "if(dayObj.getDay()==6) document.write(\"" + cms.label(Messages.XQLIU) + "\");\n");
        html.append(
            "if(dayObj.getDay()==0) document.write(\"" + cms.label(Messages.XQRI) + "\");\n");
      }
      html.append("</SCRIPT>");
      html.append("</div>\n");
    } catch (Exception e) {
      LOG.debug(e);
    }

    return html.toString();
  }
  /**
   * Fills a single item.
   *
   * <p>
   *
   * @param resource the corresponding resource.
   * @param item the item to fill.
   * @param id used for the ID column.
   */
  @SuppressWarnings("unchecked")
  private void fillItem(final CmsResource resource, final CmsListItem item, final int id) {

    CmsObject cms = this.getCms();
    CmsXmlContent xmlContent;

    I_CmsResourceType type;
    String iconPath;

    // fill path column:
    String sitePath = cms.getSitePath(resource);
    item.set(LIST_COLUMN_PATH, sitePath);

    // fill language node existence column:
    item.set(LIST_COLUMN_PATH, sitePath);
    boolean languageNodeExists = false;
    String languageNodeHtml;

    List<Locale> sysLocales = OpenCms.getLocaleManager().getAvailableLocales();
    try {
      xmlContent = CmsXmlContentFactory.unmarshal(cms, cms.readFile(resource));
      for (Locale locale : sysLocales) {
        languageNodeExists = xmlContent.hasLocale(locale);
        if (languageNodeExists) {
          languageNodeHtml = "<input type=\"checkbox\" checked=\"checked\" disabled=\"disabled\"/>";
        } else {
          languageNodeHtml = "<input type=\"checkbox\" disabled=\"disabled\"/>";
        }
        item.set(locale.toString(), languageNodeHtml);
      }
    } catch (Throwable e1) {
      LOG.error(
          Messages.get().getBundle().key(Messages.LOG_ERR_LANGUAGECOPY_DETERMINE_LANGUAGE_NODE_1),
          e1);
      languageNodeHtml = "n/a";
      for (Locale locale : sysLocales) {
        item.set(locale.toString(), languageNodeHtml);
      }
    }

    // type column:
    type = OpenCms.getResourceManager().getResourceType(resource);
    item.set(LIST_COLUMN_RESOURCETYPE, type.getTypeName());

    // icon column with title property for tooltip:
    String title = "";
    try {
      CmsProperty titleProperty =
          cms.readPropertyObject(resource, CmsPropertyDefinition.PROPERTY_TITLE, true);
      title = titleProperty.getValue();
    } catch (CmsException e) {
      LOG.warn(Messages.get().getBundle().key(Messages.LOG_WARN_LANGUAGECOPY_READPROP_1), e);
    }

    iconPath =
        getSkinUri()
            + CmsWorkplace.RES_PATH_FILETYPES
            + OpenCms.getWorkplaceManager().getExplorerTypeSetting(type.getTypeName()).getIcon();
    String iconImage;
    iconImage =
        "<img src=\""
            + iconPath
            + "\" alt=\""
            + type.getTypeName()
            + "\" title=\""
            + title
            + "\" />";
    item.set(LIST_COLUMN_ICON, iconImage);
  }