You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2008/03/17 13:48:02 UTC
svn commit: r637866 - in /incubator/sling/trunk:
jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/
scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/
scripting/jst/src/main/java/org/apache/s...
Author: cziegeler
Date: Mon Mar 17 05:48:01 2008
New Revision: 637866
URL: http://svn.apache.org/viewvc?rev=637866&view=rev
Log:
Clean up code a little bit (no functional changes)
Modified:
incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResource.java
incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableResource.java
incubator/sling/trunk/scripting/jst/src/main/java/org/apache/sling/scripting/jst/ScriptFilteredCopy.java
incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/SlingHttpServletResponseImpl.java
incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/log/FileRequestLog.java
incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/log/RequestLogger.java
incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/log/RequestLoggerService.java
incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/parameters/ParameterSupport.java
incubator/sling/trunk/sling/ujax/src/main/java/org/apache/sling/ujax/HtmlResponse.java
incubator/sling/trunk/sling/ujax/src/main/java/org/apache/sling/ujax/impl/UjaxPostProcessor.java
Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResource.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResource.java?rev=637866&r1=637865&r2=637866&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResource.java (original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResource.java Mon Mar 17 05:48:01 2008
@@ -25,9 +25,6 @@
import java.net.URL;
import java.util.Iterator;
-import javax.jcr.Item;
-import javax.jcr.Node;
-import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
@@ -46,7 +43,7 @@
private final Logger log = LoggerFactory.getLogger(getClass());
private final ResourceResolver resourceResolver;
-
+
private final Bundle bundle;
private final String path;
@@ -83,7 +80,7 @@
if (entry == null) {
entry = bundle.getEntry(path);
}
-
+
// here we either have a folder for which no same-named item exists
// or a bundle file
if (entry != null) {
@@ -104,12 +101,12 @@
metadata.setModificationTime(bundle.getLastModified());
if (path.endsWith("/")) {
-
+
this.path = path.substring(0, path.length() - 1);
this.resourceType = NT_FOLDER;
-
+
} else {
-
+
this.path = path;
this.resourceType = NT_FILE;
@@ -134,7 +131,7 @@
public String getResourceSuperType() {
return null;
}
-
+
public ResourceMetadata getResourceMetadata() {
return metadata;
}
@@ -142,7 +139,7 @@
public ResourceResolver getResourceResolver() {
return resourceResolver;
}
-
+
@SuppressWarnings("unchecked")
public <Type> Type adaptTo(Class<Type> type) {
if (type == InputStream.class) {
@@ -196,7 +193,7 @@
return url;
}
-
+
Iterator<Resource> listChildren() {
return new BundleResourceIterator(this);
}
Modified: incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableResource.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableResource.java?rev=637866&r1=637865&r2=637866&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableResource.java (original)
+++ incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableResource.java Mon Mar 17 05:48:01 2008
@@ -16,8 +16,6 @@
*/
package org.apache.sling.scripting.javascript.wrapper;
-import java.util.Iterator;
-
import org.apache.sling.api.resource.Resource;
import org.apache.sling.scripting.javascript.helper.SlingWrapper;
import org.mozilla.javascript.Context;
Modified: incubator/sling/trunk/scripting/jst/src/main/java/org/apache/sling/scripting/jst/ScriptFilteredCopy.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/jst/src/main/java/org/apache/sling/scripting/jst/ScriptFilteredCopy.java?rev=637866&r1=637865&r2=637866&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/jst/src/main/java/org/apache/sling/scripting/jst/ScriptFilteredCopy.java (original)
+++ incubator/sling/trunk/scripting/jst/src/main/java/org/apache/sling/scripting/jst/ScriptFilteredCopy.java Mon Mar 17 05:48:01 2008
@@ -26,8 +26,8 @@
/** Copy the ECT script to the output, filtering <script>
* tags on the way (see SLING-114 comment 10/Dec/07 01:00 AM).
* To simplify things, assumes each out.write statement is on
- * its own line in input.
- */
+ * its own line in input.
+ */
class ScriptFilteredCopy {
/** Read r line-by-line, process lines that need to be
@@ -37,7 +37,7 @@
final BufferedReader br = new BufferedReader(r);
String line = null;
while( (line = br.readLine()) != null) {
- final String toWrite = processLine(line);
+ final String toWrite = processLine(line);
w.write(toWrite, 0, toWrite.length());
w.write('\n');
}
@@ -47,21 +47,20 @@
* <pre>
* out.write("something and a <script> tag");
* </pre>
- *
+ *
* Into
* <pre>
* out.write("something and a <");
* out.write("script> tag");
* </pre>
- *
- * To work around browsers problems when they
- * see a </script> tag in a String.
+ *
+ * To work around browsers problems when they
+ * see a </script> tag in a String.
*/
String processLine(String line) {
if(line.startsWith("out.write(") && line.endsWith("\");")) {
return line.replaceAll("script>","\");\nout.write(\"script>");
- } else {
- return line;
}
+ return line;
}
}
Modified: incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/SlingHttpServletResponseImpl.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/SlingHttpServletResponseImpl.java?rev=637866&r1=637865&r2=637866&view=diff
==============================================================================
--- incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/SlingHttpServletResponseImpl.java (original)
+++ incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/SlingHttpServletResponseImpl.java Mon Mar 17 05:48:01 2008
@@ -215,7 +215,7 @@
// ---------- Error handling through Sling Error Resolver -----------------
-
+
@Override
public void sendRedirect(String location) throws IOException {
super.sendRedirect(location);
@@ -454,7 +454,7 @@
}
//---------- byte/character counting output channels ----------------------
-
+
// byte transfer counting ServletOutputStream
private static class LoggerResponseOutputStream extends ServletOutputStream {
private ServletOutputStream delegatee;
Modified: incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/log/FileRequestLog.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/log/FileRequestLog.java?rev=637866&r1=637865&r2=637866&view=diff
==============================================================================
--- incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/log/FileRequestLog.java (original)
+++ incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/log/FileRequestLog.java Mon Mar 17 05:48:01 2008
@@ -24,7 +24,6 @@
import java.io.PrintWriter;
import java.io.Writer;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
import org.apache.sling.core.RequestLog;
@@ -64,7 +63,7 @@
private static File relPathRoot;
// The map of shared open files (actually PrintWriter instances)
- private static Map logFiles = new HashMap();
+ private static Map<String, PrintWriter> logFiles = new HashMap<String, PrintWriter>();
// Initialize class with the root directory for relative log file paths
static void init(String relPathRoot) {
@@ -73,15 +72,14 @@
// Dispose class by closing all open PrintWeiter instances
static void dispose() {
- for (Iterator li = logFiles.values().iterator(); li.hasNext();) {
- Writer w = (Writer) li.next();
+ for (final Writer w : logFiles.values()) {
try {
w.close();
} catch (IOException ioe) {
// don't care
}
- li.remove();
}
+ logFiles.clear();
}
// The PrintWriter used by this instance to write the messages
@@ -98,7 +96,7 @@
fileName = file.getAbsolutePath();
synchronized (logFiles) {
- this.output = (PrintWriter) logFiles.get(fileName);
+ this.output = logFiles.get(fileName);
if (this.output == null) {
// ensure location of the log file
Modified: incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/log/RequestLogger.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/log/RequestLogger.java?rev=637866&r1=637865&r2=637866&view=diff
==============================================================================
--- incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/log/RequestLogger.java (original)
+++ incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/log/RequestLogger.java Mon Mar 17 05:48:01 2008
@@ -19,7 +19,7 @@
package org.apache.sling.core.impl.log;
import java.util.Dictionary;
-import java.util.Properties;
+import java.util.Hashtable;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
@@ -96,17 +96,6 @@
private static final String ACCESS_LOG_FORMAT = "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"";
/**
- * The counter for request gone through this filter. As this is the first
- * request level filter hit, this counter should actually count each request
- * which at least enters the request level component filter processing.
- * <p>
- * This counter is reset to zero, when this component is activated. That is,
- * each time this component is restarted (system start, bundle start,
- * reconfiguration), the request counter restarts at zero.
- */
- private int requestCounter;
-
- /**
* The list of {@link RequestLoggerService} called when the request enters
* processing. The order of the services in this list determined by the
* registration order.
@@ -185,15 +174,13 @@
org.osgi.service.component.ComponentContext osgiContext) {
BundleContext bundleContext = osgiContext.getBundleContext();
+ @SuppressWarnings("unchecked")
Dictionary props = osgiContext.getProperties();
// initialize the FileRequestLog with sling.home as the root for
// relative log file paths
FileRequestLog.init(bundleContext.getProperty("sling.home"));
- // reset the request counter
- this.requestCounter = 0;
-
// prepare the request loggers if a name is configured and the
// request loggers are enabled
Object requestLogName = props.get(PROP_REQUEST_LOG_OUTPUT);
@@ -318,7 +305,7 @@
private RequestLoggerService createRequestLoggerService(
BundleContext bundleContext, boolean onEntry, Object format,
Object output, Object outputType) {
- Properties config = new Properties();
+ final Hashtable<String, Object> config = new Hashtable<String, Object>();
config.put(RequestLoggerService.PARAM_ON_ENTRY, onEntry
? Boolean.TRUE
: Boolean.FALSE);
Modified: incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/log/RequestLoggerService.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/log/RequestLoggerService.java?rev=637866&r1=637865&r2=637866&view=diff
==============================================================================
--- incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/log/RequestLoggerService.java (original)
+++ incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/log/RequestLoggerService.java Mon Mar 17 05:48:01 2008
@@ -74,11 +74,11 @@
public RequestLoggerService() {
}
- RequestLoggerService(BundleContext bundleContext, Dictionary configuration) {
+ RequestLoggerService(BundleContext bundleContext, Dictionary<String, Object> configuration) {
this.setup(bundleContext, configuration);
}
- void setup(BundleContext bundleContext, Dictionary configuration) {
+ void setup(BundleContext bundleContext, Dictionary<String, Object> configuration) {
// whether to log on request entry or request exit
Object onEntryObject = configuration.get(PARAM_ON_ENTRY);
this.onEntry = (onEntryObject instanceof Boolean)
@@ -123,6 +123,7 @@
// ---------- SCR integration ----------------------------------------------
+ @SuppressWarnings("unchecked")
protected void activate(ComponentContext context) {
this.setup(context.getBundleContext(), context.getProperties());
}
Modified: incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/parameters/ParameterSupport.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/parameters/ParameterSupport.java?rev=637866&r1=637865&r2=637866&view=diff
==============================================================================
--- incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/parameters/ParameterSupport.java (original)
+++ incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/parameters/ParameterSupport.java Mon Mar 17 05:48:01 2008
@@ -18,7 +18,6 @@
*/
package org.apache.sling.core.impl.parameters;
-import java.io.UnsupportedEncodingException;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
Modified: incubator/sling/trunk/sling/ujax/src/main/java/org/apache/sling/ujax/HtmlResponse.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/ujax/src/main/java/org/apache/sling/ujax/HtmlResponse.java?rev=637866&r1=637865&r2=637866&view=diff
==============================================================================
--- incubator/sling/trunk/sling/ujax/src/main/java/org/apache/sling/ujax/HtmlResponse.java (original)
+++ incubator/sling/trunk/sling/ujax/src/main/java/org/apache/sling/ujax/HtmlResponse.java Mon Mar 17 05:48:01 2008
@@ -74,7 +74,7 @@
// TODO
public static final String PN_IS_CREATED = "isCreate";
-
+
/**
* human readable changelog
*/
@@ -82,7 +82,7 @@
// TODO
public static final String PN_ERROR = "error";
-
+
/**
* name of the html template
*/
@@ -100,13 +100,12 @@
/**
* Creates a new ujax html response
- * @param provider the status provider
*/
public HtmlResponse() {
}
//---------- Settings for the response ------------------------------------
-
+
/**
* Returns the path of the node that was the parent of the property
* modifications.
@@ -115,7 +114,7 @@
public String getPath() {
return getProperty(PN_PATH, String.class);
}
-
+
public void setPath(String path) {
setProperty(PN_PATH, path);
}
@@ -127,7 +126,7 @@
public boolean isCreateRequest() {
return getProperty(PN_IS_CREATED, Boolean.class);
}
-
+
public void setCreateRequest(boolean isCreateRequest) {
setProperty(PN_IS_CREATED, isCreateRequest);
}
@@ -144,7 +143,7 @@
public void setLocation(String location) {
setProperty(PN_LOCATION, location);
}
-
+
/**
* Returns the parent location of the modification. this is the externalized
* form of the parent node of the current path.
@@ -157,7 +156,7 @@
public void setParentLocation(String parentLocation) {
setProperty(PN_PARENT_LOCATION, parentLocation);
}
-
+
/**
* Returns any recorded error or <code>null</code>
* @return an error or <code>null</code>
@@ -169,7 +168,7 @@
public void setError(Throwable error) {
setProperty(PN_ERROR, error);
}
-
+
/**
* Returns the referer as from the 'referer' request header.
* @return the referer or <code>null</code> if the referer is empty.
@@ -181,9 +180,9 @@
public void setReferer(String referer) {
setProperty(PN_REFERER, referer);
}
-
+
//---------- ChangeLog ----------------------------------------------------
-
+
/**
* Records a 'modified' change
* @param path path of the item that was modified
@@ -235,9 +234,9 @@
}
changes.append(");<br/>");
}
-
+
//---------- Response Generation ------------------------------------------
-
+
/**
* prepares the response properties
*/
@@ -257,13 +256,13 @@
}
}
}
-
+
String referer = getReferer();
if (referer == null) {
referer = "";
}
setReferer(referer);
-
+
// get changelog
changes.insert(0, "<pre>");
changes.append("</pre>");
@@ -296,7 +295,7 @@
public void setProperty(String name, Object value) {
properties.put(name, value);
}
-
+
/**
* Returns the generic response property with the given name and type or
* <code>null</code> if no such property exists or the property is not
@@ -308,10 +307,10 @@
if (type.isInstance(value)) {
return (Type) value;
}
-
+
return null;
}
-
+
/**
* Returns the generic response property with the given name and type or
* <code>null</code> if no such property exists.
@@ -325,22 +324,22 @@
* by the value of the respective property. if the property is not defined
* the pattern is not modified.
* @param response to send to
- * @param setStatus whether to set the status code on the response
+ * @param setStatus whether to set the status code on the response
* @throws IOException if an i/o exception occurs
*/
public void send(HttpServletResponse response, boolean setStatus) throws IOException {
prepare();
-
+
if (setStatus) {
Object status = getProperty(PN_STATUS_CODE);
if (status instanceof Number) {
response.setStatus(((Number) status).intValue());
}
}
-
+
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
-
+
Writer out = response.getWriter();
InputStream template = getClass().getResourceAsStream(TEMPLATE_NAME);
Reader in = new BufferedReader(new InputStreamReader(template));
@@ -389,5 +388,5 @@
in.close();
out.flush();
}
-
+
}
Modified: incubator/sling/trunk/sling/ujax/src/main/java/org/apache/sling/ujax/impl/UjaxPostProcessor.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/ujax/src/main/java/org/apache/sling/ujax/impl/UjaxPostProcessor.java?rev=637866&r1=637865&r2=637866&view=diff
==============================================================================
--- incubator/sling/trunk/sling/ujax/src/main/java/org/apache/sling/ujax/impl/UjaxPostProcessor.java (original)
+++ incubator/sling/trunk/sling/ujax/src/main/java/org/apache/sling/ujax/impl/UjaxPostProcessor.java Mon Mar 17 05:48:01 2008
@@ -49,8 +49,8 @@
public static final String ORDER_FIRST = "first";
public static final String ORDER_BEFORE = "before ";
public static final String ORDER_AFTER = "after ";
- public static final String ORDER_LAST = "last";
-
+ public static final String ORDER_LAST = "last";
+
/**
* handler that deals with properties
*/
@@ -68,7 +68,7 @@
// TODO
private final String rootPath;
-
+
/**
* utility class for parsing date strings
*/
@@ -91,7 +91,7 @@
private String savePrefix;
private HtmlResponse htmlResponse;
-
+
/**
* map of properties that form the content
*/
@@ -114,7 +114,7 @@
this.request = request;
this.session = session;
this.htmlResponse = new HtmlResponse();
-
+
htmlResponse.setReferer(request.getHeader("referer"));
// default to non-creating request (trailing DEFAULT_CREATE_SUFFIX)
@@ -206,7 +206,7 @@
}
public HtmlResponse getHtmlResponse() {
-
+
String path = htmlResponse.getPath();
if (path == null) {
path = rootPath;
@@ -221,7 +221,7 @@
return htmlResponse;
}
-
+
/**
* Returns the request of this processor
* @return the sling servlet request
@@ -233,7 +233,7 @@
/**
* Resolves the given path with respect to the current root path.
*
- * @param path the path to resolve
+ * @param relPath the path to resolve
* @return the given path if it starts with a '/';
* a resolved path otherwise.
*/
@@ -413,7 +413,7 @@
throw new ServletException("Collision in generated node names for path=" + path);
}
}
-
+
htmlResponse.setPath(path);
}
@@ -629,7 +629,7 @@
}
return savePrefix;
}
-
+
private void processOrder() throws RepositoryException {
final String orderCode = request.getParameter(UjaxPostServlet.RP_ORDER);
if (orderCode!=null) {