diff --git a/src/main/java/com/ntlab/irisserver/models/KeywordManager.java b/src/main/java/com/ntlab/irisserver/models/KeywordManager.java index 9b44c4e..2103fd6 100644 --- a/src/main/java/com/ntlab/irisserver/models/KeywordManager.java +++ b/src/main/java/com/ntlab/irisserver/models/KeywordManager.java @@ -2,13 +2,53 @@ import org.springframework.stereotype.Component; +import java.io.*; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import org.apache.catalina.core.ApplicationContext; +import com.ntlab.irisserver.utils.Base64Decode; +import org.apache.catalina.core.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.beans.BeansException; + +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Response; + + @Component public class KeywordManager { private static KeywordManager theInstance = null; - String[] keywords = {"りんご", - "ごりら","らっぱ","ぱんつ","つみき"}; + String[] keywords = {"0"}; + /*= {"りんご", + "ごりら","らっぱ","ぱんつ","つみき",};*/ + private List FileRead(String path) { + List ss = new ArrayList(); + try { + BufferedReader buffReader = + new BufferedReader(new FileReader(path)); + String s; + + while ((s = buffReader.readLine()) != null) { + ss.add(s); + } + buffReader.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + return ss; + + } + public static KeywordManager getInstance() { if(theInstance == null) { theInstance = new KeywordManager(); @@ -16,7 +56,18 @@ return theInstance; } - public String[] getKeywords(){ + public String[] getKeywords(String path){ + var response = Response.status(Response.Status.NO_CONTENT); + + if(path == null){ + response.status(400).entity("パスがありません"); + throw new WebApplicationException(response.build()); + } else if(FileRead(path).size() == 0){ + response.status(400).entity(path+"に対応したファイルがありません"); + throw new WebApplicationException(response.build()); + } else { + keywords = FileRead(path).toArray(new String[FileRead(path).size()]); + } return keywords; } }