Skip to content

Commit

Permalink
formating
Browse files Browse the repository at this point in the history
  • Loading branch information
LinneyS committed Nov 13, 2017
1 parent b7dadf7 commit b21190d
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 19 deletions.
3 changes: 2 additions & 1 deletion src/main/java/onlyoffice/AuthContext.java
Expand Up @@ -18,7 +18,8 @@ public class AuthContext
public static boolean checkUserAuthorisation(HttpServletRequest request, HttpServletResponse response) throws IOException
{
Principal principal = request.getUserPrincipal();
if (principal == null) {
if (principal == null)
{
log.error("User is not authenticated");
String fullUrl = getLoginUrl(request);
response.sendRedirect(fullUrl);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/onlyoffice/ConfigurationManager.java
Expand Up @@ -11,7 +11,8 @@ public Properties GetProperties() throws IOException
{
Properties properties = new Properties();
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("onlyoffice-config.properties");
if (inputStream != null) {
if (inputStream != null)
{
properties.load(inputStream);
}
return properties;
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/onlyoffice/DocumentManager.java
Expand Up @@ -37,7 +37,9 @@ public static long GetMaxFileSize()
Properties properties = configurationManager.GetProperties();
String filesizeMax = properties.getProperty("filesize-max");
size = Long.parseLong(filesizeMax);
} catch (Exception ex) {
}
catch (Exception ex)
{
size = 0;
}

Expand All @@ -53,7 +55,9 @@ public static List<String> GetEditedExts()
String exts = properties.getProperty("files.docservice.edited-docs");

return Arrays.asList(exts.split("\\|"));
} catch (IOException e) {
}
catch (IOException e)
{
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
Expand All @@ -67,7 +71,8 @@ public static String GetExternalUri(Long attachmentId, String documentStorageUrl
String key = getKeyOfFile(attachmentId);
String externalUri;

if (CacheMap.containsKey(key)) {
if (CacheMap.containsKey(key))
{
externalUri = CacheMap.get(key);
log.info("externalUri from cache " + externalUri);
return externalUri;
Expand Down Expand Up @@ -128,7 +133,9 @@ public static String CreateHash(String str)

String base64 = Base64.getEncoder().encodeToString(payload.getBytes("UTF-8"));
return base64;
} catch (Exception ex) {
}
catch (Exception ex)
{
log.error(ex);
}
return "";
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/onlyoffice/OnlyOfficeConfServlet.java
Expand Up @@ -69,7 +69,8 @@ public void doGet(HttpServletRequest request, HttpServletResponse response)

PluginSettings pluginSettings = pluginSettingsFactory.createGlobalSettings();
String apiUrl = (String) pluginSettings.get("onlyoffice.apiUrl");
if (apiUrl == null || apiUrl.isEmpty()) {
if (apiUrl == null || apiUrl.isEmpty())
{
apiUrl = "";
}

Expand Down Expand Up @@ -114,7 +115,9 @@ public void doPost(HttpServletRequest request, HttpServletResponse response)
JSONObject jsonObj = new JSONObject(body);

apiUrl = jsonObj.getString("apiUrl");
} catch (Exception ex) {
}
catch (Exception ex)
{
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ex.printStackTrace(pw);
Expand All @@ -135,11 +138,14 @@ private String getBody(InputStream stream)
{
Scanner scanner = null;
Scanner scannerUseDelimiter = null;
try {
try
{
scanner = new Scanner(stream);
scannerUseDelimiter = scanner.useDelimiter("\\A");
return scanner.hasNext() ? scanner.next() : "";
} finally {
}
finally
{
scannerUseDelimiter.close();
scanner.close();
}
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/onlyoffice/OnlyOfficeEditorServlet.java
Expand Up @@ -49,13 +49,15 @@ public OnlyOfficeEditorServlet(PluginSettingsFactory pluginSettingsFactory)
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
if (!AuthContext.checkUserAuthorisation(request, response)) {
if (!AuthContext.checkUserAuthorisation(request, response))
{
return;
}

PluginSettings pluginSettings = pluginSettingsFactory.createGlobalSettings();
String apiUrl = (String) pluginSettings.get("onlyoffice.apiUrl");
if (apiUrl == null || apiUrl.isEmpty()) {
if (apiUrl == null || apiUrl.isEmpty())
{
apiUrl = "";
}

Expand All @@ -72,7 +74,8 @@ public void doGet(HttpServletRequest request, HttpServletResponse response)
String attachmentIdString = request.getParameter("attachmentId");
Long attachmentId;

try {
try
{
attachmentId = Long.parseLong(attachmentIdString);
log.info("attachmentId " + attachmentId);

Expand All @@ -90,11 +93,15 @@ public void doGet(HttpServletRequest request, HttpServletResponse response)
{
callbackUrl = DocumentManager.getCallbackUrl(attachmentId);
}
} else {
}
else
{
log.error("access deny");
errorMessage = "You don not have enough permission to view the file";
}
} catch (Exception ex) {
}
catch (Exception ex)
{
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ex.printStackTrace(pw);
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/onlyoffice/OnlyOfficeSaveFileServlet.java
Expand Up @@ -109,15 +109,19 @@ private boolean processData(String attachmentIdString, InputStream requestStream
}

return true;
} catch (Exception ex) {
}
catch (Exception ex)
{
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ex.printStackTrace(pw);
String error = ex.toString() + "\n" + sw.toString();
log.error(error);

return false;
} finally {
}
finally
{
if (connection != null)
{
connection.disconnect();
Expand All @@ -129,11 +133,14 @@ private String getBody(InputStream stream)
{
Scanner scanner = null;
Scanner scannerUseDelimiter = null;
try {
try
{
scanner = new Scanner(stream);
scannerUseDelimiter = scanner.useDelimiter("\\A");
return scanner.hasNext() ? scanner.next() : "";
} finally {
}
finally
{
scannerUseDelimiter.close();
scanner.close();
}
Expand Down

0 comments on commit b21190d

Please sign in to comment.