Exemple #1
1
  @Override
  public <T> Page<T> searchPage(String sql, Class<T> clazz, List<Object> params, Page<T> page)
      throws Exception {
    if (StringUtils.isBlank(sql)) {
      List<T> list = new ArrayList<>();
      page.setTotalCount(0);
      page.setResult(list);
      return page;
    }
    if (params == null) {
      params = new ArrayList<>();
    }
    StringBuilder sb = new StringBuilder(sql);
    int count = getCount(sb.toString(), params);
    page.setTotalCount(count);
    if (!StringUtils.isBlank(page.getOrder())) {
      sb.append(" ORDER BY ").append(page.getOrder());
      if (!StringUtils.isBlank(page.getSort())) {
        sb.append(" ").append(page.getSort());
      }
    }
    sb.append(" LIMIT ");
    sb.append(String.valueOf(page.getFirstResult()));
    sb.append(",");
    sb.append(String.valueOf(page.getPageSize()));
    List<T> list = searchForList(sb.toString(), clazz, params);
    page.setResult(list);

    return page;
  }
Exemple #2
0
 public void removePage(int id, Session session) {
   Page page = findPage(id);
   if (page != null && page.getModule() != null && page.getModule().getPageList() != null) {
     page.getModule().getPageList().remove(page);
     session.delete(page);
   }
 }
Exemple #3
0
 public Page findPage(int pageId) {
   for (Module module : getModuleList()) {
     for (Page page : module.getPageList()) {
       if (page.getId() == pageId) return page;
     }
   }
   return null;
 }
Exemple #4
0
 private void displayPage() throws IOException {
   Page page = newPage();
   layoutErrorBlock(page);
   ServletUtil.layoutExplanationBlock(page, "Debug Actions");
   page.add(makeForm());
   page.add("<br>");
   endPage(page);
 }
Exemple #5
0
 /**
  * Reads a record from the file, given its id.
  *
  * @throws IllegalArgumentException if the rid is invalid
  */
 public byte[] selectRecord(RID rid) {
   PageId pid = rid.pageno;
   if (!pids.contains(pid.pid)) throw new IllegalArgumentException("the RID is invalid");
   Page page = new Page();
   global.Minibase.BufferManager.pinPage(pid, page, false);
   global.Minibase.BufferManager.unpinPage(pid, false);
   return page.getData();
 }
 // Called when a servlet doesn't get the parameters it expects/needs
 protected void paramError() throws IOException {
   // FIXME: As of 2006-03-15 this method and its only caller checkParam() are not called from
   // anywhere
   PrintWriter wrtr = resp.getWriter();
   Page page = new Page();
   // add referer, params, msg to contact lockss unless from old bookmark
   // or manually entered url
   page.add("Parameter error");
   page.write(wrtr);
 }
 protected Page addBarePageHeading(Page page) {
   // FIXME: Move the following fragment elsewhere
   // It causes the doctype statement to appear in the middle,
   // after the <body> tag.
   page.add("<!doctype html public \"-//w3c//dtd html 4.0 transitional//en\">");
   page.addHeader("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">");
   page.addHeader("<meta http-equiv=\"content-type\" content=\"text/html;charset=ISO-8859-1\">");
   page.addHeader("<link rel=\"shortcut icon\" href=\"/favicon.ico\" type=\"image/x-icon\" />");
   return page;
 }
Exemple #8
0
 public Action findAction(int actionId) {
   for (Module module : getModuleList()) {
     for (Page page : module.getPageList()) {
       for (Action action : page.getActionList()) {
         if (action.getId() == actionId) return action;
       }
     }
   }
   return null;
 }
 /** Display a message in lieu of the normal page */
 protected void displayMsgInLieuOfPage(String msg) throws IOException {
   // TODO: Look at HTML
   Page page = newPage();
   Composite warning = new Composite();
   warning.add(msg);
   warning.add("<br>");
   page.add(warning);
   layoutFooter(page);
   page.write(resp.getWriter());
 }
Exemple #10
0
 @Override
 public <T> Page<T> searchPage(SqlHelper sqlHelper, Class<T> clazz, Page<T> page)
     throws Exception {
   if (sqlHelper == null || StringUtils.isBlank(sqlHelper.getSql())) {
     List<T> list = new ArrayList<>();
     page.setTotalCount(0);
     page.setResult(list);
     return page;
   }
   return searchPage(sqlHelper.getSql(), clazz, sqlHelper.getParameters(), page);
 }
Exemple #11
0
 public List<Action> getAllAction() {
   List<Action> list = new ArrayList<Action>();
   for (Module m : this.moduleList) {
     for (Page p : m.getPageList()) {
       for (Action a : p.getActionList()) {
         list.add(a);
       }
     }
   }
   return list;
 }
Exemple #12
0
  /**
   * If the given name already denotes a file, this opens it; otherwise, this creates a new empty
   * file. A null name produces a temporary heap file which requires no DB entry.
   */
  public HeapFile(String name) throws ChainException {
    this.name = name;
    PageId firstPageId;
    Page page = new Page();
    pages = new ArrayList<PageId>();
    pids = new HashSet<Integer>();
    if (name == null) {
      // Temporary heap file
      firstPageId = global.Minibase.BufferManager.newPage(page, 1);
      current = new HFPage(page);
      current.setCurPage(firstPageId);
      pages.add(firstPageId);
      pids.add(firstPageId.pid);
      global.Minibase.BufferManager.unpinPage(firstPageId, true);
    } else {

      firstPageId = global.Minibase.DiskManager.get_file_entry(name);
      if (firstPageId == null) {
        firstPageId = global.Minibase.BufferManager.newPage(page, 1);
        global.Minibase.DiskManager.add_file_entry(name, firstPageId);
        global.Minibase.BufferManager.unpinPage(firstPageId, true);
        pages.add(firstPageId);
        pids.add(firstPageId.pid);
        global.Minibase.BufferManager.pinPage(firstPageId, page, false);

        recordNumber = 0;
        current = new HFPage(page);
        current.setCurPage(firstPageId);
        global.Minibase.BufferManager.unpinPage(firstPageId, true);
        return;
      }
      // add the new HFPages
      global.Minibase.BufferManager.pinPage(firstPageId, page, false);
      // System.err.println("hahahaha"+page.getData());
      current = new HFPage(page);
      current.setData(page.getData());
      pages.add(firstPageId);
      pids.add(firstPageId.pid);
      recordNumber += amount(current);
      global.Minibase.BufferManager.unpinPage(firstPageId, false);
      PageId currentPageId = current.getNextPage();
      while (currentPageId.pid != 0 & currentPageId.pid != -1) {
        HFPage temp = new HFPage();
        global.Minibase.BufferManager.pinPage(currentPageId, temp, false);
        pages.add(currentPageId);
        pids.add(currentPageId.pid);
        recordNumber += amount(temp);
        global.Minibase.BufferManager.unpinPage(currentPageId, false);
        currentPageId = temp.getNextPage();
      }
    }
  }
 // see DbFile.java for javadocs
 public void writePage(Page page) throws IOException {
   // some code goes here
   long offset = page.getId().pageNumber() * BufferPool.PAGE_SIZE;
   byte[] data = page.getPageData();
   try {
     raf.seek(offset);
     for (int i = 0; i < data.length; i++) {
       raf.writeByte(data[i]);
     }
   } catch (FileNotFoundException e) {
     e.printStackTrace();
   }
 }
  /** Test of run method, of class FileContentLoaderImpl. */
  public void testRun1() {
    System.out.println("run");

    Site mockSite = new SiteImpl();
    Page mockPage1 = new PageImpl();
    mockPage1.setURL("http://my.testUrl1.org");
    Page mockPage2 = new PageImpl();
    mockPage2.setURL("http://my.testUrl2.org");

    mockSite.addChild(mockPage1);
    mockSite.addChild(mockPage2);

    ContentFactory mockContentFactory = EasyMock.createMock(ContentFactory.class);
    SSP mockSSP = EasyMock.createMock(SSP.class);

    Date date = new Date();
    DateFactory mockDateFactory = EasyMock.createMock(DateFactory.class);
    EasyMock.expect(mockDateFactory.createDate()).andReturn(date).times(2);

    EasyMock.expect(
            mockContentFactory.createSSP(
                date, "http://my.testUrl1.org", "My Page Content 1", mockPage1, HttpStatus.SC_OK))
        .andReturn(mockSSP)
        .once();

    EasyMock.expect(
            mockContentFactory.createSSP(
                date, "http://my.testUrl2.org", "My Page Content 2", mockPage2, HttpStatus.SC_OK))
        .andReturn(mockSSP)
        .once();

    Map<String, String> fileMap = new HashMap<String, String>();
    fileMap.put("http://my.testUrl1.org", "My Page Content 1");
    fileMap.put("http://my.testUrl2.org", "My Page Content 2");

    EasyMock.replay(mockSSP);
    EasyMock.replay(mockContentFactory);
    EasyMock.replay(mockDateFactory);

    FileContentLoaderImpl instance =
        new FileContentLoaderImpl(mockContentFactory, fileMap, mockDateFactory);
    instance.setWebResource(mockSite);
    instance.run();

    assertTrue(instance.getResult().contains(mockSSP));

    EasyMock.verify(mockSSP);
    EasyMock.verify(mockContentFactory);
    EasyMock.verify(mockDateFactory);
  }
Exemple #15
0
  /**
   * @return Map complete pages.
   * @throws RepositoryException
   */
  public Map<String, JsonNode> getPagesContent() throws RepositoryException {
    if (!this.connector.exist(this.gameModelId)) {
      return new TreeMap<>();
    }
    NodeIterator it = this.connector.listChildren(this.gameModelId);
    Map<String, JsonNode> ret = new TreeMap<>(new AlphanumericComparator<String>());
    while (it.hasNext()) {
      Node n = (Node) it.next();
      Page p = new Page(n);
      // pageMap.put(p.getId().toString(),  p.getContent());
      ret.put(p.getId(), p.getContent());
    }
    // this.connector.close();

    return ret;
  }
Exemple #16
0
 public Parameter findParameter(int parameterId, boolean isRequestType) {
   for (Module module : getModuleList()) {
     for (Page page : module.getPageList()) {
       for (Action action : page.getActionList()) {
         for (Parameter parameter :
             (isRequestType
                 ? action.getRequestParameterList()
                 : action.getResponseParameterList())) {
           if (parameter.getId() == parameterId) {
             return parameter;
           }
         }
       }
     }
   }
   return null;
 }
  public void drawOn(Page page) throws Exception {
    if (fill_shape) {
      page.setBrushColor(color[0], color[1], color[2]);
    } else {
      page.setPenColor(color[0], color[1], color[2]);
    }
    page.setPenWidth(width);
    page.setLinePattern(pattern);

    for (int i = 0; i < points.size(); i++) {
      Point point = points.get(i);
      point.x += box_x;
      point.y += box_y;
    }

    if (fill_shape) {
      page.drawPath(points, 'f');
    } else {
      if (close_path) {
        page.drawPath(points, 's');
      } else {
        page.drawPath(points, 'S');
      }
    }

    for (int i = 0; i < points.size(); i++) {
      Point point = points.get(i);
      point.x -= box_x;
      point.y -= box_y;
    }
  }
 public static Page forUrl(final PwmURL pwmURL) {
   final String url = pwmURL.toString();
   for (final Page page : Page.values()) {
     if (url.endsWith(page.urlSuffix)) {
       return page;
     }
   }
   return null;
 }
 protected void handleSelectPageRequest(
     final PwmRequest pwmRequest, final GuestRegistrationBean guestRegistrationBean)
     throws PwmUnrecoverableException, IOException, ServletException {
   final String requestedPage = pwmRequest.readParameterAsString("page");
   try {
     guestRegistrationBean.setCurrentPage(Page.valueOf(requestedPage));
   } catch (IllegalArgumentException e) {
     LOGGER.error(pwmRequest, "unknown page select request: " + requestedPage);
   }
   this.forwardToJSP(pwmRequest, guestRegistrationBean);
 }
Exemple #20
0
  private String path(UriComponentsBuilder builder, Page page, boolean encode) {
    Map<String, Object> params = new HashMap<>();

    PageTree pageTree =
        (PageTree) processingContext.getContext().getVariables().get("PAGE_TREE_ALL");
    //		PageTree pageTree =
    // defaultModelAttributeService.readPageTree(LocaleContextHolder.getLocale().getLanguage());
    List<String> codes = new LinkedList<>();
    Page parent = page.getParent();
    while (parent != null) {
      codes.add(parent.getCode());
      parent =
          (parent.getParent() != null)
              ? pageTree.getPageByCode(parent.getParent().getCode())
              : null;
    }

    Collections.reverse(codes);
    codes.add(page.getCode());

    for (int i = 0; i < codes.size(); i++) {
      String key = "code" + i;
      builder.path("/{" + key + "}");
      params.put(key, codes.get(i));
    }

    UriComponents components = builder.buildAndExpand(params);
    if (encode) {
      components = components.encode();
    }
    return components.toUriString();
  }
  /** Common page setup. */
  protected Page newPage() {
    // Compute heading
    String heading = getHeading();
    if (heading == null) {
      heading = "Box Administration";
    }

    // Create page and layout header
    Page page = ServletUtil.doNewPage(getPageTitle(), isFramed());
    Iterator inNavIterator;
    if (myServletDescr().hasNoNavTable()) {
      inNavIterator = CollectionUtil.EMPTY_ITERATOR;
    } else {
      inNavIterator =
          new FilterIterator(
              new ObjectArrayIterator(getServletDescrs()),
              new Predicate() {
                public boolean evaluate(Object obj) {
                  return isServletInNav((ServletDescr) obj);
                }
              });
    }
    ServletUtil.layoutHeader(
        this,
        page,
        heading,
        isLargeLogo(),
        getMachineName(),
        getLockssApp().getStartDate(),
        inNavIterator);
    String warnMsg = CurrentConfig.getParam(PARAM_UI_WARNING);
    if (warnMsg != null) {
      Composite warning = new Composite();
      warning.add("<center><font color=red size=+1>");
      warning.add(warnMsg);
      warning.add("</font></center><br>");
      page.add(warning);
    }
    return page;
  }
Exemple #22
0
  /**
   * Inserts a new record into the file and returns its RID.
   *
   * @throws IllegalArgumentException if the record is too large
   */
  public RID insertRecord(byte[] record) throws IllegalArgumentException, ChainException {
    if (record.length > GlobalConst.MAX_TUPSIZE)
      throw new IllegalArgumentException("the record's size is too large");

    for (int i = 0; i < pages.size(); i++) {
      PageId pid = pages.get(i);
      Page page = new Page();
      global.Minibase.BufferManager.pinPage(pid, page, false);
      HFPage hfpage = new HFPage(page);
      hfpage.setCurPage(pid);
      hfpage.setData(page.getData());
      if (hfpage.getFreeSpace() > record.length) {

        RID rid = hfpage.insertRecord(record);
        recordNumber++;
        global.Minibase.BufferManager.unpinPage(pid, true);
        return rid;
      }
      global.Minibase.BufferManager.unpinPage(pid, false);
    }

    Page page = new Page();
    PageId pid = global.Minibase.BufferManager.newPage(page, 1);
    HFPage hfpage = new HFPage(page);
    // initialize HFPage
    hfpage.initDefaults();
    hfpage.setCurPage(pid);
    // hfpage.print();
    RID rid = hfpage.insertRecord(record);
    pages.add(pid);
    pids.add(pid.pid);
    hfpage.setNextPage(pid);
    hfpage.setPrevPage(current.getCurPage());
    current = hfpage;
    global.Minibase.BufferManager.unpinPage(pid, true);
    // hfpage.print();
    // System.out.println ("The PID is "+pid);
    recordNumber++;
    return rid;
  }
Exemple #23
0
  public Parameter findChildParameter(int parameterId) {
    for (Module module : getModuleList()) {
      for (Page page : module.getPageList()) {
        for (Action action : page.getActionList()) {
          for (Parameter parameter : action.getRequestParameterList()) {
            Parameter pRecur = findParameterRecursively(parameter, parameterId);
            if (pRecur != null) {
              return pRecur;
            }
          }

          for (Parameter parameter : action.getResponseParameterList()) {
            Parameter pRecur = findParameterRecursively(parameter, parameterId);
            if (pRecur != null) {
              return pRecur;
            }
          }
        }
      }
    }
    return null;
  }
Exemple #24
0
  /**
   * Move page to new index. Updating other pages accordingly.
   *
   * @param pageId page's id to move
   * @param pos position to move page to.
   * @throws RepositoryException
   */
  public void move(final String pageId, final int pos) throws RepositoryException {
    Page page;
    int oldPos = -1;
    final LinkedList<Page> pages = this.getPages();
    for (int i = 0; i < pages.size(); i++) {
      if (pages.get(i).getId().equals(pageId)) {
        oldPos = i;
        break;
      }
    }
    if (oldPos != -1) {
      page = pages.remove(oldPos);
      pages.add(pos, page);
    }
    for (int start = 0; start < pages.size(); start++) {
      page = pages.get(start);
      page.setIndex(start);
      this.updateIndex(page);
    }
    //        final NodeIterator query = this.connector.query("Select * FROM [nt:base] as n WHERE
    // ISDESCENDANTNODE('" + this.gameModelId + "') order by n.index, localname(n)," +
    //            " LIMIT " + (Math.abs(pos - oldPos) + 1L) + " OFFSET " + Math.min(pos, oldPos));

  }
  public boolean hasNext() throws DbException, TransactionAbortedException, IOException {
    // System.out.println("hf has next: " + _currentPageId +_numPages);
    if (_tupleIterator == null) return false;
    if (_tupleIterator.hasNext()) return true;

    // If we have more pages
    // System.out.println(_currentPageId+"   llllll   "+_numPages);
    while (_currentPageId < (_numPages)) {
      _currentPage = readPage(_currentPageId++);
      _tupleIterator = _currentPage.iterator();
      if (_tupleIterator.hasNext()) {
        _pagesRead++;
        return true;
      }
    }

    return false;
  }
  public Tuple previous() throws DbException, TransactionAbortedException, IOException {
    //	System.out.println("previous ");
    if (_tupleIterator == null) {
      throw new NoSuchElementException("Tuple iterator not opened");
    }

    if (((HeapPageIterator) _tupleIterator).hasPrevious()) {
      return ((HeapPageIterator) _tupleIterator).previous();
    } else {
      if (_currentPageId > 1) {
        // System.out.println("CUURENT PAGEID "+_currentPageId);
        _currentPageId = _currentPageId - 2;
        _currentPage = readPage(_currentPageId++);
        // System.out.println("NOW "+_currentPageId);
        _pagesRead++;
        _tupleIterator = _currentPage.iterator();
        ((HeapPageIterator) _tupleIterator).setLast();
        if (((HeapPageIterator) _tupleIterator).hasPrevious()) {
          return ((HeapPageIterator) _tupleIterator).previous();
        }
      } else return null;
    }
    return null;
  }
  public void open() throws DbException, TransactionAbortedException, IOException {
    _currentPage = readPage(_currentPageId++);

    _pagesRead++;
    _tupleIterator = _currentPage.iterator();
  }
Exemple #28
0
 /**
  * @param page
  * @throws RepositoryException
  */
 public void setMeta(Page page) throws RepositoryException {
   Node n = this.connector.addChild(this.gameModelId, page.getId());
   if (page.getName() != null) {
     n.setProperty(Page.NAME_KEY, page.getName());
   }
 }
Exemple #29
0
 public List getPages() {
   return Page.find("SELECT p FROM Page p WHERE p.admin = ?", this).fetch();
 }
Exemple #30
0
 private void updateIndex(Page page) throws RepositoryException {
   Node n = this.connector.addChild(this.gameModelId, page.getId());
   if (page.getIndex() != null) {
     n.setProperty(Page.INDEX_KEY, page.getIndex());
   }
 }