예제 #1
0
  /**
   * 解析分类标签
   *
   * @param htmlContent  原始html内容
   * @param column
   * @param websiteUrl 网站连接地址
   * @return
   */
  private String parseChannel() {
    // 替换完文章标签后的HTML模版

    // 当只存在栏目ID时,解析相关的文章中的栏目标签
    if (column != null) {
      ColumnEntity tmp = null;
      String columnTitle = column.getCategoryTitle();
      int columnId = column.getCategoryId();
      // 解析当前栏目信息
      htmlContent = new ColumnParser(htmlContent, column, this.getWebsiteUrl()).parse();
      // 解析当前栏目id// 替换文章所在栏目标签:{ms:field.typeid/}
      ArticleTypeIdParser atId = new ArticleTypeIdParser(htmlContent, columnId + "");
      if (atId.isTop()) {
        if (column.getCategoryCategoryId() > 0) {
          tmp = (ColumnEntity) columnBiz.getEntity(column.getCategoryCategoryId());
          columnId = tmp.getCategoryId();
        }
      }
      htmlContent = new ArticleTypeIdParser(htmlContent, column.getCategoryId() + "").parse();
      // 替换文章所在栏目标签:{ms:field.typetitle/}
      ArticleTypeTitleParser attp = new ArticleTypeTitleParser(htmlContent, columnTitle);
      if (attp.isTop()) {
        if (column.getCategoryCategoryId() > 0) {
          tmp = (ColumnEntity) columnBiz.getEntity(column.getCategoryCategoryId());
          columnTitle = tmp.getCategoryTitle();
        }
      }
      attp.setNewCotent(columnTitle);
      htmlContent = attp.parse();
      // 替换文章栏目链接标签{ms:filed.typelink/}
      ArticleTypeLinkParser atlp =
          new ArticleTypeLinkParser(
              htmlContent,
              this.getWebsiteUrl()
                  + column.getColumnPath()
                  + File.separator
                  + IParserRegexConstant.HTML_INDEX);
      if (atlp.isTop()) {
        if (column.getCategoryCategoryId() > 0) { // 如果用户写分类名称标签的时候没有使用top属性,而在使用连接标签的时候使用就再次查询分类
          tmp = (ColumnEntity) columnBiz.getEntity(column.getCategoryCategoryId());
          atlp.setNewCotent(
              this.getWebsiteUrl()
                  + tmp.getColumnPath()
                  + File.separator
                  + IParserRegexConstant.HTML_INDEX);
        } else {
          atlp.setNewCotent(
              this.getWebsiteUrl()
                  + column.getColumnPath()
                  + File.separator
                  + IParserRegexConstant.HTML_INDEX);
        }
      }
      htmlContent = atlp.parse();
    }
    // //----------------------------解析栏目标签----------------------------

    // //替换完列表标签后的HTML文件
    String channel = htmlContent;

    // 查找当前模版页面拥有多少个栏目列表标签
    int strNumType = ChannelParser.channelNum(channel);

    for (int i = 0; i < strNumType; i++) {
      // 当前列表栏目中属性的集合
      Map<String, String> mapProperty = ChannelParser.channelProperty(channel);

      // 取当前标签下的栏目ID
      int tempColumnId = StringUtil.string2Int(mapProperty.get(ChannelParser.CHANNEL_TYPEID));

      if (tempColumnId == 0 && column != null) {
        tempColumnId = column.getCategoryId();
      }
      List<ColumnEntity> categoryList = null;
      // 指定要显示的栏目数量
      String size = mapProperty.get(ChannelParser.CHANNEL_TYPE_SIZE);
      Integer _size = null;
      if (!StringUtil.isBlank(size) && StringUtil.isInteger(size)) {
        if (StringUtil.string2Int(size) > 0) {
          _size = StringUtil.string2Int(size);
        }
      }
      if (tempColumnId != 0) {
        // 取出栏目的取值范围
        String type = mapProperty.get(ChannelParser.CHANNEL_TYPE);
        // 同级栏目是否显示属性
        String childType = mapProperty.get(ChannelParser.CHANNEL_TYP_SIBLING);
        // 根据范围在BIZ中取出不同的栏目信息

        // 判断用户填写的栏目属性,如果未填写那么取当前栏目的下级栏目,如果但前栏目没有下级栏目那么晚取本级栏目
        // 如果填写:son,那么取下级栏目,没有下级栏目则取本级栏目
        // 如果为:top,那么取上级栏目,如果没有上级栏目则取本级栏目
        // 如果为:level,则取本级栏目
        if (type == null) {
          categoryList = columnBiz.queryChildListByColumnId(tempColumnId, _size);
          // 当值为true表示不存在子级分类时,显示他的同级分类
          if (childType != null && childType.equals("true") && categoryList.size() <= 0) {
            categoryList = columnBiz.querySibling(tempColumnId, _size);
          }
        } else if (type.equals(ChannelParser.CHANNEL_TYPE_SON)) {
          categoryList = columnBiz.queryChildListByColumnId(tempColumnId, _size);
        } else if (type.equals(ChannelParser.CHANNEL_TYPE_TOP)) {
          categoryList = columnBiz.queryTopSiblingListByColumnId(tempColumnId, _size);
        } else if (type.equals(ChannelParser.CHANNEL_TYPE_LEVEL)) {
          categoryList = columnBiz.querySibling(tempColumnId, _size);
        }
        // 替换栏目标签
        htmlContent =
            new ChannelParser(
                    channel,
                    categoryList,
                    this.getWebsiteUrl(),
                    column != null ? column.getCategoryId() : 0,
                    mapProperty.get(ChannelParser.CHANNEL_CLASS))
                .parse();
        // 替换完栏目标签后的HTML代码
        channel = htmlContent;
      } else {
        categoryList = columnBiz.queryChild(tempColumnId, app.getAppId(), modelId, _size);
        // 替换栏目标签
        htmlContent = new ChannelParser(channel, categoryList, this.getWebsiteUrl()).parse();
        // 替换完栏目标签后的HTML代码
        channel = htmlContent;
      }
    }
    // 替换完封面标签后的TML文件
    String channelContHtml = channel;
    // 查找当前模版页面拥有多少个封面列表标签
    int channelConNum = ChannelContParser.channelContNum(channelContHtml);
    for (int i = 0; i < channelConNum; i++) {
      // 取出当前封面标签中的封面ID
      int channelTypeId = ChannelContParser.channelContTypeId(channelContHtml);
      if (channelTypeId == 0 && column != null) {
        channelTypeId = column.getCategoryId();
      }
      String channelCont = "";
      // 取出当前封面的内容
      if (channelTypeId != 0) {
        List<ArticleEntity> arctile = articleBiz.queryListByColumnId(channelTypeId);
        if (arctile != null) {
          if (arctile.size() > 0) {
            channelCont = arctile.get(arctile.size() - 1).getArticleContent();
          } else {
            channelCont = arctile.get(arctile.size()).getArticleContent();
          }
        }
      }
      // 替换封面标签
      htmlContent = new ChannelContParser(channelContHtml, channelCont).parse();
      channelContHtml = htmlContent;
    }

    return htmlContent;
  }
예제 #2
0
  /**
   * 解析文章内容
   *
   * @param article 当前文章
   * @param previous当前文章的上一篇
   * @param next当前文章的下一篇
   * @return
   */
  private String parseArticle() {
    if (article == null) {
      return htmlContent;
    }
    // 获取文章所属的栏目实体
    ColumnEntity column = (ColumnEntity) columnBiz.getEntity(article.getBasicCategoryId());
    if (column == null) {
      return htmlContent;
    }
    // 替换文章作者标签:{ms:field.author/}
    htmlContent = new ArticleAuthorParser(htmlContent, article.getArticleAuthor()).parse();

    // 替换文章内容标签:{ms:field.content/}
    htmlContent = new ArticleContentParser(htmlContent, article.getArticleContent()).parse();

    // 替换文章时间标签:{ms:field.date fmt="yyyy-mm-dd"/}
    htmlContent = new ArticleDateParser(htmlContent, article.getBasicDateTime()).parse();

    // 替换文章发布来源标签:{ms:field.source/}
    htmlContent = new ArticleSourceParser(htmlContent, article.getArticleSource()).parse();

    // 替换文章标题标签: {ms:field.title/}
    htmlContent = new ArticleTitleParser(htmlContent, article.getBasicTitle()).parse();

    // 替换文章点击数标签: {ms:field.hit/}
    htmlContent = new ArticleHitParser(htmlContent, article.getBasicHit() + "").parse();

    // 替换文章id标签: {ms:field.id/}
    htmlContent = new ArticleIdParser(htmlContent, article.getBasicId() + "").parse();

    // 替换文章描述: {ms:field.Descrip/}
    htmlContent = new ArticleDescripParser(htmlContent, article.getBasicDescription()).parse();

    // 替换文章关键字: {ms:field.keyword/}
    htmlContent = new ArticleKeywordParser(htmlContent, article.getArticleKeyword()).parse();

    // 替换文章缩略图标签
    htmlContent = new ArticleLitpicParser(htmlContent, article.getBasicThumbnails()).parse();
    // 解析当前栏目信息
    htmlContent = new ColumnParser(htmlContent, column, this.getWebsiteUrl()).parse();
    // 替换文章栏目链接标签{ms:filed.typelink/}
    ColumnEntity tmp = null;
    htmlContent = new ArticleTypeIdParser(htmlContent, column.getCategoryId() + "").parse();
    ArticleTypeTitleParser attp =
        new ArticleTypeTitleParser(htmlContent, column.getCategoryTitle());
    if (attp.isTop()) {
      if (column.getCategoryCategoryId() > 0) {
        tmp = (ColumnEntity) columnBiz.getEntity(column.getCategoryCategoryId());
        attp.setNewCotent(tmp.getCategoryTitle());
      }
    } else {
      attp.setNewCotent(column.getCategoryTitle());
    }
    htmlContent = attp.parse();

    // 替换文章栏目链接标签{ms:filed.typelink/}
    ArticleTypeLinkParser atlp =
        new ArticleTypeLinkParser(
            htmlContent,
            this.getWebsiteUrl()
                + column.getColumnPath()
                + File.separator
                + IParserRegexConstant.HTML_INDEX);
    if (atlp.isTop()) {
      if (tmp == null
          && column.getCategoryCategoryId() > 0) { // 如果用户写分类名称标签的时候没有使用top属性,而在使用连接标签的时候使用就再次查询分类
        tmp = (ColumnEntity) columnBiz.getEntity(column.getCategoryCategoryId());
      }
      atlp.setNewCotent(
          this.getWebsiteUrl()
              + tmp.getColumnPath()
              + File.separator
              + IParserRegexConstant.HTML_INDEX);
    }
    htmlContent = atlp.parse();

    // 替换当前文章内容链接标签:{ms:field.link}
    htmlContent = new ArticleLinkParser(htmlContent, article.getArticleLinkURL()).parse();

    // 替换上一篇文章、下一篇文章,链接、标题,标签
    htmlContent = new ArticleHistoryParser(htmlContent, previous, next).parse();

    // 判断该文章是否有新增字段
    if (column.getColumnContentModelId() != 0) {
      // 根据表单类型id查找出所有的字段信息
      List<BaseEntity> listField = fieldBiz.queryListByCmid(column.getColumnContentModelId());
      // 遍历所有的字段实体,得到字段名列表信息
      List<String> listFieldName = new ArrayList<String>();
      for (int i = 0; i < listField.size(); i++) {
        ContentModelFieldEntity field = (ContentModelFieldEntity) listField.get(i);
        listFieldName.add(field.getFieldFieldName());
      }
      ContentModelEntity contentModel =
          (ContentModelEntity) contentBiz.getEntity(column.getColumnContentModelId());
      // 组织where条件
      Map<String, Integer> where = new HashMap<String, Integer>();
      where.put("basicId", article.getBasicId());
      // 获取各字段的值
      // 根据表单类型id查找出所有的字段信息
      List fieldLists = fieldBiz.queryBySQL(contentModel.getCmTableName(), listFieldName, where);
      if (fieldLists.size() > 0) {
        Map filedValue = (Map) fieldLists.get(0);
        if (filedValue != null) {
          htmlContent =
              new TaglibParser(
                      htmlContent,
                      filedValue,
                      column.getColumnContentModelId(),
                      fieldBiz,
                      listField)
                  .parse();
        }
      }

      // 读取并解析各标签内容
    }
    return htmlContent;
  }