< 2021SC@SDUSC Software engineering application and practice of Shandong University JPress code analysis

Keywords: Java Back-end


This article analyzes the direct package and sitemap package of module page web.

Note: because the code is short and concise, the analysis of the code is placed in the remarks of the code segment.

1.directive package architecture

This folder contains three classes and a static inner class.

  • PageCommentPageDirective.java provides rendering of a single comment.
  • The static internal class TemplatePaginateDirective.java provides paging processing for comments.
  • PageDirective.java provides rendering of a single page.
  • PagesDirective.java provides rendering of multiple pages.
  • The direct package is responsible for providing the controller with direct "guiding" methods, such as obtaining url, page and other functions.


Because the functions of the three classes in the package are similar, they are nothing more than the rendering of a single comment, a single interface and multiple interfaces. Each class has onRender() method and hasEnd() method. So next, take the onRender () method and hasEnd () method in PageCommentPageDirective.java as examples to analyze the code.

2.1 onRender()

public void onRender(Env env, Scope scope, Writer writer) {
		//Set the initial number of interfaces to 1
    int page = 1;
		//Decode the url and obtain the current target through the pseudo static processor JPressHandler
    String target = StrUtil.urlDecode(JPressHandler.getCurrentTarget());
		//If the target contains "-"
    if (target.contains("-")) {
        int indexOf = target.lastIndexOf('-');
				//Get page string
        String pageString = target.substring(indexOf + 1);
				//If the page string is not blank and can be converted to a number
        if (StrUtil.isNotBlank(pageString) && StrUtil.isNumeric(pageString)) {
						//Convert the value and set the page value
            page = Integer.valueOf(pageString);
		//Use the getPara method of the Controller to obtain the page size
    int pageSize = getParaToInt("pageSize", scope, 10);

    Controller controller = JbootControllerContext.get();
		//Use the getAttr method to get the parameters in the url
    SinglePage singlePage = controller.getAttr("page");
    if (singlePage != null) {
        Page<SinglePageComment> articlePage = service.paginateByPageIdInNormal(page, pageSize, singlePage.getId());
        scope.setGlobal("commentPage", articlePage);
        renderBody(env, scope, writer);

2.2 hasEnd()

Judge whether the current value has an end value.

public boolean hasEnd() {
    return true;


This class is a static inner class of PageCommentPageDirective. Provides methods to obtain URLs and interfaces.

3.1 parent PaginateDirectiveBase

  • TemplatePaginateDirective inherits from PaginateDirectiveBase.
  • PaginateDirectiveBase defines many static constants about page state.
boolean onlyShowPreviousAndNext = this.getParaToBool("onlyShowPreviousAndNext", scope, false);
String previousText = (String)this.getPara("previousText", scope, "previous page");
String nextText = (String)this.getPara("nextText", scope, "next page");
String pageItemsName = (String)this.getPara("pageItemsName", scope, "pages");
String pageDataKey = (String)this.getPara("pageData", scope, "pageData");
  • TemplatePaginateDirective implements two abstract methods in the parent class, getUrl() and getPage().

3.2 getUrl()

Get the url of the new interface

protected String getUrl(int pageNumber, Env env, Scope scope, Writer writer) {
		//Get page parameters
    SinglePage page = JbootControllerContext.get().getAttr("page");
		//Get the url of the page by the number of pages
    String url = page.getUrlWithPageNumber(pageNumber);
		//Obtain the parameter value named anchor according to the passed in url
    String anchor = getPara("anchor", scope);
		//Returns the new url of the page
    return StrUtil.isBlank(anchor) ? url : url + "#" + anchor;

3.3 getPage()

Get this comment page

protected Page<?> getPage(Env env, Scope scope, Writer writer) {
    return (Page<?>) scope.get("commentPage");

4.sitemap package architecture

  • The sitemap package contains two class files.
  • PageModuleInitializer implements the initialization of buttons related to page functions.
  • When PageNotifyKit is used to realize page comment, the selection of comment function is realized by email notification to administrator and SMS notification to administrator.


  • Inheriting ModuleBase is the basis of module class implementation.
  • ModuleBase inherits JbootAppListenerBase and implements modulelistener and jbootapplistener interfaces. Implement listening to MenuGroup.
  • There is only one method in PageModuleInitializer.
public void onConfigAdminMenu(List<MenuGroup> adminMenus) {

    MenuGroup menuGroup = new MenuGroup();
    menuGroup.setIcon("<i class=\"fas fa-file\"></i>");



In fact, the option group of the page is added on the background interface of JPress:


In the background management interface of JPress, there is a method to notify the administrator of comments, which is realized by PageNotifyKit.

6.1 function purpose

public static void notify(SinglePage page, SinglePageComment comment, User user)

Incoming pages, comments, users, notify administrators

private static void bySms(SinglePage page, SinglePageComment comment)

Notify administrator via SMS

private static void doSendSms()

Send SMS

public static void byEmail(SinglePage page, SinglePageComment comment, User user)

Notify administrator by mail

private static void doSendEmail(SinglePage page, SinglePageComment comment, User user)

Send mail

7. Summary

This article analyzes the directive package and the sitemap package, because the methods and parameters invoked in the method have been introduced in the previous code analysis reports, and no more analysis is repeated here.

Posted by siddscool19 on Tue, 09 Nov 2021 11:33:56 -0800