cms.pageList.entity.SearcherLabel.java Source code

Java tutorial

Introduction

Here is the source code for cms.pageList.entity.SearcherLabel.java

Source

/**
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * 
 * Founder admin@love320.com
 * 
 * http://www.love320.com
 */
package cms.pageList.entity;

import java.util.List;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springside.modules.orm.Page;
import org.springside.modules.orm.PropertyFilter;

import cms.entity.account.Archives;
import cms.entity.account.TagLabel;
import cms.pageList.LabelInterface;
import cms.service.account.ArchivesTypeManager;

@Component
@Scope("prototype")
public class SearcherLabel implements LabelInterface {

    private Page<Archives> page;

    private ArchivesTypeManager atm;

    // ?PropertyFilter
    private String pfValue(String pfName, List<PropertyFilter> filters) {

        String pfValue = "0";
        // ??
        for (PropertyFilter pfTest : filters) {
            if (pfTest.getPropertyName().equals(pfName)) {
                // ?
                pfValue = pfTest.getMatchValue().toString();
            }

            // System.out.println(pfTest.getPropertyName().toString());
            // System.out.println(pfTest.getMatchValue().toString());
        }

        return pfValue;
    }

    public String getIterativeString(TagLabel tagLabel, List<PropertyFilter> filters) {

        String strTag = tagLabel.getTagName();// ??

        // System.out.println("------------------------------------");

        if (tagLabel == null)
            return strTag;

        // 

        // ??
        if ((!tagLabel.getOrderby().trim().equalsIgnoreCase(""))
                && (!tagLabel.getOrderbyType().trim().equalsIgnoreCase(""))) {

            String arcattStr = null;// 
            for (Long flagid : tagLabel.getflagIds()) {
                arcattStr += "," + flagid;
            }

            // 
            if (arcattStr != null) {
                // ?0,?
                if (tagLabel.getTypeid() == 0) {
                    addArchivesList(tagLabel.getRow(), 1, tagLabel.getOrderby(), tagLabel.getOrderbyType(),
                            Restrictions.ge("arcrank", 0),
                            Restrictions.sqlRestriction(
                                    "id in  ( select archives_id from archives_arcatt where arcatt_id in("
                                            + arcattStr + ") )"),
                            Restrictions.or(
                                    Restrictions.like("title", pfValue("title", filters), MatchMode.ANYWHERE),
                                    Restrictions.like("body", pfValue("title", filters), MatchMode.ANYWHERE)));
                } else {
                    addArchivesList(tagLabel.getRow(), 1, tagLabel.getOrderby(), tagLabel.getOrderbyType(),
                            Restrictions.eq("typeid", tagLabel.getTypeid()), Restrictions.ge("arcrank", 0),
                            Restrictions.sqlRestriction(
                                    "id in  ( select archives_id from archives_arcatt where arcatt_id in("
                                            + arcattStr + ") )"),
                            Restrictions.or(
                                    Restrictions.like("title", pfValue("title", filters), MatchMode.ANYWHERE),
                                    Restrictions.like("body", pfValue("title", filters), MatchMode.ANYWHERE)));
                }
            } else { // 

                // ?0,?
                if (tagLabel.getTypeid() == 0) {
                    addArchivesList(tagLabel.getRow(), 1, tagLabel.getOrderby(), tagLabel.getOrderbyType(),
                            Restrictions.ge("arcrank", 0),
                            Restrictions.or(
                                    Restrictions.like("title", pfValue("title", filters), MatchMode.ANYWHERE),
                                    Restrictions.like("body", pfValue("title", filters), MatchMode.ANYWHERE)));
                } else {
                    addArchivesList(tagLabel.getRow(), 1, tagLabel.getOrderby(), tagLabel.getOrderbyType(),
                            Restrictions.ge("arcrank", 0), Restrictions.eq("typeid", tagLabel.getTypeid()),
                            Restrictions.or(
                                    Restrictions.like("title", pfValue("title", filters), MatchMode.ANYWHERE),
                                    Restrictions.like("body", pfValue("title", filters), MatchMode.ANYWHERE)));
                }

            }

        } else { // ?
            // ?0,?

            if (tagLabel.getTypeid() == 0) {
                addArchivesList(tagLabel.getRow(), 1, "senddate", "desc", Restrictions.ge("arcrank", 0),
                        Restrictions.eq("typeid", tagLabel.getTypeid()));
            } else {
                addArchivesList(tagLabel.getRow(), 1, "senddate", "desc", Restrictions.ge("arcrank", 0));
            }

        }

        /*strTag = "<s:iterator value=\"pagecontent.listLabel.get("
        + pfValue("getNum", filters)
        + ").getPage().getResult()\" status=\"st\">"
        + tagLabel.getBody() + "</s:iterator>";*/
        strTag = "<#list pagecontent.listLabel.get(" + pfValue("getNum", filters)
                + ").getPage().getResult() as xx >" + tagLabel.getBody() + "</#list>";

        return strTag;
    }

    // ?(?)
    public void addArchivesList(int size, final Criterion... criterions) {
        addArchivesList(size, 1, null, null, criterions);
    }

    // ?(?)
    public void addArchivesList(int size, int pageNo, String orderBy, String order, final Criterion... criterions) {
        // ?
        if (size == 0)
            size = 10;
        page = new Page<Archives>(size);
        // ??
        if ((orderBy != null) && (order != null)) {
            page.setOrderBy(orderBy);
            page.setOrder(order);
        }
        // ??
        if (!page.isOrderBySetted()) {
            page.setOrderBy("sortrank");
            page.setOrder(Page.DESC);
        }
        // pageNo
        if (pageNo > 0) {
            page.setPageNo(pageNo);
        }
        // ??
        page = atm.getArchivesManager().getAdviceList(page, criterions);

    }

    @Autowired
    public void setAtm(ArchivesTypeManager atm) {
        this.atm = atm;
    }

    public Page getPage() {
        return page;
    }
}