Skip to content

Commit

Permalink
NAS-2520: Added some layout to some of the pages.
Browse files Browse the repository at this point in the history
  • Loading branch information
nclarkekb committed Oct 20, 2016
1 parent a8fba72 commit 925b285
Show file tree
Hide file tree
Showing 5 changed files with 227 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dk.netarkivet.harvester.webinterface.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

Expand All @@ -9,6 +10,16 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.antiaction.common.filter.Caching;
import com.antiaction.common.templateengine.Template;
import com.antiaction.common.templateengine.TemplateParts;
import com.antiaction.common.templateengine.TemplatePlaceBase;
import com.antiaction.common.templateengine.TemplatePlaceHolder;

import dk.netarkivet.common.CommonSettings;
import dk.netarkivet.common.Constants;
import dk.netarkivet.common.utils.Settings;

public class IndexResource implements ResourceAbstract {

private NASEnvironment environment;
Expand Down Expand Up @@ -45,6 +56,25 @@ public void index(HttpServletRequest req, HttpServletResponse resp, List<Integer
resp.setContentType("text/html; charset=UTF-8");
ServletOutputStream out = resp.getOutputStream();

Caching.caching_disable_headers(resp);

Template template = environment.templateMaster.getTemplate("master.tpl");

TemplatePlaceHolder titlePlace = TemplatePlaceBase.getTemplatePlaceHolder("title");
TemplatePlaceHolder headingPlace = TemplatePlaceBase.getTemplatePlaceHolder("heading");
TemplatePlaceHolder contentPlace = TemplatePlaceBase.getTemplatePlaceHolder("content");
TemplatePlaceHolder versionPlace = TemplatePlaceBase.getTemplatePlaceHolder("version");
TemplatePlaceHolder environmentPlace = TemplatePlaceBase.getTemplatePlaceHolder("environment");

List<TemplatePlaceBase> placeHolders = new ArrayList<TemplatePlaceBase>();
placeHolders.add(titlePlace);
placeHolders.add(headingPlace);
placeHolders.add(contentPlace);
placeHolders.add(versionPlace);
placeHolders.add(environmentPlace);

TemplateParts templateParts = template.filterTemplate(placeHolders, resp.getCharacterEncoding());

StringBuilder sb = new StringBuilder();

sb.append("Heritrix3 command control center.");
Expand Down Expand Up @@ -90,30 +120,49 @@ public void index(HttpServletRequest req, HttpServletResponse resp, List<Integer
sb.append(lines);
sb.append("<br />\n");
sb.append("<br />\n");
}

/*
sb.append("<pre>");
AnypathResult anypathResult = h3wrapper.anypath(jobResult.job.crawlLogFilePath, null, null);
byte[] tmpBuf = new byte[8192];
int read;
try {
while ((read = anypathResult.in.read(tmpBuf)) != -1) {
sb.append(new String(tmpBuf, 0, read));
}
anypathResult.close();
} catch (IOException e) {
e.printStackTrace();
}
if (titlePlace != null) {
titlePlace.setText("Runnings job monitor");
}

sb.append("</pre>");
*/
if (headingPlace != null) {
headingPlace.setText("Runnings job monitor");
}

if (contentPlace != null) {
contentPlace.setText(sb.toString());
}

if (versionPlace != null) {
versionPlace.setText(Constants.getVersionString());
}

if (environmentPlace != null) {
environmentPlace.setText(Settings.get(CommonSettings.ENVIRONMENT_NAME));
}

out.write(sb.toString().getBytes("UTF-8"));
for (int i = 0; i < templateParts.parts.size(); ++i) {
out.write(templateParts.parts.get(i).getBytes());
}
out.flush();
out.close();

/*
sb.append("<pre>");
AnypathResult anypathResult = h3wrapper.anypath(jobResult.job.crawlLogFilePath, null, null);
byte[] tmpBuf = new byte[8192];
int read;
try {
while ((read = anypathResult.in.read(tmpBuf)) != -1) {
sb.append(new String(tmpBuf, 0, read));
}
anypathResult.close();
} catch (IOException e) {
e.printStackTrace();
}
sb.append("</pre>");
*/
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletContext;
Expand All @@ -12,6 +13,16 @@

import org.netarchivesuite.heritrix3wrapper.ScriptResult;

import com.antiaction.common.filter.Caching;
import com.antiaction.common.templateengine.Template;
import com.antiaction.common.templateengine.TemplateParts;
import com.antiaction.common.templateengine.TemplatePlaceBase;
import com.antiaction.common.templateengine.TemplatePlaceHolder;

import dk.netarkivet.common.CommonSettings;
import dk.netarkivet.common.Constants;
import dk.netarkivet.common.utils.Settings;

public class JobResource implements ResourceAbstract {

private static final String NAS_GROOVY_RESOURCE_PATH = "dk/netarkivet/harvester/webinterface/servlet/nas.groovy";
Expand Down Expand Up @@ -66,6 +77,25 @@ public void job(HttpServletRequest req, HttpServletResponse resp, List<Integer>
resp.setContentType("text/html; charset=UTF-8");
ServletOutputStream out = resp.getOutputStream();

Caching.caching_disable_headers(resp);

Template template = environment.templateMaster.getTemplate("master.tpl");

TemplatePlaceHolder titlePlace = TemplatePlaceBase.getTemplatePlaceHolder("title");
TemplatePlaceHolder headingPlace = TemplatePlaceBase.getTemplatePlaceHolder("heading");
TemplatePlaceHolder contentPlace = TemplatePlaceBase.getTemplatePlaceHolder("content");
TemplatePlaceHolder versionPlace = TemplatePlaceBase.getTemplatePlaceHolder("version");
TemplatePlaceHolder environmentPlace = TemplatePlaceBase.getTemplatePlaceHolder("environment");

List<TemplatePlaceBase> placeHolders = new ArrayList<TemplatePlaceBase>();
placeHolders.add(titlePlace);
placeHolders.add(headingPlace);
placeHolders.add(contentPlace);
placeHolders.add(versionPlace);
placeHolders.add(environmentPlace);

TemplateParts templateParts = template.filterTemplate(placeHolders, resp.getCharacterEncoding());

StringBuilder sb = new StringBuilder();

Heritrix3JobMonitor h3Job = environment.h3JobMonitorThread.getRunningH3Job(numerics.get(0));
Expand Down Expand Up @@ -99,7 +129,29 @@ public void job(HttpServletRequest req, HttpServletResponse resp, List<Integer>
sb.append(" is not running.");
}

out.write(sb.toString().getBytes("UTF-8"));
if (titlePlace != null) {
titlePlace.setText("Runnings job monitor");
}

if (headingPlace != null) {
headingPlace.setText("Runnings job monitor");
}

if (contentPlace != null) {
contentPlace.setText(sb.toString());
}

if (versionPlace != null) {
versionPlace.setText(Constants.getVersionString());
}

if (environmentPlace != null) {
environmentPlace.setText(Settings.get(CommonSettings.ENVIRONMENT_NAME));
}

for (int i = 0; i < templateParts.parts.size(); ++i) {
out.write(templateParts.parts.get(i).getBytes());
}
out.flush();
out.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@
import javax.servlet.ServletContext;
import javax.servlet.ServletException;

import com.antiaction.common.templateengine.TemplateMaster;
import com.antiaction.common.templateengine.login.LoginTemplateHandler;
import com.antiaction.common.templateengine.storage.TemplateFileStorageManager;

public class NASEnvironment {

/** servletConfig. */
public ServletConfig servletConfig = null;
protected ServletConfig servletConfig = null;

protected TemplateMaster templateMaster = null;

protected String login_template_name = null;

protected LoginTemplateHandler<NASUser> loginHandler = null;

protected Heritrix3JobMonitorThread h3JobMonitorThread;

Expand All @@ -16,6 +26,17 @@ public class NASEnvironment {
public static String servicePath;

public NASEnvironment(ServletContext servletContext, ServletConfig theServletConfig) throws ServletException {
login_template_name = "login.html";

templateMaster = TemplateMaster.getInstance("default");
templateMaster.addTemplateStorage(TemplateFileStorageManager.getInstance(servletContext.getRealPath("/"), "UTF-8"));

loginHandler = new LoginTemplateHandler<NASUser>();
loginHandler.templateMaster = templateMaster;
loginHandler.templateName = login_template_name;
loginHandler.title = "Webdanica - Login";
loginHandler.adminPath = "/";

this.servletConfig = theServletConfig;
h3JobMonitorThread = new Heritrix3JobMonitorThread();
h3JobMonitorThread.start();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
package dk.netarkivet.harvester.webinterface.servlet;

public class NASUser {
import javax.servlet.http.HttpServletRequest;

import com.antiaction.common.templateengine.login.LoginTemplateUser;

public class NASUser implements LoginTemplateUser {

public String id;

public String username;

public boolean active = false;

public static NASUser getAdminByCredentials(String id, String password) {
return getDefaultUser();
}

@Override
public String get_cookie_token(HttpServletRequest req) {
return null; // Not needed to further implement at the moment
}

public static NASUser getDefaultUser() {
NASUser u = new NASUser();
u.active=true;
u.id = "svc@kb.dk";
u.username="admin";
return u;
}

}
58 changes: 58 additions & 0 deletions harvester/history-gui/src/main/webapp/master.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta content="text/html; charset=UTF-8" http-equiv= "content-type" /><meta http-equiv="Expires" content="0"/>
<meta http-equiv="Cache-Control" content="no-cache"/>
<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="refresh" content="60"/>
<title><placeholder id ="title" /></title>
<script type="text/javascript">
<!--
function giveFocus() {
var e = document.getElementById('focusElement');
if (e != null) {
var elms = e.getElementsByTagName('*');
if (elms != null && elms.length != null && elms.item != null && elms.length > 0) {
var e2 = elms.item(0);
if (e2 != null && e2.focus != null) {
}
e2.focus();
}
}
}
-->
</script>

<link rel="stylesheet" href="/History/netarkivet.css" type="text/css" />
<link rel="stylesheet" href="/History/jscalendar/calendar-win2k-cold-1.css" title="/History/jscalendar/win2k-cold-1" type="text/css" media="all" />
</head>
<body onload="giveFocus()">
<table id ="main_table">
<tr>
<td valign="top" id="menu">
<table id="menu_table">
<tr><td><a class="sidebarHeader" href="index.jsp"><img src="/History/transparent_menu_logo.png" alt="Menu"/> Menu</a></td></tr>
<tr><td><a href="/HarvestDefinition/Definitions-selective-harvests.jsp">Definitions</a></td>
</tr><tr><td><a href="/History/Harveststatus-alljobs.jsp">Harvest status</a></td>
</tr><tr><td>&nbsp; &nbsp; <a href="/History/Harveststatus-alljobs.jsp"> All Jobs</a></td>
</tr><tr><td>&nbsp; &nbsp; <a href="/History/Harveststatus-deprecatedperdomain.jsp"> All Jobs per domain</a></td>
</tr><tr><td>&nbsp; &nbsp; <a href="/History/Harveststatus-running.jsp"> Running Jobs</a></td>
</tr><tr><td><a href="/HarvestChannel/HarvestChannel-edit-harvest-mappings.jsp">Harvest Channels</a></td>
</tr><tr><td><a href="/BitPreservation/Bitpreservation-filestatus.jsp">Bitpreservation</a></td>
</tr><tr><td><a href="/QA/QA-status.jsp">Quality Assurance</a></td>
</tr><tr><td><a href="/Status/Monitor-JMXsummary.jsp">Systemstate</a></td>
</tr></table>
</td>
<td valign = "top" >
<div class="languagelinks"><a href="lang.jsp?locale=da&amp;name=Dansk">Dansk</a>&nbsp;<a href="lang.jsp?locale=en&amp;name=English">English</a>&nbsp;<a href="lang.jsp?locale=de&amp;name=Deutsch">Deutsch</a>&nbsp;<a href="lang.jsp?locale=it&amp;name=Italiano">Italiano</a>&nbsp;<a href="lang.jsp?locale=fr&amp;name=Fran%C3%A7ais">Français</a>&nbsp;</div>

<h3 class="page_heading"><placeholder id="heading" /></h3>

<placeholder id="content" />

</td>
</tr>
</table>
<div class='systeminfo'>NetarchiveSuite <placeholder id="version" />, <placeholder id="environment" /></div>
</body>
</html>

0 comments on commit 925b285

Please sign in to comment.