diff options
Diffstat (limited to 'server/src/main/java/com/vaadin')
11 files changed, 49 insertions, 29 deletions
diff --git a/server/src/main/java/com/vaadin/server/BootstrapHandler.java b/server/src/main/java/com/vaadin/server/BootstrapHandler.java index 6b43dc3a64..ed6778bf53 100644 --- a/server/src/main/java/com/vaadin/server/BootstrapHandler.java +++ b/server/src/main/java/com/vaadin/server/BootstrapHandler.java @@ -16,6 +16,8 @@ package com.vaadin.server; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.BufferedWriter; import java.io.IOException; import java.io.OutputStreamWriter; @@ -323,7 +325,8 @@ public abstract class BootstrapHandler extends SynchronizedRequestHandler { protected String encodeQueryStringParameterValue(String queryString) { String encodedString = null; try { - encodedString = URLEncoder.encode(queryString, "UTF-8"); + encodedString = URLEncoder.encode(queryString, + UTF_8.name()); } catch (UnsupportedEncodingException e) { // should never happen throw new RuntimeException("Could not find UTF-8", e); @@ -495,7 +498,7 @@ public abstract class BootstrapHandler extends SynchronizedRequestHandler { response.setContentType( ApplicationConstants.CONTENT_TYPE_TEXT_HTML_UTF_8); try (BufferedWriter writer = new BufferedWriter( - new OutputStreamWriter(response.getOutputStream(), "UTF-8"))) { + new OutputStreamWriter(response.getOutputStream(), UTF_8))) { writer.append(html); } } @@ -517,7 +520,8 @@ public abstract class BootstrapHandler extends SynchronizedRequestHandler { "content", ApplicationConstants.CONTENT_TYPE_TEXT_HTML_UTF_8); // Force IE 11 to use IE 11 mode. - head.appendElement("meta").attr("http-equiv", "X-UA-Compatible").attr("content", "IE=11"); + head.appendElement("meta").attr("http-equiv", "X-UA-Compatible") + .attr("content", "IE=11"); Class<? extends UI> uiClass = context.getUIClass(); diff --git a/server/src/main/java/com/vaadin/server/ResourceReference.java b/server/src/main/java/com/vaadin/server/ResourceReference.java index 1ff5f13706..a5a3520eae 100644 --- a/server/src/main/java/com/vaadin/server/ResourceReference.java +++ b/server/src/main/java/com/vaadin/server/ResourceReference.java @@ -15,6 +15,8 @@ */ package com.vaadin.server; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.UnsupportedEncodingException; import java.net.URLEncoder; @@ -102,7 +104,7 @@ public class ResourceReference extends URLReference { static String urlEncode(String filename) { try { - return URLEncoder.encode(filename, "UTF-8"); + return URLEncoder.encode(filename, UTF_8.name()); } catch (UnsupportedEncodingException e) { throw new RuntimeException( "UTF-8 charset not available (\"this should never happen\")", diff --git a/server/src/main/java/com/vaadin/server/VaadinService.java b/server/src/main/java/com/vaadin/server/VaadinService.java index ba1ecf6740..509b29f9d3 100644 --- a/server/src/main/java/com/vaadin/server/VaadinService.java +++ b/server/src/main/java/com/vaadin/server/VaadinService.java @@ -16,6 +16,8 @@ package com.vaadin.server; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.BufferedWriter; import java.io.File; import java.io.IOException; @@ -1664,7 +1666,7 @@ public abstract class VaadinService implements Serializable { final OutputStream out = response.getOutputStream(); try (PrintWriter outWriter = new PrintWriter( - new BufferedWriter(new OutputStreamWriter(out, "UTF-8")))) { + new BufferedWriter(new OutputStreamWriter(out, UTF_8)))) { outWriter.print(reponseString); } } diff --git a/server/src/main/java/com/vaadin/server/VaadinServlet.java b/server/src/main/java/com/vaadin/server/VaadinServlet.java index 7f2edbfbfd..62bfeb0207 100644 --- a/server/src/main/java/com/vaadin/server/VaadinServlet.java +++ b/server/src/main/java/com/vaadin/server/VaadinServlet.java @@ -15,6 +15,8 @@ */ package com.vaadin.server; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; @@ -306,12 +308,13 @@ public class VaadinServlet extends HttpServlet implements Constants { * @return the created deployment configuration * * @throws ServletException - * if construction of the {@link Properties} for - * {@link #createDeploymentConfiguration(Properties)} fails + * if construction of the {@link Properties} for + * {@link #createDeploymentConfiguration(Properties)} fails * * @since 8.2 */ - protected DeploymentConfiguration createDeploymentConfiguration() throws ServletException { + protected DeploymentConfiguration createDeploymentConfiguration() + throws ServletException { Properties initParameters = new Properties(); readUiFromEnclosingClass(initParameters); @@ -363,9 +366,9 @@ public class VaadinServlet extends HttpServlet implements Constants { * @return the created vaadin servlet service * * @throws ServletException - * if creating a deployment configuration fails + * if creating a deployment configuration fails * @throws ServiceException - * if creating the vaadin servlet service fails + * if creating the vaadin servlet service fails * * @since 8.2 */ @@ -383,7 +386,7 @@ public class VaadinServlet extends HttpServlet implements Constants { * @return the created vaadin servlet service * * @throws ServiceException - * if creating the vaadin servlet service fails + * if creating the vaadin servlet service fails * * @since 7.0.0 */ @@ -667,7 +670,7 @@ public class VaadinServlet extends HttpServlet implements Constants { final OutputStream out = response.getOutputStream(); try ( // Set the response type PrintWriter outWriter = new PrintWriter(new BufferedWriter( - new OutputStreamWriter(out, "UTF-8")))) { + new OutputStreamWriter(out, UTF_8)))) { outWriter.print(output); outWriter.flush(); } @@ -1396,7 +1399,8 @@ public class VaadinServlet extends HttpServlet implements Constants { + request.getServerName() + (request.isSecure() && request.getServerPort() == 443 || !request.isSecure() && request.getServerPort() == 80 - ? "" : ":" + request.getServerPort()) + ? "" + : ":" + request.getServerPort()) + request.getRequestURI()); String servletPath = ""; if (request diff --git a/server/src/main/java/com/vaadin/server/communication/FileUploadHandler.java b/server/src/main/java/com/vaadin/server/communication/FileUploadHandler.java index fb02819c23..1323bb1eaa 100644 --- a/server/src/main/java/com/vaadin/server/communication/FileUploadHandler.java +++ b/server/src/main/java/com/vaadin/server/communication/FileUploadHandler.java @@ -16,6 +16,8 @@ package com.vaadin.server.communication; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.BufferedWriter; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -226,8 +228,6 @@ public class FileUploadHandler implements RequestHandler { private static final String CRLF = "\r\n"; - private static final String UTF8 = "UTF-8"; - private static final String DASHDASH = "--"; /* @@ -315,7 +315,7 @@ public class FileUploadHandler implements RequestHandler { readByte = stream.read(); } byte[] bytes = bout.toByteArray(); - return new String(bytes, 0, bytes.length - 1, UTF8); + return new String(bytes, 0, bytes.length - 1, UTF_8); } /** @@ -368,7 +368,7 @@ public class FileUploadHandler implements RequestHandler { */ while (!atStart) { String readLine = readLine(inputStream); - contentLength -= (readLine.getBytes(UTF8).length + CRLF.length()); + contentLength -= (readLine.getBytes(UTF_8).length + CRLF.length()); if (readLine.startsWith("Content-Disposition:") && readLine.indexOf("filename=") > 0) { rawfilename = readLine.replaceAll(".*filename=", ""); @@ -686,7 +686,7 @@ public class FileUploadHandler implements RequestHandler { ApplicationConstants.CONTENT_TYPE_TEXT_HTML_UTF_8); try (OutputStream out = response.getOutputStream()) { final PrintWriter outWriter = new PrintWriter( - new BufferedWriter(new OutputStreamWriter(out, "UTF-8"))); + new BufferedWriter(new OutputStreamWriter(out, UTF_8))); outWriter.print("<html><body>download handled</body></html>"); outWriter.flush(); } diff --git a/server/src/main/java/com/vaadin/server/communication/PortletDummyRequestHandler.java b/server/src/main/java/com/vaadin/server/communication/PortletDummyRequestHandler.java index a3e3fac898..3ff0cf0c65 100644 --- a/server/src/main/java/com/vaadin/server/communication/PortletDummyRequestHandler.java +++ b/server/src/main/java/com/vaadin/server/communication/PortletDummyRequestHandler.java @@ -15,6 +15,8 @@ */ package com.vaadin.server.communication; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.BufferedWriter; import java.io.IOException; import java.io.OutputStream; @@ -61,7 +63,7 @@ public class PortletDummyRequestHandler implements RequestHandler { final OutputStream out = ((ResourceResponse) response) .getPortletOutputStream(); try (PrintWriter outWriter = new PrintWriter( - new BufferedWriter(new OutputStreamWriter(out, "UTF-8")))) { + new BufferedWriter(new OutputStreamWriter(out, UTF_8)))) { outWriter.print("<html><body>dummy page</body></html>"); } diff --git a/server/src/main/java/com/vaadin/server/communication/UIInitHandler.java b/server/src/main/java/com/vaadin/server/communication/UIInitHandler.java index 02b0637af8..c2992fc29c 100644 --- a/server/src/main/java/com/vaadin/server/communication/UIInitHandler.java +++ b/server/src/main/java/com/vaadin/server/communication/UIInitHandler.java @@ -16,6 +16,8 @@ package com.vaadin.server.communication; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.IOException; import java.io.OutputStream; import java.io.StringWriter; @@ -111,7 +113,7 @@ public abstract class UIInitHandler extends SynchronizedRequestHandler { // iOS 6 Safari requires this (#9732) response.setHeader("Cache-Control", "no-cache"); - byte[] b = json.getBytes("UTF-8"); + byte[] b = json.getBytes(UTF_8); response.setContentLength(b.length); OutputStream outputStream = response.getOutputStream(); diff --git a/server/src/main/java/com/vaadin/ui/CustomLayout.java b/server/src/main/java/com/vaadin/ui/CustomLayout.java index 76107d7992..2026038316 100644 --- a/server/src/main/java/com/vaadin/ui/CustomLayout.java +++ b/server/src/main/java/com/vaadin/ui/CustomLayout.java @@ -16,6 +16,8 @@ package com.vaadin.ui; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -113,7 +115,7 @@ public class CustomLayout extends AbstractLayout implements LegacyComponent { protected void initTemplateContentsFromInputStream( InputStream templateStream) throws IOException { BufferedReader reader = new BufferedReader( - new InputStreamReader(templateStream, "UTF-8")); + new InputStreamReader(templateStream, UTF_8)); StringBuilder builder = new StringBuilder(BUFFER_SIZE); try { char[] cbuf = new char[BUFFER_SIZE]; diff --git a/server/src/main/java/com/vaadin/ui/UI.java b/server/src/main/java/com/vaadin/ui/UI.java index 5c89c7f040..5a8c87f48f 100644 --- a/server/src/main/java/com/vaadin/ui/UI.java +++ b/server/src/main/java/com/vaadin/ui/UI.java @@ -16,6 +16,8 @@ package com.vaadin.ui; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.lang.reflect.Method; @@ -249,7 +251,7 @@ public abstract class UI extends AbstractSingleComponentContainer Design.write((Component) connector, baos); getLogger().info("Design for " + connector + " requested from debug window:\n" - + baos.toString("UTF-8")); + + baos.toString(UTF_8.name())); } catch (IOException e) { getLogger().log(Level.WARNING, "Error producing design for " + connector, e); diff --git a/server/src/main/java/com/vaadin/ui/declarative/Design.java b/server/src/main/java/com/vaadin/ui/declarative/Design.java index 761ce3c355..65565eb47a 100644 --- a/server/src/main/java/com/vaadin/ui/declarative/Design.java +++ b/server/src/main/java/com/vaadin/ui/declarative/Design.java @@ -15,6 +15,8 @@ */ package com.vaadin.ui.declarative; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.beans.IntrospectionException; import java.io.IOException; import java.io.InputStream; @@ -67,8 +69,6 @@ import com.vaadin.util.ReflectTools; */ public class Design implements Serializable { - private static final String UTF8 = "UTF-8"; - /** * Callback for creating instances of a given component class when reading * designs. The default implementation, {@link DefaultComponentFactory} will @@ -392,7 +392,8 @@ public class Design implements Serializable { */ private static Document parse(InputStream html) { try { - Document doc = Jsoup.parse(html, UTF8, "", Parser.htmlParser()); + Document doc = Jsoup.parse(html, UTF_8.name(), "", + Parser.htmlParser()); return doc; } catch (IOException e) { throw new DesignException("The html document cannot be parsed."); @@ -808,7 +809,7 @@ public class Design implements Serializable { doc.outputSettings().indentAmount(4); doc.outputSettings().syntax(Syntax.html); doc.outputSettings().prettyPrint(true); - outputStream.write(doc.html().getBytes(UTF8)); + outputStream.write(doc.html().getBytes(UTF_8)); } private Design() { diff --git a/server/src/main/java/com/vaadin/util/EncodeUtil.java b/server/src/main/java/com/vaadin/util/EncodeUtil.java index 68cdb600e1..19cade5a47 100644 --- a/server/src/main/java/com/vaadin/util/EncodeUtil.java +++ b/server/src/main/java/com/vaadin/util/EncodeUtil.java @@ -15,7 +15,7 @@ */ package com.vaadin.util; -import java.nio.charset.Charset; +import static java.nio.charset.StandardCharsets.UTF_8; /** * Utilities related to various encoding schemes. @@ -24,7 +24,6 @@ import java.nio.charset.Charset; * @since 7.7.7 */ public final class EncodeUtil { - private static final Charset UTF8 = Charset.forName("UTF-8"); private EncodeUtil() { // Static utils only @@ -49,7 +48,7 @@ public final class EncodeUtil { // Create string from a single code point String cpAsString = new String(new int[] { cp }, 0, 1); - appendHexBytes(builder, cpAsString.getBytes(UTF8)); + appendHexBytes(builder, cpAsString.getBytes(UTF_8)); } // Advance to the next code point |