Esempio n. 1
0
  // 生成home页面的主文章列表html代码
  public String generateHomeMainHtml(List<TArticle> articles) throws Exception {
    String listHtml = "";
    if (articles != null) {
      int size = articles.size();
      for (int i = 0; i < size; i++) {
        TArticle article = articles.get(i);

        // 组织标签的html
        String tagsHtml = "";
        String[] tags = article.getArticle_Tag().split(",");
        for (int j = 0; j < tags.length; j++) {
          String tag = URLEncoder.encode(URLEncoder.encode(tags[j], "utf-8"));
          if (j == 0) {
            tagsHtml +=
                "<a title='"
                    + tags[j]
                    + "' rel='tag' href='/doit/search/"
                    + tag
                    + "/0/2/search' style='font-size:13px;'>"
                    + tags[j]
                    + "</a>";
          } else {
            tagsHtml +=
                " , <a title='"
                    + tags[j]
                    + "' rel='tag' href='/doit/search/"
                    + tag
                    + "/0/2/search' style='font-size:13px;'>"
                    + tags[j]
                    + "</a>";
          }
        }

        OperateString operateString = new OperateString();
        String contentHtml = article.getArticle_Content();
        // String contentHtml = "dsafkjbsdkds<pre class='brush: js;'>function
        // helloSyntaxHighlighter(){return 'hi!';}</pre><div class='ui segment '><img src='123.png'
        // /><IMG src='456.png' /></div>afkjbsdkdsafkjbsdk中文结尾";
        // 过滤图片
        OperateImage operateImage = new OperateImage();
        contentHtml = operateImage.filterImage(contentHtml);
        // 过滤html所有标签
        contentHtml = operateString.filterHtmlTag(contentHtml);
        // 截取字符串
        contentHtml = operateString.interceptCharacters(contentHtml, 0, 200);

        String item = "";
        item += "<div id='item" + article.getArticle_ID() + "' class='ui stacked segment'>";
        item += "	<h2 class='article_title'>";
        item +=
            "		<a href='/doit/show/"
                + article.getArticle_ID()
                + "' style='font-size:24px;'>"
                + article.getArticle_Title()
                + "</a>";
        item += "	</h2>";
        item += "	<h2></h2>";
        item += "	<div class='article_date'>";
        item +=
            "		<span property='dc:date dc:created' content='2013-11-10T12:30:01+08:00' datatype='xsd:dateTime' rel='sioc:has_creator' style='margin-right:20px;'>	发布时间 : "
                + article.getArticle_Date()
                + " </span>";
        item += "		<span style='color:#434A54;'>Tags : </span>";
        item += tagsHtml;
        item += "	</div>";
        item += "	<div class='row'>";
        item +=
            "		<a class='thumbnail' href='/doit/show/"
                + article.getArticle_ID()
                + "' style='float:left;width:240px;oveflow:hidden;'>";
        item +=
            "			<img src='"
                + article.getArticle_Cover()
                + "' style='height: 175px; width: 100%; display: block;' data-src='holder.js/100%x175'>";
        item += "		</a>";
        item +=
            "		<span id='artContent"
                + article.getArticle_ID()
                + "' class='sDiv article_content'>"
                + contentHtml
                + "</span>";
        item += "	</div>";
        item += "</div>";

        listHtml += item;
      }
    }
    System.out.println(listHtml);
    return listHtml;
  }
Esempio n. 2
0
  // 生成个人作品页面的作品列表html代码
  public String generateWorksMainHtml(List<TArticle> articles) throws UnsupportedEncodingException {
    String listHtml = "";
    if (articles != null) {
      int size = articles.size();
      for (int i = 0; i < size; i++) {

        if (i % 2 != 0) { // 奇数
          TArticle prevArticle = articles.get(i - 1); // 获得这一行的第一个
          TArticle nowArticle = articles.get(i); // 获得这一行的第二个

          // 获取封面
          String prevCoverHtml = "";
          String nowCoverHtml = "";
          if (prevArticle.getArticle_Cover() == "") {
            prevCoverHtml = "/doit/common/images/cover_default.png";
          } else {
            prevCoverHtml = prevArticle.getArticle_Cover();
          }
          if (nowArticle.getArticle_Cover() == "") {
            nowCoverHtml = "/doit/common/images/cover_default.png";
          } else {
            nowCoverHtml = nowArticle.getArticle_Cover();
          }

          // 组织html
          String rowItem = "";
          rowItem += "<div class='row'>";
          rowItem += "	<div class='col-md-6'>";
          rowItem +=
              "		<a class='works_item' href='/doit/show/" + prevArticle.getArticle_ID() + "'>";
          rowItem += "			<div class='works_pic'>";
          rowItem +=
              "				<img class='img-responsive' xsalt='Responsive image' src='"
                  + prevCoverHtml
                  + "' />";
          rowItem += "			</div>";
          rowItem += "			<div class='works_info'>";
          rowItem += "				<div class='works_name'>" + prevArticle.getArticle_Title() + "</div>";
          rowItem += "				<div class='works_others'>";
          rowItem += "					<span class='works_others_guide'>";
          rowItem += "						<span>" + prevArticle.getArticle_Tag() + "</span>";
          rowItem += "					</span>";
          rowItem += "					<span class='works_others_info'>";
          rowItem +=
              "						<i class='unhide icon' style='margin:0 2px 0 20px;'></i>"
                  + prevArticle.getRead_Num()
                  + "";
          rowItem +=
              "						<i class='heart icon' style='margin:0 2px 0 10px;'></i>"
                  + prevArticle.getRecommend_Num()
                  + "";
          rowItem += "					</span>";
          rowItem += "				</div>";
          rowItem += "			</div>";
          rowItem += "		</a>";
          rowItem += "	</div>";
          rowItem += "	<div class='col-md-6'>";
          rowItem +=
              "		<a class='works_item' href='/doit/show/" + nowArticle.getArticle_ID() + "'>";
          rowItem += "			<div class='works_pic'>";
          rowItem +=
              "				<img class='img-responsive' xsalt='Responsive image' src='"
                  + nowCoverHtml
                  + "' />";
          rowItem += "			</div>";
          rowItem += "			<div class='works_info'>";
          rowItem += "				<div class='works_name'>" + nowArticle.getArticle_Title() + "</div>";
          rowItem += "				<div class='works_others'>";
          rowItem += "					<span class='works_others_guide'>";
          rowItem += "						<span>" + nowArticle.getArticle_Tag() + "</span>";
          rowItem += "					</span>";
          rowItem += "					<span class='works_others_info'>";
          rowItem +=
              "						<i class='unhide icon' style='margin:0 2px 0 20px;'></i>"
                  + nowArticle.getRead_Num()
                  + "";
          rowItem +=
              "						<i class='heart icon' style='margin:0 2px 0 10px;'></i>"
                  + nowArticle.getRecommend_Num()
                  + "";
          rowItem += "					</span>";
          rowItem += "				</div>";
          rowItem += "			</div>";
          rowItem += "		</a>";
          rowItem += "	</div>";
          rowItem += "</div>";

          listHtml += rowItem;
        } else { // 偶数
          if (i + 1 == size) { // 最后一个
            TArticle nowArticle = articles.get(i); // 获得这一行的第二个

            // 获取封面
            String nowCoverHtml = "";
            if (nowArticle.getArticle_Cover() == "") {
              nowCoverHtml = "/doit/common/images/cover_default.png";
            } else {
              nowCoverHtml = nowArticle.getArticle_Cover();
            }

            // 组织html
            String rowItem = "";
            rowItem += "<div class='row'>";
            rowItem += "	<div class='col-md-6'>";
            rowItem +=
                "		<a class='works_item' href='/doit/show/" + nowArticle.getArticle_ID() + "'>";
            rowItem += "			<div class='works_pic'>";
            rowItem +=
                "				<img class='img-responsive' xsalt='Responsive image' src='"
                    + nowCoverHtml
                    + "' />";
            rowItem += "			</div>";
            rowItem += "			<div class='works_info'>";
            rowItem += "				<div class='works_name'>" + nowArticle.getArticle_Title() + "</div>";
            rowItem += "				<div class='works_others'>";
            rowItem += "					<span class='works_others_guide'>";
            rowItem += "						<span>" + nowArticle.getArticle_Tag() + "</span>";
            rowItem += "					</span>";
            rowItem += "					<span class='works_others_info'>";
            rowItem +=
                "						<i class='unhide icon' style='margin:0 2px 0 20px;'></i>"
                    + nowArticle.getRead_Num()
                    + "";
            rowItem +=
                "						<i class='heart icon' style='margin:0 2px 0 10px;'></i>"
                    + nowArticle.getRecommend_Num()
                    + "";
            rowItem += "					</span>";
            rowItem += "				</div>";
            rowItem += "			</div>";
            rowItem += "		</a>";
            rowItem += "	</div>";
            rowItem += "</div>";

            listHtml += rowItem;
          }
        }
      }
    }
    return listHtml;
  }