%@ page import="java.text.SimpleDateFormat"%> <%@ page import="java.io.File"%> <%@ page import="java.net.URL"%> <%@ page import="java.net.URLEncoder"%> <%@ page import="java.net.MalformedURLException"%> <%@ page import="java.io.IOException"%> <%@ page import="java.io.FileOutputStream"%> <%@ page import="java.io.FileInputStream"%> <%@ page import="java.io.InputStream"%> <%@ page import="java.util.Vector"%> <%@ page import="org.crosswire.community.data.User"%> <%@ page import="org.crosswire.community.data.Document"%> <%@ page import="org.crosswire.xml.XMLRepo"%> <%@ page import="org.crosswire.sword.mgr.SWMgr"%> <%@ page import="org.crosswire.sword.modules.SWModule"%> <%@ page import="org.crosswire.sword.mgr.SWConfig"%> <%@ page import="com.objectspace.jgl.HashMap"%> <%@ page import="com.objectspace.jgl.Map"%> <%@ page import="java.util.Enumeration"%> <%@ page import="java.awt.image.BufferedImage"%> <%@ page import="java.awt.Graphics2D"%> <%@ page import="javax.imageio.ImageIO"%> <% XMLRepo repo = XMLRepo.instance(pageContext); String projectName = request.getParameter("project"); if (projectName == null) projectName = "indexing"; /* { User user = (User) session.getAttribute("user"); if (user == null) { User u = (User)repo.get(new User("scribe"), false); session.setAttribute("user", u); } } */ User user = (User) session.getAttribute("user"); if (user == null) { out .print("
"); return; } { boolean saveProps = false; SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy"); String root = session.getServletContext().getContextPath(); String libURL = "/users/" + user.getID() + "/library"; String libPath = session.getServletContext() .getRealPath(libURL); File file = new File(libPath); if (!file.exists()) { file.mkdir(); new File(libPath, "modules").mkdir(); new File(libPath, "mods.d").mkdir(); } file = new File(libPath + "/mods.d", "globals.conf"); if (!file.exists()) { file.createNewFile(); FileOutputStream fout = new FileOutputStream(file, false); fout.write(("[globals]\nowner=" + user.getID()).getBytes()); fout.close(); } boolean reload = false; String action = request.getParameter("action"); if ("newMod".equals(action)) { String newName = request.getParameter("newName"); if (newName != null) { String fileName = newName.replace(' ', '_'); file = new File(libPath + "/mods.d", fileName+".conf"); if (!file.exists()) { FileOutputStream fout = new FileOutputStream(file, false); fout.write(("["+fileName+"]\nModDrv=RawText\nDataPath=modules/"+fileName+"\nDescription="+newName+"\nAbout="+newName+"\n").getBytes()); fout.close(); new File(libPath + "/modules", fileName).mkdir(); new File(libPath + "/modules/"+fileName, "cache").mkdir(); Document d = new Document(user.getID(), fileName); d.setGAName(newName); repo.save(d); reload = true; } else action = ""; // we couldn't add, so we'll clear action in case we do other new doc stuff below session.setAttribute("modName", fileName); } } if ("selectMod".equals(action)) { String selName = request.getParameter("selName"); if (selName != null) { session.setAttribute("modName", selName); } } String modName = (String)session.getAttribute("modName"); Document modDoc = null; if ("delete".equals(action)) { new File(libPath + "/mods.d", modName+".conf").delete(); new File(libPath + "/modules/"+modName, "module.properties").delete(); modDoc = (Document)repo.get(new Document(user.getID(), modName), false); if (modDoc != null) repo.remove(modDoc); session.setAttribute("modName", ""); modName = null; modDoc = null; reload = true; } SWMgr mgr = SWMgr.getInstance(libPath); if (reload) { mgr.config = null; mgr.Load(); } SWConfig swconfig = mgr.config; HashMap modSection = null; if (modName != null) { modSection = (HashMap)swconfig.sections.get(modName); modDoc = (Document)repo.get(new Document(user.getID(), modName), false); } if (("saveDoc".equals(action)) || ("newMod".equals(action))) { String val = request.getParameter("baseURL"); if (val != null) { val = val.replace(" ", "%20"); modDoc.setBaseURL(val); } val = request.getParameter("ganame"); if (val != null) { modDoc.setGAName(val); } val = request.getParameter("desc"); if (val != null) { modDoc.setDescription(val); } val = request.getParameter("abbr"); if (val != null) { modDoc.setAbbrevPref(val); } val = request.getParameter("otherAbbr"); if (val != null) { modDoc.setAbbrevOther(val); } val = request.getParameter("dateMean"); if (val != null) { modDoc.setDateMean(val); } val = request.getParameter("dateRange"); if (val != null) { modDoc.setDateRange(val); } val = request.getParameter("loc"); if (val != null) { modDoc.setLocation(val); } saveProps = true; } if ("loadAllImages".equals(action)) { String d=""; URL url = new URL(modDoc.getBaseURL()); try { InputStream responseStream = url.openStream(); byte line[] = new byte[254]; int len = 0; d = ""; while ((len = responseStream.read(line)) != -1) { d += new String(line, 0, len, "UTF-8"); } responseStream.close(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } int i = 0; int baseCount = modDoc.getPages().length; while (true) { int last = i; i = d.indexOf("href", last); if (i < 0) i = d.indexOf("HREF", last); if (i > -1) { int s = d.indexOf('"', i); if (s < 0) s = d.indexOf('\'', i); if (s > -1) { s++; int e = d.indexOf('"', s); if (e < 0) e = d.indexOf('\'', s); if (e > -1) { boolean valid = false; String ref = d.substring(s, e); if ( ref.toLowerCase().endsWith(".jpg") || ref.toLowerCase().endsWith(".bmp") || ref.toLowerCase().endsWith(".tif") || ref.toLowerCase().endsWith(".tiff") || ref.toLowerCase().endsWith(".jpeg") || ref.toLowerCase().endsWith(".gif") ) { if (ref.startsWith(url.toString())) { ref = ref.substring(url.toString().length()); baseCount++; valid = true; } else if (ref.startsWith(url.getPath())) { ref = ref.substring(url.getPath().length()); baseCount++; valid = true; } // find new baseURL if we haven't yet added any images at out current base else if (baseCount < 1) { int us = ref.lastIndexOf('/'); String newBase = ref.substring(0, us+1); ref = ref.substring(us+1); newBase = newBase.replace(" ", "%20"); modDoc.setBaseURL(newBase); url = new URL(newBase); baseCount = 1; saveProps = true; valid = true; } if (valid) { boolean exists = false; for (Document.Page p : modDoc.getPages()) { if (p.getURL().equals(ref)) { exists = true; break; } } if (!exists) { Document.Page p = modDoc.setPage(new Document.Page(Integer.toString(modDoc.getHighestPageID()+1))); p.setURL(ref); p.setDescription(""); p.setBibleCoverage(""); saveProps = true; } } } i = e; } } } else break; last = ++i; } } if (saveProps) { repo.save(modDoc); } %><%= (selected?"=>":"")%> | "><%= desc %> |