示例#1
0
文件: Time.java 项目: skyzluo/langhua
  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();
  }
示例#2
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();
  }
  /**
   * 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);
  }