fixed sonar findings
This commit is contained in:
@ -6,12 +6,7 @@ package de.muehlencord.shared.configuration;
|
|||||||
*/
|
*/
|
||||||
public class ConfigurationException extends Exception {
|
public class ConfigurationException extends Exception {
|
||||||
|
|
||||||
/**
|
private static final long serialVersionUID = 2714239259852576278L;
|
||||||
* Creates a new instance of
|
|
||||||
* <code>ParameterException</code> without detail message.
|
|
||||||
*/
|
|
||||||
public ConfigurationException() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an instance of
|
* Constructs an instance of
|
||||||
|
|||||||
@ -6,12 +6,8 @@ package de.muehlencord.shared.configuration;
|
|||||||
*/
|
*/
|
||||||
public class ConverterException extends Exception {
|
public class ConverterException extends Exception {
|
||||||
|
|
||||||
/**
|
private static final long serialVersionUID = 3587621400600640847L;
|
||||||
* Creates a new instance of
|
|
||||||
* <code>ConverterException</code> without detail message.
|
|
||||||
*/
|
|
||||||
public ConverterException() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an instance of
|
* Constructs an instance of
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package de.muehlencord.shared.configuration;
|
package de.muehlencord.shared.configuration;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
@ -121,7 +122,7 @@ public abstract class Parameter<T> {
|
|||||||
* @return the list of parameters the given parameter requires
|
* @return the list of parameters the given parameter requires
|
||||||
*/
|
*/
|
||||||
public List<Parameter<?>> getRequiredParameter() {
|
public List<Parameter<?>> getRequiredParameter() {
|
||||||
return requiredParameters;
|
return new ArrayList<>(requiredParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -149,10 +150,9 @@ public abstract class Parameter<T> {
|
|||||||
if (o == null) {
|
if (o == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (o instanceof Parameter) {
|
if (o.getClass() == this.getClass()) {
|
||||||
Parameter param = (Parameter) o;
|
Parameter param = (Parameter) o;
|
||||||
return param.getName().equals(getName());
|
return param.getName().equals(getName());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,12 +6,8 @@ package de.muehlencord.shared.configuration;
|
|||||||
*/
|
*/
|
||||||
public class ValidationException extends Exception {
|
public class ValidationException extends Exception {
|
||||||
|
|
||||||
/**
|
private static final long serialVersionUID = -5137890709720975939L;
|
||||||
* Creates a new instance of
|
|
||||||
* <code>ValidationException</code> without detail message.
|
|
||||||
*/
|
|
||||||
public ValidationException() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an instance of
|
* Constructs an instance of
|
||||||
|
|||||||
@ -1,38 +0,0 @@
|
|||||||
package de.muehlencord.shared.configuration;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
import junit.framework.TestSuite;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unit test for simple App.
|
|
||||||
*/
|
|
||||||
public class AppTest
|
|
||||||
extends TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Create the test case
|
|
||||||
*
|
|
||||||
* @param testName name of the test case
|
|
||||||
*/
|
|
||||||
public AppTest( String testName )
|
|
||||||
{
|
|
||||||
super( testName );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the suite of tests being tested
|
|
||||||
*/
|
|
||||||
public static Test suite()
|
|
||||||
{
|
|
||||||
return new TestSuite( AppTest.class );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rigourous Test :-)
|
|
||||||
*/
|
|
||||||
public void testApp()
|
|
||||||
{
|
|
||||||
assertTrue( true );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -19,7 +19,7 @@ public class IpInformation {
|
|||||||
|
|
||||||
/* *** getter / setter *** */
|
/* *** getter / setter *** */
|
||||||
public List<PortInformation> getPortInformation() {
|
public List<PortInformation> getPortInformation() {
|
||||||
return portInformation;
|
return new ArrayList<>(portInformation);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PortInformation> getOpenPorts() {
|
public List<PortInformation> getOpenPorts() {
|
||||||
@ -34,7 +34,7 @@ public class IpInformation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setPortInformation(List<PortInformation> portInformation) {
|
public void setPortInformation(List<PortInformation> portInformation) {
|
||||||
this.portInformation = portInformation;
|
this.portInformation = new ArrayList<>(portInformation);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIpAddress() {
|
public String getIpAddress() {
|
||||||
|
|||||||
@ -16,7 +16,7 @@ public class NetworkScanner {
|
|||||||
private final static Logger LOGGER = LogManager.getLogger(NetworkScanner.class);
|
private final static Logger LOGGER = LogManager.getLogger(NetworkScanner.class);
|
||||||
|
|
||||||
private String networkString;
|
private String networkString;
|
||||||
private NetworkInformation networkInformation = null; // TODO add scan for information
|
// private NetworkInformation networkInformation = null; // TODO add scan for information
|
||||||
private List<IpInformation> ipinformationList = new ArrayList<>();
|
private List<IpInformation> ipinformationList = new ArrayList<>();
|
||||||
|
|
||||||
public NetworkScanner(String network) {
|
public NetworkScanner(String network) {
|
||||||
@ -43,7 +43,7 @@ public class NetworkScanner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<IpInformation> getIpsInNetwork() {
|
public List<IpInformation> getIpsInNetwork() {
|
||||||
return ipinformationList;
|
return new ArrayList<>(ipinformationList);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean atLeastOnePortOpen(List<PortInformation> portInformation) {
|
private boolean atLeastOnePortOpen(List<PortInformation> portInformation) {
|
||||||
|
|||||||
@ -1,7 +1,3 @@
|
|||||||
/*
|
|
||||||
* To change this template, choose Tools | Templates
|
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
|
||||||
package de.muehlencord.shared.network.ftp;
|
package de.muehlencord.shared.network.ftp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -10,17 +6,8 @@ package de.muehlencord.shared.network.ftp;
|
|||||||
*/
|
*/
|
||||||
public class FTPConnectionException extends Exception {
|
public class FTPConnectionException extends Exception {
|
||||||
|
|
||||||
/**
|
private static final long serialVersionUID = 1001347648193052240L;
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static final long serialVersionUID = 4393979078434188521L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new instance of
|
|
||||||
* <code>FTPConnectionException</code> without detail message.
|
|
||||||
*/
|
|
||||||
public FTPConnectionException() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an instance of
|
* Constructs an instance of
|
||||||
|
|||||||
@ -6,17 +6,9 @@ package de.muehlencord.shared.network.http;
|
|||||||
*/
|
*/
|
||||||
public class MessageNotSendException extends Exception {
|
public class MessageNotSendException extends Exception {
|
||||||
|
|
||||||
/**
|
private static final long serialVersionUID = -7720277941333614648L;
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static final long serialVersionUID = -8959773341187046577L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new instance of
|
|
||||||
* <code>MessageNotSendException</code> without detail message.
|
|
||||||
*/
|
|
||||||
public MessageNotSendException() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an instance of
|
* Constructs an instance of
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
*/
|
*/
|
||||||
package de.muehlencord.shared.network.mail;
|
package de.muehlencord.shared.network.mail;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -213,7 +214,7 @@ public class MailMessage {
|
|||||||
* @return the receiver
|
* @return the receiver
|
||||||
*/
|
*/
|
||||||
public List<String> getReceiver() {
|
public List<String> getReceiver() {
|
||||||
return receiver;
|
return new ArrayList<>(receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -249,7 +250,7 @@ public class MailMessage {
|
|||||||
* @return the ccReceiver
|
* @return the ccReceiver
|
||||||
*/
|
*/
|
||||||
public List<String> getCcReceiver() {
|
public List<String> getCcReceiver() {
|
||||||
return ccReceiver;
|
return new ArrayList<>(ccReceiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -276,7 +277,7 @@ public class MailMessage {
|
|||||||
* @return the bccReceiver
|
* @return the bccReceiver
|
||||||
*/
|
*/
|
||||||
public List<String> getBccReceiver() {
|
public List<String> getBccReceiver() {
|
||||||
return bccReceiver;
|
return new ArrayList<>(bccReceiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -6,17 +6,7 @@ package de.muehlencord.shared.network.mail;
|
|||||||
*/
|
*/
|
||||||
public class MailMessageException extends Exception {
|
public class MailMessageException extends Exception {
|
||||||
|
|
||||||
/**
|
private static final long serialVersionUID = -8147768630871997864L;
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static final long serialVersionUID = 6699249884047524285L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new instance of
|
|
||||||
* <code>MailMessageException</code> without detail message.
|
|
||||||
*/
|
|
||||||
public MailMessageException() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an instance of
|
* Constructs an instance of
|
||||||
|
|||||||
@ -27,32 +27,55 @@ import org.apache.logging.log4j.Logger;
|
|||||||
*/
|
*/
|
||||||
public abstract class MailMessageUtils {
|
public abstract class MailMessageUtils {
|
||||||
|
|
||||||
/** the logging object */
|
/**
|
||||||
|
* the logging object
|
||||||
|
*/
|
||||||
private static final Logger LOGGER = LogManager.getLogger(MailMessageUtils.class.getName());
|
private static final Logger LOGGER = LogManager.getLogger(MailMessageUtils.class.getName());
|
||||||
|
|
||||||
/** content type of mutipart messages - e.g. multipart_alternative or _mixed */
|
/**
|
||||||
|
* content type of mutipart messages - e.g. multipart_alternative or _mixed
|
||||||
|
*/
|
||||||
private static final String CONTENTTYPE_MULTIPART = "multipart/";
|
private static final String CONTENTTYPE_MULTIPART = "multipart/";
|
||||||
/** content type of text messages - like text/plain or text/html */
|
/**
|
||||||
|
* content type of text messages - like text/plain or text/html
|
||||||
|
*/
|
||||||
private static final String CONTENTTYPE_TEXT = "text/";
|
private static final String CONTENTTYPE_TEXT = "text/";
|
||||||
/** content type of text/plain messages */
|
/**
|
||||||
|
* content type of text/plain messages
|
||||||
|
*/
|
||||||
private static final String CONTENTTYPE_TEXT_PLAIN = "text/plain";
|
private static final String CONTENTTYPE_TEXT_PLAIN = "text/plain";
|
||||||
/** content type of text/html messages */
|
/**
|
||||||
|
* content type of text/html messages
|
||||||
|
*/
|
||||||
private static final String CONTENTTYPE_TEXT_HTML = "text/html";
|
private static final String CONTENTTYPE_TEXT_HTML = "text/html";
|
||||||
/** content type of application based messages - e.g. application/pdf */
|
/**
|
||||||
|
* content type of application based messages - e.g. application/pdf
|
||||||
|
*/
|
||||||
private static final String CONTENTTYPE_APPLICATION = "application/";
|
private static final String CONTENTTYPE_APPLICATION = "application/";
|
||||||
/** content type of application pgp-signature */
|
/**
|
||||||
|
* content type of application pgp-signature
|
||||||
|
*/
|
||||||
private static final String CONTENTTYPE_APPLICATION_PGPSIGNATURE = "application/pgp-signature";
|
private static final String CONTENTTYPE_APPLICATION_PGPSIGNATURE = "application/pgp-signature";
|
||||||
/** content type of embedded message */
|
/**
|
||||||
|
* content type of embedded message
|
||||||
|
*/
|
||||||
private static final String CONTENTTYPE_MESSAGE = "message/";
|
private static final String CONTENTTYPE_MESSAGE = "message/";
|
||||||
/** content type of attached images */
|
/**
|
||||||
|
* content type of attached images
|
||||||
|
*/
|
||||||
private static final String CONTENTTYPE_IMAGE = "image/";
|
private static final String CONTENTTYPE_IMAGE = "image/";
|
||||||
/** content type of attached videos */
|
/**
|
||||||
|
* content type of attached videos
|
||||||
|
*/
|
||||||
private static final String CONTENTTYPE_VIDEO = "video/";
|
private static final String CONTENTTYPE_VIDEO = "video/";
|
||||||
/** content type of attached audios */
|
/**
|
||||||
|
* content type of attached audios
|
||||||
|
*/
|
||||||
private static final String CONTENTTYPE_AUDIO = "audio/";
|
private static final String CONTENTTYPE_AUDIO = "audio/";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates a new instance of MailMessage based on the given javax.mail.Message object
|
* creates a new instance of MailMessage based on the given
|
||||||
|
* javax.mail.Message object
|
||||||
*
|
*
|
||||||
* @param message the message object to create the message from
|
* @param message the message object to create the message from
|
||||||
* @return the MailMessage object created from the given javax.mail.Message
|
* @return the MailMessage object created from the given javax.mail.Message
|
||||||
@ -172,13 +195,10 @@ public abstract class MailMessageUtils {
|
|||||||
} catch (MailMessageException | IOException | MessagingException ex) {
|
} catch (MailMessageException | IOException | MessagingException ex) {
|
||||||
throw new MailMessageException("Error while converting nested message. Reason: " + ex.getMessage(), ex);
|
throw new MailMessageException("Error while converting nested message. Reason: " + ex.getMessage(), ex);
|
||||||
}
|
}
|
||||||
} else if (contentType.contains(CONTENTTYPE_APPLICATION)) {
|
} else if ((contentType.contains(CONTENTTYPE_APPLICATION)) || (contentType.contains(CONTENTTYPE_TEXT))) {
|
||||||
// message with only attachment
|
// message with only attachment
|
||||||
returnMessage = new MailMessage(subject, "", messageId);
|
returnMessage = new MailMessage(subject, "", messageId);
|
||||||
LOGGER.debug("Found attachment - not yet supported, skipping"); // TODO add attachment
|
LOGGER.debug("Found attachment - not yet supported, skipping"); // TODO add attachment
|
||||||
} else if (contentType.contains(CONTENTTYPE_TEXT)) {
|
|
||||||
returnMessage = new MailMessage(subject, "", messageId);
|
|
||||||
LOGGER.debug("Found attachment - not yet supported, skipping"); // TODO add attachment
|
|
||||||
} else {
|
} else {
|
||||||
String hint = "Unkonwn message format Converting MimeMessage of contentType " + contentType + " not yet implemented.";
|
String hint = "Unkonwn message format Converting MimeMessage of contentType " + contentType + " not yet implemented.";
|
||||||
|
|
||||||
@ -220,8 +240,9 @@ public abstract class MailMessageUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns the content type based on the content-type header. The messad asures the contentype is selected correctly from the string, including trim and
|
* returns the content type based on the content-type header. The messad
|
||||||
* tolower case
|
* asures the contentype is selected correctly from the string, including
|
||||||
|
* trim and tolower case
|
||||||
*
|
*
|
||||||
* @param contentType the contenttype string read from email header
|
* @param contentType the contenttype string read from email header
|
||||||
* @return the content type of the email (small letters)
|
* @return the content type of the email (small letters)
|
||||||
@ -238,8 +259,10 @@ public abstract class MailMessageUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns the content of the given bodypart which needs to be a text based bodypart The method tries to read the messages as it is. In case of an
|
* returns the content of the given bodypart which needs to be a text based
|
||||||
* unsupported encoding it reads the message with the default encoding (accepting "ugly" characters)
|
* bodypart The method tries to read the messages as it is. In case of an
|
||||||
|
* unsupported encoding it reads the message with the default encoding
|
||||||
|
* (accepting "ugly" characters)
|
||||||
*
|
*
|
||||||
* @param bp the body part to read the content from
|
* @param bp the body part to read the content from
|
||||||
* @return the content of the body part
|
* @return the content of the body part
|
||||||
@ -269,8 +292,9 @@ public abstract class MailMessageUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns the content of the given body part by reading the stream directly. This ommits getting unsupported encoding exceptions, as the content is read
|
* returns the content of the given body part by reading the stream
|
||||||
* with the given encoding
|
* directly. This ommits getting unsupported encoding exceptions, as the
|
||||||
|
* content is read with the given encoding
|
||||||
*
|
*
|
||||||
* @param bp the bodypart to read the content from
|
* @param bp the bodypart to read the content from
|
||||||
* @param encoding the encoding to force
|
* @param encoding the encoding to force
|
||||||
@ -332,26 +356,20 @@ public abstract class MailMessageUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns true, if the contentType string is one of the known attachment types.
|
* returns true, if the contentType string is one of the known attachment
|
||||||
|
* types.
|
||||||
*
|
*
|
||||||
* @param contentType the contentType to check
|
* @param contentType the contentType to check
|
||||||
* @return true, if the contentType string is one of the known attachment types. False otherwise.
|
* @return true, if the contentType string is one of the known attachment
|
||||||
|
* types. False otherwise.
|
||||||
*/
|
*/
|
||||||
private static boolean isSupportedAttachmentType(String contentType) {
|
private static boolean isSupportedAttachmentType(String contentType) {
|
||||||
if (contentType.contains(CONTENTTYPE_APPLICATION)) {
|
boolean contentTypeOther = contentType.contains(CONTENTTYPE_APPLICATION)
|
||||||
return true;
|
|| (contentType.contains(CONTENTTYPE_MESSAGE))
|
||||||
} else if (contentType.contains(CONTENTTYPE_MESSAGE)) {
|
|| (contentType.contains(CONTENTTYPE_TEXT));
|
||||||
return true;
|
boolean contentTypeMedia = (contentType.contains(CONTENTTYPE_IMAGE))
|
||||||
} else if (contentType.contains(CONTENTTYPE_TEXT)) {
|
|| (contentType.contains(CONTENTTYPE_VIDEO))
|
||||||
return true;
|
|| (contentType.contains(CONTENTTYPE_AUDIO));
|
||||||
} else if (contentType.contains(CONTENTTYPE_IMAGE)) {
|
return contentTypeOther || contentTypeMedia;
|
||||||
return true;
|
|
||||||
} else if (contentType.contains(CONTENTTYPE_VIDEO)) {
|
|
||||||
return true;
|
|
||||||
} else if (contentType.contains(CONTENTTYPE_AUDIO)) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,17 +6,7 @@ package de.muehlencord.shared.network.mail;
|
|||||||
*/
|
*/
|
||||||
public class MailReaderConfigurationException extends Exception {
|
public class MailReaderConfigurationException extends Exception {
|
||||||
|
|
||||||
/**
|
private static final long serialVersionUID = -2079782382789782710L;
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static final long serialVersionUID = 3874572911465653501L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new instance of
|
|
||||||
* <code>MailReaderConfigurationException</code> without detail message.
|
|
||||||
*/
|
|
||||||
public MailReaderConfigurationException() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an instance of
|
* Constructs an instance of
|
||||||
|
|||||||
@ -14,7 +14,9 @@ import org.apache.logging.log4j.Logger;
|
|||||||
*/
|
*/
|
||||||
public abstract class MailReaderConfigurationFactory {
|
public abstract class MailReaderConfigurationFactory {
|
||||||
|
|
||||||
/** the logging object */
|
/**
|
||||||
|
* the logging object
|
||||||
|
*/
|
||||||
private final static Logger LOGGER = LogManager.getLogger(MailReaderConfigurationFactory.class);
|
private final static Logger LOGGER = LogManager.getLogger(MailReaderConfigurationFactory.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,7 +25,8 @@ public abstract class MailReaderConfigurationFactory {
|
|||||||
* @param configFile the file to read
|
* @param configFile the file to read
|
||||||
* @return the configured MailReaderConfiguration object
|
* @return the configured MailReaderConfiguration object
|
||||||
*
|
*
|
||||||
* @throws MailReaderConfigurationException if the file does not exist or the config cannot be created
|
* @throws MailReaderConfigurationException if the file does not exist or
|
||||||
|
* the config cannot be created
|
||||||
*/
|
*/
|
||||||
public static MailReaderConfiguration getConfiguration(String configFile) throws MailReaderConfigurationException {
|
public static MailReaderConfiguration getConfiguration(String configFile) throws MailReaderConfigurationException {
|
||||||
File f = new File(configFile);
|
File f = new File(configFile);
|
||||||
@ -40,7 +43,9 @@ public abstract class MailReaderConfigurationFactory {
|
|||||||
throw new MailReaderConfigurationException("Error while reading config file. Reason: " + ex.getMessage(), ex);
|
throw new MailReaderConfigurationException("Error while reading config file. Reason: " + ex.getMessage(), ex);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
|
if (is != null) {
|
||||||
is.close();
|
is.close();
|
||||||
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LOGGER.error("Error while reading input file.");
|
LOGGER.error("Error while reading input file.");
|
||||||
LOGGER.debug(StringUtil.getStackTraceString(ex));
|
LOGGER.debug(StringUtil.getStackTraceString(ex));
|
||||||
|
|||||||
@ -1,7 +1,3 @@
|
|||||||
/*
|
|
||||||
* To change this template, choose Tools | Templates
|
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
|
||||||
package de.muehlencord.shared.network.mail;
|
package de.muehlencord.shared.network.mail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -10,17 +6,9 @@ package de.muehlencord.shared.network.mail;
|
|||||||
*/
|
*/
|
||||||
public class MailReaderConnectionException extends Exception {
|
public class MailReaderConnectionException extends Exception {
|
||||||
|
|
||||||
/**
|
private static final long serialVersionUID = -3671887060456354046L;
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static final long serialVersionUID = -1593741665654202661L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new instance of
|
|
||||||
* <code>MailReaderConnectionException</code> without detail message.
|
|
||||||
*/
|
|
||||||
public MailReaderConnectionException() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an instance of
|
* Constructs an instance of
|
||||||
|
|||||||
@ -1,7 +1,3 @@
|
|||||||
/*
|
|
||||||
* To change this template, choose Tools | Templates
|
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
|
||||||
package de.muehlencord.shared.network.mail;
|
package de.muehlencord.shared.network.mail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -10,17 +6,7 @@ package de.muehlencord.shared.network.mail;
|
|||||||
*/
|
*/
|
||||||
public class MailReaderException extends Exception {
|
public class MailReaderException extends Exception {
|
||||||
|
|
||||||
/**
|
private static final long serialVersionUID = -7351011499789639376L;
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static final long serialVersionUID = 4850689622364462635L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new instance of
|
|
||||||
* <code>MailReaderException</code> without detail message.
|
|
||||||
*/
|
|
||||||
public MailReaderException() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an instance of
|
* Constructs an instance of
|
||||||
|
|||||||
@ -2,8 +2,6 @@ package de.muehlencord.shared.network.whois;
|
|||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import org.apache.commons.net.whois.WhoisClient;
|
import org.apache.commons.net.whois.WhoisClient;
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -12,7 +10,7 @@ import org.apache.logging.log4j.Logger;
|
|||||||
public class Whois {
|
public class Whois {
|
||||||
|
|
||||||
/** logger object */
|
/** logger object */
|
||||||
private final static Logger LOGGER = LogManager.getLogger(Whois.class);
|
// private static final Logger LOGGER = LogManager.getLogger(Whois.class);
|
||||||
/** whoisClient client from commons-net package to execute commands with */
|
/** whoisClient client from commons-net package to execute commands with */
|
||||||
WhoisClient whoisClient;
|
WhoisClient whoisClient;
|
||||||
/** the complete output */
|
/** the complete output */
|
||||||
|
|||||||
@ -1,7 +1,3 @@
|
|||||||
/*
|
|
||||||
* To change this template, choose Tools | Templates
|
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
|
||||||
package de.muehlencord.shared.network.whois;
|
package de.muehlencord.shared.network.whois;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -10,12 +6,7 @@ package de.muehlencord.shared.network.whois;
|
|||||||
*/
|
*/
|
||||||
public class WhoisException extends Exception {
|
public class WhoisException extends Exception {
|
||||||
|
|
||||||
/**
|
private static final long serialVersionUID = 8101593509067902021L;
|
||||||
* Creates a new instance of
|
|
||||||
* <code>WhoisException</code> without detail message.
|
|
||||||
*/
|
|
||||||
public WhoisException() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an instance of
|
* Constructs an instance of
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package de.muehlencord.shared.network.whois;
|
package de.muehlencord.shared.network.whois;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -27,28 +28,28 @@ public class WhoisInformation {
|
|||||||
* @return the network
|
* @return the network
|
||||||
*/
|
*/
|
||||||
public List<String> getNetwork() {
|
public List<String> getNetwork() {
|
||||||
return network;
|
return new ArrayList<>(network);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param network the network to set
|
* @param network the network to set
|
||||||
*/
|
*/
|
||||||
public void setNetwork(List<String> network) {
|
public void setNetwork(List<String> network) {
|
||||||
this.network = network;
|
this.network = new ArrayList<>(network);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the rootNetwork
|
* @return the rootNetwork
|
||||||
*/
|
*/
|
||||||
public List<String> getRootNetwork() {
|
public List<String> getRootNetwork() {
|
||||||
return rootNetwork;
|
return new ArrayList<>(rootNetwork);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param rootNetwork the rootNetwork to set
|
* @param rootNetwork the rootNetwork to set
|
||||||
*/
|
*/
|
||||||
public void setRootNetwork(List<String> rootNetwork) {
|
public void setRootNetwork(List<String> rootNetwork) {
|
||||||
this.rootNetwork = rootNetwork;
|
this.rootNetwork = new ArrayList<>(rootNetwork);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import java.io.InputStream;
|
|||||||
*
|
*
|
||||||
* @author joern@muehlencord.de
|
* @author joern@muehlencord.de
|
||||||
*/
|
*/
|
||||||
public class BaseTest {
|
public abstract class BaseTest {
|
||||||
|
|
||||||
public String readContentFromFile(String name) throws IOException {
|
public String readContentFromFile(String name) throws IOException {
|
||||||
|
|
||||||
|
|||||||
@ -10,7 +10,9 @@ import org.apache.commons.codec.binary.Base64;
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author joern@muehlencord.de
|
* @author joern@muehlencord.de
|
||||||
|
* @Deprecated uses old algorithms, do not use this class anylonger
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public abstract class OldPasswordUtil {
|
public abstract class OldPasswordUtil {
|
||||||
|
|
||||||
/** logging object */
|
/** logging object */
|
||||||
|
|||||||
@ -18,11 +18,11 @@ public class PasswordUtil {
|
|||||||
private final static int PARALLELIZATION = 1;
|
private final static int PARALLELIZATION = 1;
|
||||||
private final static int KEY_LENGTH = 32;
|
private final static int KEY_LENGTH = 32;
|
||||||
|
|
||||||
private final String SYSTEMSALT;
|
private final String systemsalt;
|
||||||
|
|
||||||
public PasswordUtil(String systemSaltBase64Coded) {
|
public PasswordUtil(String systemSaltBase64Coded) {
|
||||||
// TODO make some tests like lengths etc
|
// TODO make some tests like lengths etc
|
||||||
this.SYSTEMSALT = systemSaltBase64Coded;
|
this.systemsalt = systemSaltBase64Coded;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHash(String clearPassword) {
|
public String getHash(String clearPassword) {
|
||||||
@ -33,7 +33,7 @@ public class PasswordUtil {
|
|||||||
String userSalt = new String(Base64.encode(userSaltBytes));
|
String userSalt = new String(Base64.encode(userSaltBytes));
|
||||||
|
|
||||||
// create passwordhash with salt
|
// create passwordhash with salt
|
||||||
String passwordHash = getPasswordHash(SYSTEMSALT, userSalt, clearPassword);
|
String passwordHash = getPasswordHash(systemsalt, userSalt, clearPassword);
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append(userSalt);
|
sb.append(userSalt);
|
||||||
@ -52,7 +52,7 @@ public class PasswordUtil {
|
|||||||
String userSalt = passwordHashWithSalt.substring(0, passwordHashWithSalt.indexOf(":"));
|
String userSalt = passwordHashWithSalt.substring(0, passwordHashWithSalt.indexOf(":"));
|
||||||
String passwordHash = passwordHashWithSalt.substring(passwordHashWithSalt.indexOf(":")+1);
|
String passwordHash = passwordHashWithSalt.substring(passwordHashWithSalt.indexOf(":")+1);
|
||||||
|
|
||||||
String validationHash = getPasswordHash(SYSTEMSALT, userSalt, clearPassword);
|
String validationHash = getPasswordHash(systemsalt, userSalt, clearPassword);
|
||||||
return validationHash.equals(passwordHash);
|
return validationHash.equals(passwordHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import java.net.Authenticator;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.security.KeyManagementException;
|
import java.security.KeyManagementException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.security.cert.X509Certificate;
|
||||||
import javax.net.ssl.HttpsURLConnection;
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.SSLContext;
|
||||||
import javax.net.ssl.TrustManager;
|
import javax.net.ssl.TrustManager;
|
||||||
@ -50,13 +51,13 @@ public class SPContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void checkClientTrusted(
|
public void checkClientTrusted(X509Certificate[] certs, String authType) {
|
||||||
java.security.cert.X509Certificate[] certs, String authType) {
|
// trust all SSLs, do not check
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void checkServerTrusted(
|
public void checkServerTrusted(X509Certificate[] certs, String authType) {
|
||||||
java.security.cert.X509Certificate[] certs, String authType) {
|
// trust all SSLs, do not check
|
||||||
}
|
}
|
||||||
}};
|
}};
|
||||||
// Install the all-trusting trust manager
|
// Install the all-trusting trust manager
|
||||||
|
|||||||
@ -9,36 +9,14 @@ import java.util.Date;
|
|||||||
*/
|
*/
|
||||||
public class SPHelper {
|
public class SPHelper {
|
||||||
|
|
||||||
private static final SimpleDateFormat dateOnlyFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
||||||
// private static final SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
|
|
||||||
|
|
||||||
/* -- Format for Date Only Field -- */
|
/* -- Format for Date Only Field -- */
|
||||||
public static String toSPDate(Date d) {
|
public static synchronized String toSPDate(Date d) {
|
||||||
|
SimpleDateFormat dateOnlyFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
if (d == null) {
|
if (d == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
String result;
|
return dateOnlyFormat.format(d);
|
||||||
synchronized (dateOnlyFormat) {
|
|
||||||
result = dateOnlyFormat.format(d);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -- Format for DateTime Field -- */
|
|
||||||
/*
|
|
||||||
private static String toSPDateAndTime(Date d) {
|
|
||||||
if (d == null) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
String result;
|
|
||||||
|
|
||||||
synchronized (dateTimeFormat) {
|
|
||||||
result = dateTimeFormat.format(d);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,7 +38,7 @@ public abstract class SPJaxbObject<T> extends AbstractSpJaxbObject {
|
|||||||
+ ":de.muehlencord.shared.sharepoint.api.usergroup"; //
|
+ ":de.muehlencord.shared.sharepoint.api.usergroup"; //
|
||||||
|
|
||||||
/** the JAX-B context to use */
|
/** the JAX-B context to use */
|
||||||
private static JAXBContext jaxbContext = null;
|
private static volatile JAXBContext jaxbContext = null;
|
||||||
|
|
||||||
/** the value object */
|
/** the value object */
|
||||||
protected T value;
|
protected T value;
|
||||||
|
|||||||
@ -35,10 +35,8 @@ public class SPValidationEventHandler implements ValidationEventHandler {
|
|||||||
switch (event.getSeverity()) {
|
switch (event.getSeverity()) {
|
||||||
case ValidationEvent.WARNING:
|
case ValidationEvent.WARNING:
|
||||||
return true; // continue after warinings
|
return true; // continue after warinings
|
||||||
case ValidationEvent.ERROR:
|
case ValidationEvent.ERROR: // terminate after errors
|
||||||
return false; // terminate after errors
|
case ValidationEvent.FATAL_ERROR: // terminate after fatal errors
|
||||||
case ValidationEvent.FATAL_ERROR:
|
|
||||||
return false; // terminate after fatal errors
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,9 +38,7 @@ public class SPUser extends SPJaxbObject<User> {
|
|||||||
returnValue = getValue().login;
|
returnValue = getValue().login;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (returnValue == null) {
|
if ((returnValue == null) || (returnValue.equals (""))) {
|
||||||
return null;
|
|
||||||
} else if (returnValue.equals("")) {
|
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
return returnValue.substring(7); // drop [i:0#.w|
|
return returnValue.substring(7); // drop [i:0#.w|
|
||||||
|
|||||||
@ -17,7 +17,7 @@ import org.junit.Before;
|
|||||||
*
|
*
|
||||||
* @author jomu
|
* @author jomu
|
||||||
*/
|
*/
|
||||||
public class BaseTest {
|
public abstract class BaseTest {
|
||||||
|
|
||||||
protected SPContext context = null;
|
protected SPContext context = null;
|
||||||
|
|
||||||
|
|||||||
@ -16,67 +16,67 @@ public class BOM {
|
|||||||
/**
|
/**
|
||||||
* UTF32(Big Endian)
|
* UTF32(Big Endian)
|
||||||
*/
|
*/
|
||||||
public static final int[] BOM_UTF32_BE = {0x00, 0x00, 0xFE, 0xFF}; //
|
protected static final int[] BOM_UTF32_BE = {0x00, 0x00, 0xFE, 0xFF}; //
|
||||||
/**
|
/**
|
||||||
* UTF32(Little Endian)
|
* UTF32(Little Endian)
|
||||||
*/
|
*/
|
||||||
public static final int[] BOM_UTF32_LE = {0xFF, 0xFE, 0x00, 0x00}; //
|
protected static final int[] BOM_UTF32_LE = {0xFF, 0xFE, 0x00, 0x00}; //
|
||||||
/**
|
/**
|
||||||
* UTF-1
|
* UTF-1
|
||||||
*/
|
*/
|
||||||
public static final int[] BOM_UTF1 = {0xF7, 0x64, 0x4C}; // UTF-1
|
protected static final int[] BOM_UTF1 = {0xF7, 0x64, 0x4C}; // UTF-1
|
||||||
/**
|
/**
|
||||||
* UTF7 - version 1
|
* UTF7 - version 1
|
||||||
*/
|
*/
|
||||||
public static final int[] BOM_UTF7_1 = {0x2B, 0x2F, 0x76, 0x38}; // UTF-7
|
protected static final int[] BOM_UTF7_1 = {0x2B, 0x2F, 0x76, 0x38}; // UTF-7
|
||||||
/**
|
/**
|
||||||
* UTF7 - version 2
|
* UTF7 - version 2
|
||||||
*/
|
*/
|
||||||
public static final int[] BOM_UTF7_2 = {0x2B, 0x2F, 0x76, 0x39}; // UTF-7
|
protected static final int[] BOM_UTF7_2 = {0x2B, 0x2F, 0x76, 0x39}; // UTF-7
|
||||||
/**
|
/**
|
||||||
* UTF7 - version 3
|
* UTF7 - version 3
|
||||||
*/
|
*/
|
||||||
public static final int[] BOM_UTF7_3 = {0x2B, 0x2F, 0x76, 0x2B}; // UTF-7
|
protected static final int[] BOM_UTF7_3 = {0x2B, 0x2F, 0x76, 0x2B}; // UTF-7
|
||||||
/**
|
/**
|
||||||
* UTF7 - version 4
|
* UTF7 - version 4
|
||||||
*/
|
*/
|
||||||
public static final int[] BOM_UTF7_4 = {0x2B, 0x2F, 0x76, 0x2F}; // UTF-7
|
protected static final int[] BOM_UTF7_4 = {0x2B, 0x2F, 0x76, 0x2F}; // UTF-7
|
||||||
/**
|
/**
|
||||||
* UTF-EBCDIC
|
* UTF-EBCDIC
|
||||||
*/
|
*/
|
||||||
public static final int[] BOM_UTF_EBCDIC = {0xDD, 0x73, 0x66, 0x73}; // UTF - EBCDIC
|
protected static final int[] BOM_UTF_EBCDIC = {0xDD, 0x73, 0x66, 0x73}; // UTF - EBCDIC
|
||||||
/**
|
/**
|
||||||
* UTF-8
|
* UTF-8
|
||||||
*/
|
*/
|
||||||
public static final int[] BOM_UTF8 = {0xEF, 0xBB, 0xBF}; // UTF-8
|
protected static final int[] BOM_UTF8 = {0xEF, 0xBB, 0xBF}; // UTF-8
|
||||||
/**
|
/**
|
||||||
* SCSU
|
* SCSU
|
||||||
*/
|
*/
|
||||||
public static final int[] BOM_SCSU = {0x0E, 0xFE, 0xFF}; // SCSU
|
protected static final int[] BOM_SCSU = {0x0E, 0xFE, 0xFF}; // SCSU
|
||||||
/**
|
/**
|
||||||
* BOCU-1 - version 1
|
* BOCU-1 - version 1
|
||||||
*/
|
*/
|
||||||
public static final int[] BOM_BOCU1_1 = {0xFB, 0xEE, 0x28}; // BOCU-1
|
protected static final int[] BOM_BOCU1_1 = {0xFB, 0xEE, 0x28}; // BOCU-1
|
||||||
/**
|
/**
|
||||||
* BOCU-2 - version 2
|
* BOCU-2 - version 2
|
||||||
*/
|
*/
|
||||||
public static final int[] BOM_BOCU1_2 = {0xFB, 0xEE, 0x28, 0xFF}; // BOCU-1
|
protected static final int[] BOM_BOCU1_2 = {0xFB, 0xEE, 0x28, 0xFF}; // BOCU-1
|
||||||
/**
|
/**
|
||||||
* UTF-16 - big endian
|
* UTF-16 - big endian
|
||||||
*/
|
*/
|
||||||
public static final int[] BOM_UTF16_BE = {0xFE, 0xFF}; // UTF-16 (Big Endian)
|
protected static final int[] BOM_UTF16_BE = {0xFE, 0xFF}; // UTF-16 (Big Endian)
|
||||||
/**
|
/**
|
||||||
* UTF-16 - little endian
|
* UTF-16 - little endian
|
||||||
*/
|
*/
|
||||||
public static final int[] BOM_UTF16_LE = {0xFF, 0xFE}; // UTF-16 (Little Endian)
|
protected static final int[] BOM_UTF16_LE = {0xFF, 0xFE}; // UTF-16 (Little Endian)
|
||||||
/**
|
/**
|
||||||
* GB-18030
|
* GB-18030
|
||||||
*/
|
*/
|
||||||
public static final int[] BOM_GB_18030 = {0x84, 0x31, 0x95, 0x33}; // GB-18030
|
protected static final int[] BOM_GB_18030 = {0x84, 0x31, 0x95, 0x33}; // GB-18030
|
||||||
/**
|
/**
|
||||||
* mapping from bom bytes to encoding name
|
* mapping from bom bytes to encoding name
|
||||||
*/
|
*/
|
||||||
private static Map<BOM, String> bomMap = null;
|
private static volatile Map<BOM, String> bomMap = null;
|
||||||
/**
|
/**
|
||||||
* key1 of the BOM
|
* key1 of the BOM
|
||||||
*/
|
*/
|
||||||
@ -94,28 +94,6 @@ public class BOM {
|
|||||||
*/
|
*/
|
||||||
private int key4 = 0;
|
private int key4 = 0;
|
||||||
|
|
||||||
/**
|
|
||||||
* setups the bom bytes to encoding name map
|
|
||||||
*/
|
|
||||||
private static void initBomMap() {
|
|
||||||
bomMap = new HashMap<>();
|
|
||||||
bomMap.put(new BOM(BOM_UTF1), "UTF-1");
|
|
||||||
bomMap.put(new BOM(BOM_UTF7_1), "UTF-7");
|
|
||||||
bomMap.put(new BOM(BOM_UTF7_2), "UTF-7");
|
|
||||||
bomMap.put(new BOM(BOM_UTF7_3), "UTF-7");
|
|
||||||
bomMap.put(new BOM(BOM_UTF7_4), "UTF-7");
|
|
||||||
bomMap.put(new BOM(BOM_UTF8), "UTF-8");
|
|
||||||
bomMap.put(new BOM(BOM_UTF16_BE), "UTF-16_BE");
|
|
||||||
bomMap.put(new BOM(BOM_UTF16_LE), "UTF-16_LE");
|
|
||||||
bomMap.put(new BOM(BOM_UTF32_BE), "UTF-32_BE");
|
|
||||||
bomMap.put(new BOM(BOM_UTF32_LE), "UTF-32_LE");
|
|
||||||
bomMap.put(new BOM(BOM_UTF_EBCDIC), "UTF_EBCDIC");
|
|
||||||
bomMap.put(new BOM(BOM_SCSU), "UTF-8");
|
|
||||||
bomMap.put(new BOM(BOM_BOCU1_1), "BOCU-1");
|
|
||||||
bomMap.put(new BOM(BOM_BOCU1_2), "BOCU-1");
|
|
||||||
bomMap.put(new BOM(BOM_GB_18030), "GB-18030");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates a new instance of a BOM
|
* creates a new instance of a BOM
|
||||||
*
|
*
|
||||||
@ -182,13 +160,14 @@ public class BOM {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns true, if the given object is a BOM and represents the same encoding as this object
|
* returns true, if the given object is a BOM and represents the same
|
||||||
|
* encoding as this object
|
||||||
*
|
*
|
||||||
* @param o the object to compare to
|
* @param o the object to compare to
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (o instanceof BOM) {
|
if (o.getClass() == this.getClass()) {
|
||||||
BOM b = (BOM) o;
|
BOM b = (BOM) o;
|
||||||
boolean equalsKey1 = this.key1 == b.key1;
|
boolean equalsKey1 = this.key1 == b.key1;
|
||||||
boolean equalsKey2 = this.key2 == b.key2;
|
boolean equalsKey2 = this.key2 == b.key2;
|
||||||
@ -220,11 +199,28 @@ public class BOM {
|
|||||||
*
|
*
|
||||||
* @param bomBytes the bytes representing the bom
|
* @param bomBytes the bytes representing the bom
|
||||||
* @return the name of the encoding for the given bom bytes
|
* @return the name of the encoding for the given bom bytes
|
||||||
* @throws UnsupportedEncodingException if no valid encoding name can be found
|
* @throws UnsupportedEncodingException if no valid encoding name can be
|
||||||
|
* found
|
||||||
*/
|
*/
|
||||||
public static String getEncoding(final int[] bomBytes) throws UnsupportedEncodingException {
|
public static String getEncoding(final int[] bomBytes) throws UnsupportedEncodingException {
|
||||||
if (bomMap == null) {
|
if (bomMap == null) {
|
||||||
initBomMap();
|
|
||||||
|
bomMap = new HashMap<>();
|
||||||
|
bomMap.put(new BOM(BOM_UTF1), "UTF-1");
|
||||||
|
bomMap.put(new BOM(BOM_UTF7_1), "UTF-7");
|
||||||
|
bomMap.put(new BOM(BOM_UTF7_2), "UTF-7");
|
||||||
|
bomMap.put(new BOM(BOM_UTF7_3), "UTF-7");
|
||||||
|
bomMap.put(new BOM(BOM_UTF7_4), "UTF-7");
|
||||||
|
bomMap.put(new BOM(BOM_UTF8), "UTF-8");
|
||||||
|
bomMap.put(new BOM(BOM_UTF16_BE), "UTF-16_BE");
|
||||||
|
bomMap.put(new BOM(BOM_UTF16_LE), "UTF-16_LE");
|
||||||
|
bomMap.put(new BOM(BOM_UTF32_BE), "UTF-32_BE");
|
||||||
|
bomMap.put(new BOM(BOM_UTF32_LE), "UTF-32_LE");
|
||||||
|
bomMap.put(new BOM(BOM_UTF_EBCDIC), "UTF_EBCDIC");
|
||||||
|
bomMap.put(new BOM(BOM_SCSU), "UTF-8");
|
||||||
|
bomMap.put(new BOM(BOM_BOCU1_1), "BOCU-1");
|
||||||
|
bomMap.put(new BOM(BOM_BOCU1_2), "BOCU-1");
|
||||||
|
bomMap.put(new BOM(BOM_GB_18030), "GB-18030");
|
||||||
}
|
}
|
||||||
|
|
||||||
BOM currentBOM = new BOM(bomBytes);
|
BOM currentBOM = new BOM(bomBytes);
|
||||||
|
|||||||
@ -16,7 +16,7 @@ public class BOMStripperInputStream extends PushbackInputStream {
|
|||||||
*
|
*
|
||||||
* @see http://en.wikipedia.org/wiki/Byte-order_mark for details
|
* @see http://en.wikipedia.org/wiki/Byte-order_mark for details
|
||||||
*/
|
*/
|
||||||
public static final int[][] BOMS = {
|
protected static final int[][] BOMS = {
|
||||||
BOM.BOM_UTF32_BE,
|
BOM.BOM_UTF32_BE,
|
||||||
BOM.BOM_UTF32_LE,
|
BOM.BOM_UTF32_LE,
|
||||||
BOM.BOM_UTF1,
|
BOM.BOM_UTF1,
|
||||||
|
|||||||
@ -19,6 +19,7 @@ import java.text.Format;
|
|||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import org.apache.logging.log4j.Level;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
@ -66,12 +67,15 @@ public abstract class FileUtil {
|
|||||||
} // method getFilesFromDirecotry
|
} // method getFilesFromDirecotry
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns a file handle to a file in the given folder using the given formater and the given number.
|
* returns a file handle to a file in the given folder using the given
|
||||||
|
* formater and the given number.
|
||||||
*
|
*
|
||||||
* @param outputFolder the folder to link the file to as strnig
|
* @param outputFolder the folder to link the file to as strnig
|
||||||
* @param ft a format object to use to format the filename of the given file
|
* @param ft a format object to use to format the filename of the given file
|
||||||
* @param number a number used to call the given formater to name the file number
|
* @param number a number used to call the given formater to name the file
|
||||||
* @return a file handle build from formater and number linked to given directory
|
* number
|
||||||
|
* @return a file handle build from formater and number linked to given
|
||||||
|
* directory
|
||||||
*/
|
*/
|
||||||
public static File getFileName(final String outputFolder, final Format ft, final int number) {
|
public static File getFileName(final String outputFolder, final Format ft, final int number) {
|
||||||
String folderName = outputFolder;
|
String folderName = outputFolder;
|
||||||
@ -198,7 +202,10 @@ public abstract class FileUtil {
|
|||||||
}
|
}
|
||||||
message = s.toString();
|
message = s.toString();
|
||||||
} catch (FileNotFoundException fnex) {
|
} catch (FileNotFoundException fnex) {
|
||||||
throw new FileNotFoundException("Error occured while reading file. Reason:" + fnex.getMessage());
|
if (LOGGER.isDebugEnabled()) {
|
||||||
|
LOGGER.log(Level.DEBUG, "Error occured while readoing file. Reason:" + fnex, fnex);
|
||||||
|
}
|
||||||
|
throw new FileNotFoundException("Error occured while reading file. Reason:" + fnex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return message;
|
return message;
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import java.io.InputStream;
|
|||||||
*
|
*
|
||||||
* @author joern@muehlencord.de
|
* @author joern@muehlencord.de
|
||||||
*/
|
*/
|
||||||
public class DefaultTest {
|
public abstract class DefaultTest {
|
||||||
|
|
||||||
public String readContentFromFile(String name) throws IOException {
|
public String readContentFromFile(String name) throws IOException {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user