Skip to content

Commit

Permalink
Fix #72 -> Improve BeerXML parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
DougEdey authored and DougEdey committed Jan 25, 2016
1 parent 00ea562 commit 35bd19e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 3 deletions.
1 change: 1 addition & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/Maven: org.powermock:powermock-api-mockito:1.6.2"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/Maven: org.mockito:mockito-all:1.10.19"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/Maven: org.powermock:powermock-api-support:1.6.2"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/Maven: org.apache.tika:tika-core:1.11"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
Binary file modified Elsinore.jar
Binary file not shown.
1 change: 1 addition & 0 deletions SB_Elsinore_Server.eml
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,6 @@
<level name="Maven: org.powermock:powermock-api-mockito:1.6.2" value="project"/>
<level name="Maven: org.mockito:mockito-all:1.10.19" value="project"/>
<level name="Maven: org.powermock:powermock-api-support:1.6.2" value="project"/>
<level name="Maven: org.apache.tika:tika-core:1.11" value="project"/>
</levels>
</component>
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
<version>1.11</version>
</dependency>
</dependencies>


Expand Down
25 changes: 24 additions & 1 deletion src/main/java/ca/strangebrew/recipe/Mash.java
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,35 @@ public String getInfuseTemp() {

public void setMashRatio(String mashRatio) {
try {
this.mashRatio = Double.parseDouble(mashRatio);
mashRatio = mashRatio.trim();

this.mashRatio = readDouble(mashRatio);
} catch (NumberFormatException nfe) {
nfe.printStackTrace();
}
}
public double readDouble(String s)
{
s = s.trim();
StringBuilder sb = new StringBuilder(s);
int i = sb.indexOf(",");
while (i > 0)
{
// if we're at the decimal point, change it to a .
if (i == (sb.length() - 2))
{
sb.replace(i, i+1, ",");
}
// otherwise remove it
else
{
sb.replace(i, i+1, "");
}
i = sb.indexOf(",");
}

return Double.parseDouble(sb.toString());
}
public double getMashRatio() {
return mashRatio;
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/sb/elsinore/UrlEndpoints.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.*;
import java.util.Map.Entry;

import org.apache.tika.Tika;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
Expand Down Expand Up @@ -2113,8 +2114,8 @@ public Response uploadBeerXML() {

try {
File uploadedFile = new File(entry.getValue());
String fileType = Files.probeContentType(
uploadedFile.toPath());
String fileType = new Tika().detect(
uploadedFile);

if (fileType.endsWith("/xml"))
{
Expand Down

0 comments on commit 35bd19e

Please sign in to comment.