/sun/src/ak/strutsx/ErrorHandlerX.java |
---|
0,0 → 1,23 |
/** |
* Extends and based on Apache Struts source code. |
* |
* Copyleft Anatoli Klassen (anatoli@aksoft.net) |
*/ |
package ak.strutsx; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
import org.apache.struts.action.ActionMapping; |
import org.apache.struts.action.ActionForm; |
public interface ErrorHandlerX { |
public void handleErrors(ActionMapping mapping, |
ActionForm form, |
HttpServletRequest request, |
HttpServletResponse response) |
throws Exception; |
} |
/sun/src/ak/strutsx/RequestProcessorX.java |
---|
0,0 → 1,231 |
/** |
* Extends and based on Apache Struts source code. |
* |
* Copyleft Anatoli Klassen (anatoli@aksoft.net) |
*/ |
package ak.strutsx; |
import java.io.IOException; |
import javax.servlet.ServletException; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
import org.apache.struts.Globals; |
import org.apache.struts.action.Action; |
import org.apache.struts.action.ActionErrors; |
import org.apache.struts.action.ActionForward; |
import org.apache.struts.action.ActionMapping; |
import org.apache.struts.action.ActionForm; |
import org.apache.struts.action.RequestProcessor; |
import org.apache.struts.config.ForwardConfig; |
/** |
* To use this processor add |
* <controller processorClass="ak.strutsx.RequestProcessorX" /> |
* into the struts-config.xml file. |
*/ |
public class RequestProcessorX |
extends RequestProcessor |
{ |
/** |
* <p>Process an <code>HttpServletRequest</code> and create the |
* corresponding <code>HttpServletResponse</code>.</p> |
* |
* @param request The servlet request we are processing |
* @param response The servlet response we are creating |
* |
* @exception IOException if an input/output error occurs |
* @exception ServletException if a processing exception occurs |
*/ |
public void process(HttpServletRequest request, |
HttpServletResponse response) |
throws IOException, ServletException { |
// Wrap multipart requests with a special wrapper |
request = processMultipart(request); |
// Identify the path component we will use to select a mapping |
String path = processPath(request, response); |
if (path == null) { |
return; |
} |
if (log.isDebugEnabled()) { |
log.debug("Processing a '" + request.getMethod() + |
"' for path '" + path + "'"); |
} |
// Select a Locale for the current user if requested |
processLocale(request, response); |
// Set the content type and no-caching headers if requested |
processContent(request, response); |
processNoCache(request, response); |
// General purpose preprocessing hook |
if (!processPreprocess(request, response)) { |
return; |
} |
// Identify the mapping for this request |
ActionMapping mapping = processMapping(request, response, path); |
if (mapping == null) { |
return; |
} |
// Check for any role required to perform this action |
if (!processRoles(request, response, mapping)) { |
return; |
} |
// Create or acquire the Action instance to process this request |
// Do this here, because we need the action in case form validation is failed |
Action action = null; |
if (mapping.getType() != null) { |
action = processActionCreate(request, response, mapping); |
} |
// Process any ActionForm bean related to this request |
ActionForm form = processActionForm(request, response, mapping); |
processPopulate(request, response, form, mapping); |
if (!processValidate(request, response, action, form, mapping)) { |
return; |
} |
// Process a forward or include specified by this mapping |
if (!processForward(request, response, mapping)) { |
return; |
} |
if (!processInclude(request, response, mapping)) { |
return; |
} |
// no action |
if (action == null) { |
return; |
} |
// Call the Action instance itself |
ActionForward forward = |
processActionPerform(request, response, |
action, form, mapping); |
// Process the returned ActionForward instance |
processForwardConfig(request, response, forward); |
} |
/** |
* <p>If this request was not cancelled, and the request's |
* {@link ActionMapping} has not disabled validation, call the |
* <code>validate()</code> method of the specified {@link ActionForm}, |
* and forward back to the input form if there were any errors. |
* Return <code>true</code> if we should continue processing, |
* or <code>false</code> if we have already forwarded control back |
* to the input form.</p> |
* |
* @param request The servlet request we are processing |
* @param response The servlet response we are creating |
* @param action The Action instance we are populating |
* @param form The ActionForm instance we are populating |
* @param mapping The ActionMapping we are using |
* |
* @exception IOException if an input/output error occurs |
* @exception ServletException if a servlet exception occurs |
*/ |
protected boolean processValidate(HttpServletRequest request, |
HttpServletResponse response, |
Action action, |
ActionForm form, |
ActionMapping mapping) |
throws IOException, ServletException { |
if (form == null) { |
return (true); |
} |
// Was this request cancelled? |
if (request.getAttribute(Globals.CANCEL_KEY) != null) { |
if (log.isDebugEnabled()) { |
log.debug(" Cancelled transaction, skipping validation"); |
} |
return (true); |
} |
// Has validation been turned off for this mapping? |
if (!mapping.getValidate()) { |
return (true); |
} |
// Call the form bean's validation method |
if (log.isDebugEnabled()) { |
log.debug(" Validating input form properties"); |
} |
ActionErrors errors = form.validate(mapping, request); |
if ((errors == null) || errors.isEmpty()) { |
if (log.isTraceEnabled()) { |
log.trace(" No errors detected, accepting input"); |
} |
return (true); |
} |
// Form validation failed, try to inform the action |
if((action != null) && (action instanceof ErrorHandlerX)) { |
processValidationFailed(request, response, |
(ErrorHandlerX)action, form, mapping); |
} |
// Special handling for multipart request |
if (form.getMultipartRequestHandler() != null) { |
if (log.isTraceEnabled()) { |
log.trace(" Rolling back multipart request"); |
} |
form.getMultipartRequestHandler().rollback(); |
} |
// Has an input form been specified for this mapping? |
String input = mapping.getInput(); |
if (input == null) { |
if (log.isTraceEnabled()) { |
log.trace(" Validation failed but no input form available"); |
} |
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, |
getInternal().getMessage("noInput", |
mapping.getPath())); |
return (false); |
} |
// Save our error messages and return to the input form if possible |
if (log.isDebugEnabled()) { |
log.debug(" Validation failed, returning to '" + input + "'"); |
} |
request.setAttribute(Globals.ERROR_KEY, errors); |
if (moduleConfig.getControllerConfig().getInputForward()) { |
ForwardConfig forward = mapping.findForward(input); |
processForwardConfig( request, response, forward); |
} else { |
internalModuleRelativeForward(input, request, response); |
} |
return (false); |
} |
protected void |
processValidationFailed(HttpServletRequest request, |
HttpServletResponse response, |
ErrorHandlerX errorHandler, |
ActionForm form, |
ActionMapping mapping) |
throws IOException, ServletException { |
try { |
errorHandler.handleErrors(mapping, form, request, response); |
} catch (Exception e) { |
processException(request, response, e, form, mapping); |
} |
} |
} |
/sun/src/ak/strutsx/RequestUtilsX.java |
---|
0,0 → 1,107 |
/** |
* Extends and based on Apache Struts source code. |
* |
* Copyleft Anatoli Klassen (anatoli@aksoft.net) |
*/ |
package ak.strutsx; |
import javax.servlet.ServletException; |
import javax.servlet.http.HttpServletRequest; |
import org.apache.struts.Globals; |
import org.apache.struts.action.Action; |
import org.apache.struts.action.ActionForm; |
import org.apache.struts.action.ActionServlet; |
import org.apache.struts.action.DynaActionForm; |
import org.apache.struts.action.DynaActionFormClass; |
import org.apache.struts.config.ModuleConfig; |
import org.apache.struts.config.FormBeanConfig; |
import org.apache.struts.config.FormPropertyConfig; |
import org.apache.struts.util.RequestUtils; |
public class RequestUtilsX |
extends RequestUtils |
{ |
public static ActionForm populateActionForm( |
Action action, |
HttpServletRequest request, |
String name) |
throws ServletException { |
ActionForm form = createActionForm(action, request, name); |
RequestUtils.populate(form, request); |
request.setAttribute(name, form); |
return form; |
} |
public static ActionForm createActionForm( |
Action action, |
HttpServletRequest request, |
String name) { |
return createActionForm(name, |
(ModuleConfig)request.getAttribute(Globals.MODULE_KEY), action.getServlet()); |
} |
public static ActionForm createActionForm( |
String name, |
ModuleConfig moduleConfig, |
ActionServlet servlet) { |
FormBeanConfig config = moduleConfig.findFormBeanConfig(name); |
ActionForm instance = null; |
// Create and return a new form bean instance |
if (config.getDynamic()) { |
try { |
DynaActionFormClass dynaClass = |
DynaActionFormClass.createDynaActionFormClass(config); |
instance = (ActionForm) dynaClass.newInstance(); |
initializeDynaActionForm((DynaActionForm) instance, config); |
if (log.isDebugEnabled()) { |
log.debug( |
" Creating new DynaActionForm instance " |
+ "of type '" |
+ config.getType() |
+ "'"); |
log.trace(" --> " + instance); |
} |
} catch (Throwable t) { |
log.error(servlet.getInternal().getMessage("formBean", config.getType()), t); |
return (null); |
} |
} else { |
try { |
instance = (ActionForm) applicationInstance(config.getType()); |
if (log.isDebugEnabled()) { |
log.debug( |
" Creating new ActionForm instance " |
+ "of type '" |
+ config.getType() |
+ "'"); |
log.trace(" --> " + instance); |
} |
} catch (Throwable t) { |
log.error(servlet.getInternal().getMessage("formBean", config.getType()), t); |
return (null); |
} |
} |
instance.setServlet(servlet); |
return (instance); |
} |
public static void initializeDynaActionForm(DynaActionForm instance, FormBeanConfig config) { |
if (config == null) { |
return; |
} |
FormPropertyConfig props[] = config.findFormPropertyConfigs(); |
for (int i = 0; i < props.length; i++) { |
instance.set(props[i].getName(), props[i].initial()); |
} |
} |
} |
/sun/src/ak/strutsx/ResizeableDynaValidatorForm.java |
---|
0,0 → 1,91 |
package ak.strutsx; |
import java.util.Iterator; |
import java.util.TreeSet; |
import java.lang.reflect.Array; |
import javax.servlet.http.HttpServletRequest; |
import org.apache.struts.validator.DynaValidatorForm; |
import org.apache.struts.action.ActionErrors; |
import org.apache.struts.action.ActionMapping; |
import org.apache.struts.config.FormBeanConfig; |
import org.apache.struts.config.FormPropertyConfig; |
public final class ResizeableDynaValidatorForm |
extends DynaValidatorForm |
{ |
public void reset(ActionMapping mapping, HttpServletRequest request) |
{ |
super.reset(mapping, request); |
resize(mapping, request); |
} |
protected void resize(ActionMapping mapping, HttpServletRequest request) |
{ |
String name = mapping.getName(); |
if (name == null) return; |
FormBeanConfig config = mapping.getModuleConfig().findFormBeanConfig(name); |
if (config == null) return; |
FormPropertyConfig props[] = config.findFormPropertyConfigs(); |
for (int i = 0; i < props.length; i++) { |
if(props[i].getSize() > 0) // for arrays only |
resize(mapping, request, props[i]); |
} |
} |
protected void resize(ActionMapping mapping, HttpServletRequest request, |
FormPropertyConfig prop) |
{ |
String nameStart = prop.getName() + "["; |
// get all indices |
TreeSet indices = new TreeSet(); |
for(Iterator i = request.getParameterMap().keySet().iterator(); i.hasNext(); ) { |
String name = (String)i.next(); |
if(name.startsWith(nameStart)) { |
int p = name.indexOf("]"); |
if(p > 0) { |
String index = name.substring(nameStart.length(), p); |
try { |
indices.add(new Integer(index)); |
} |
catch(NumberFormatException ex) { |
} |
} |
} |
} |
// find last index in sequence |
int lastIndex = -1; |
for(Iterator i = indices.iterator(); i.hasNext(); ) { |
Integer idx = (Integer)i.next(); |
if(idx.intValue() == lastIndex+1) |
lastIndex++; |
else |
break; |
} |
// grow |
if(lastIndex > 0) { |
Class clazz = prop.getTypeClass(); |
Object initialValue = Array.newInstance(clazz.getComponentType(), lastIndex+1); |
for (int i = 0; i < lastIndex+1; i++) { |
try { |
Array.set(initialValue, i, clazz.getComponentType().newInstance()); |
} |
catch (Throwable t) { |
; // Probably does not have a zero-args constructor |
} |
} |
set(prop.getName(), initialValue); |
} |
} |
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) |
{ |
ActionErrors errors = super.validate(mapping, request); |
return errors; |
} |
} |
/sun/src/ak/backpath/BackPath.java |
---|
0,0 → 1,384 |
package ak.backpath; |
import java.io.InputStream; |
import java.io.OutputStream; |
import java.io.ByteArrayInputStream; |
import java.io.ByteArrayOutputStream; |
import java.io.IOException; |
import java.util.Arrays; |
import java.util.List; |
import java.util.Iterator; |
import java.util.Map; |
import java.util.ArrayList; |
import java.util.Set; |
import java.util.TreeSet; |
import java.util.Collections; |
import java.util.zip.DeflaterOutputStream; |
import java.util.zip.InflaterInputStream; |
import java.net.URL; |
import java.net.URLEncoder; |
import javax.servlet.http.HttpServletRequest; |
import org.apache.commons.logging.Log; |
import org.apache.commons.logging.LogFactory; |
public class BackPath |
{ |
private static Log log = LogFactory.getLog(BackPath.class); |
public static final String DEFAULT_KEY = BackPath.class.getName(); |
public static final String DEFAULT_PARAM = "backpath"; |
public static final String OUT_CHARSET = "UTF-8"; |
public static final String URL_CHARSET = "UTF-8"; |
public static final String IGNORES_DELIMITER = "\\s*;\\s*"; |
public static final boolean DEFAULT_ZIP = true; |
public static final String[] METHODS_TO_SAVE_PARAMS = {"GET"}; |
public static final char URL_PARAM_START = '?'; |
public static final char URL_PARAM_SEPARATOR = '&'; |
public static final char URL_PARAM_VALUE = '='; |
public static final char URL_PARAM_VALUE_SEP = ','; |
protected static final byte URL_DELIMITER = 0; |
protected static final int BUFFER_SIZE = 1024; |
protected static final int INIT_STREAM_SIZE_COEF = 100; |
protected static final String URL_PARAM_START_STR = "" + URL_PARAM_START; |
protected static Set methodsToSaveParams; |
// List(String) |
protected List stack = new ArrayList(); |
protected String param = DEFAULT_PARAM; |
protected String[] ignoreParams = null; |
/** zip the stack */ |
protected boolean zip = DEFAULT_ZIP; |
// string cache |
protected String forwardParams; |
protected boolean forwardParamsFormed = false; |
protected String currentParams; |
protected boolean currentParamsFormed = false; |
protected String backwardParams; |
protected boolean backwardParamsFormed = false; |
protected String backwardUrl; |
protected boolean backwardUrlFormed = false; |
static { |
methodsToSaveParams = Collections.unmodifiableSet( |
new TreeSet(Arrays.asList(METHODS_TO_SAVE_PARAMS))); |
} |
public static BackPath findBackPath(HttpServletRequest request) |
throws Exception |
{ |
return findBackPath(request, DEFAULT_KEY, DEFAULT_PARAM, (String)null, DEFAULT_ZIP); |
} |
public static BackPath findBackPath(HttpServletRequest request, String backPathKey, |
String backPathParam, String backPathIgnore, boolean zip) |
throws Exception |
{ |
Object backPathObj = request.getAttribute(backPathKey); |
if(backPathObj == null) { |
BackPath backPath; |
String[] ignores = null; |
if(backPathIgnore != null) |
ignores = backPathIgnore.trim().split(IGNORES_DELIMITER); |
backPath = new BackPath(request, backPathParam, ignores, zip); |
request.setAttribute(backPathKey, backPath); |
return backPath; |
} |
else if(backPathObj instanceof BackPath) { |
return (BackPath)backPathObj; |
} |
else { |
throw new Exception("An object under key " + backPathKey |
+ " is not a " + BackPath.class.getName()); |
} |
} |
public BackPath(HttpServletRequest request, String param, String[] ignoreParams, boolean zip) |
{ |
this.zip = zip; |
this.param = param; |
this.ignoreParams = ignoreParams; |
init(request); |
} |
public boolean getZip() |
{ |
return zip; |
} |
public void setZip(boolean zip) |
{ |
this.zip = zip; |
resetCachedStrings(); |
} |
public String getParam() |
{ |
return param; |
} |
public void setParam(String param) |
{ |
this.param = param; |
resetCachedStrings(); |
} |
public String[] getIgnoreParams() |
{ |
return ignoreParams; |
} |
public void setIgnoreParams(String[] ignoreParams) |
{ |
this.ignoreParams = ignoreParams; |
resetCachedStrings(); |
} |
public boolean getHasBack() |
{ |
return (stack.size() > 1); |
} |
// List(String) |
public List getStack() |
{ |
return Collections.unmodifiableList(stack); |
} |
public String getForwardParams() |
{ |
if(!forwardParamsFormed) { |
forwardParams = formForwardParams(); |
forwardParamsFormed = true; |
} |
return forwardParams; |
} |
protected String formForwardParams() |
{ |
try { |
return encode(stack, zip, 0); |
} |
catch(IOException ex) { |
log.error("Cannot form forward params", ex); |
return null; |
} |
} |
public String getBackwardParams() |
{ |
if(!backwardParamsFormed) { |
backwardParams = formBackwardParams(); |
backwardParamsFormed = true; |
} |
return backwardParams; |
} |
protected String formBackwardParams() |
{ |
try { |
if(stack.size() <= 2) |
return null; |
else |
return encode(stack, zip, 2); |
} |
catch(IOException ex) { |
log.error("Cannot form backward params", ex); |
return null; |
} |
} |
public String getBackwardUrl() |
{ |
if(!backwardParamsFormed) { |
backwardUrl = formBackwardUrl(); |
backwardUrlFormed = true; |
} |
return backwardUrl; |
} |
protected String formBackwardUrl() |
{ |
if(stack.size() < 2) return null; |
try { |
StringBuffer url = new StringBuffer((String)stack.get(stack.size()-2)); |
if(stack.size() > 2) { |
String s = encode(stack, zip, 2); |
if(url.indexOf(URL_PARAM_START_STR) >= 0) url.append(URL_PARAM_SEPARATOR); |
else url.append(URL_PARAM_START); |
url.append(param).append(URL_PARAM_VALUE).append(s); |
} |
return url.toString(); |
} |
catch(IOException ex) { |
log.error("Cannot form backward url", ex); |
return null; |
} |
} |
public String getCurrentParams() |
{ |
if(!currentParamsFormed) { |
currentParams = formCurrentParams(); |
currentParamsFormed = true; |
} |
return currentParams; |
} |
protected String formCurrentParams() |
{ |
try { |
if(stack.size() <= 1) |
return null; |
else |
return encode(stack, zip, 1); |
} |
catch(IOException ex) { |
log.error("Cannot form current params", ex); |
return null; |
} |
} |
public void init(HttpServletRequest request) |
{ |
try { |
resetCachedStrings(); |
// get old |
decode(stack, request.getParameter(param), zip); |
// add new |
String url = (new URL(request.getRequestURL().toString())).getPath(); |
if(methodsToSaveParams.contains(request.getMethod())) { |
// to ignore |
Set ignore = new TreeSet(); |
if(ignoreParams != null) { |
for(int i = 0; i < ignoreParams.length; i++) |
ignore.add(ignoreParams[i]); |
} |
ignore.add(param); |
// form query string |
StringBuffer query = new StringBuffer(); |
Map requestParams = request.getParameterMap(); |
for(Iterator i = requestParams.keySet().iterator(); i.hasNext(); ) { |
String name = (String)i.next(); |
if(ignore.contains(name)) continue; |
if(query.length() == 0) |
query.append(URL_PARAM_START); |
else |
query.append(URL_PARAM_SEPARATOR); |
query.append(URLEncoder.encode(name, URL_CHARSET)); |
query.append(URL_PARAM_VALUE); |
String[] values = (String[])requestParams.get(name); |
for(int j = 0; j < values.length; j++) { |
if(j > 0) query.append(URL_PARAM_VALUE_SEP); |
query.append(URLEncoder.encode(values[j], URL_CHARSET)); |
} |
} |
// form url |
if(query.length() > 0) url = query.insert(0, url).toString(); |
} |
stack.add(url); |
} |
catch(IOException ex) { |
log.error("Cannot init", ex); |
} |
} |
/** |
* @param stack List(String) |
*/ |
protected String encode(List stack, boolean zip, int suffix) |
throws IOException |
{ |
ByteArrayOutputStream buf = new ByteArrayOutputStream(stack.size()*INIT_STREAM_SIZE_COEF); |
OutputStream out; |
if(zip) { |
out = new DeflaterOutputStream(new Base64.OutputStream(buf)); |
} |
else { |
out = new Base64.OutputStream(buf); |
} |
for(int i = 0; i < stack.size()-suffix; i++) { |
String s = (String)stack.get(i); |
if(i > 0) out.write(URL_DELIMITER); |
out.write(s.getBytes(URL_CHARSET)); |
} |
out.close(); |
return buf.toString(OUT_CHARSET); |
} |
/** |
* @param stack List(String) |
*/ |
protected void decode(List stack, String path, boolean zip) |
throws IOException |
{ |
log.debug("decode [" + path + "] zipped=" + zip); |
stack.clear(); |
if(path == null || path.equals("")) return; |
ByteArrayInputStream enc = new ByteArrayInputStream(path.getBytes()); |
InputStream in; |
if(zip) { |
in = new InflaterInputStream(new Base64.InputStream(enc)); |
} |
else { |
in = new Base64.InputStream(enc); |
} |
ByteArrayOutputStream dec = new ByteArrayOutputStream(stack.size()*INIT_STREAM_SIZE_COEF); |
byte[] tmp = new byte[BUFFER_SIZE]; |
int l; |
while((l = in.read(tmp, 0, tmp.length)) >= 0) { |
dec.write(tmp, 0, l); |
} |
in.close(); |
try { |
byte[] buf = dec.toByteArray(); |
for(int start = 0, end = 0; end <= buf.length; end++) { |
if(end == buf.length || buf[end] == URL_DELIMITER) { |
stack.add(new String(buf, start, end-start, URL_CHARSET)); |
start = end+1; |
} |
} |
} |
catch(Exception ex) { // if some mistake in stack, then ignore it completely |
stack.clear(); |
log.info("Cannot parse stack", ex); |
} |
} |
protected void resetCachedStrings() |
{ |
forwardParams = null; |
forwardParamsFormed = false; |
currentParams = null; |
currentParamsFormed = false; |
backwardParams = null; |
backwardParamsFormed = false; |
backwardUrl = null; |
backwardUrlFormed = false; |
} |
} |
/sun/src/ak/backpath/taglib/BackwardStackTag.java |
---|
0,0 → 1,14 |
package ak.backpath.taglib; |
import javax.servlet.jsp.JspException; |
import javax.servlet.jsp.tagext.TagSupport; |
import org.apache.struts.util.ResponseUtils; |
import ak.backpath.BackPath; |
public class BackwardStackTag extends StackTagBase |
{ |
protected String getStack() throws JspException |
{ |
return findBackPath().getBackwardParams(); |
} |
} |
/sun/src/ak/backpath/taglib/ForwardTag.java |
---|
0,0 → 1,17 |
package ak.backpath.taglib; |
import javax.servlet.jsp.JspException; |
import ak.backpath.BackPath; |
public class ForwardTag extends HiddenTagBase |
{ |
public int doStartTag() throws JspException |
{ |
this.property = backPathParam; |
this.value = TaglibUtils.findBackPath(pageContext, backPathKey, |
backPathParam, backPathIgnore, zip).getForwardParams(); |
if(this.value == null) this.value = ""; |
return super.doStartTag(); |
} |
} |
/sun/src/ak/backpath/taglib/HiddenTagBase.java |
---|
0,0 → 1,71 |
package ak.backpath.taglib; |
import javax.servlet.jsp.JspException; |
import org.apache.struts.taglib.html.BaseFieldTag; |
import ak.backpath.BackPath; |
public abstract class HiddenTagBase extends BaseFieldTag |
{ |
protected String backPathKey = BackPath.DEFAULT_KEY; |
public String getBackPathKey() |
{ |
return this.backPathKey; |
} |
public void setBackPathKey(String backPathKey) |
{ |
this.backPathKey = backPathKey; |
} |
protected String backPathParam = BackPath.DEFAULT_PARAM; |
public String getBackPathParam() |
{ |
return this.backPathParam; |
} |
public void setBackPathParam(String backPathParam) |
{ |
this.backPathParam = backPathParam; |
} |
protected String backPathIgnore = null; |
public String getBackPathIgnore() |
{ |
return this.backPathIgnore; |
} |
public void setBackPathIgnore(String backPathIgnore) |
{ |
this.backPathIgnore = backPathIgnore; |
} |
protected boolean zip = BackPath.DEFAULT_ZIP; |
public boolean getZip() |
{ |
return this.zip; |
} |
public void setZip(boolean zip) |
{ |
this.zip = zip; |
} |
public HiddenTagBase() |
{ |
super(); |
this.type = "hidden"; |
} |
public void release() |
{ |
super.release(); |
backPathKey = BackPath.DEFAULT_KEY; |
backPathParam = BackPath.DEFAULT_PARAM; |
backPathIgnore = null; |
zip = BackPath.DEFAULT_ZIP; |
} |
} |
/sun/src/ak/backpath/taglib/TaglibUtils.java |
---|
0,0 → 1,23 |
package ak.backpath.taglib; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.jsp.JspException; |
import javax.servlet.jsp.PageContext; |
import javax.servlet.jsp.tagext.TagSupport; |
import ak.backpath.BackPath; |
public abstract class TaglibUtils |
{ |
public static BackPath findBackPath(PageContext pageContext, String backPathKey, |
String backPathParam, String backPathIgnore, boolean zip) |
throws JspException |
{ |
try { |
return BackPath.findBackPath((HttpServletRequest)pageContext.getRequest(), |
backPathKey, backPathParam, backPathIgnore, zip); |
} |
catch(Exception ex) { |
throw new JspException(ex); |
} |
} |
} |
/sun/src/ak/backpath/taglib/CurrentStackTag.java |
---|
0,0 → 1,14 |
package ak.backpath.taglib; |
import javax.servlet.jsp.JspException; |
import javax.servlet.jsp.tagext.TagSupport; |
import org.apache.struts.util.ResponseUtils; |
import ak.backpath.BackPath; |
public class CurrentStackTag extends StackTagBase |
{ |
protected String getStack() throws JspException |
{ |
return findBackPath().getCurrentParams(); |
} |
} |
/sun/src/ak/backpath/taglib/LinkTagBase.java |
---|
0,0 → 1,72 |
package ak.backpath.taglib; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.jsp.JspException; |
import org.apache.struts.taglib.html.LinkTag; |
import ak.backpath.BackPath; |
public abstract class LinkTagBase extends LinkTag |
{ |
protected String backPathKey = BackPath.DEFAULT_KEY; |
public String getBackPathKey() |
{ |
return this.backPathKey; |
} |
public void setBackPathKey(String backPathKey) |
{ |
this.backPathKey = backPathKey; |
} |
protected String backPathParam = BackPath.DEFAULT_PARAM; |
public String getBackPathParam() |
{ |
return this.backPathParam; |
} |
public void setBackPathParam(String backPathParam) |
{ |
this.backPathParam = backPathParam; |
} |
protected String backPathIgnore = null; |
public String getBackPathIgnore() |
{ |
return this.backPathIgnore; |
} |
public void setBackPathIgnore(String backPathIgnore) |
{ |
this.backPathIgnore = backPathIgnore; |
} |
protected boolean zip = BackPath.DEFAULT_ZIP; |
public boolean getZip() |
{ |
return this.zip; |
} |
public void setZip(boolean zip) |
{ |
this.zip = zip; |
} |
public void release() |
{ |
super.release(); |
backPathKey = BackPath.DEFAULT_KEY; |
backPathParam = BackPath.DEFAULT_PARAM; |
backPathIgnore = null; |
zip = BackPath.DEFAULT_ZIP; |
} |
protected BackPath findBackPath() throws JspException |
{ |
return TaglibUtils.findBackPath(pageContext, backPathKey, |
backPathParam, backPathIgnore, zip); |
} |
} |
/sun/src/ak/backpath/taglib/EmptyTagBase.java |
---|
0,0 → 1,87 |
package ak.backpath.taglib; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.jsp.JspException; |
import javax.servlet.jsp.tagext.TagSupport; |
import ak.backpath.BackPath; |
public abstract class EmptyTagBase extends TagSupport |
{ |
protected String backPathKey = BackPath.DEFAULT_KEY; |
public String getBackPathKey() |
{ |
return this.backPathKey; |
} |
public void setBackPathKey(String backPathKey) |
{ |
this.backPathKey = backPathKey; |
} |
protected String backPathParam = BackPath.DEFAULT_PARAM; |
public String getBackPathParam() |
{ |
return this.backPathParam; |
} |
public void setBackPathParam(String backPathParam) |
{ |
this.backPathParam = backPathParam; |
} |
protected String backPathIgnore = null; |
public String getBackPathIgnore() |
{ |
return this.backPathIgnore; |
} |
public void setBackPathIgnore(String backPathIgnore) |
{ |
this.backPathIgnore = backPathIgnore; |
} |
protected boolean zip = BackPath.DEFAULT_ZIP; |
public boolean getZip() |
{ |
return this.zip; |
} |
public void setZip(boolean zip) |
{ |
this.zip = zip; |
} |
public void release() |
{ |
super.release(); |
backPathKey = BackPath.DEFAULT_KEY; |
backPathParam = BackPath.DEFAULT_PARAM; |
backPathIgnore = null; |
zip = BackPath.DEFAULT_ZIP; |
} |
public int doStartTag() throws JspException |
{ |
if (condition()) |
return (EVAL_BODY_INCLUDE); |
else |
return (SKIP_BODY); |
} |
public int doEndTag() throws JspException |
{ |
return (EVAL_PAGE); |
} |
protected abstract boolean condition() throws JspException; |
protected BackPath findBackPath() throws JspException |
{ |
return TaglibUtils.findBackPath(pageContext, backPathKey, |
backPathParam, backPathIgnore, zip); |
} |
} |
/sun/src/ak/backpath/taglib/ForwardStackTag.java |
---|
0,0 → 1,14 |
package ak.backpath.taglib; |
import javax.servlet.jsp.JspException; |
import javax.servlet.jsp.tagext.TagSupport; |
import org.apache.struts.util.ResponseUtils; |
import ak.backpath.BackPath; |
public class ForwardStackTag extends StackTagBase |
{ |
protected String getStack() throws JspException |
{ |
return findBackPath().getForwardParams(); |
} |
} |
/sun/src/ak/backpath/taglib/BackwardLinkTag.java |
---|
0,0 → 1,50 |
package ak.backpath.taglib; |
import javax.servlet.jsp.JspException; |
import ak.backpath.BackPath; |
public class BackwardLinkTag extends LinkTagBase |
{ |
protected boolean skipEmpty = true; |
public boolean getSkipEmpty() |
{ |
return this.skipEmpty; |
} |
public void setSkipEmpty(boolean skipEmpty) |
{ |
this.skipEmpty = skipEmpty; |
} |
public int doStartTag() throws JspException |
{ |
if(!skipEmpty || findBackPath().getHasBack()) |
return super.doStartTag(); |
else |
return SKIP_BODY; |
} |
public int doAfterBody() throws JspException |
{ |
if(!skipEmpty || findBackPath().getHasBack()) |
return super.doAfterBody(); |
else |
return SKIP_BODY; |
} |
public int doEndTag() throws JspException |
{ |
if(!skipEmpty || findBackPath().getHasBack()) |
return super.doEndTag(); |
else |
return EVAL_PAGE; |
} |
protected String calculateURL() throws JspException |
{ |
String url = findBackPath().getBackwardUrl(); |
if(url == null) url = "/"; |
return url; |
} |
} |
/sun/src/ak/backpath/taglib/ak-backpath.tld |
---|
0,0 → 1,548 |
<?xml version="1.0" encoding="UTF-8"?> |
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd"> |
<taglib> |
<tlibversion>1.0</tlibversion> |
<jspversion>1.1</jspversion> |
<shortname>backpath</shortname> |
<uri>http://26th.net/backpath</uri> |
<tag> |
<name>backlink</name> |
<tagclass>ak.backpath.taglib.BackwardLinkTag</tagclass> |
<attribute> |
<name>accesskey</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>anchor</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>indexId</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>linkName</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>name</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>onblur</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>onclick</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>ondblclick</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>onfocus</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>onkeydown</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>onkeypress</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>onkeyup</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>onmousedown</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>onmousemove</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>onmouseout</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>onmouseover</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>onmouseup</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>property</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>scope</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>style</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>styleClass</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>styleId</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>tabindex</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>target</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>title</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>backPathKey</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>backPathParam</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>backPathIgnore</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>zip</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>skipEmpty</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
</tag> |
<tag> |
<name>link</name> |
<tagclass>ak.backpath.taglib.ForwardLinkTag</tagclass> |
<attribute> |
<name>accesskey</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>action</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>anchor</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>forward</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>href</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>indexed</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>indexId</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>linkName</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>name</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>onblur</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>onclick</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>ondblclick</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>onfocus</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>onkeydown</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>onkeypress</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>onkeyup</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>onmousedown</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>onmousemove</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>onmouseout</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>onmouseover</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>onmouseup</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>page</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>paramId</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>paramName</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>paramProperty</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>paramScope</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>property</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>scope</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>style</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>styleClass</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>styleId</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>tabindex</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>target</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>title</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>titleKey</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>transaction</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>backPathKey</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>backPathParam</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>backPathIgnore</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>zip</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
</tag> |
<tag> |
<name>empty</name> |
<tagclass>ak.backpath.taglib.EmptyTag</tagclass> |
<attribute> |
<name>backPathKey</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>backPathParam</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>backPathIgnore</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>zip</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
</tag> |
<tag> |
<name>notEmpty</name> |
<tagclass>ak.backpath.taglib.NotEmptyTag</tagclass> |
<attribute> |
<name>backPathKey</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>backPathParam</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>backPathIgnore</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>zip</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
</tag> |
<tag> |
<name>current</name> |
<tagclass>ak.backpath.taglib.CurrentTag</tagclass> |
<bodycontent>empty</bodycontent> |
<attribute> |
<name>backPathKey</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>backPathParam</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>backPathIgnore</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>zip</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
</tag> |
<tag> |
<name>forward</name> |
<tagclass>ak.backpath.taglib.ForwardTag</tagclass> |
<bodycontent>empty</bodycontent> |
<attribute> |
<name>backPathKey</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>backPathParam</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>backPathIgnore</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>zip</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
</tag> |
<tag> |
<name>forwardStack</name> |
<tagclass>ak.backpath.taglib.ForwardStackTag</tagclass> |
<bodycontent>empty</bodycontent> |
<attribute> |
<name>backPathKey</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>backPathParam</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>backPathIgnore</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>zip</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
</tag> |
<tag> |
<name>currentStack</name> |
<tagclass>ak.backpath.taglib.CurrentStackTag</tagclass> |
<bodycontent>empty</bodycontent> |
<attribute> |
<name>backPathKey</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>backPathParam</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>backPathIgnore</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>zip</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
</tag> |
<tag> |
<name>backwardStack</name> |
<tagclass>ak.backpath.taglib.BackwardStackTag</tagclass> |
<bodycontent>empty</bodycontent> |
<attribute> |
<name>backPathKey</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>backPathParam</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>backPathIgnore</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
<attribute> |
<name>zip</name> |
<required>false</required> |
<rtexprvalue>true</rtexprvalue> |
</attribute> |
</tag> |
</taglib> |
/sun/src/ak/backpath/taglib/EmptyTag.java |
---|
0,0 → 1,11 |
package ak.backpath.taglib; |
import javax.servlet.jsp.JspException; |
public class EmptyTag extends EmptyTagBase |
{ |
protected boolean condition() throws JspException |
{ |
return !findBackPath().getHasBack(); |
} |
} |
/sun/src/ak/backpath/taglib/NotEmptyTag.java |
---|
0,0 → 1,11 |
package ak.backpath.taglib; |
import javax.servlet.jsp.JspException; |
public class NotEmptyTag extends EmptyTagBase |
{ |
protected boolean condition() throws JspException |
{ |
return findBackPath().getHasBack(); |
} |
} |
/sun/src/ak/backpath/taglib/StackTagBase.java |
---|
0,0 → 1,82 |
package ak.backpath.taglib; |
import javax.servlet.jsp.JspException; |
import javax.servlet.jsp.tagext.TagSupport; |
import org.apache.struts.util.ResponseUtils; |
import ak.backpath.BackPath; |
public abstract class StackTagBase extends TagSupport |
{ |
protected String backPathKey = BackPath.DEFAULT_KEY; |
public String getBackPathKey() |
{ |
return this.backPathKey; |
} |
public void setBackPathKey(String backPathKey) |
{ |
this.backPathKey = backPathKey; |
} |
protected String backPathParam = BackPath.DEFAULT_PARAM; |
public String getBackPathParam() |
{ |
return this.backPathParam; |
} |
public void setBackPathParam(String backPathParam) |
{ |
this.backPathParam = backPathParam; |
} |
protected String backPathIgnore = null; |
public String getBackPathIgnore() |
{ |
return this.backPathIgnore; |
} |
public void setBackPathIgnore(String backPathIgnore) |
{ |
this.backPathIgnore = backPathIgnore; |
} |
protected boolean zip = BackPath.DEFAULT_ZIP; |
public boolean getZip() |
{ |
return this.zip; |
} |
public void setZip(boolean zip) |
{ |
this.zip = zip; |
} |
public void release() |
{ |
super.release(); |
backPathKey = BackPath.DEFAULT_KEY; |
backPathParam = BackPath.DEFAULT_PARAM; |
backPathIgnore = null; |
zip = BackPath.DEFAULT_ZIP; |
} |
public int doStartTag() throws JspException |
{ |
String stack = getStack(); |
if(stack == null) stack = ""; |
ResponseUtils.write(pageContext, stack); |
return SKIP_BODY; |
} |
protected BackPath findBackPath() throws JspException |
{ |
return TaglibUtils.findBackPath(pageContext, backPathKey, |
backPathParam, backPathIgnore, zip); |
} |
protected abstract String getStack() throws JspException; |
} |
/sun/src/ak/backpath/taglib/CurrentTag.java |
---|
0,0 → 1,17 |
package ak.backpath.taglib; |
import javax.servlet.jsp.JspException; |
import ak.backpath.BackPath; |
public class CurrentTag extends HiddenTagBase |
{ |
public int doStartTag() throws JspException |
{ |
this.property = backPathParam; |
this.value = TaglibUtils.findBackPath(pageContext, backPathKey, |
backPathParam, backPathIgnore, zip).getCurrentParams(); |
if(this.value == null) this.value = ""; |
return super.doStartTag(); |
} |
} |
/sun/src/ak/backpath/taglib/ForwardLinkTag.java |
---|
0,0 → 1,21 |
package ak.backpath.taglib; |
import javax.servlet.jsp.JspException; |
import ak.backpath.BackPath; |
public class ForwardLinkTag extends LinkTagBase |
{ |
protected String calculateURL() throws JspException |
{ |
String url = super.calculateURL(); |
if(url == null) return null; |
String params = findBackPath().getForwardParams(); |
if(params == null) return url; |
if(url.indexOf("?") > 0) |
return url + "&" + backPathParam + "=" + params; |
else |
return url + "?" + backPathParam + "=" + params; |
} |
} |
/sun/src/ak/backpath/Base64.java |
---|
0,0 → 1,315 |
package ak.backpath; |
/** |
* Special version for packpath (ak) - |
* symbols +/= replaced with .*! to produce correct URL-parts; |
* most methods are deleted</li> |
* |
* Original author Robert Harder (rob@iharder.net) |
*/ |
class Base64 |
{ |
/** The equals sign (=) as a byte. */ |
private final static byte EQUALS_SIGN = (byte)'!'; |
/** The new line character (\n) as a byte. */ |
private final static byte NEW_LINE = (byte)'\n'; |
/** Preferred encoding. */ |
private final static String PREFERRED_ENCODING = "UTF-8"; |
/** The 64 valid Base64 values. */ |
private final static byte[] ALPHABET; |
private final static byte[] _NATIVE_ALPHABET = /* May be something funny like EBCDIC */ |
{ |
(byte)'A', (byte)'B', (byte)'C', (byte)'D', (byte)'E', (byte)'F', (byte)'G', |
(byte)'H', (byte)'I', (byte)'J', (byte)'K', (byte)'L', (byte)'M', (byte)'N', |
(byte)'O', (byte)'P', (byte)'Q', (byte)'R', (byte)'S', (byte)'T', (byte)'U', |
(byte)'V', (byte)'W', (byte)'X', (byte)'Y', (byte)'Z', |
(byte)'a', (byte)'b', (byte)'c', (byte)'d', (byte)'e', (byte)'f', (byte)'g', |
(byte)'h', (byte)'i', (byte)'j', (byte)'k', (byte)'l', (byte)'m', (byte)'n', |
(byte)'o', (byte)'p', (byte)'q', (byte)'r', (byte)'s', (byte)'t', (byte)'u', |
(byte)'v', (byte)'w', (byte)'x', (byte)'y', (byte)'z', |
(byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', |
(byte)'6', (byte)'7', (byte)'8', (byte)'9', (byte)'.', (byte)'*' |
}; |
/** Determine which ALPHABET to use. */ |
static |
{ |
byte[] __bytes; |
try |
{ |
__bytes = new String("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.*") |
.getBytes( PREFERRED_ENCODING ); |
} |
catch (java.io.UnsupportedEncodingException use) |
{ |
__bytes = _NATIVE_ALPHABET; // Fall back to native encoding |
} |
ALPHABET = __bytes; |
} |
/** |
* Translates a Base64 value to either its 6-bit reconstruction value |
* or a negative number indicating some other meaning. |
**/ |
private final static byte[] DECODABET = |
{ |
-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 0 - 8 |
-5,-5, // Whitespace: Tab and Linefeed |
-9,-9, // Decimal 11 - 12 |
-5, // Whitespace: Carriage Return |
-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 14 - 26 |
-9,-9,-9,-9,-9, // Decimal 27 - 31 |
-5, // Whitespace: Space |
-1, // ! at decimal 33 |
-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 34 - 41 |
63, // * at decimal 42 |
-9, // Plus sign at decimal 43 |
-9,-9,62, // Decimal 44 - 46 |
-9, // Slash at decimal 47 |
52,53,54,55,56,57,58,59,60,61, // Numbers zero through nine |
-9,-9,-9, // Decimal 58 - 60 |
-9, // Equals sign at decimal 61 |
-9,-9,-9, // Decimal 62 - 64 |
0,1,2,3,4,5,6,7,8,9,10,11,12,13, // Letters 'A' through 'N' |
14,15,16,17,18,19,20,21,22,23,24,25, // Letters 'O' through 'Z' |
-9,-9,-9,-9,-9,-9, // Decimal 91 - 96 |
26,27,28,29,30,31,32,33,34,35,36,37,38, // Letters 'a' through 'm' |
39,40,41,42,43,44,45,46,47,48,49,50,51, // Letters 'n' through 'z' |
-9,-9,-9,-9 // Decimal 123 - 126 |
}; |
private final static byte BAD_ENCODING = -9; // Indicates error in encoding |
private final static byte WHITE_SPACE_ENC = -5; // Indicates white space in encoding |
private final static byte EQUALS_SIGN_ENC = -1; // Indicates equals sign in encoding |
private Base64(){} |
private static byte[] encode3to4(byte[] destination, byte[] source, int numSigBytes) |
{ |
// 1 2 3 |
// 01234567890123456789012345678901 Bit position |
// --------000000001111111122222222 Array position from threeBytes |
// --------| || || || | Six bit groups to index ALPHABET |
// >>18 >>12 >> 6 >> 0 Right shift necessary |
// 0x3f 0x3f 0x3f Additional AND |
// Create buffer with zero-padding if there are only one or two |
// significant bytes passed in the array. |
// We have to shift left 24 in order to flush out the 1's that appear |
// when Java treats a value as negative that is cast from a byte to an int. |
int inBuff = ( numSigBytes > 0 ? ((source[ 0 ] << 24) >>> 8) : 0 ) |
| ( numSigBytes > 1 ? ((source[ 1 ] << 24) >>> 16) : 0 ) |
| ( numSigBytes > 2 ? ((source[ 2 ] << 24) >>> 24) : 0 ); |
switch( numSigBytes ) |
{ |
case 3: |
destination[ 0 ] = ALPHABET[ (inBuff >>> 18) ]; |
destination[ 1 ] = ALPHABET[ (inBuff >>> 12) & 0x3f ]; |
destination[ 2 ] = ALPHABET[ (inBuff >>> 6) & 0x3f ]; |
destination[ 3 ] = ALPHABET[ (inBuff ) & 0x3f ]; |
return destination; |
case 2: |
destination[ 0 ] = ALPHABET[ (inBuff >>> 18) ]; |
destination[ 1 ] = ALPHABET[ (inBuff >>> 12) & 0x3f ]; |
destination[ 2 ] = ALPHABET[ (inBuff >>> 6) & 0x3f ]; |
destination[ 3 ] = EQUALS_SIGN; |
return destination; |
case 1: |
destination[ 0 ] = ALPHABET[ (inBuff >>> 18) ]; |
destination[ 1 ] = ALPHABET[ (inBuff >>> 12) & 0x3f ]; |
destination[ 2 ] = EQUALS_SIGN; |
destination[ 3 ] = EQUALS_SIGN; |
return destination; |
default: |
return destination; |
} |
} |
private static int decode4to3( byte[] source, int srcOffset, byte[] destination, int destOffset ) |
{ |
// Example: Dk== |
if( source[ srcOffset + 2] == EQUALS_SIGN ) |
{ |
int outBuff = ( ( DECODABET[ source[ srcOffset ] ] & 0xFF ) << 18 ) |
| ( ( DECODABET[ source[ srcOffset + 1] ] & 0xFF ) << 12 ); |
destination[ destOffset ] = (byte)( outBuff >>> 16 ); |
return 1; |
} |
// Example: DkL= |
else if( source[ srcOffset + 3 ] == EQUALS_SIGN ) |
{ |
int outBuff = ( ( DECODABET[ source[ srcOffset ] ] & 0xFF ) << 18 ) |
| ( ( DECODABET[ source[ srcOffset + 1 ] ] & 0xFF ) << 12 ) |
| ( ( DECODABET[ source[ srcOffset + 2 ] ] & 0xFF ) << 6 ); |
destination[ destOffset ] = (byte)( outBuff >>> 16 ); |
destination[ destOffset + 1 ] = (byte)( outBuff >>> 8 ); |
return 2; |
} |
// Example: DkLE |
else |
{ |
try{ |
int outBuff = ( ( DECODABET[ source[ srcOffset ] ] & 0xFF ) << 18 ) |
| ( ( DECODABET[ source[ srcOffset + 1 ] ] & 0xFF ) << 12 ) |
| ( ( DECODABET[ source[ srcOffset + 2 ] ] & 0xFF ) << 6) |
| ( ( DECODABET[ source[ srcOffset + 3 ] ] & 0xFF ) ); |
destination[ destOffset ] = (byte)( outBuff >> 16 ); |
destination[ destOffset + 1 ] = (byte)( outBuff >> 8 ); |
destination[ destOffset + 2 ] = (byte)( outBuff ); |
return 3; |
}catch( Exception e){ |
return -1; |
} |
} |
} |
static class InputStream extends java.io.FilterInputStream |
{ |
private int position; // Current position in the buffer |
private byte[] buffer; // Small buffer holding converted data |
private int bufferLength; // Length of buffer (3 or 4) |
private int numSigBytes; // Number of meaningful bytes in the buffer |
public InputStream( java.io.InputStream in) |
{ |
super( in ); |
this.bufferLength = 3; |
this.buffer = new byte[ bufferLength ]; |
this.position = -1; |
} |
public int read() throws java.io.IOException |
{ |
// Do we need to get data? |
if( position < 0 ) |
{ |
byte[] b4 = new byte[4]; |
int i = 0; |
for( i = 0; i < 4; i++ ) |
{ |
// Read four "meaningful" bytes: |
int b = 0; |
do{ b = in.read(); } |
while( b >= 0 && DECODABET[ b & 0x7f ] <= WHITE_SPACE_ENC ); |
if( b < 0 ) |
break; // Reads a -1 if end of stream |
b4[i] = (byte)b; |
} |
if( i == 4 ) |
{ |
numSigBytes = decode4to3( b4, 0, buffer, 0 ); |
position = 0; |
} |
else if( i == 0 ){ |
return -1; |
} |
else |
{ |
throw new java.io.IOException( "Improperly padded Base64 input." ); |
} |
} |
// Got data? |
if( position >= 0 ) |
{ |
if( position >= numSigBytes ) |
return -1; |
int b = buffer[ position++ ]; |
if( position >= bufferLength ) |
position = -1; |
return b & 0xFF; |
} |
else |
{ |
throw new java.io.IOException( "Error in Base64 code reading stream." ); |
} |
} |
public int read( byte[] dest, int off, int len ) throws java.io.IOException |
{ |
int i; |
int b; |
for( i = 0; i < len; i++ ) |
{ |
b = read(); |
if( b >= 0 ) |
dest[off + i] = (byte)b; |
else if( i == 0 ) |
return -1; |
else |
break; |
} |
return i; |
} |
} |
static class OutputStream extends java.io.FilterOutputStream |
{ |
private int position; |
private byte[] buffer; |
private int bufferLength; |
private byte[] b4; |
public OutputStream( java.io.OutputStream out) |
{ |
super( out ); |
this.bufferLength = 3; |
this.buffer = new byte[ bufferLength ]; |
this.position = 0; |
this.b4 = new byte[4]; |
} |
public void write(int theByte) throws java.io.IOException |
{ |
buffer[ position++ ] = (byte)theByte; |
if( position >= bufferLength ) // Enough to encode. |
{ |
out.write( encode3to4( b4, buffer, bufferLength ) ); |
position = 0; |
} |
} |
public void write( byte[] theBytes, int off, int len ) throws java.io.IOException |
{ |
for( int i = 0; i < len; i++ ) |
{ |
write( theBytes[ off + i ] ); |
} |
} |
public void close() throws java.io.IOException |
{ |
if( position > 0 ) |
{ |
out.write( encode3to4( b4, buffer, position ) ); |
position = 0; |
} |
super.close(); |
buffer = null; |
out = null; |
} |
} |
} |
/sun/src/ak/webcontrol/core/action/MailboxAction.java |
---|
0,0 → 1,151 |
package ak.webcontrol.core.action; |
import java.util.List; |
import java.util.Collections; |
import java.util.ArrayList; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
import org.apache.struts.action.Action; |
import org.apache.struts.action.ActionMapping; |
import org.apache.struts.action.ActionForm; |
import org.apache.struts.action.DynaActionForm; |
import org.apache.struts.action.ActionForward; |
import org.apache.struts.action.ActionMessages; |
import org.apache.struts.action.ActionErrors; |
import org.apache.struts.action.ActionError; |
import ak.strutsx.RequestUtilsX; |
import ak.strutsx.ErrorHandlerX; |
import ak.backpath.BackPath; |
import ak.webcontrol.util.StringConverter; |
import ak.webcontrol.core.model.User; |
import ak.webcontrol.core.model.UserManager; |
import ak.webcontrol.core.model.Mailbox; |
import ak.webcontrol.core.model.MailboxManager; |
import ak.webcontrol.core.model.SystemUserManager; |
import ak.webcontrol.core.model.InetDomainManager; |
public final class MailboxAction |
extends Action |
implements ErrorHandlerX |
{ |
public void handleErrors(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
if("submit".equals(mapping.getParameter())) { |
initLists(request); |
} |
} |
public ActionForward execute(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
User user = (User)request.getSession().getAttribute("user"); |
if("list".equals(mapping.getParameter())) { |
List list = new ArrayList(MailboxManager.getInstance().listMailboxes()); |
Collections.sort(list, MailboxManager.LOGIN_COMPARATOR); |
request.setAttribute("mailboxes", list); |
return mapping.findForward("default"); |
} |
else if("edit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long boxId = StringConverter.parseLong(theForm.get("id")); |
DynaActionForm showForm = (DynaActionForm)RequestUtilsX.populateActionForm( |
this, request, "ak.webcontrol.core.form.MailboxEditForm"); |
if(boxId == null) { |
} |
else { |
Mailbox mailbox = MailboxManager.getInstance().get(boxId); |
showForm.set("login", mailbox.getLogin()); |
if(mailbox.getDomain() != null) |
showForm.set("domain", StringConverter.toString(mailbox.getDomain().getId())); |
if(mailbox.getOwner() != null) |
showForm.set("owner", StringConverter.toString(mailbox.getOwner().getId())); |
showForm.set("viruscheck", mailbox.getVirusCheck()); |
showForm.set("spamcheck", mailbox.getSpamCheck()); |
if(mailbox.getSystemUser() != null) |
showForm.set("systemuser", StringConverter.toString(mailbox.getSystemUser().getId())); |
} |
initLists(request); |
return mapping.findForward("default"); |
} |
else if("delete".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long boxId = StringConverter.parseLong(theForm.get("id")); |
Mailbox mailbox = MailboxManager.getInstance().get(boxId); |
MailboxManager.getInstance().delete(mailbox); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
else if("submit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long boxId = StringConverter.parseLong(theForm.get("id")); |
Mailbox mailbox; |
String password = (String)theForm.get("password"); |
if(boxId == null) { |
if(password == null || password.equals("")) |
throw new Exception("empty password"); // FIXME: exception type and message? |
mailbox = MailboxManager.getInstance().create(); |
// FIXME: create an user as owner of the new mailbox here |
} |
else { |
mailbox = MailboxManager.getInstance().get(boxId); |
} |
mailbox.setLogin((String)theForm.get("login")); |
mailbox.setDomain(InetDomainManager.getInstance().get( |
StringConverter.parseLong(theForm.get("domain")))); |
mailbox.setOwner(UserManager.getInstance().get( |
StringConverter.parseLong(theForm.get("owner")))); |
mailbox.setVirusCheck((Boolean)theForm.get("viruscheck")); |
mailbox.setSpamCheck((Boolean)theForm.get("spamcheck")); |
Long systemUserId = StringConverter.parseLong(theForm.get("systemuser")); |
if(systemUserId == null) { |
mailbox.setSystemUser(null); |
} |
else { |
mailbox.setSystemUser(SystemUserManager.getInstance().get(systemUserId)); |
} |
if(password != null && !password.equals("")) |
mailbox.setNewPassword(password); |
MailboxManager.getInstance().save(mailbox); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
else { |
throw new Exception("unknown mapping parameter"); |
} |
} |
private void initLists(HttpServletRequest request) |
throws Exception |
{ |
List users = new ArrayList(UserManager.getInstance().listUsers()); |
Collections.sort(users, UserManager.LOGIN_COMPARATOR); |
request.setAttribute("users", users); |
List systemUsers = new ArrayList(SystemUserManager.getInstance().listSystemUsers()); |
Collections.sort(systemUsers, SystemUserManager.UID_COMPARATOR); |
request.setAttribute("systemusers", systemUsers); |
List domains = new ArrayList(InetDomainManager.getInstance().listInetDomains()); |
Collections.sort(domains, InetDomainManager.NAME_COMPARATOR); |
request.setAttribute("domains", domains); |
} |
} |
/sun/src/ak/webcontrol/core/action/MailAliasAction.java |
---|
0,0 → 1,238 |
package ak.webcontrol.core.action; |
import java.util.List; |
import java.util.Iterator; |
import java.util.Collections; |
import java.util.ArrayList; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
import org.apache.commons.beanutils.BeanUtils; |
import org.apache.struts.action.Action; |
import org.apache.struts.action.ActionMapping; |
import org.apache.struts.action.ActionForm; |
import org.apache.struts.action.DynaActionForm; |
import org.apache.struts.action.ActionForward; |
import org.apache.struts.action.ActionMessages; |
import org.apache.struts.action.ActionErrors; |
import org.apache.struts.action.ActionError; |
import ak.strutsx.RequestUtilsX; |
import ak.strutsx.ErrorHandlerX; |
import ak.backpath.BackPath; |
import ak.webcontrol.util.StringConverter; |
import ak.webcontrol.core.model.User; |
import ak.webcontrol.core.model.UserManager; |
import ak.webcontrol.core.model.Mailbox; |
import ak.webcontrol.core.model.MailboxManager; |
import ak.webcontrol.core.model.MailAlias; |
import ak.webcontrol.core.model.MailAliasManager; |
import ak.webcontrol.core.model.MailAliasDestination; |
import ak.webcontrol.core.model.MailAliasDestinationManager; |
import ak.webcontrol.core.model.InetDomainManager; |
import ak.webcontrol.core.form.MailAliasDestBean; |
public final class MailAliasAction |
extends Action |
implements ErrorHandlerX |
{ |
public void handleErrors(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
if("submit".equals(mapping.getParameter())) { |
User user = (User)request.getSession().getAttribute("user"); |
initLists(request, user); |
} |
} |
public ActionForward execute(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
User user = (User)request.getSession().getAttribute("user"); |
if("list".equals(mapping.getParameter())) { |
List list = new ArrayList(MailAliasManager.getInstance().listMailAliases()); |
Collections.sort(list, MailAliasManager.ADDRESS_COMPARATOR); |
request.setAttribute("aliases", list); |
return mapping.findForward("default"); |
} |
else if("edit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long aliasId = StringConverter.parseLong(theForm.get("id")); |
DynaActionForm showForm = (DynaActionForm)RequestUtilsX.populateActionForm( |
this, request, "ak.webcontrol.core.form.MailAliasEditForm"); |
if(aliasId == null) { |
} |
else { |
MailAlias alias = MailAliasManager.getInstance().get(aliasId); |
List dests = new ArrayList(MailAliasDestinationManager.getInstance() |
.listMailAliasesDestination(alias)); |
MailAliasDestBean[] d = new MailAliasDestBean[dests.size()]; |
// FIXME: sort dests here |
for(int i = 0; i < dests.size(); i++) { |
d[i] = new MailAliasDestBean((MailAliasDestination)dests.get(i)); |
} |
showForm.set("dests", d); |
showForm.set("address", alias.getAddress()); |
if(alias.getDomain() != null) |
showForm.set("domain", |
StringConverter.toString(alias.getDomain().getId())); |
if(alias.getOwner() != null) |
showForm.set("owner", |
StringConverter.toString(alias.getOwner().getId())); |
} |
initLists(request, user); |
return mapping.findForward("default"); |
} |
else if("delete".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long aliasId = StringConverter.parseLong(theForm.get("id")); |
MailAlias alias = MailAliasManager.getInstance().get(aliasId); |
MailAliasManager.getInstance().delete(alias); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
else if("submit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long aliasId = StringConverter.parseLong(theForm.get("id")); |
MailAlias alias = (aliasId == null) ? null |
: MailAliasManager.getInstance().get(aliasId); |
MailAliasDestBean[] dests = (MailAliasDestBean[])theForm.get("dests"); |
// submit |
if(request.getParameter("submit") != null) { |
if(alias == null) |
alias = MailAliasManager.getInstance().create(); |
alias.getDestinations().clear(); |
for(int i = 0; i < dests.length; i++) { |
// FIXME: validate dest id, mailbox id, email |
// skip empty rows |
if((dests[i].getMailbox() == null) |
&& (dests[i].getEmail() == null || dests[i].getEmail().equals(""))) |
continue; |
// get bean |
Long destId = StringConverter.parseLong(dests[i].getId()); |
Long mailboxId = StringConverter.parseLong(dests[i].getMailbox()); |
MailAliasDestination dest; |
if(destId == null) |
dest = MailAliasDestinationManager.getInstance().create(); |
else |
dest = MailAliasDestinationManager.getInstance().get(destId); |
// set mailbox or email |
if(mailboxId != null) { |
dest.setMailbox(MailboxManager.getInstance().get(mailboxId)); |
dest.setEmail(null); |
} |
else if(dests[i].getEmail() != null && !dests[i].getEmail().equals("")) { |
dest.setMailbox(null); |
dest.setEmail(dests[i].getEmail()); |
} |
// connect |
dest.setAlias(alias); |
alias.getDestinations().add(dest); |
} |
alias.setAddress((String)theForm.get("address")); |
alias.setDomain(InetDomainManager.getInstance().get( |
StringConverter.parseLong(theForm.get("domain")))); |
alias.setOwner(UserManager.getInstance().get( |
StringConverter.parseLong(theForm.get("owner")))); |
// update alias |
MailAliasManager.getInstance().save(alias); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
// add |
else if(request.getParameter("add") != null) { |
MailAliasDestBean[] newDests = new MailAliasDestBean[dests.length+1]; |
System.arraycopy(dests, 0, newDests, 0, dests.length); |
newDests[dests.length] = new MailAliasDestBean(); |
theForm.set("dests", newDests); |
initLists(request, user); |
return mapping.findForward("back"); |
} |
// delete |
else { |
Iterator iter = request.getParameterMap().keySet().iterator(); |
while(iter.hasNext()) { |
String name = (String)iter.next(); |
if(name.startsWith("delete.dests[")) { |
int p = name.indexOf("]"); |
if(p > 0) { |
String index = name.substring("delete.dests[".length(), p); |
try { |
int n = Integer.parseInt(index); |
if(n < 0 || n >= dests.length) break; |
MailAliasDestBean[] newDests; |
if(dests.length <= 1) { |
newDests = new MailAliasDestBean[1]; |
newDests[0] = new MailAliasDestBean(); |
} |
else { |
newDests = new MailAliasDestBean[dests.length-1]; |
if(n > 0) |
System.arraycopy(dests, 0, newDests, 0, n); |
if(n < dests.length-1) |
System.arraycopy(dests, n+1, newDests, |
n, dests.length-n-1); |
} |
theForm.set("dests", newDests); |
break; |
} |
catch(NumberFormatException ex) { |
} |
} |
} |
} |
initLists(request, user); |
return mapping.findForward("back"); |
} |
} |
else { |
throw new Exception("unknown mapping parameter"); |
} |
} |
private void initLists(HttpServletRequest request, User user) |
throws Exception |
{ |
// list of mailboxes to redirect to |
List mailboxes = new ArrayList(MailboxManager.getInstance().listMailboxes(user)); |
Collections.sort(mailboxes, MailboxManager.LOGIN_COMPARATOR); |
request.setAttribute("mailboxes", mailboxes); |
List users = new ArrayList(UserManager.getInstance().listUsers()); |
Collections.sort(users, UserManager.LOGIN_COMPARATOR); |
request.setAttribute("users", users); |
List domains = new ArrayList(InetDomainManager.getInstance().listInetDomains()); |
Collections.sort(domains, InetDomainManager.NAME_COMPARATOR); |
request.setAttribute("domains", domains); |
} |
} |
/sun/src/ak/webcontrol/core/action/UserExceptionHandler.java |
---|
0,0 → 1,62 |
package ak.webcontrol.core.action; |
import javax.servlet.ServletException; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
import org.apache.struts.Globals; |
import org.apache.struts.action.ActionError; |
import org.apache.struts.action.ActionErrors; |
import org.apache.struts.action.ActionMessages; |
import org.apache.struts.action.ExceptionHandler; |
import org.apache.struts.action.ActionMapping; |
import org.apache.struts.action.ActionForm; |
import org.apache.struts.action.ActionForward; |
import org.apache.struts.config.ExceptionConfig; |
import org.apache.log4j.Logger; |
import ak.strutsx.ErrorHandlerX; |
import ak.webcontrol.util.UserException; |
import ak.webcontrol.util.FormException; |
public final class UserExceptionHandler |
extends ExceptionHandler |
{ |
private static final Logger logger = Logger.getLogger(UserExceptionHandler.class); |
public ActionForward execute(Exception ex, ExceptionConfig config, |
ActionMapping mapping, ActionForm formInstance, |
HttpServletRequest request, HttpServletResponse response) |
throws ServletException |
{ |
if(!(ex instanceof UserException)) |
throw new ServletException("Unknown type of exception: " + ex.getClass()); |
UserException userEx = (UserException)ex; |
logger.info("begin exception handle:" + userEx.getMessage()); |
// try to get property for this exception if any |
String property = ActionMessages.GLOBAL_MESSAGE; |
if(userEx instanceof FormException) { |
FormException formEx = (FormException)userEx; |
if(formEx.getProperty() != null) |
property = formEx.getProperty(); |
} |
// create new error message |
ActionErrors errors = (ActionErrors)request.getAttribute(Globals.ERROR_KEY); |
if(errors == null) { |
errors = new ActionErrors(); |
request.setAttribute(Globals.ERROR_KEY, errors); |
} |
errors.add(property, new ActionError(userEx.getMessage(), userEx.getValues())); |
// find forward |
if(mapping.getInput() == null) |
return mapping.findForward("error"); |
else |
return mapping.getInputForward(); |
} |
} |
/sun/src/ak/webcontrol/core/action/UserAction.java |
---|
0,0 → 1,104 |
package ak.webcontrol.core.action; |
import java.util.List; |
import java.util.Collections; |
import java.util.ArrayList; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
import org.apache.struts.action.Action; |
import org.apache.struts.action.ActionMapping; |
import org.apache.struts.action.ActionForm; |
import org.apache.struts.action.DynaActionForm; |
import org.apache.struts.action.ActionForward; |
import org.apache.struts.action.ActionMessages; |
import org.apache.struts.action.ActionErrors; |
import org.apache.struts.action.ActionError; |
import ak.strutsx.RequestUtilsX; |
import ak.backpath.BackPath; |
import ak.webcontrol.util.StringConverter; |
import ak.webcontrol.util.UserException; |
import ak.webcontrol.core.CoreResources; |
import ak.webcontrol.core.model.User; |
import ak.webcontrol.core.model.UserManager; |
public final class UserAction |
extends Action |
{ |
public ActionForward execute(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
User user = (User)request.getSession().getAttribute("user"); |
if("list".equals(mapping.getParameter())) { |
List list = new ArrayList(UserManager.getInstance().listUsers()); |
Collections.sort(list, UserManager.LOGIN_COMPARATOR); |
request.setAttribute("users", list); |
return mapping.findForward("default"); |
} |
else if("edit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long userId = StringConverter.parseLong(theForm.get("id")); |
DynaActionForm showForm = (DynaActionForm)RequestUtilsX.populateActionForm( |
this, request, "ak.webcontrol.core.form.UserEditForm"); |
if(userId == null) { |
} |
else { |
User u = UserManager.getInstance().get(userId); |
showForm.set("login", u.getLogin()); |
} |
return mapping.findForward("default"); |
} |
else if("delete".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long userId = StringConverter.parseLong(theForm.get("id")); |
User u = UserManager.getInstance().get(userId); |
if(u.equals(user)) |
throw new UserException(CoreResources.DELETE_ME_SELF); |
// FIXME: invalidate session of deleted user if it is logged in |
// FIXME: if two admins delete each other at the same time |
UserManager.getInstance().delete(u); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
else if("submit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long userId = StringConverter.parseLong(theForm.get("id")); |
User u; |
String password = (String)theForm.get("password"); |
if(userId == null) { |
if(password == null || password.equals("")) |
throw new UserException(CoreResources.PASSWORD_REQUIRED); |
u = UserManager.getInstance().create(); |
} |
else { |
u = UserManager.getInstance().get(userId); |
} |
u.setLogin((String)theForm.get("login")); |
if(password != null && !password.equals("")) |
u.setNewPassword(password); |
UserManager.getInstance().save(u); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
else { |
throw new Exception("unknown mapping parameter"); |
} |
} |
} |
/sun/src/ak/webcontrol/core/action/SystemUserAction.java |
---|
0,0 → 1,92 |
package ak.webcontrol.core.action; |
import java.util.List; |
import java.util.Collections; |
import java.util.ArrayList; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
import org.apache.struts.action.Action; |
import org.apache.struts.action.ActionMapping; |
import org.apache.struts.action.ActionForm; |
import org.apache.struts.action.DynaActionForm; |
import org.apache.struts.action.ActionForward; |
import org.apache.struts.action.ActionMessages; |
import org.apache.struts.action.ActionErrors; |
import org.apache.struts.action.ActionError; |
import ak.strutsx.RequestUtilsX; |
import ak.backpath.BackPath; |
import ak.webcontrol.util.StringConverter; |
import ak.webcontrol.core.model.User; |
import ak.webcontrol.core.model.SystemUser; |
import ak.webcontrol.core.model.SystemUserManager; |
public final class SystemUserAction |
extends Action |
{ |
public ActionForward execute(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
User user = (User)request.getSession().getAttribute("user"); |
if("list".equals(mapping.getParameter())) { |
List list = new ArrayList(SystemUserManager.getInstance().listSystemUsers()); |
Collections.sort(list, SystemUserManager.NAME_COMPARATOR); |
request.setAttribute("users", list); |
return mapping.findForward("default"); |
} |
else if("edit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long userId = StringConverter.parseLong(theForm.get("id")); |
DynaActionForm showForm = (DynaActionForm)RequestUtilsX.populateActionForm( |
this, request, "ak.webcontrol.core.form.SystemUserEditForm"); |
if(userId == null) { |
} |
else { |
SystemUser u = SystemUserManager.getInstance().get(userId); |
showForm.set("uid", StringConverter.toString(u.getUid())); |
showForm.set("name", u.getName()); |
} |
return mapping.findForward("default"); |
} |
else if("delete".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long userId = StringConverter.parseLong(theForm.get("id")); |
SystemUser u = SystemUserManager.getInstance().get(userId); |
SystemUserManager.getInstance().delete(u); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
else if("submit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long userId = StringConverter.parseLong(theForm.get("id")); |
SystemUser u; |
if(userId == null) { |
u = SystemUserManager.getInstance().create(); |
} |
else { |
u = SystemUserManager.getInstance().get(userId); |
} |
u.setUid(StringConverter.parseInteger(theForm.get("uid"))); |
u.setName((String)theForm.get("name")); |
SystemUserManager.getInstance().save(u); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
else { |
throw new Exception("unknown mapping parameter"); |
} |
} |
} |
/sun/src/ak/webcontrol/core/action/IndexAction.java |
---|
0,0 → 1,28 |
package ak.webcontrol.core.action; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
import org.apache.struts.action.Action; |
import org.apache.struts.action.ActionMapping; |
import org.apache.struts.action.ActionForm; |
import org.apache.struts.action.ActionForward; |
import ak.strutsx.ErrorHandlerX; |
public final class IndexAction |
extends Action |
implements ErrorHandlerX |
{ |
public void handleErrors(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
} |
public ActionForward execute(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
return mapping.findForward("success"); |
} |
} |
/sun/src/ak/webcontrol/core/action/InetDomainAction.java |
---|
0,0 → 1,115 |
package ak.webcontrol.core.action; |
import java.util.List; |
import java.util.Collections; |
import java.util.ArrayList; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
import org.apache.struts.action.Action; |
import org.apache.struts.action.ActionMapping; |
import org.apache.struts.action.ActionForm; |
import org.apache.struts.action.DynaActionForm; |
import org.apache.struts.action.ActionForward; |
import org.apache.struts.action.ActionMessages; |
import org.apache.struts.action.ActionErrors; |
import org.apache.struts.action.ActionError; |
import ak.strutsx.RequestUtilsX; |
import ak.strutsx.ErrorHandlerX; |
import ak.backpath.BackPath; |
import ak.webcontrol.util.StringConverter; |
import ak.webcontrol.core.model.User; |
import ak.webcontrol.core.model.UserManager; |
import ak.webcontrol.core.model.InetDomain; |
import ak.webcontrol.core.model.InetDomainManager; |
public final class InetDomainAction |
extends Action |
implements ErrorHandlerX |
{ |
public void handleErrors(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
if("submit".equals(mapping.getParameter())) { |
initUserList(request); |
} |
} |
public ActionForward execute(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
User user = (User)request.getSession().getAttribute("user"); |
if("list".equals(mapping.getParameter())) { |
List list = new ArrayList(InetDomainManager.getInstance().listInetDomains()); |
Collections.sort(list, InetDomainManager.NAME_COMPARATOR); |
request.setAttribute("domains", list); |
return mapping.findForward("default"); |
} |
else if("edit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long domainId = StringConverter.parseLong(theForm.get("id")); |
DynaActionForm showForm = (DynaActionForm)RequestUtilsX.populateActionForm( |
this, request, "ak.webcontrol.core.form.InetDomainEditForm"); |
if(domainId == null) { |
} |
else { |
InetDomain domain = InetDomainManager.getInstance().get(domainId); |
showForm.set("name", domain.getName()); |
if(domain.getOwner() != null) |
showForm.set("owner", StringConverter.toString(domain.getOwner().getId())); |
} |
initUserList(request); |
return mapping.findForward("default"); |
} |
else if("delete".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long domainId = StringConverter.parseLong(theForm.get("id")); |
InetDomain domain = InetDomainManager.getInstance().get(domainId); |
InetDomainManager.getInstance().delete(domain); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
else if("submit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long domainId = StringConverter.parseLong(theForm.get("id")); |
InetDomain domain; |
if(domainId == null) { |
domain = InetDomainManager.getInstance().create(); |
} |
else { |
domain = InetDomainManager.getInstance().get(domainId); |
} |
domain.setName((String)theForm.get("name")); |
domain.setOwner(UserManager.getInstance().get( |
StringConverter.parseLong(theForm.get("owner")))); |
InetDomainManager.getInstance().save(domain); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
else { |
throw new Exception("unknown mapping parameter"); |
} |
} |
private void initUserList(HttpServletRequest request) |
throws Exception |
{ |
List list = new ArrayList(UserManager.getInstance().listUsers()); |
Collections.sort(list, UserManager.LOGIN_COMPARATOR); |
request.setAttribute("users", list); |
} |
} |
/sun/src/ak/webcontrol/core/action/ChangePasswordAction.java |
---|
0,0 → 1,51 |
package ak.webcontrol.core.action; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
import org.apache.struts.action.Action; |
import org.apache.struts.action.ActionMapping; |
import org.apache.struts.action.ActionForm; |
import org.apache.struts.action.DynaActionForm; |
import org.apache.struts.action.ActionForward; |
import org.apache.struts.action.ActionMessages; |
import org.apache.struts.action.ActionErrors; |
import org.apache.struts.action.ActionError; |
import ak.backpath.BackPath; |
import ak.webcontrol.core.CoreResources; |
import ak.webcontrol.core.model.User; |
import ak.webcontrol.core.model.UserManager; |
public final class ChangePasswordAction |
extends Action |
{ |
public ActionForward execute(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
if("first".equals(mapping.getParameter())) { |
return mapping.findForward("default"); |
} |
else { |
DynaActionForm theForm = (DynaActionForm)form; |
User user = (User)request.getSession().getAttribute("user"); |
if(user.checkPassword((String)theForm.get("oldpassword"))) { |
user.setNewPassword((String)theForm.get("password")); |
UserManager.getInstance().save(user); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
else { |
ActionErrors errors = new ActionErrors(); |
errors.add(ActionMessages.GLOBAL_MESSAGE, |
new ActionError(CoreResources.OLD_PASSWORD_WRONG)); |
saveErrors(request, errors); |
return mapping.getInputForward(); |
} |
} |
} |
} |
/sun/src/ak/webcontrol/core/action/LoginAction.java |
---|
0,0 → 1,53 |
package ak.webcontrol.core.action; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
import org.apache.struts.action.Action; |
import org.apache.struts.action.ActionMapping; |
import org.apache.struts.action.ActionForm; |
import org.apache.struts.action.DynaActionForm; |
import org.apache.struts.action.ActionForward; |
import org.apache.struts.action.ActionMessages; |
import org.apache.struts.action.ActionErrors; |
import org.apache.struts.action.ActionError; |
import ak.backpath.BackPath; |
import ak.webcontrol.core.CoreResources; |
import ak.webcontrol.core.model.User; |
import ak.webcontrol.core.model.UserManager; |
public final class LoginAction |
extends Action |
{ |
public ActionForward execute(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
DynaActionForm theForm = (DynaActionForm)form; |
User user = UserManager.getInstance().loginUser( |
(String)theForm.get("login"), (String)theForm.get("password")); |
if(user == null) { |
ActionErrors errors = new ActionErrors(); |
errors.add(ActionMessages.GLOBAL_MESSAGE, |
new ActionError(CoreResources.LOGIN_FAILED)); |
saveErrors(request, errors); |
return mapping.getInputForward(); |
} |
else { |
request.getSession().setAttribute("user", user); |
String origin = BackPath.findBackPath(request).getBackwardUrl(); |
if(origin == null || origin.length() <= 0) { |
return mapping.findForward("default"); |
} |
else { |
response.sendRedirect(origin); |
return null; |
} |
} |
} |
} |
/sun/src/ak/webcontrol/core/action/LogoutAction.java |
---|
0,0 → 1,27 |
package ak.webcontrol.core.action; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
import org.apache.struts.action.Action; |
import org.apache.struts.action.ActionMapping; |
import org.apache.struts.action.ActionForm; |
import org.apache.struts.action.DynaActionForm; |
import org.apache.struts.action.ActionForward; |
import org.apache.struts.action.ActionMessages; |
import org.apache.struts.action.ActionErrors; |
import org.apache.struts.action.ActionError; |
public final class LogoutAction |
extends Action |
{ |
public ActionForward execute(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
if(request.getSession() != null) |
request.getSession().invalidate(); |
return mapping.findForward("default"); |
} |
} |
/sun/src/ak/webcontrol/core/CoreResources.properties |
---|
0,0 → 1,164 |
ak.webcontrol.core.type.user=user |
ak.webcontrol.core.type.systemUser=system user |
ak.webcontrol.core.type.domain=domain |
ak.webcontrol.core.type.mailbox=mailbox |
ak.webcontrol.core.type.mailAlias=mail alias |
ak.webcontrol.core.type.mailAliasDestination=mail alias destination |
ak.webcontrol.core.login.failed=Wrong login or password |
ak.webcontrol.core.login.required=You have to enter the login |
ak.webcontrol.core.password.required=You have to enter the password |
ak.webcontrol.core.oldpassword.required=You have to enter the old password |
ak.webcontrol.core.oldpassword.wrong=Wrong old password |
ak.webcontrol.core.password.dontMatch=The passwords you entered doesn't match |
ak.webcontrol.core.user.password.change.id.wrong=Please select an user from the list |
ak.webcontrol.core.user.deletemeself=Can not delete the user you are logged in |
ak.webcontrol.core.mailbox.edit.id.wrong=Please select a mailbox from the list |
ak.webcontrol.core.mailbox.edit.login.empty=You have to enter the login |
ak.webcontrol.core.mailbox.edit.domain.wrong=Please select a domain from the list |
ak.webcontrol.core.mailbox.edit.owner.wrong=Please select an owner from the list |
ak.webcontrol.core.mailbox.edit.systemuser.wrong=Please select a system user from the list |
ak.webcontrol.core.mail.alias.edit.id.wrong=Please select a mail alias from the list |
ak.webcontrol.core.mail.alias.edit.dest.id.wrong=Wrong ID |
ak.webcontrol.core.mail.alias.edit.mailbox.id.wrong=Please select a mailbox from the list |
ak.webcontrol.core.mail.alias.edit.email.wrong=Please enter an email |
ak.webcontrol.core.mail.alias.edit.address.empty=Please enter an address |
ak.webcontrol.core.mail.alias.edit.domain.wrong=Please select a domain from the list |
ak.webcontrol.core.mail.alias.edit.owner.wrong=Please select an owner from the list |
ak.webcontrol.core.user.system.edit.id.wrong=Please select an user from the list |
ak.webcontrol.core.user.system.edit.uid.wrong=Please enter the UID |
ak.webcontrol.core.user.system.edit.name.required=Please enter name of the user |
ak.webcontrol.core.domain.edit.id.wrong=Please select a domain from the list |
ak.webcontrol.core.domain.edit.owner.wrong=Please select an owner from the list |
ak.webcontrol.core.domain.edit.name.empty=Please enter domain name |
ak.webcontrol.core.mail.alias.edit.id.wrong=Please select an alias from the list |
ak.webcontrol.page.error.title=webcontrol - error |
ak.webcontrol.page.error.back=back |
ak.webcontrol.page.generalError.title=webcontrol - error |
ak.webcontrol.page.generalError.message=There is internal server error occured. Please go back and try again. If the error occurs again continue with the start page. |
ak.webcontrol.page.generalError.index=start page |
ak.webcontrol.page.generalError.back=back |
ak.webcontrol.page.index.title=webcontrol |
ak.webcontrol.page.index.password_change=change password |
ak.webcontrol.page.index.user_list=users |
ak.webcontrol.page.index.system_user_list=system users |
ak.webcontrol.page.index.domain_list=domains |
ak.webcontrol.page.index.mail_alias_list=mail aliases |
ak.webcontrol.page.index.mail_box_list=mail boxes |
ak.webcontrol.page.index.logout=logout |
ak.webcontrol.page.index.login=Logged in as |
ak.webcontrol.page.system.login.title=webcontrol - login |
ak.webcontrol.page.system.login.login=Login |
ak.webcontrol.page.system.login.password=Password |
ak.webcontrol.page.system.login.submit=Login |
ak.webcontrol.page.system.login.reset=Reset |
ak.webcontrol.page.system.logout.title=webcontrol - logout |
ak.webcontrol.page.system.logout.message=You are logged out sucessfully. See you later! |
ak.webcontrol.page.system.logout.login=start new session |
ak.webcontrol.page.system.logout.back=return to system |
ak.webcontrol.page.user.password.change.title=webcontrol - change password |
ak.webcontrol.page.user.password.change.old_password=Old password |
ak.webcontrol.page.user.password.change.new_password=New password |
ak.webcontrol.page.user.password.change.new_password_again=New password again |
ak.webcontrol.page.user.password.change.submit=Change |
ak.webcontrol.page.user.password.change.cancel=Cancel |
ak.webcontrol.page.user.list.title=webcontrol - users - list |
ak.webcontrol.page.user.list.login=Login |
ak.webcontrol.page.user.list.delete=delete |
ak.webcontrol.page.user.list.edit=edit |
ak.webcontrol.page.user.list.add=add new user |
ak.webcontrol.page.user.list.back=back |
ak.webcontrol.page.user.edit.title=webcontrol - user - edit |
ak.webcontrol.page.user.edit.login=Login |
ak.webcontrol.page.user.edit.password=Password |
ak.webcontrol.page.user.edit.password_again=Password again |
ak.webcontrol.page.user.edit.submit=submit |
ak.webcontrol.page.user.edit.back=back |
ak.webcontrol.page.user.system.list.title=webcontrol - system users - list |
ak.webcontrol.page.user.system.list.uid=System ID |
ak.webcontrol.page.user.system.list.name=User name |
ak.webcontrol.page.user.system.list.delete=delete |
ak.webcontrol.page.user.system.list.edit=edit |
ak.webcontrol.page.user.system.list.add=add new user |
ak.webcontrol.page.user.system.list.back=back |
ak.webcontrol.page.user.system.edit.title=webcontrol - system user - edit |
ak.webcontrol.page.user.system.edit.uid=System ID |
ak.webcontrol.page.user.system.edit.name=User name |
ak.webcontrol.page.user.system.edit.submit=submit |
ak.webcontrol.page.user.system.edit.back=back |
ak.webcontrol.page.domain.list.title=webcontrol - domains - list |
ak.webcontrol.page.domain.list.name=Name |
ak.webcontrol.page.domain.list.owner=Owner |
ak.webcontrol.page.domain.list.delete=delete |
ak.webcontrol.page.domain.list.edit=edit |
ak.webcontrol.page.domain.list.add=add new domain |
ak.webcontrol.page.domain.list.back=back |
ak.webcontrol.page.domain.edit.title=webcontrol - domain - edit |
ak.webcontrol.page.domain.edit.name=Name |
ak.webcontrol.page.domain.edit.owner=Owner |
ak.webcontrol.page.domain.edit.owner.empty=-- please select -- |
ak.webcontrol.page.domain.edit.submit=submit |
ak.webcontrol.page.domain.edit.back=back |
ak.webcontrol.page.mail.alias.list.title=webcontrol - mail aliases - list |
ak.webcontrol.page.mail.alias.list.alias=Alias |
ak.webcontrol.page.mail.alias.list.edit=edit |
ak.webcontrol.page.mail.alias.list.delete=delete |
ak.webcontrol.page.mail.alias.list.back=back |
ak.webcontrol.page.mail.alias.list.add=add new mail alias |
ak.webcontrol.page.mail.alias.edit.title=webcontrol - mail alias - edit |
ak.webcontrol.page.mail.alias.edit.address=Address |
ak.webcontrol.page.mail.alias.edit.domain=Domain |
ak.webcontrol.page.mail.alias.edit.domain.empty=-- please select -- |
ak.webcontrol.page.mail.alias.edit.owner=Owner |
ak.webcontrol.page.mail.alias.edit.owner.empty=-- please select -- |
ak.webcontrol.page.mail.alias.edit.header.tomailbox=To mailbox |
ak.webcontrol.page.mail.alias.edit.header.toexternal=or to external email |
ak.webcontrol.page.mail.alias.edit.external=external redirect |
ak.webcontrol.page.mail.alias.edit.add=add new destination |
ak.webcontrol.page.mail.alias.edit.delete=delete |
ak.webcontrol.page.mail.alias.edit.submit=submit |
ak.webcontrol.page.mail.alias.edit.cancel=cancel |
ak.webcontrol.page.mail.box.list.title=webcontrol - mail boxes - list |
ak.webcontrol.page.mail.box.list.login=Box |
ak.webcontrol.page.mail.box.list.domain=Domain |
ak.webcontrol.page.mail.box.list.owner=Owner |
ak.webcontrol.page.mail.box.list.edit=edit |
ak.webcontrol.page.mail.box.list.delete=delete |
ak.webcontrol.page.mail.box.list.add=add new mail box |
ak.webcontrol.page.mail.box.list.back=back |
ak.webcontrol.page.mail.box.edit.title=webcontrol - mail box - edit |
ak.webcontrol.page.mail.box.edit.login=Box |
ak.webcontrol.page.mail.box.edit.password=Password |
ak.webcontrol.page.mail.box.edit.password_again=Password again |
ak.webcontrol.page.mail.box.edit.domain=Domain |
ak.webcontrol.page.mail.box.edit.domain.empty=-- please select -- |
ak.webcontrol.page.mail.box.edit.owner=Owner |
ak.webcontrol.page.mail.box.edit.owner.empty=-- please select -- |
ak.webcontrol.page.mail.box.edit.systemuser=System user |
ak.webcontrol.page.mail.box.edit.systemuser.empty=-- please select -- |
ak.webcontrol.page.mail.box.edit.viruscheck=check mails for viruses |
ak.webcontrol.page.mail.box.edit.spamcheck=check mails for spam |
ak.webcontrol.page.mail.box.edit.submit=submit |
ak.webcontrol.page.mail.box.edit.back=back |
/sun/src/ak/webcontrol/core/model/InetDomainManager.java |
---|
0,0 → 1,145 |
package ak.webcontrol.core.model; |
import java.util.*; |
import net.sf.hibernate.*; |
import ak.webcontrol.util.HibernateUtil; |
import ak.webcontrol.util.ModelException; |
public class InetDomainManager |
{ |
private static boolean registered = false; |
protected static void register() |
{ |
synchronized(InetDomainManager.class) { |
if(registered) return; |
registered = true; |
try { |
HibernateUtil.getConfiguration().addResource( |
"/ak/webcontrol/core/model/InetDomain.hbm.xml"); |
} |
catch(Exception ex) { |
ex.printStackTrace(); |
throw new RuntimeException(ex.getMessage()); |
} |
} |
} |
static { |
register(); |
} |
private InetDomainManager() |
{ |
} |
public InetDomain create() |
{ |
return new InetDomain(); |
} |
public InetDomain get(Long id) |
throws ModelException |
{ |
try { |
return (InetDomain)HibernateUtil.currentSession().load(InetDomain.class, id); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public InetDomain findForName(String name) |
throws ModelException |
{ |
try { |
List list = HibernateUtil.currentSession().find( |
"from InetDomain where name=?", name, Hibernate.STRING); |
if(list.size() == 0) |
return null; |
else |
return (InetDomain)list.get(0); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public void save(InetDomain inetDomain) |
throws ModelException |
{ |
try { |
HibernateUtil.currentSession().saveOrUpdate(inetDomain); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public void delete(InetDomain inetDomain) |
throws ModelException |
{ |
try { |
HibernateUtil.currentSession().delete(inetDomain); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public Collection listInetDomains() |
throws ModelException |
{ |
try { |
return HibernateUtil.currentSession().find("from InetDomain"); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
private static InetDomainManager inetDomainManager = null; |
public static InetDomainManager getInstance() |
{ |
if(inetDomainManager == null) |
inetDomainManager = new InetDomainManager(); |
return inetDomainManager; |
} |
public static final Comparator NAME_COMPARATOR = new NameComparator(); |
private static class NameComparator |
implements Comparator |
{ |
public int compare(Object o1, Object o2) |
{ |
if(!(o1 instanceof InetDomain) || !(o2 instanceof InetDomain)) |
throw new ClassCastException("not a InetDomain"); |
InetDomain a1 = (InetDomain)o1; |
InetDomain a2 = (InetDomain)o2; |
if(a1 == null && a2 == null) |
return 0; |
else if(a1 == null && a2 != null) |
return -1; |
else if(a1 != null && a2 == null) |
return 1; |
else |
return a1.getName().compareToIgnoreCase(a2.getName()); |
} |
public boolean equals(Object obj) |
{ |
return (obj instanceof NameComparator); |
} |
} |
} |
/sun/src/ak/webcontrol/core/model/SystemUser.java |
---|
0,0 → 1,88 |
package ak.webcontrol.core.model; |
import java.util.Date; |
/** |
* |
* @hibernate.class table="systemusers" |
*/ |
public class SystemUser |
implements ModelObject |
{ |
private Long id; |
/** user id in the OS */ |
private Integer uid; |
private String name; |
private Date modStamp; |
protected SystemUser() |
{ |
} |
/** |
* |
* @hibernate.id generator-class="native" |
*/ |
public Long getId() |
{ |
return id; |
} |
public void setId(Long id) |
{ |
this.id = id; |
} |
/** |
* |
* @hibernate.property |
*/ |
public Integer getUid() |
{ |
return uid; |
} |
public void setUid(Integer uid) |
{ |
this.uid = uid; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getName() |
{ |
return name; |
} |
public void setName(String name) |
{ |
this.name = name; |
} |
/** |
* |
* @hibernate.timestamp column="mod_stamp" |
*/ |
public Date getModStamp() |
{ |
return modStamp; |
} |
public void setModStamp(Date modStamp) |
{ |
this.modStamp = modStamp; |
} |
public String getTypeKey() |
{ |
return ak.webcontrol.core.CoreResources.TYPE_SYSTEM_USER; |
} |
public String getIdentificationString() |
{ |
return getName() + " (" + getUid() + ")"; // FIXME: is it really so good style? |
} |
} |
/sun/src/ak/webcontrol/core/model/MailboxManager.java |
---|
0,0 → 1,158 |
package ak.webcontrol.core.model; |
import java.util.*; |
import net.sf.hibernate.*; |
import ak.webcontrol.util.HibernateUtil; |
import ak.webcontrol.util.ModelException; |
public class MailboxManager |
{ |
private static boolean registered = false; |
protected static void register() |
{ |
synchronized(MailboxManager.class) { |
if(registered) return; |
registered = true; |
try { |
HibernateUtil.getConfiguration().addResource( |
"/ak/webcontrol/core/model/Mailbox.hbm.xml"); |
} |
catch(Exception ex) { |
ex.printStackTrace(); |
throw new RuntimeException(ex.getMessage()); |
} |
} |
} |
static { |
register(); |
} |
private MailboxManager() |
{ |
} |
public Mailbox create() |
{ |
return new Mailbox(); |
} |
public Mailbox get(Long id) |
throws ModelException |
{ |
try { |
return (Mailbox)HibernateUtil.currentSession().load(Mailbox.class, id); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public Mailbox findForLogin(String login) |
throws ModelException |
{ |
try { |
List list = HibernateUtil.currentSession().find( |
"from Mailbox where login=?", login, Hibernate.STRING); |
if(list.size() == 0) |
return null; |
else |
return (Mailbox)list.get(0); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public void save(Mailbox mailbox) |
throws ModelException |
{ |
try { |
HibernateUtil.currentSession().saveOrUpdate(mailbox); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public void delete(Mailbox mailbox) |
throws ModelException |
{ |
try { |
HibernateUtil.currentSession().delete(mailbox); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public Collection listMailboxes() |
throws ModelException |
{ |
try { |
return HibernateUtil.currentSession().find("from Mailbox"); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public Collection listMailboxes(User owner) |
throws ModelException |
{ |
try { |
return HibernateUtil.currentSession().find( |
"from Mailbox where owner=?", owner, Hibernate.entity(User.class)); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
private static MailboxManager mailboxManager = null; |
public static MailboxManager getInstance() |
{ |
if(mailboxManager == null) |
mailboxManager = new MailboxManager(); |
return mailboxManager; |
} |
public static final Comparator LOGIN_COMPARATOR = new LoginComparator(); |
private static class LoginComparator |
implements Comparator |
{ |
public int compare(Object o1, Object o2) |
{ |
if(!(o1 instanceof Mailbox) || !(o2 instanceof Mailbox)) |
throw new ClassCastException("not a Mailbox"); |
Mailbox a1 = (Mailbox)o1; |
Mailbox a2 = (Mailbox)o2; |
if(a1 == null && a2 == null) |
return 0; |
else if(a1 == null && a2 != null) |
return -1; |
else if(a1 != null && a2 == null) |
return 1; |
else |
return a1.getLogin().compareToIgnoreCase(a2.getLogin()); |
} |
public boolean equals(Object obj) |
{ |
return (obj instanceof LoginComparator); |
} |
} |
} |
/sun/src/ak/webcontrol/core/model/InetDomain.java |
---|
0,0 → 1,86 |
package ak.webcontrol.core.model; |
import java.util.Date; |
/** |
* |
* @hibernate.class table="domains" |
*/ |
public class InetDomain |
implements ModelObject |
{ |
private Long id; |
private String name; |
private User owner; |
private Date modStamp; |
protected InetDomain() |
{ |
} |
/** |
* |
* @hibernate.id generator-class="native" |
*/ |
public Long getId() |
{ |
return id; |
} |
public void setId(Long id) |
{ |
this.id = id; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getName() |
{ |
return name; |
} |
public void setName(String name) |
{ |
this.name = name; |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public User getOwner() |
{ |
return owner; |
} |
public void setOwner(User owner) |
{ |
this.owner = owner; |
} |
/** |
* |
* @hibernate.timestamp column="mod_stamp" |
*/ |
public Date getModStamp() |
{ |
return modStamp; |
} |
public void setModStamp(Date modStamp) |
{ |
this.modStamp = modStamp; |
} |
public String getTypeKey() |
{ |
return ak.webcontrol.core.CoreResources.TYPE_DOMAIN; |
} |
public String getIdentificationString() |
{ |
return getName(); |
} |
} |
/sun/src/ak/webcontrol/core/model/MailAliasManager.java |
---|
0,0 → 1,160 |
package ak.webcontrol.core.model; |
import java.util.*; |
import net.sf.hibernate.*; |
import ak.webcontrol.util.HibernateUtil; |
import ak.webcontrol.util.ModelException; |
public class MailAliasManager |
{ |
private static boolean registered = false; |
protected static void register() |
{ |
synchronized(MailAliasManager.class) { |
if(registered) return; |
registered = true; |
try { |
HibernateUtil.getConfiguration().addResource( |
"/ak/webcontrol/core/model/MailAlias.hbm.xml"); |
} |
catch(Exception ex) { |
ex.printStackTrace(); |
throw new RuntimeException(ex.getMessage()); |
} |
} |
} |
static { |
register(); |
} |
private MailAliasManager() |
{ |
} |
public MailAlias create() |
{ |
MailAlias alias = new MailAlias(); |
alias.setDestinations(new ArrayList()); |
return alias; |
} |
public MailAlias get(Long id) |
throws ModelException |
{ |
try { |
return (MailAlias)HibernateUtil.currentSession().load(MailAlias.class, id); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public MailAlias findForName(String name) |
throws ModelException |
{ |
try { |
List list = HibernateUtil.currentSession().find( |
"from MailAlias where name=?", name, Hibernate.STRING); |
if(list.size() == 0) |
return null; |
else |
return (MailAlias)list.get(0); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public void save(MailAlias mailAlias) |
throws ModelException |
{ |
try { |
HibernateUtil.currentSession().saveOrUpdate(mailAlias); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public void delete(MailAlias mailAlias) |
throws ModelException |
{ |
try { |
HibernateUtil.currentSession().delete(mailAlias); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public Collection listMailAliases() |
throws ModelException |
{ |
try { |
return HibernateUtil.currentSession().find("from MailAlias"); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public Collection listMailAliases(User owner) |
throws ModelException |
{ |
try { |
return HibernateUtil.currentSession().find( |
"from MailAlias where owner=?", owner, Hibernate.entity(User.class)); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
private static MailAliasManager mailAliasManager = null; |
public static MailAliasManager getInstance() |
{ |
if(mailAliasManager == null) |
mailAliasManager = new MailAliasManager(); |
return mailAliasManager; |
} |
public static final Comparator ADDRESS_COMPARATOR = new AddressComparator(); |
private static class AddressComparator |
implements Comparator |
{ |
public int compare(Object o1, Object o2) |
{ |
if(!(o1 instanceof MailAlias) || !(o2 instanceof MailAlias)) |
throw new ClassCastException("not a MailAlias"); |
MailAlias a1 = (MailAlias)o1; |
MailAlias a2 = (MailAlias)o2; |
if(a1 == null && a2 == null) |
return 0; |
else if(a1 == null && a2 != null) |
return -1; |
else if(a1 != null && a2 == null) |
return 1; |
else |
return a1.getAddress().compareToIgnoreCase(a2.getAddress()); |
} |
public boolean equals(Object obj) |
{ |
return (obj instanceof AddressComparator); |
} |
} |
} |
/sun/src/ak/webcontrol/core/model/ModelObject.java |
---|
0,0 → 1,8 |
package ak.webcontrol.core.model; |
public interface ModelObject |
{ |
public String getTypeKey(); |
public String getIdentificationString(); |
} |
/sun/src/ak/webcontrol/core/model/MailAliasDestinationManager.java |
---|
0,0 → 1,135 |
package ak.webcontrol.core.model; |
import java.util.*; |
import net.sf.hibernate.*; |
import ak.webcontrol.util.HibernateUtil; |
import ak.webcontrol.util.ModelException; |
public class MailAliasDestinationManager |
{ |
private static boolean registered = false; |
protected static void register() |
{ |
synchronized(MailAliasDestinationManager.class) { |
if(registered) return; |
registered = true; |
try { |
HibernateUtil.getConfiguration().addResource( |
"/ak/webcontrol/core/model/MailAliasDestination.hbm.xml"); |
} |
catch(Exception ex) { |
ex.printStackTrace(); |
throw new RuntimeException(ex.getMessage()); |
} |
} |
} |
static { |
register(); |
} |
private MailAliasDestinationManager() |
{ |
} |
public MailAliasDestination create() |
{ |
return new MailAliasDestination(); |
} |
public MailAliasDestination get(Long id) |
throws ModelException |
{ |
try { |
return (MailAliasDestination)HibernateUtil.currentSession() |
.load(MailAliasDestination.class, id); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public void save(MailAliasDestination mailAliasDestination) |
throws ModelException |
{ |
try { |
HibernateUtil.currentSession().saveOrUpdate(mailAliasDestination); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public void delete(MailAliasDestination mailAliasDestination) |
throws ModelException |
{ |
try { |
HibernateUtil.currentSession().delete(mailAliasDestination); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public Collection listMailAliasesDestination() |
{ |
return null; |
} |
public Collection listMailAliasesDestination(MailAlias alias) |
throws ModelException |
{ |
try { |
return HibernateUtil.currentSession().find( |
"from MailAliasDestination where alias=?", |
alias, Hibernate.entity(MailAlias.class)); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
private static MailAliasDestinationManager mailAliasDestinationManager = null; |
public static MailAliasDestinationManager getInstance() |
{ |
if(mailAliasDestinationManager == null) |
mailAliasDestinationManager = new MailAliasDestinationManager(); |
return mailAliasDestinationManager; |
} |
public static final Comparator EMAIL_COMPARATOR = new EmailComparator(); |
private static class EmailComparator |
implements Comparator |
{ |
public int compare(Object o1, Object o2) |
{ |
if(!(o1 instanceof MailAliasDestination) || !(o2 instanceof MailAliasDestination)) |
throw new ClassCastException("not a MailAliasDestination"); |
MailAliasDestination a1 = (MailAliasDestination)o1; |
MailAliasDestination a2 = (MailAliasDestination)o2; |
if(a1 == null && a2 == null) |
return 0; |
else if(a1 == null && a2 != null) |
return -1; |
else if(a1 != null && a2 == null) |
return 1; |
else |
return a1.getEmail().compareToIgnoreCase(a2.getEmail()); |
} |
public boolean equals(Object obj) |
{ |
return (obj instanceof EmailComparator); |
} |
} |
} |
/sun/src/ak/webcontrol/core/model/UserManager.java |
---|
0,0 → 1,162 |
package ak.webcontrol.core.model; |
import java.util.*; |
import net.sf.hibernate.*; |
import ak.webcontrol.util.HibernateUtil; |
import ak.webcontrol.util.ModelException; |
public class UserManager |
{ |
private static boolean registered = false; |
protected static void register() |
{ |
synchronized(MailboxManager.class) { |
if(registered) return; |
registered = true; |
try { |
HibernateUtil.getConfiguration().addResource( |
"/ak/webcontrol/core/model/User.hbm.xml"); |
} |
catch(Exception ex) { |
ex.printStackTrace(); |
throw new RuntimeException(ex.getMessage()); |
} |
} |
} |
static { |
register(); |
} |
private UserManager() |
{ |
} |
public User create() |
{ |
return new User(); |
} |
public User get(Long id) |
throws ModelException |
{ |
try { |
return (User)HibernateUtil.currentSession().load(User.class, id); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public User findForLogin(String login) |
throws ModelException |
{ |
try { |
List list = HibernateUtil.currentSession().find( |
"from User where login=?", login, Hibernate.STRING); |
if(list.size() == 0) |
return null; |
else |
return (User)list.get(0); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public void save(User user) |
throws ModelException |
{ |
try { |
HibernateUtil.currentSession().saveOrUpdate(user); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public void delete(User user) |
throws ModelException |
{ |
try { |
HibernateUtil.currentSession().delete(user); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public Collection listUsers() |
throws ModelException |
{ |
try { |
return HibernateUtil.currentSession().find("from User"); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public User loginUser(String login, String password) |
throws ModelException |
{ |
if(login == null || password == null) |
return null; |
User user = findForLogin(login); |
if(user != null) { |
if(user.checkPassword(password)) |
return user; |
} |
// wrong login or password |
return null; |
} |
private static UserManager userManager = null; |
public static UserManager getInstance() |
{ |
if(userManager == null) |
userManager = new UserManager(); |
return userManager; |
} |
public static final Comparator LOGIN_COMPARATOR = new LoginComparator(); |
private static class LoginComparator |
implements Comparator |
{ |
public int compare(Object o1, Object o2) |
{ |
if(!(o1 instanceof User) || !(o2 instanceof User)) |
throw new ClassCastException("not a User"); |
User a1 = (User)o1; |
User a2 = (User)o2; |
if(a1 == null && a2 == null) |
return 0; |
else if(a1 == null && a2 != null) |
return -1; |
else if(a1 != null && a2 == null) |
return 1; |
else |
return a1.getLogin().compareToIgnoreCase(a2.getLogin()); |
} |
public boolean equals(Object obj) |
{ |
return (obj instanceof LoginComparator); |
} |
} |
} |
/sun/src/ak/webcontrol/core/model/Mailbox.java |
---|
0,0 → 1,170 |
package ak.webcontrol.core.model; |
import java.util.Date; |
import ak.webcontrol.util.Digest; |
/** |
* |
* @hibernate.class table="mailboxes" |
*/ |
public class Mailbox |
implements ModelObject |
{ |
private Long id; |
private String login; |
private String password; |
private InetDomain domain; |
private User owner; |
private Boolean virusCheck; |
private Boolean spamCheck; |
private SystemUser systemUser; |
private Date modStamp; |
protected Mailbox() |
{ |
} |
/** |
* |
* @hibernate.id generator-class="native" |
*/ |
public Long getId() |
{ |
return id; |
} |
public void setId(Long id) |
{ |
this.id = id; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getLogin() |
{ |
return login; |
} |
public void setLogin(String login) |
{ |
this.login = login; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getPassword() |
{ |
return password; |
} |
public void setPassword(String password) |
{ |
this.password = password; |
} |
public void setNewPassword(String password) |
{ |
if(password == null) |
throw new NullPointerException("Null password"); |
this.password = Digest.encode(password); |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public InetDomain getDomain() |
{ |
return domain; |
} |
public void setDomain(InetDomain domain) |
{ |
this.domain = domain; |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public User getOwner() |
{ |
return owner; |
} |
public void setOwner(User owner) |
{ |
this.owner = owner; |
} |
/** |
* |
* @hibernate.property |
*/ |
public Boolean getVirusCheck() |
{ |
return virusCheck; |
} |
public void setVirusCheck(Boolean virusCheck) |
{ |
this.virusCheck = virusCheck; |
} |
/** |
* |
* @hibernate.property |
*/ |
public Boolean getSpamCheck() |
{ |
return spamCheck; |
} |
public void setSpamCheck(Boolean spamCheck) |
{ |
this.spamCheck = spamCheck; |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public SystemUser getSystemUser() |
{ |
return systemUser; |
} |
public void setSystemUser(SystemUser systemUser) |
{ |
this.systemUser = systemUser; |
} |
/** |
* |
* @hibernate.timestamp column="mod_stamp" |
*/ |
public Date getModStamp() |
{ |
return modStamp; |
} |
public void setModStamp(Date modStamp) |
{ |
this.modStamp = modStamp; |
} |
public String getTypeKey() |
{ |
return ak.webcontrol.core.CoreResources.TYPE_MAILBOX; |
} |
public String getIdentificationString() |
{ |
return getLogin() + "@" + getDomain().getName(); |
} |
} |
/sun/src/ak/webcontrol/core/model/MailAlias.java |
---|
0,0 → 1,123 |
package ak.webcontrol.core.model; |
import java.util.Collection; |
import java.util.Date; |
/** |
* |
* @hibernate.class table="mailaliases" |
*/ |
public class MailAlias |
implements ModelObject |
{ |
private Long id; |
private String address; |
private InetDomain domain; |
private User owner; |
private Collection destinations; // Collection(MailAliasDestintion) |
private Date modStamp; |
protected MailAlias() |
{ |
} |
/** |
* |
* @hibernate.id generator-class="native" |
*/ |
public Long getId() |
{ |
return id; |
} |
public void setId(Long id) |
{ |
this.id = id; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getAddress() |
{ |
return address; |
} |
public void setAddress(String address) |
{ |
this.address = address; |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public InetDomain getDomain() |
{ |
return domain; |
} |
public void setDomain(InetDomain domain) |
{ |
this.domain = domain; |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public User getOwner() |
{ |
return owner; |
} |
public void setOwner(User owner) |
{ |
this.owner = owner; |
} |
/** |
* @return Collection(MailAliasDestination) |
* |
* @hibernate.bag inverse="true" cascade="all-delete-orphan" |
* @hibernate.collection-key column="alias" |
* @hibernate.collection-one-to-many class="ak.webcontrol.core.model.MailAliasDestination" |
*/ |
public Collection getDestinations() |
{ |
return destinations; |
} |
/** |
* @param destinations Collection(MailAliasDestination) |
*/ |
protected void setDestinations(Collection destinations) |
{ |
this.destinations = destinations; |
} |
/** |
* |
* @hibernate.timestamp column="mod_stamp" |
*/ |
public Date getModStamp() |
{ |
return modStamp; |
} |
public void setModStamp(Date modStamp) |
{ |
this.modStamp = modStamp; |
} |
public String getTypeKey() |
{ |
return ak.webcontrol.core.CoreResources.TYPE_MAIL_ALIAS; |
} |
public String getIdentificationString() |
{ |
return getAddress() + "@" + getDomain().getName(); |
} |
} |
/sun/src/ak/webcontrol/core/model/MailAliasDestination.java |
---|
0,0 → 1,101 |
package ak.webcontrol.core.model; |
import java.util.Date; |
/** |
* |
* @hibernate.class table="mailaliasdests" |
*/ |
public class MailAliasDestination |
implements ModelObject |
{ |
private Long id; |
private MailAlias alias; |
private Mailbox mailbox; |
private String email; |
private Date modStamp; |
protected MailAliasDestination() |
{ |
} |
/** |
* |
* @hibernate.id generator-class="native" |
*/ |
public Long getId() |
{ |
return id; |
} |
public void setId(Long id) |
{ |
this.id = id; |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public MailAlias getAlias() |
{ |
return alias; |
} |
public void setAlias(MailAlias alias) |
{ |
this.alias = alias; |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public Mailbox getMailbox() |
{ |
return mailbox; |
} |
public void setMailbox(Mailbox mailbox) |
{ |
this.mailbox = mailbox; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getEmail() |
{ |
return email; |
} |
public void setEmail(String email) |
{ |
this.email = email; |
} |
/** |
* |
* @hibernate.timestamp column="mod_stamp" |
*/ |
public Date getModStamp() |
{ |
return modStamp; |
} |
public void setModStamp(Date modStamp) |
{ |
this.modStamp = modStamp; |
} |
public String getTypeKey() |
{ |
return ak.webcontrol.core.CoreResources.TYPE_MAIL_ALIAS_DESTINATION; |
} |
public String getIdentificationString() |
{ |
return (getMailbox() == null) ? getEmail() : getMailbox().getIdentificationString(); |
} |
} |
/sun/src/ak/webcontrol/core/model/SystemUserManager.java |
---|
0,0 → 1,191 |
package ak.webcontrol.core.model; |
import java.util.*; |
import net.sf.hibernate.*; |
import ak.webcontrol.util.HibernateUtil; |
import ak.webcontrol.util.ModelException; |
public class SystemUserManager |
{ |
private static boolean registered = false; |
protected static void register() |
{ |
synchronized(SystemUserManager.class) { |
if(registered) return; |
registered = true; |
try { |
HibernateUtil.getConfiguration().addResource( |
"/ak/webcontrol/core/model/SystemUser.hbm.xml"); |
} |
catch(Exception ex) { |
ex.printStackTrace(); |
throw new RuntimeException(ex.getMessage()); |
} |
} |
} |
static { |
register(); |
} |
private SystemUserManager() |
{ |
} |
public SystemUser create() |
{ |
return new SystemUser(); |
} |
public SystemUser get(Long id) |
throws ModelException |
{ |
try { |
return (SystemUser)HibernateUtil.currentSession().load(SystemUser.class, id); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public SystemUser findForName(String name) |
throws ModelException |
{ |
try { |
List list = HibernateUtil.currentSession().find( |
"from SystemUser where name=?", name, Hibernate.STRING); |
if(list.size() == 0) |
return null; |
else |
return (SystemUser)list.get(0); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public SystemUser findForUid(Integer uid) |
throws ModelException |
{ |
try { |
List list = HibernateUtil.currentSession().find( |
"from SystemUser where uid=?", uid, Hibernate.INTEGER); |
if(list.size() == 0) |
return null; |
else |
return (SystemUser)list.get(0); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public void save(SystemUser systemUser) |
throws ModelException |
{ |
try { |
HibernateUtil.currentSession().saveOrUpdate(systemUser); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public void delete(SystemUser systemUser) |
throws ModelException |
{ |
try { |
HibernateUtil.currentSession().delete(systemUser); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public Collection listSystemUsers() |
throws ModelException |
{ |
try { |
return HibernateUtil.currentSession().find("from SystemUser"); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
private static SystemUserManager systemUserManager = null; |
public static SystemUserManager getInstance() |
{ |
if(systemUserManager == null) |
systemUserManager = new SystemUserManager(); |
return systemUserManager; |
} |
public static final Comparator UID_COMPARATOR = new UidComparator(); |
public static final Comparator NAME_COMPARATOR = new NameComparator(); |
private static class UidComparator |
implements Comparator |
{ |
public int compare(Object o1, Object o2) |
{ |
if(!(o1 instanceof SystemUser) || !(o2 instanceof SystemUser)) |
throw new ClassCastException("not a SystemUser"); |
SystemUser a1 = (SystemUser)o1; |
SystemUser a2 = (SystemUser)o2; |
if(a1 == null && a2 == null) |
return 0; |
else if(a1 == null && a2 != null) |
return -1; |
else if(a1 != null && a2 == null) |
return 1; |
else |
return a1.getUid().compareTo(a2.getUid()); |
} |
public boolean equals(Object obj) |
{ |
return (obj instanceof UidComparator); |
} |
} |
private static class NameComparator |
implements Comparator |
{ |
public int compare(Object o1, Object o2) |
{ |
if(!(o1 instanceof SystemUser) || !(o2 instanceof SystemUser)) |
throw new ClassCastException("not a SystemUser"); |
SystemUser a1 = (SystemUser)o1; |
SystemUser a2 = (SystemUser)o2; |
if(a1 == null && a2 == null) |
return 0; |
else if(a1 == null && a2 != null) |
return -1; |
else if(a1 != null && a2 == null) |
return 1; |
else |
return a1.getName().compareToIgnoreCase(a2.getName()); |
} |
public boolean equals(Object obj) |
{ |
return (obj instanceof NameComparator); |
} |
} |
} |
/sun/src/ak/webcontrol/core/model/User.java |
---|
0,0 → 1,124 |
package ak.webcontrol.core.model; |
import java.util.Date; |
import ak.webcontrol.util.Digest; |
/** |
* |
* @hibernate.class table="users" |
*/ |
public class User |
implements ModelObject |
{ |
private Long id; |
private String login; |
private String password; |
private Date modStamp; |
protected User() |
{ |
} |
/** |
* |
* @hibernate.id generator-class="native" |
*/ |
public Long getId() |
{ |
return id; |
} |
public void setId(Long id) |
{ |
this.id = id; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getLogin() |
{ |
return login; |
} |
public void setLogin(String login) |
{ |
this.login = login; |
} |
/** |
* |
* @hibernate.property |
*/ |
protected String getPassword() |
{ |
return password; |
} |
protected void setPassword(String password) |
{ |
this.password = password; |
} |
public void setNewPassword(String password) |
{ |
if(password == null) |
throw new NullPointerException("Null password"); |
this.password = Digest.encode(password); |
} |
public boolean checkPassword(String password) |
{ |
if(password == null) |
throw new NullPointerException("Null password"); |
return checkMd5Password(Digest.encode(password)); |
} |
public boolean checkMd5Password(String password) |
{ |
return this.password.equals(password); |
} |
/** |
* |
* @hibernate.timestamp column="mod_stamp" |
*/ |
public Date getModStamp() |
{ |
return modStamp; |
} |
public void setModStamp(Date modStamp) |
{ |
this.modStamp = modStamp; |
} |
public boolean equals(Object o) |
{ |
if(!(o instanceof User)) return false; |
User u = (User)o; |
return (id != null) && (u.getId() != null) && (id.equals(u.getId())); |
} |
public int hashCode() |
{ |
if(id == null) |
return 0; |
else |
return id.hashCode(); |
} |
public String getTypeKey() |
{ |
return ak.webcontrol.core.CoreResources.TYPE_USER; |
} |
public String getIdentificationString() |
{ |
return getLogin(); |
} |
} |
/sun/src/ak/webcontrol/core/model/test/Test.java |
---|
0,0 → 1,164 |
package ak.webcontrol.core.model.test; |
import net.sf.hibernate.*; |
import ak.webcontrol.core.model.*; |
import ak.webcontrol.util.*; |
public class Test |
{ |
public static void test() |
throws Exception |
{ |
// delete objects if they are already in the database |
HibernateUtil.currentSession().delete( |
"from MailAlias where address like ?", "%@test.domain", Hibernate.STRING); |
HibernateUtil.currentSession().delete( |
"from SystemUser where uid=?", new Integer(1001), Hibernate.INTEGER); |
HibernateUtil.currentSession().delete( |
"from Mailbox where login=?", "testuser@test.domain", Hibernate.STRING); |
HibernateUtil.currentSession().delete( |
"from InetDomain where name=?", "test.domain", Hibernate.STRING); |
HibernateUtil.currentSession().delete( |
"from User where login=?", "testuser", Hibernate.STRING); |
HibernateUtil.currentSession().flush(); |
User user; |
InetDomain inetDomain; |
Mailbox mailbox; |
MailAlias mailAlias; |
SystemUser systemUser; |
// create objects |
user = UserManager.getInstance().create(); |
user.setLogin("testuser"); |
user.setNewPassword("none"); |
UserManager.getInstance().save(user); |
inetDomain = InetDomainManager.getInstance().create(); |
inetDomain.setName("test.domain"); |
inetDomain.setOwner(UserManager.getInstance().findForLogin("testuser")); |
InetDomainManager.getInstance().save(inetDomain); |
systemUser = SystemUserManager.getInstance().create(); |
systemUser.setUid(new Integer(1001)); |
systemUser.setName("test"); |
SystemUserManager.getInstance().save(systemUser); |
mailbox = MailboxManager.getInstance().create(); |
mailbox.setLogin("testuser@test.domain"); |
mailbox.setDomain(InetDomainManager.getInstance().findForName("test.domain")); |
mailbox.setOwner(UserManager.getInstance().findForLogin("testuser")); |
mailbox.setVirusCheck(new Boolean(true)); |
mailbox.setSpamCheck(new Boolean(false)); |
mailbox.setSystemUser(systemUser); |
MailboxManager.getInstance().save(mailbox); |
mailAlias = MailAliasManager.getInstance().create(); |
mailAlias.setAddress("some.name@test.domain"); |
mailAlias.setDomain(InetDomainManager.getInstance().findForName("test.domain")); |
mailAlias.setOwner(UserManager.getInstance().findForLogin("testuser")); |
MailAliasManager.getInstance().save(mailAlias); |
HibernateUtil.currentSession().flush(); |
} |
public static void testUser() |
throws Exception |
{ |
User user = UserManager.getInstance().findForLogin("testuser"); |
if(user == null) { |
System.out.println("create new user"); |
user = UserManager.getInstance().create(); |
} |
else { |
System.out.println("get existing user"); |
} |
user.setLogin("testuser"); |
// |
// benchmark hibernate update |
// |
int benchmarkCount = 100; |
// first measure object change time |
long startTime = System.currentTimeMillis(); |
for(int i = 0; i < benchmarkCount; i++) { |
user.setNewPassword((i % 2 == 0) ? "a" : "b"); |
} |
// then object change & DB update |
long betweenTime = System.currentTimeMillis(); |
for(int i = 0; i < benchmarkCount; i++) { |
user.setNewPassword((i % 2 == 0) ? "a" : "b"); |
UserManager.getInstance().save(user); |
HibernateUtil.currentSession().flush(); |
} |
// results |
long endTime = System.currentTimeMillis(); |
System.out.println("Object change: " + (betweenTime-startTime) + " ms"); |
System.out.println("DB update: " + (endTime-betweenTime) + " ms"); |
user.setNewPassword("none"); |
UserManager.getInstance().save(user); |
} |
public static void testInetDomain() |
throws Exception |
{ |
InetDomain inetDomain = InetDomainManager.getInstance().findForName("test.domain"); |
if(inetDomain == null) { |
System.out.println("create new domain"); |
inetDomain = InetDomainManager.getInstance().create(); |
} |
else { |
System.out.println("get existing domain"); |
} |
inetDomain.setName("test.domain"); |
inetDomain.setOwner(UserManager.getInstance().findForLogin("testuser")); |
InetDomainManager.getInstance().save(inetDomain); |
} |
public static void main(String[] args) |
throws Exception |
{ |
UserManager.getInstance(); |
InetDomainManager.getInstance(); |
SystemUserManager.getInstance(); |
MailboxManager.getInstance(); |
MailAliasManager.getInstance(); |
try { |
HibernateUtil.beginTransaction(); |
//testUser(); |
//testInetDomain(); |
test(); |
HibernateUtil.commitTransaction(); |
} |
catch(Exception ex) { |
ex.printStackTrace(); |
HibernateUtil.rollbackTransaction(); |
throw ex; |
} |
finally { |
HibernateUtil.closeSession(); |
} |
} |
private static String randomString(int len) |
throws java.io.UnsupportedEncodingException |
{ |
byte[] buf = new byte[len]; |
for(int i = 0; i < len; i++) { |
buf[i] = (byte)(Math.random() * 26 + 97); |
} |
return new String(buf, "ascii"); |
} |
} |
/sun/src/ak/webcontrol/core/CoreResources.java |
---|
0,0 → 1,18 |
package ak.webcontrol.core; |
public abstract class CoreResources |
{ |
public static final String LOGIN_FAILED = "ak.webcontrol.core.login.failed"; |
public static final String OLD_PASSWORD_WRONG = "ak.webcontrol.core.oldpassword.wrong"; |
public static final String DELETE_ME_SELF = "ak.webcontrol.core.user.deletemeself"; |
public static final String PASSWORD_REQUIRED = "ak.webcontrol.core.password.required"; |
public static final String PASSWORDS_DONT_MATCH = "ak.webcontrol.core.password.dontMatch"; |
public static final String TYPE_USER = "ak.webcontrol.core.type.user"; |
public static final String TYPE_SYSTEM_USER = "ak.webcontrol.core.type.systemUser"; |
public static final String TYPE_DOMAIN = "ak.webcontrol.core.type.domain"; |
public static final String TYPE_MAILBOX = "ak.webcontrol.core.type.mailbox"; |
public static final String TYPE_MAIL_ALIAS = "ak.webcontrol.core.type.mailAlias"; |
public static final String TYPE_MAIL_ALIAS_DESTINATION |
= "ak.webcontrol.core.type.mailAliasDestination"; |
} |
/sun/src/ak/webcontrol/core/form/MailAliasDestBean.java |
---|
0,0 → 1,53 |
package ak.webcontrol.core.form; |
import ak.webcontrol.util.StringConverter; |
import ak.webcontrol.core.model.MailAliasDestination; |
public final class MailAliasDestBean |
{ |
private String id; |
private String mailbox; |
private String email; |
public MailAliasDestBean() |
{ |
} |
public MailAliasDestBean(MailAliasDestination dest) |
{ |
this.id = StringConverter.toString(dest.getId()); |
this.mailbox = (dest.getMailbox() == null) |
? null : StringConverter.toString(dest.getMailbox().getId()); |
this.email = dest.getEmail(); |
} |
public String getId() |
{ |
return id; |
} |
public void setId(String id) |
{ |
this.id = id; |
} |
public String getMailbox() |
{ |
return mailbox; |
} |
public void setMailbox(String mailbox) |
{ |
this.mailbox = mailbox; |
} |
public String getEmail() |
{ |
return email; |
} |
public void setEmail(String email) |
{ |
this.email = email; |
} |
} |
/sun/src/ak/webcontrol/core/form/UserPasswordForm.java |
---|
0,0 → 1,30 |
package ak.webcontrol.core.form; |
import javax.servlet.http.HttpServletRequest; |
import org.apache.struts.action.ActionError; |
import org.apache.struts.action.ActionErrors; |
import org.apache.struts.action.ActionForm; |
import org.apache.struts.action.ActionMapping; |
import ak.webcontrol.core.CoreResources; |
public final class UserPasswordForm |
extends org.apache.struts.validator.DynaValidatorForm |
{ |
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) |
{ |
ActionErrors errors = super.validate(mapping, request); |
if(errors == null || errors.size() == 0) { // if no errors in simple checks |
String password = (String)get("password"); |
String password2 = (String)get("password2"); |
if(!password.equals(password2)) { |
if(errors == null) errors = new ActionErrors(); |
errors.add("password", new ActionError(CoreResources.PASSWORDS_DONT_MATCH)); |
} |
} |
return errors; |
} |
} |
/sun/src/ak/webcontrol/core/servlet/EncodingFilter.java |
---|
0,0 → 1,37 |
package ak.webcontrol.core.servlet; |
import java.io.IOException; |
import javax.servlet.Filter; |
import javax.servlet.FilterChain; |
import javax.servlet.FilterConfig; |
import javax.servlet.ServletException; |
import javax.servlet.ServletRequest; |
import javax.servlet.ServletResponse; |
public class EncodingFilter |
implements Filter |
{ |
public static final String ENCODING = "UTF-8"; |
private FilterConfig filterConfig; |
public void init(FilterConfig filterConfig) |
throws ServletException |
{ |
this.filterConfig = filterConfig; |
} |
public void doFilter(ServletRequest request, ServletResponse response, |
FilterChain chain) |
throws IOException, ServletException |
{ |
if(request.getCharacterEncoding() == null) |
request.setCharacterEncoding(ENCODING); |
chain.doFilter(request, response); |
} |
public void destroy() |
{ |
} |
} |
/sun/src/ak/webcontrol/core/servlet/LoginFilter.java |
---|
0,0 → 1,169 |
package ak.webcontrol.core.servlet; |
import java.util.List; |
import java.util.ArrayList; |
import java.util.StringTokenizer; |
import java.io.IOException; |
import java.net.URLEncoder; |
import java.security.Principal; |
import java.security.AccessControlException; |
import javax.servlet.Filter; |
import javax.servlet.FilterChain; |
import javax.servlet.FilterConfig; |
import javax.servlet.ServletException; |
import javax.servlet.ServletRequest; |
import javax.servlet.ServletResponse; |
import javax.servlet.http.HttpSession; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
import org.apache.log4j.Logger; |
import ak.backpath.BackPath; |
import ak.webcontrol.core.model.User; |
/** |
* Ensures that user is logged in to the system to process its request. |
*/ |
public class LoginFilter |
implements Filter |
{ |
private static final Logger logger = Logger.getLogger(LoginFilter.class); |
private FilterConfig filterConfig; |
private String loginUrl; |
private String loginServlet; |
private List passUrls = new ArrayList(); |
private List passMasks = new ArrayList(); |
public void init(FilterConfig filterConfig) |
throws ServletException |
{ |
// get config |
this.filterConfig = filterConfig; |
if(filterConfig == null) |
throw new ServletException("No configuration for the filter"); |
// get login url |
loginUrl = filterConfig.getInitParameter("loginUrl"); |
if(loginUrl == null) |
throw new ServletException("No login URL specified"); |
// ensure it's absolute path |
if(!loginUrl.startsWith("/")) |
loginUrl = "/" + loginUrl; |
// get servlet part ot the url |
int qPos = loginUrl.indexOf("?"); |
if(qPos < 0) |
loginServlet = loginUrl; |
else |
loginServlet = loginUrl.substring(0, qPos); |
// get pass through URLs |
String passUrlsStr = filterConfig.getInitParameter("passUrls"); |
if(passUrlsStr != null) { |
String[] urls = passUrlsStr.split("\\s*;\\s*"); |
for(int i = 0; i < urls.length; i++) { |
if(urls[i].endsWith("*")) { |
passMasks.add(urls[i].substring(0, urls[i].length()-1)); |
} |
else { |
passUrls.add(urls[i]); |
} |
} |
} |
// avoid loop |
if(!isPassThrough(loginServlet)) { |
passUrls.add(loginServlet); |
} |
} |
private boolean isPassThrough(String url) |
{ |
for(int i = 0; i < passUrls.size(); i++) { |
if(url.equals((String)passUrls.get(i))) return true; |
} |
for(int i = 0; i < passMasks.size(); i++) { |
if(url.startsWith((String)passMasks.get(i))) return true; |
} |
return false; |
} |
public void doFilter(ServletRequest request, ServletResponse response, |
FilterChain chain) |
throws IOException, ServletException |
{ |
boolean processNext; |
if(!(request instanceof HttpServletRequest)) |
throw new ServletException("Do not know how to handle non-HTTP requests"); |
if(!(response instanceof HttpServletResponse)) |
throw new ServletException("Do not know how to handle non-HTTP response"); |
HttpServletRequest httpRequest = (HttpServletRequest)request; |
HttpServletResponse httpResponse = (HttpServletResponse)response; |
logger.debug("Requested " + httpRequest.getServletPath()); |
if(isPassThrough(httpRequest.getServletPath())) { |
processNext = true; |
logger.debug("pass through"); |
} |
else { |
try { |
HttpSession session = httpRequest.getSession(false); |
if(session == null) |
throw new AccessControlException("No session"); |
Object userObj = session.getAttribute("user"); |
if(userObj == null) |
throw new AccessControlException("No user"); |
if(!(userObj instanceof User)) |
throw new ServletException( |
"Wrong type of user information: " + userObj.getClass().getName()); |
processNext = true; |
logger.debug("User found - OK"); |
} |
catch(AccessControlException ex) { |
String origin = httpRequest.getRequestURI(); |
String originParams = httpRequest.getQueryString(); |
String redirectUrl; |
try { |
redirectUrl = httpRequest.getContextPath() + loginUrl |
+ BackPath.findBackPath(httpRequest).getForwardParams(); |
} |
catch(Exception ex2) { |
logger.error("Cannot get forward redirect", ex2); |
redirectUrl = httpRequest.getContextPath() + loginUrl; |
} |
logger.info("Redirect because of '" + ex.getMessage() + "' to " + redirectUrl); |
httpResponse.sendRedirect(httpResponse.encodeRedirectURL(redirectUrl)); |
processNext = false; |
} |
} |
if(processNext) { // no problems found |
chain.doFilter(request, response); |
} |
} |
public void destroy() |
{ |
} |
} |
/sun/src/ak/webcontrol/core/servlet/HibernateFilter.java |
---|
0,0 → 1,106 |
package ak.webcontrol.core.servlet; |
import java.util.List; |
import java.util.ArrayList; |
import java.util.StringTokenizer; |
import java.io.IOException; |
import java.net.URLEncoder; |
import java.security.Principal; |
import java.security.AccessControlException; |
import javax.servlet.Filter; |
import javax.servlet.FilterChain; |
import javax.servlet.FilterConfig; |
import javax.servlet.ServletException; |
import javax.servlet.ServletRequest; |
import javax.servlet.ServletResponse; |
import javax.servlet.http.HttpSession; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
import org.apache.log4j.Logger; |
import net.sf.hibernate.HibernateException; |
import ak.webcontrol.util.HibernateUtil; |
import ak.webcontrol.util.ModelException; |
public class HibernateFilter |
implements Filter |
{ |
private static final Logger logger = Logger.getLogger(HibernateFilter.class); |
private FilterConfig filterConfig; |
public void init(FilterConfig filterConfig) |
throws ServletException |
{ |
// get config |
this.filterConfig = filterConfig; |
if(filterConfig != null) { |
// register hibernate classes |
String toRegister = filterConfig.getInitParameter("register"); |
if(toRegister != null) { |
String[] registers = toRegister.split("\\s*;\\s*"); |
for(int i = 0; i < registers.length; i++) { |
try { |
String name = registers[i].trim(); |
if(name.equals("")) continue; |
Class cl = Class.forName(name); |
} |
catch(Exception ex) { |
logger.error("cannot register class", ex); |
} |
} |
} |
} |
} |
public void doFilter(ServletRequest request, ServletResponse response, |
FilterChain chain) |
throws IOException, ServletException |
{ |
try { |
logger.info("begin transaction"); |
HibernateUtil.beginTransaction(); |
chain.doFilter(request, response); |
if(HibernateUtil.isTransactionOpen()) { |
logger.info("commit transaction"); |
HibernateUtil.commitTransaction(); |
} |
} |
catch(Exception ex) { |
logger.error("exception by program execution", ex); |
try { |
if(HibernateUtil.isTransactionOpen()) { |
logger.info("rollback transaction"); |
HibernateUtil.rollbackTransaction(); |
} |
} |
catch(Exception ex2) { |
logger.error("cannot rollback transaction", ex2); |
} |
if(ex instanceof ServletException) |
throw (ServletException)ex; |
else |
throw new ServletException("Internal server error"); |
} |
try { |
HibernateUtil.closeSession(); |
} |
catch(Exception ex) { |
logger.error("cannot close session", ex); |
} |
} |
public void destroy() |
{ |
} |
} |
/sun/src/ak/webcontrol/util/UserException.java |
---|
0,0 → 1,28 |
package ak.webcontrol.util; |
public class UserException |
extends Exception |
{ |
private Object[] values; |
public UserException() |
{ |
this(null, null); |
} |
public UserException(String message) |
{ |
this(message, null); |
} |
public UserException(String message, Object[] values) |
{ |
super(message); |
this.values = values; |
} |
public Object[] getValues() |
{ |
return values; |
} |
} |
/sun/src/ak/webcontrol/util/StringConverter.java |
---|
0,0 → 1,42 |
package ak.webcontrol.util; |
public abstract class StringConverter |
{ |
public static Long parseLong(Object o) |
throws NumberFormatException |
{ |
if(o instanceof String) { |
String s = (String)o; |
if(s == null || s.equals("")) |
return null; |
else |
return new Long(s); |
} |
else { |
throw new ClassCastException("String is expected, but it is " + o.getClass()); |
} |
} |
public static Integer parseInteger(Object o) |
throws NumberFormatException |
{ |
if(o instanceof String) { |
String s = (String)o; |
if(s == null || s.equals("")) |
return null; |
else |
return new Integer(s); |
} |
else { |
throw new ClassCastException("String is expected, but it is " + o.getClass()); |
} |
} |
public static String toString(Object o) |
{ |
if(o == null) |
return null; |
else |
return o.toString(); |
} |
} |
/sun/src/ak/webcontrol/util/Digest.java |
---|
0,0 → 1,51 |
package ak.webcontrol.util; |
import java.security.MessageDigest; |
import java.security.NoSuchAlgorithmException; |
public class Digest |
{ |
/** |
* digest to encode passwords |
*/ |
protected static MessageDigest digest = null; |
private static final char[] hexDigits = { |
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' |
}; |
public static String encode(String password) |
{ |
return bytesToHex(digest.digest(password.getBytes())); |
} |
/** |
* converts password bytes to hex string |
*/ |
protected static String bytesToHex(byte[] bytes) |
{ |
char[] buffer = new char[bytes.length * 2]; |
for (int i = 0; i < bytes.length; i++) { |
int low = (int)( bytes[i] & 0x0f); |
int high = (int)((bytes[i] & 0xf0) >> 4); |
buffer[i * 2] = hexDigits[high]; |
buffer[i * 2 + 1] = hexDigits[low]; |
} |
return new String(buffer); |
} |
/** |
* digest initialization |
*/ |
static { |
try { |
digest = MessageDigest.getInstance("MD5"); |
} |
catch(NoSuchAlgorithmException ex) { |
ex.printStackTrace(); |
} |
} |
} |
/sun/src/ak/webcontrol/util/HibernateUtil.java |
---|
0,0 → 1,109 |
package ak.webcontrol.util; |
import net.sf.hibernate.*; |
import net.sf.hibernate.cfg.*; |
public class HibernateUtil |
{ |
private static Configuration configuration; |
private static SessionFactory sessionFactory; |
private static final ThreadLocal hibernateBean = new ThreadLocal(); |
public static Configuration getConfiguration() |
throws HibernateException |
{ |
if(configuration == null) |
configuration = new Configuration(); |
return configuration; |
} |
public static SessionFactory getSessionFactory() |
throws HibernateException |
{ |
if(sessionFactory == null) |
sessionFactory = getConfiguration().configure().buildSessionFactory(); |
return sessionFactory; |
} |
private static HibernateBean currentBean() |
throws HibernateException |
{ |
HibernateBean hb = (HibernateBean)hibernateBean.get(); |
if(hb == null) { |
hb = new HibernateBean(); |
hb.session = getSessionFactory().openSession(); |
hibernateBean.set(hb); |
} |
return hb; |
} |
public static Session currentSession() |
throws HibernateException |
{ |
return currentBean().session; |
} |
public static void closeSession() |
throws HibernateException, ModelException |
{ |
HibernateBean hb = (HibernateBean)hibernateBean.get(); |
if(hb == null) |
throw new ModelException("No session found for this thread"); |
hibernateBean.set(null); |
hb.session.close(); |
} |
public static void beginTransaction() |
throws HibernateException, ModelException |
{ |
HibernateBean hb = (HibernateBean)hibernateBean.get(); |
if(hb != null && hb.transaction != null) |
throw new ModelException("Transaction is already open"); |
currentBean().transaction = currentSession().beginTransaction(); |
} |
public static boolean isTransactionOpen() |
throws HibernateException, ModelException |
{ |
HibernateBean hb = (HibernateBean)hibernateBean.get(); |
return (hb != null) && (hb.transaction != null); |
} |
public static void commitTransaction() |
throws HibernateException, ModelException |
{ |
HibernateBean hb = (HibernateBean)hibernateBean.get(); |
if(hb == null || hb.transaction == null) |
throw new ModelException("No open transaction"); |
hb.transaction.commit(); |
hb.transaction = null; |
} |
public static void rollbackTransaction() |
throws HibernateException, ModelException |
{ |
HibernateBean hb = (HibernateBean)hibernateBean.get(); |
if(hb == null || hb.transaction == null) |
throw new ModelException("No open transaction"); |
hb.transaction.rollback(); |
hb.transaction = null; |
} |
static class HibernateBean |
{ |
public Session session; |
public Transaction transaction; |
} |
} |
/sun/src/ak/webcontrol/util/ModelException.java |
---|
0,0 → 1,44 |
package ak.webcontrol.util; |
public class ModelException |
extends Exception |
{ |
private Exception chainedException; |
public ModelException() |
{ |
this(null, null); |
} |
public ModelException(String message) |
{ |
this(message, null); |
} |
public ModelException(Exception chainedException) |
{ |
this(null, chainedException); |
} |
public ModelException(String message, Exception chainedException) |
{ |
super(message); |
this.chainedException = chainedException; |
} |
public Exception getChainedException() |
{ |
return chainedException; |
} |
public void setChainedException(Exception chainedException) |
{ |
this.chainedException = chainedException; |
} |
public String toString() |
{ |
return super.toString() |
+ (chainedException == null ? "" : "\n" + chainedException.toString()); |
} |
} |
/sun/src/ak/webcontrol/util/FormException.java |
---|
0,0 → 1,39 |
package ak.webcontrol.util; |
public class FormException |
extends UserException |
{ |
private String property; |
public FormException() |
{ |
this(null, null, null); |
} |
public FormException(String message) |
{ |
this(message, null, null); |
} |
public FormException(String message, String property) |
{ |
this(message, property, null); |
} |
public FormException(String message, String property, Object[] values) |
{ |
super(message, values); |
this.property = property; |
} |
public String getProperty() |
{ |
return property; |
} |
public String toString() |
{ |
return super.toString() |
+ (property == null ? "" : " for " + property); |
} |
} |