Skip to content

Commit

Permalink
Merge pull request #12 from indigo-dc/devel
Browse files Browse the repository at this point in the history
Adapted to google chesktyle and SSL bugfix
  • Loading branch information
Alfonso Pérez committed Apr 6, 2016
2 parents f06f129 + 0c5ab6c commit c29724c
Show file tree
Hide file tree
Showing 31 changed files with 2,338 additions and 1,885 deletions.
7 changes: 7 additions & 0 deletions .checkstyle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false">
<fileset name="all" enabled="true" check-config-name="Google Checks" local="false">
<file-match-pattern match-pattern="." include-pattern="true"/>
</fileset>
</fileset-config>
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>es.upv.i3m.grycap</groupId>
<artifactId>im-java-api</artifactId>
<version>0.3.0</version>
<version>0.3.1</version>
<name>IM Java API</name>
<description>Java client for the REST API of the IM</description>

Expand Down
42 changes: 42 additions & 0 deletions src/main/java/es/upv/i3m/grycap/file/EscapedNewLinesFile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Copyright (C) GRyCAP - I3M - UPV
*
* <p>Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* <p>http://www.apache.org/licenses/LICENSE-2.0
*
* <p>Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package es.upv.i3m.grycap.file;

import es.upv.i3m.grycap.im.exceptions.FileException;

public final class EscapedNewLinesFile implements File {

private final File file;

public EscapedNewLinesFile(final File file) {
this.file = file;
}

/**
* Read the file specified and escapes all the new lines (i.e. replace all the
* '\n' with '\\n').
*
* @return : String with the newlines replaced
* @throws FileException
* : file related exception
*/
@Override
public String read() throws FileException {
return this.file.read().replace("\n", "\\n");
}

}
25 changes: 25 additions & 0 deletions src/main/java/es/upv/i3m/grycap/file/File.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (C) GRyCAP - I3M - UPV
*
* <p>Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* <p>http://www.apache.org/licenses/LICENSE-2.0
*
* <p>Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package es.upv.i3m.grycap.file;

import es.upv.i3m.grycap.im.exceptions.FileException;

public interface File {

public String read() throws FileException;

}
74 changes: 0 additions & 74 deletions src/main/java/es/upv/i3m/grycap/file/FileIO.java

This file was deleted.

51 changes: 51 additions & 0 deletions src/main/java/es/upv/i3m/grycap/file/NoNullOrEmptyFile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Copyright (C) GRyCAP - I3M - UPV
*
* <p>Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* <p>http://www.apache.org/licenses/LICENSE-2.0
*
* <p>Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package es.upv.i3m.grycap.file;

import es.upv.i3m.grycap.im.exceptions.AuthorizationFileException;
import es.upv.i3m.grycap.im.exceptions.FileException;
import es.upv.i3m.grycap.im.lang.ImMessages;
import es.upv.i3m.grycap.logger.ImJavaApiLogger;

public final class NoNullOrEmptyFile implements File {

private final File file;

public NoNullOrEmptyFile(final File file) {
this.file = file;
}

/**
* Read the file specified and checks that the file is not null or empty.
*
* @return : String with the content of the file
* @throws FileException
* : file related exception
*/
@Override
public String read() throws FileException {
String fileContent = this.file.read();
if (fileContent == null || fileContent.isEmpty()) {
ImJavaApiLogger.severe(this.getClass(),
ImMessages.EXCEPTION_AUTHORIZATION_NULL_OR_EMPTY);
throw new AuthorizationFileException(
ImMessages.EXCEPTION_AUTHORIZATION_NULL_OR_EMPTY);
}
return fileContent;
}

}
57 changes: 57 additions & 0 deletions src/main/java/es/upv/i3m/grycap/file/Utf8File.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Copyright (C) GRyCAP - I3M - UPV
*
* <p>Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* <p>http://www.apache.org/licenses/LICENSE-2.0
*
* <p>Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package es.upv.i3m.grycap.file;

import es.upv.i3m.grycap.im.exceptions.FileException;
import es.upv.i3m.grycap.im.lang.ImMessages;
import es.upv.i3m.grycap.logger.ImJavaApiLogger;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;

public final class Utf8File implements File {

private String filePath;

public Utf8File(final String filePath) {
this.filePath = filePath;
}

/**
* Read the file specified by the path parameter using the standard charset
* UTF8.
*
* @return : String with the loaded file
* @throws FileException
* : file related exception
*/
@Override
public String read() throws FileException {
try {
return new String(Files.readAllBytes(Paths.get(this.filePath)),
StandardCharsets.UTF_8);
} catch (IOException ex) {
ImJavaApiLogger.severe(this.getClass(),
ImMessages.EXCEPTION_READING_AUTHORIZATION_FILE);
throw new FileException(ImMessages.EXCEPTION_READING_AUTHORIZATION_FILE,
ex);
}
}

}
79 changes: 43 additions & 36 deletions src/main/java/es/upv/i3m/grycap/im/api/ImValues.java
Original file line number Diff line number Diff line change
@@ -1,63 +1,70 @@
/**
* Copyright (C) GRyCAP - I3M - UPV
*
* Licensed under the Apache License, Version 2.0 (the "License");
* <p>Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* <p>http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* <p>Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package es.upv.i3m.grycap.im.api;

import es.upv.i3m.grycap.im.exceptions.NoEnumFoundException;
import es.upv.i3m.grycap.im.lang.ImMessages;

/**
* Enumerates static values related with the Infrastructure.<br>
*/
public enum ImValues {

START("start"),
STOP("stop"),
CONTMSG("contmsg"),
RADL("radl"),
STATE("state"),
RECONFIGURE("reconfigure");
START("start"),
STOP("stop"),
CONTMSG("contmsg"),
RADL("radl"),
STATE("state"),
RECONFIGURE("reconfigure");

private final String value;
private final String value;

ImValues(String value) {
this.value = value;
}
ImValues(String value) {
this.value = value;
}

@Override
public String toString() {
return getValue();
}
@Override
public String toString() {
return getValue();
}

public String getValue() {
return value;
}
public String getValue() {
return value;
}

/**
* Returns a ImValue if the String passed is the same as one of the states
* of the enum<br>
*
* @param value
* : string of the value to retrieve
* @return A ImValue, null if not found.
*/
public static ImValues getEnumFromValue(String value) {
if (value != null) {
for (ImValues imValue : ImValues.values()) {
if (value.equalsIgnoreCase(imValue.getValue())) {
return imValue;
}
}
/**
* Returns a ImValue if the String passed is the same as one of the states of
* the enum<br>
*
* @param value
* : string of the value to retrieve
* @return A ImValue, null if not found.
* @throws NoEnumFoundException
* : No enumerator found
*/
public static ImValues getEnumFromValue(String value)
throws NoEnumFoundException {
if (value != null) {
for (ImValues imValue : ImValues.values()) {
if (value.equalsIgnoreCase(imValue.getValue())) {
return imValue;
}
return null;
}
}
throw new NoEnumFoundException(ImMessages.EXCEPTION_NO_IM_VALUE_ENUM_FOUND);
}
}
Loading

0 comments on commit c29724c

Please sign in to comment.