aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.http.server/src/org/eclipse/jgit
diff options
context:
space:
mode:
authorSasa Zivkov <sasa.zivkov@sap.com>2010-05-19 16:59:28 +0200
committerShawn O. Pearce <spearce@spearce.org>2010-05-19 14:37:16 -0700
commitf3d8a8ecad614906a2c4ec0077cdb24129da6c6d (patch)
tree34d041692beff0f392c27869f49b76c0fc2053e6 /org.eclipse.jgit.http.server/src/org/eclipse/jgit
parent2e961989e42b1fe7e8bd9eaa7a3d2e88a0d1d001 (diff)
downloadjgit-f3d8a8ecad614906a2c4ec0077cdb24129da6c6d.tar.gz
jgit-f3d8a8ecad614906a2c4ec0077cdb24129da6c6d.zip
Externalize strings from JGit
The strings are externalized into the root resource bundles. The resource bundles are stored under the new "resources" source folder to get proper maven build. Strings from tests are, in general, not externalized. Only in cases where it was necessary to make the test pass the strings were externalized. This was typically necessary in cases where e.getMessage() was used in assert and the exception message was slightly changed due to reuse of the externalized strings. Change-Id: Ic0f29c80b9a54fcec8320d8539a3e112852a1f7b Signed-off-by: Sasa Zivkov <sasa.zivkov@sap.com>
Diffstat (limited to 'org.eclipse.jgit.http.server/src/org/eclipse/jgit')
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/FileSender.java5
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitServlet.java11
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/HttpServerText.java82
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java2
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java7
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ServletUtils.java7
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java2
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/glue/MetaServlet.java7
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/glue/RegexGroupFilter.java7
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/glue/ServletBinderImpl.java8
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/ServiceNotAuthorizedException.java4
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/ServiceNotEnabledException.java4
12 files changed, 122 insertions, 24 deletions
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/FileSender.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/FileSender.java
index 280450d01a..6b746e3193 100644
--- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/FileSender.java
+++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/FileSender.java
@@ -57,6 +57,7 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.io.RandomAccessFile;
+import java.text.MessageFormat;
import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest;
@@ -100,7 +101,7 @@ final class FileSender {
}
final FileNotFoundException r;
- r = new FileNotFoundException("Cannot get length of " + path);
+ r = new FileNotFoundException(MessageFormat.format(HttpServerText.get().cannotGetLengthOf, path));
r.initCause(e);
throw r;
}
@@ -143,7 +144,7 @@ final class FileSender {
final int r = (int) Math.min(buf.length, end - pos);
final int n = source.read(buf, 0, r);
if (n < 0) {
- throw new EOFException("Unexpected EOF on " + path);
+ throw new EOFException(MessageFormat.format(HttpServerText.get().unexpectedeOFOn, path));
}
out.write(buf, 0, n);
pos += n;
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitServlet.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitServlet.java
index dced779c98..cc4cf6a800 100644
--- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitServlet.java
+++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitServlet.java
@@ -44,6 +44,7 @@
package org.eclipse.jgit.http.server;
import java.io.File;
+import java.text.MessageFormat;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
@@ -169,7 +170,7 @@ public class GitServlet extends MetaServlet {
private void assertNotInitialized() {
if (initialized)
- throw new IllegalStateException("Already initialized by container");
+ throw new IllegalStateException(HttpServerText.get().alreadyInitializedByContainer);
}
@Override
@@ -259,11 +260,11 @@ public class GitServlet extends MetaServlet {
private File getFile(final String param) throws ServletException {
String n = getInitParameter(param);
if (n == null || "".equals(n))
- throw new ServletException("Parameter " + param + " not set");
+ throw new ServletException(MessageFormat.format(HttpServerText.get().parameterNotSet, param));
File path = new File(n);
if (!path.exists())
- throw new ServletException(path + " (for " + param + ") not found");
+ throw new ServletException(MessageFormat.format(HttpServerText.get().pathForParamNotFound, path, param));
return path;
}
@@ -274,14 +275,14 @@ public class GitServlet extends MetaServlet {
try {
return StringUtils.toBoolean(n);
} catch (IllegalArgumentException err) {
- throw new ServletException("Invalid boolean " + param + " = " + n);
+ throw new ServletException(MessageFormat.format(HttpServerText.get().invalidBoolean, param, n));
}
}
@Override
protected ServletBinder register(ServletBinder binder) {
if (resolver == null)
- throw new IllegalStateException("No resolver available");
+ throw new IllegalStateException(HttpServerText.get().noResolverAvailable);
binder = binder.through(new NoCacheFilter());
binder = binder.through(new RepositoryFilter(resolver));
return binder;
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/HttpServerText.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/HttpServerText.java
new file mode 100644
index 0000000000..8ad0eb0497
--- /dev/null
+++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/HttpServerText.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2010, Sasa Zivkov <sasa.zivkov@sap.com>
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.eclipse.jgit.http.server;
+
+import org.eclipse.jgit.nls.NLS;
+import org.eclipse.jgit.nls.TranslationBundle;
+
+/**
+ * Translation bundle for JGit http server
+ */
+public class HttpServerText extends TranslationBundle {
+
+ /**
+ * @return an instance of this translation bundle
+ */
+ public static HttpServerText get() {
+ return NLS.getBundleFor(HttpServerText.class);
+ }
+
+ /***/ public String alreadyInitializedByContainer;
+ /***/ public String cannotGetLengthOf;
+ /***/ public String encodingNotSupportedByThisLibrary;
+ /***/ public String expectedRepositoryAttribute;
+ /***/ public String filterMustNotBeNull;
+ /***/ public String internalErrorDuringReceivePack;
+ /***/ public String internalErrorDuringUploadPack;
+ /***/ public String internalServerErrorRequestAttributeWasAlreadySet;
+ /***/ public String invalidBoolean;
+ /***/ public String invalidIndex;
+ /***/ public String invalidRegexGroup;
+ /***/ public String noResolverAvailable;
+ /***/ public String parameterNotSet;
+ /***/ public String pathForParamNotFound;
+ /***/ public String pathNotSupported;
+ /***/ public String serviceNotEnabled;
+ /***/ public String serviceNotPermitted;
+ /***/ public String servletAlreadyInitialized;
+ /***/ public String servletMustNotBeNull;
+ /***/ public String servletWasAlreadyBound;
+ /***/ public String unexpectedeOFOn;
+}
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java
index ba8b8ab669..49fd535a71 100644
--- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java
+++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java
@@ -120,7 +120,7 @@ class ReceivePackServlet extends HttpServlet {
return;
} catch (IOException e) {
- getServletContext().log("Internal error during receive-pack", e);
+ getServletContext().log(HttpServerText.get().internalErrorDuringReceivePack, e);
rsp.sendError(SC_INTERNAL_SERVER_ERROR);
return;
}
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java
index a212f0d7ba..7975809e87 100644
--- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java
+++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java
@@ -50,6 +50,7 @@ import static javax.servlet.http.HttpServletResponse.SC_UNAUTHORIZED;
import static org.eclipse.jgit.http.server.ServletUtils.ATTRIBUTE_REPOSITORY;
import java.io.IOException;
+import java.text.MessageFormat;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
@@ -109,9 +110,9 @@ public class RepositoryFilter implements Filter {
final ServletResponse rsp, final FilterChain chain)
throws IOException, ServletException {
if (request.getAttribute(ATTRIBUTE_REPOSITORY) != null) {
- context.log("Internal server error, request attribute "
- + ATTRIBUTE_REPOSITORY + " was already set when "
- + getClass().getName() + " was invoked.");
+ context.log(MessageFormat.format(HttpServerText.get().internalServerErrorRequestAttributeWasAlreadySet
+ , ATTRIBUTE_REPOSITORY
+ , getClass().getName()));
((HttpServletResponse) rsp).sendError(SC_INTERNAL_SERVER_ERROR);
return;
}
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ServletUtils.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ServletUtils.java
index 7514d7c7e7..28dabe4cc7 100644
--- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ServletUtils.java
+++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ServletUtils.java
@@ -54,6 +54,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.MessageDigest;
+import java.text.MessageFormat;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
@@ -85,7 +86,7 @@ public final class ServletUtils {
public static Repository getRepository(final ServletRequest req) {
Repository db = (Repository) req.getAttribute(ATTRIBUTE_REPOSITORY);
if (db == null)
- throw new IllegalStateException("Expected Repository attribute");
+ throw new IllegalStateException(HttpServerText.get().expectedRepositoryAttribute);
return db;
}
@@ -109,8 +110,8 @@ public final class ServletUtils {
if (ENCODING_GZIP.equals(enc) || "x-gzip".equals(enc)) //$NON-NLS-1$
in = new GZIPInputStream(in);
else if (enc != null)
- throw new IOException(HDR_CONTENT_ENCODING + " \"" + enc + "\""
- + ": not supported by this library.");
+ throw new IOException(MessageFormat.format(HttpServerText.get().encodingNotSupportedByThisLibrary
+ , HDR_CONTENT_ENCODING, enc));
return in;
}
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java
index 8de5f06781..92d41a0caf 100644
--- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java
+++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java
@@ -122,7 +122,7 @@ class UploadPackServlet extends HttpServlet {
return;
} catch (IOException e) {
- getServletContext().log("Internal error during upload-pack", e);
+ getServletContext().log(HttpServerText.get().internalErrorDuringUploadPack, e);
rsp.reset();
rsp.sendError(SC_INTERNAL_SERVER_ERROR);
return;
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/glue/MetaServlet.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/glue/MetaServlet.java
index d289743ba4..7764a90c12 100644
--- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/glue/MetaServlet.java
+++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/glue/MetaServlet.java
@@ -46,6 +46,7 @@ package org.eclipse.jgit.http.server.glue;
import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND;
import java.io.IOException;
+import java.text.MessageFormat;
import java.util.AbstractSet;
import java.util.ArrayList;
import java.util.IdentityHashMap;
@@ -59,6 +60,8 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.eclipse.jgit.http.server.HttpServerText;
+
/**
* Generic container servlet to manage routing to different pipelines.
* <p>
@@ -95,7 +98,7 @@ public class MetaServlet extends HttpServlet {
public ServletBinder serve(String path) {
if (path.startsWith("*"))
return register(new SuffixPipeline.Binder(path.substring(1)));
- throw new IllegalArgumentException("\"" + path + "\" not supported");
+ throw new IllegalArgumentException(MessageFormat.format(HttpServerText.get().pathNotSupported, path));
}
/**
@@ -164,7 +167,7 @@ public class MetaServlet extends HttpServlet {
private ServletBinder register(ServletBinderImpl b) {
synchronized (bindings) {
if (pipelines != null)
- throw new IllegalStateException("Servlet already initialized");
+ throw new IllegalStateException(HttpServerText.get().servletAlreadyInitialized);
bindings.add(b);
}
return register((ServletBinder) b);
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/glue/RegexGroupFilter.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/glue/RegexGroupFilter.java
index ed7b1cf694..5c7b965ff7 100644
--- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/glue/RegexGroupFilter.java
+++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/glue/RegexGroupFilter.java
@@ -44,6 +44,7 @@
package org.eclipse.jgit.http.server.glue;
import java.io.IOException;
+import java.text.MessageFormat;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
@@ -52,6 +53,8 @@ import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
+import org.eclipse.jgit.http.server.HttpServerText;
+
/**
* Switch servlet path and path info to use another regex match group.
* <p>
@@ -69,7 +72,7 @@ public class RegexGroupFilter implements Filter {
*/
public RegexGroupFilter(final int groupIdx) {
if (groupIdx < 1)
- throw new IllegalArgumentException("Invalid index: " + groupIdx);
+ throw new IllegalArgumentException(MessageFormat.format(HttpServerText.get().invalidIndex, groupIdx));
this.groupIdx = groupIdx - 1;
}
@@ -88,7 +91,7 @@ public class RegexGroupFilter implements Filter {
if (groupIdx < g.length)
chain.doFilter(g[groupIdx], rsp);
else
- throw new ServletException("Invalid regex group " + (groupIdx + 1));
+ throw new ServletException(MessageFormat.format(HttpServerText.get().invalidRegexGroup, (groupIdx + 1)));
}
private static WrappedRequest[] groupsFor(final ServletRequest r) {
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/glue/ServletBinderImpl.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/glue/ServletBinderImpl.java
index d4cd445a13..e96fc59dc3 100644
--- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/glue/ServletBinderImpl.java
+++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/glue/ServletBinderImpl.java
@@ -50,6 +50,8 @@ import javax.servlet.Filter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;
+import org.eclipse.jgit.http.server.HttpServerText;
+
abstract class ServletBinderImpl implements ServletBinder {
private final List<Filter> filters;
@@ -61,16 +63,16 @@ abstract class ServletBinderImpl implements ServletBinder {
public ServletBinder through(Filter filter) {
if (filter == null)
- throw new NullPointerException("filter must not be null");
+ throw new NullPointerException(HttpServerText.get().filterMustNotBeNull);
filters.add(filter);
return this;
}
public void with(HttpServlet servlet) {
if (servlet == null)
- throw new NullPointerException("servlet must not be null");
+ throw new NullPointerException(HttpServerText.get().servletMustNotBeNull);
if (httpServlet != null)
- throw new IllegalStateException("servlet was already bound");
+ throw new IllegalStateException(HttpServerText.get().servletWasAlreadyBound);
httpServlet = servlet;
}
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/ServiceNotAuthorizedException.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/ServiceNotAuthorizedException.java
index fca044a10c..6c9bf693d3 100644
--- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/ServiceNotAuthorizedException.java
+++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/ServiceNotAuthorizedException.java
@@ -43,12 +43,14 @@
package org.eclipse.jgit.http.server.resolver;
+import org.eclipse.jgit.http.server.HttpServerText;
+
/** Indicates the request service is not authorized for current user. */
public class ServiceNotAuthorizedException extends Exception {
private static final long serialVersionUID = 1L;
/** Indicates the request service is not available. */
public ServiceNotAuthorizedException() {
- super("Service not permitted");
+ super(HttpServerText.get().serviceNotPermitted);
}
}
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/ServiceNotEnabledException.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/ServiceNotEnabledException.java
index dedc0d4825..adc132df3d 100644
--- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/ServiceNotEnabledException.java
+++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/ServiceNotEnabledException.java
@@ -43,12 +43,14 @@
package org.eclipse.jgit.http.server.resolver;
+import org.eclipse.jgit.http.server.HttpServerText;
+
/** Indicates the request service is not enabled on a repository. */
public class ServiceNotEnabledException extends Exception {
private static final long serialVersionUID = 1L;
/** Indicates the request service is not available. */
public ServiceNotEnabledException() {
- super("Service not enabled");
+ super(HttpServerText.get().serviceNotEnabled);
}
}