Mercurial > hg > digilib
changeset 1486:c88c1d45e808
sequence plugin: dirInfo-json.jsp
author | hertzhaft |
---|---|
date | Fri, 26 Feb 2016 16:58:51 +0100 |
parents | 0831d73ce747 |
children | 684632a23c80 |
files | webapp/src/main/webapp/api/dirInfo-json.jsp |
diffstat | 1 files changed, 77 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/webapp/src/main/webapp/api/dirInfo-json.jsp Fri Feb 26 16:58:51 2016 +0100 @@ -0,0 +1,77 @@ +<%-- + #%L + digilib-webapp + %% + Copyright (C) 2004 - 2013 MPIWG Berlin + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Lesser Public License for more details. + + You should have received a copy of the GNU General Lesser Public + License along with this program. If not, see + <http://www.gnu.org/licenses/lgpl-3.0.html>. + #L% + Author: Robert Casties (robcast@berlios.de) + --%><%@ page language="java" + import="digilib.servlet.DocumentBean, + digilib.conf.DigilibServletConfiguration, + digilib.conf.DigilibServletRequest, + digilib.io.DocuDirCache, + digilib.io.DocuDirectory, + digilib.io.DocuDirent, + digilib.io.FileOps, + java.io.File"%><%! +// create DocumentBean instance for all JSP requests +DocumentBean docBean = new DocumentBean(); + +// initialize DocumentBean instance in JSP init +public void jspInit() { + try { + // set servlet init-parameter + docBean.setConfig(getServletConfig()); + } catch (javax.servlet.ServletException e) { + System.out.println(e); + } +} +%><%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %><%@ page contentType="application/json" %><% +// process request +// get digilib config +DigilibServletConfiguration dlConfig = docBean.getDlConfig(); +// parsing the query +DigilibServletRequest dlRequest = new DigilibServletRequest(request); +// dir cache +DocuDirCache dirCache = (DocuDirCache) dlConfig.getValue("servlet.dir.cache"); +// get directory +DocuDirectory dir = dirCache.getDirectory(dlRequest.getFilePath()); +FileOps.FileClass fc = FileOps.FileClass.IMAGE; +int dirSize = dir != null ? dir.size(fc) : 0; + +%> +{<% if (dir != null) { %> + "url-path" : "<%= dir.getDirName() %>", + "count" : "<%= dirSize %>", + "files" : [<% + if (!dlRequest.hasOption("mo", "dir")) { + for (int i = 0; i < dirSize; i++) { + DocuDirent f = dir.get(i, fc); + String fn = (f != null) ? f.getName() : "null"; +%> +{ + "index" : <%= i+1 %>, + "fn" : "<%=digilib.io.FileOps.basename(fn)%>", + "file" : "<%=fn%>" +}<% + if (i+1 < dirSize) {%>, +<%} + } // for + } // if not dironly + } // if dir +%> +]}