Search in sources :

Example 11 with ModuleException

use of it.vige.rubia.ModuleException in project rubia-forums by flashboss.

the class ViewForum method execute.

/**
 */
@PostConstruct
public void execute() {
    // parse the input parameters
    int forumId = -1;
    String f = getParameter(p_forumId);
    if (f != null && f.trim().length() > 0) {
        forumId = parseInt(f);
    }
    // ForumsModule is stored as a final variable so that anonymous
    // class
    // could use it.
    final ForumsModule fm = forumsModule;
    // grab the data to be displayed for this page
    if (forumId != -1) {
        // be displayed
        try {
            forum = fm.findForumById(forumId);
            // Getting sticky topics for this page
            Collection<Topic> stickies = getStickyThreads();
            // Getting announcements
            Collection<Topic> announcements = getAnnouncements();
            normalThreads = fm.findTopicsDesc(forum, NORMAL, 0, MAX_VALUE);
            normalThreadsDataModel = new ListDataModel<Topic>(normalThreads);
            Collection<Topic> listOfTopics = new LinkedList<Topic>();
            listOfTopics.addAll(stickies);
            listOfTopics.addAll(announcements);
            listOfTopics.addAll(normalThreads);
            // Getting sticky topics for this page
            topicLastPosts = fm.findLastPostsOfTopics(listOfTopics);
            // topic minipaging
            for (Topic cour : listOfTopics) {
                if (cour.getReplies() > 0) {
                    PageNavigator topicNav = new PageNavigator(cour.getReplies() + 1, // this
                    userPreferences.getPostsPerTopic(), // current page of the navigator
                    0) {

                        /**
                         */
                        private static final long serialVersionUID = 6277599446838264687L;

                        protected Collection<Integer> initializePage() {
                            return null;
                        }
                    };
                    topicNavigator.put(cour.getId(), topicNav);
                }
            }
        } catch (ModuleException e) {
            log.error(e);
        }
    }
}
Also used : PageNavigator(it.vige.rubia.ui.PageNavigator) ForumsModule(it.vige.rubia.ForumsModule) Topic(it.vige.rubia.model.Topic) ModuleException(it.vige.rubia.ModuleException) LinkedList(java.util.LinkedList) PostConstruct(javax.annotation.PostConstruct)

Example 12 with ModuleException

use of it.vige.rubia.ModuleException in project rubia-forums by flashboss.

the class FeedsServlet method doGet.

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try {
        String[] uri = request.getRequestURI().split("/");
        if (uri.length < 5 || (uri[4].equals(GLOBAL) && uri.length != 5) || (!uri[4].equals(GLOBAL) && uri.length != 6)) {
            response.sendError(SC_BAD_REQUEST, WRONG_FEED_REQ);
            return;
        }
        String type = uri[3];
        String what = uri[4];
        Integer id = null;
        if (!what.equals(GLOBAL))
            id = valueOf(uri[5]);
        SyndFeed feed = new SyndFeedImpl();
        if (!setFeedType(feed, type)) {
            response.sendError(SC_BAD_REQUEST, WRONG_FEED_TYPE + type);
            return;
        }
        String url = null;
        String urlType = null;
        String urlRequestParam = request.getParameter("url");
        String urlTypeRequestParam = request.getParameter("urlType");
        if (urlRequestParam != null && urlRequestParam.trim().length() != 0 && urlTypeRequestParam != null && urlTypeRequestParam.trim().length() != 0 && (urlTypeRequestParam.compareTo("p") == 0 || urlTypeRequestParam.compareTo("s") == 0)) {
            url = request.getParameter("url");
            urlType = urlTypeRequestParam;
        }
        String urlInitParam = getServletContext().getInitParameter(URL_INIT_PARAM_NAME);
        String urlTypeInitParam = getServletContext().getInitParameter(URL_TYPE_INIT_PARAM_NAME);
        if (urlInitParam != null && urlInitParam.trim().length() != 0 && urlTypeInitParam != null && urlTypeInitParam.trim().length() != 0) {
            url = urlInitParam;
            urlType = urlTypeInitParam;
        }
        if (url == null || urlType == null) {
            response.sendError(SC_BAD_REQUEST, WRONG_FEED_REQ);
            return;
        }
        try {
            if (what.equals(CATEGORY)) {
                createCategoryFeed(feed, id, url, urlType);
            } else if (what.equals(FORUM)) {
                createForumFeed(feed, id, url, urlType);
            } else if (what.equals(TOPIC)) {
                createTopicFeed(feed, id, url, urlType);
            } else if (what.equals(GLOBAL)) {
                createGlobalFeed(feed, id, url, urlType);
            } else {
                response.sendError(SC_BAD_REQUEST, WRONG_FEED_SHOW_TYPE + what);
                return;
            }
        } catch (ModuleException e) {
            response.sendError(SC_INTERNAL_SERVER_ERROR, e.getMessage());
            return;
        }
        response.setContentType("text/xml");
        Writer writer = response.getWriter();
        SyndFeedOutput output = new SyndFeedOutput();
        output.output(feed, writer);
        writer.flush();
    } catch (Exception e) {
        throw new ServletException(e);
    }
}
Also used : ServletException(javax.servlet.ServletException) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl) SyndFeedOutput(com.rometools.rome.io.SyndFeedOutput) ModuleException(it.vige.rubia.ModuleException) Writer(java.io.Writer) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) ModuleException(it.vige.rubia.ModuleException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 13 with ModuleException

use of it.vige.rubia.ModuleException in project rubia-forums by flashboss.

the class ModeratorAction method execute.

@PostConstruct
public void execute() {
    try {
        // trying to get forumId from request parameter
        int forumId = -1;
        String f = getParameter(p_forumId);
        if (f != null && f.trim().length() > 0) {
            forumId = parseInt(f);
        }
        checkboxes = new HashMap<Integer, Boolean>();
        // grab the data to be displayed for this page
        if (forumId != -1) {
            // setup the business objects like the forum, topics etc that
            // will
            // be displayed
            forum = forumsModule.findForumById(forumId);
        } else {
            // trying to get forumId from topicId read from request
            String t = getParameter(p_topicId);
            if (t != null && t.trim().length() > 0) {
                Topic topic = forumsModule.findTopicById(new Integer(t));
                forum = topic.getForum();
            } else {
                String p = getParameter(p_postId);
                if (p != null && p.trim().length() > 0) {
                    Post post = forumsModule.findPostById(new Integer(p));
                    Topic topic = post.getTopic();
                    forum = topic.getForum();
                }
            }
        }
        if (forum != null) {
            topics = forumsModule.findTopics(forum);
            topicsDataModel = new ListDataModel<Topic>(topics);
        }
    } catch (ModuleException e) {
        log.error(e);
    }
}
Also used : Post(it.vige.rubia.model.Post) ViewTopic(it.vige.rubia.ui.view.ViewTopic) Topic(it.vige.rubia.model.Topic) ModuleException(it.vige.rubia.ModuleException) PostConstruct(javax.annotation.PostConstruct)

Aggregations

ModuleException (it.vige.rubia.ModuleException)13 ResultPage (it.vige.rubia.search.ResultPage)8 Searching (it.vige.rubia.search.Searching)8 SortBy (it.vige.rubia.search.SortBy)8 SortOrder (it.vige.rubia.search.SortOrder)8 EntityManager (javax.persistence.EntityManager)8 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)8 Term (org.apache.lucene.index.Term)8 MultiFieldQueryParser (org.apache.lucene.queryparser.classic.MultiFieldQueryParser)8 ParseException (org.apache.lucene.queryparser.classic.ParseException)8 Builder (org.apache.lucene.search.BooleanQuery.Builder)8 TermQuery (org.apache.lucene.search.TermQuery)8 WildcardQuery (org.apache.lucene.search.WildcardQuery)8 FullTextQuery (org.hibernate.search.FullTextQuery)8 FullTextSession (org.hibernate.search.FullTextSession)8 Search.getFullTextSession (org.hibernate.search.Search.getFullTextSession)8 Topic (it.vige.rubia.model.Topic)7 Post (it.vige.rubia.model.Post)6 LinkedHashSet (java.util.LinkedHashSet)4 Query (javax.persistence.Query)4