Browse Source
Refactored App to use AppConfig for initial configuration. Updated ResourceLoader with logging. Added a default properties file, and a PropertiesService to load that properties file. Updated ImageHashDTO to include some fields. Added a HashService to manage generating hashes. moved the about file to an about.info file so we can automatically process it.
master
Refactored App to use AppConfig for initial configuration. Updated ResourceLoader with logging. Added a default properties file, and a PropertiesService to load that properties file. Updated ImageHashDTO to include some fields. Added a HashService to manage generating hashes. moved the about file to an about.info file so we can automatically process it.
master
Drew Short
11 years ago
14 changed files with 210 additions and 36 deletions
-
4.gitignore
-
24pom.xml
-
19src/includes/startCLI.sh
-
36src/main/java/com/sothr/imagetools/App.java
-
20src/main/java/com/sothr/imagetools/AppCLI.java
-
41src/main/java/com/sothr/imagetools/AppConfig.java
-
10src/main/java/com/sothr/imagetools/util/ResourceLoader.java
-
21src/main/resources/default.properties
-
3src/main/resources/documents/about
-
5src/main/resources/documents/about.info
-
6src/main/scala/com/sothr/imagetools/dto/ImageHashDTO.scala
-
17src/main/scala/com/sothr/imagetools/hash/HashService.scala
-
5src/main/scala/com/sothr/imagetools/image/Image.scala
-
33src/main/scala/com/sothr/imagetools/util/PropertiesService.scala
@ -0,0 +1,19 @@ |
|||
#!/bin/bash |
|||
echo "Welcome to Image Tools version: ${project.version}" |
|||
command="" |
|||
correct=false |
|||
while true; do |
|||
read -p "Please enter and commandline arguments you would like to include: " args |
|||
command="-cp ${project.name}-${project.version}-jfx.jar:lib/* com.sothr.imagetools.AppCLI $args" |
|||
echo "Is \"$command\" accurate? (yes/no)" |
|||
select yn in "Yes" "No"; do |
|||
case $yn in |
|||
Yes ) correct=true; break;; |
|||
No ) break;; |
|||
esac |
|||
done |
|||
case $correct in |
|||
true ) break;; |
|||
esac |
|||
done |
|||
java $command |
@ -0,0 +1,20 @@ |
|||
package com.sothr.imagetools; |
|||
|
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
|
|||
/** |
|||
* CLI interface for Image Tools |
|||
*/ |
|||
class AppCLI { |
|||
|
|||
private static Logger logger; |
|||
|
|||
public static void main(String[] args) { |
|||
AppConfig.configLogging(); |
|||
logger = LoggerFactory.getLogger(AppCLI.class); |
|||
logger.info("Started Image Tools CLI"); |
|||
System.out.println("Hello World"); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,41 @@ |
|||
package com.sothr.imagetools; |
|||
|
|||
import org.apache.log4j.PropertyConfigurator; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
|
|||
import java.io.File; |
|||
import java.util.Properties; |
|||
|
|||
class AppConfig { |
|||
|
|||
private static Logger logger; |
|||
|
|||
private static final String LOGSETTINGSFILE = "./log4j.properties"; |
|||
|
|||
public static void configLogging() { |
|||
//Logging Config |
|||
File file = new File(LOGSETTINGSFILE); |
|||
Boolean fromFile = false; |
|||
if (file.exists()) { |
|||
fromFile = true; |
|||
PropertyConfigurator.configure(LOGSETTINGSFILE); |
|||
} else { |
|||
//Simple error logging configuration |
|||
Properties defaultProps = new Properties(); |
|||
defaultProps.setProperty("log4j.rootLogger","ERROR, A1"); |
|||
//Rolling Error logger |
|||
defaultProps.setProperty("log4j.appender.A1","org.apache.log4j.RollingFileAppender"); |
|||
defaultProps.setProperty("log4j.appender.A1.File","Image-Tools.err"); |
|||
defaultProps.setProperty("log4j.appender.A1.MaxFileSize","100KB"); |
|||
defaultProps.setProperty("log4j.appender.A1.MaxBackupIndex","1"); |
|||
defaultProps.setProperty("log4j.appender.A1.layout","org.apache.log4j.EnhancedPatternLayout"); |
|||
defaultProps.setProperty("log4j.appender.A1.layout.ConversionPattern","%d{yy-MM-dd HH:mm:ss} %-5p [%c{3.}] - %m%n"); |
|||
PropertyConfigurator.configure(defaultProps); |
|||
} |
|||
logger = LoggerFactory.getLogger(AppConfig.class); |
|||
String message = fromFile ? "From File" : "From Defaults"; |
|||
logger.info(String.format("Configured Logger %s", message)); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,21 @@ |
|||
#Default Properties File |
|||
#Image Tools version: ${project.version} |
|||
version=${project.version} |
|||
|
|||
#Default Image Settings |
|||
#images must be 90% similar |
|||
image.differenceThreshold=0.90 |
|||
#control generation of hashes for new images. |
|||
image.ahash=true |
|||
image.ahashWeight=0.70 |
|||
image.dhash=true |
|||
image.dhashWeight=0.85 |
|||
#set to false if hashing images is taking too long |
|||
image.phash=true |
|||
image.phashWeight=1.0 |
|||
|
|||
#Default Thumbnail Settings |
|||
#Directory where to store thumbnails |
|||
thumbnail.directory=/cache/thumbnails/ |
|||
#Size of the thumbnail to generate and store |
|||
thumbnail.size=128 |
@ -1,3 +0,0 @@ |
|||
This is a simple about script. It demonstrates loading the about text from a file. |
|||
|
|||
It supports simple text, and nothing fancy. |
@ -0,0 +1,5 @@ |
|||
Image Tools Version: ${project.version} |
|||
|
|||
This is a simple about script. It demonstrates loading the about text from a file. |
|||
|
|||
It supports simple text, and nothing fancy. |
@ -1,5 +1,9 @@ |
|||
package com.sothr.imagetools.dto |
|||
|
|||
class ImageHashDTO { |
|||
class ImageHashDTO(val ahash:Long, val dhash:Long, val phash:Long) { |
|||
|
|||
def getAhash():Long = this.ahash |
|||
def getDhash():Long = this.dhash |
|||
def getPhash():Long = this.phash |
|||
|
|||
} |
@ -0,0 +1,17 @@ |
|||
package com.sothr.imagetools.hash |
|||
|
|||
object HashService { |
|||
|
|||
def getAhash(imageData:Array[Array[Integer]]):Long = { |
|||
return 0L |
|||
} |
|||
|
|||
def getDhash(imageData:Array[Array[Integer]]):Long = { |
|||
return 0L |
|||
} |
|||
|
|||
def getPhash(imageData:Array[Array[Integer]]):Long = { |
|||
return 0L |
|||
} |
|||
|
|||
} |
@ -0,0 +1,33 @@ |
|||
package com.sothr.imagetools.util |
|||
|
|||
import java.util.Properties |
|||
import grizzled.slf4j.Logging |
|||
|
|||
/* |
|||
* Service for loading and interacting with the properties file |
|||
*/ |
|||
object PropertiesService extends Logging { |
|||
|
|||
val properties:Properties = new Properties() |
|||
|
|||
/* |
|||
* Load the properties file from the specified location |
|||
*/ |
|||
def loadProperties(location:String) = { |
|||
info(s"Attempting to load properties from: $location") |
|||
val inputStream = ResourceLoader.get.getResourceStream(location) |
|||
val splitLocation = location.split("""\.""") |
|||
if (splitLocation(splitLocation.length) equals "xml") { |
|||
properties.loadFromXML(inputStream) |
|||
} else if (splitLocation(splitLocation.length) equals "properties") { |
|||
properties.load(inputStream); |
|||
} else { |
|||
error("Unable to load the properties file because it is not in the .properties or .xml format") |
|||
} |
|||
} |
|||
|
|||
def saveProperties(location:String) = { |
|||
|
|||
} |
|||
|
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue