| | |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.InputStreamReader; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * Helfer fuer HTTP-Methoden |
| | |
| | | public static final String HTTP_PUT = "PUT"; |
| | | public static final String HTTP_DELETE = "DELETE"; |
| | | |
| | | public static final String STR_AMP = "&"; |
| | | public static final String STR_EQUAL = "="; |
| | | |
| | | public static final String CONTENT_TYPE = "Content-Type"; |
| | | |
| | |
| | | return sb.toString(); |
| | | } |
| | | |
| | | public String getAttrStr(Map attributes, String key, String defaultValue) { |
| | | Object value = attributes.get(key); |
| | | if(value instanceof String) { |
| | | return value.toString(); |
| | | } else { |
| | | return defaultValue; |
| | | } |
| | | } |
| | | |
| | | public Map<String, String> getQueryMap(String query) { |
| | | String[] params = query.split(STR_AMP); |
| | | Map<String, String> map = new HashMap<String, String>(); |
| | | for (String param : params) { |
| | | String name = param.split(STR_EQUAL)[0]; |
| | | String value = param.split(STR_EQUAL)[1]; |
| | | map.put(name, value); |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | public File tryWelcomeFiles(HttpExchange e, String fName) { |
| | | String fileBase = e.getHttpContext().getAttributes().get(FileHandler.ATTR_FILE_BASE).toString(); |
| | | String welcomeFiles = e.getHttpContext().getAttributes().get(FileHandler.ATTR_WELCOME_FILES).toString(); |
| | | String[] fileNames = welcomeFiles.split(FileHandler.STR_COMMA); |
| | | boolean notFound = true; |
| | | int i = -1; |
| | | File file = null; |
| | | while(notFound && ++i < fileNames.length) { |
| | | file = new File(fileBase, fName + fileNames[i]); |
| | | if(file.exists()) { |
| | | notFound = false; |
| | | String fileBase = e.getHttpContext().getAttributes().get(FileHandler.ATTR_FILE_BASE).toString(); |
| | | Object welcomeFiles = e.getHttpContext().getAttributes().get(FileHandler.ATTR_WELCOME_FILES); |
| | | if(welcomeFiles instanceof String) { |
| | | String[] fileNames = welcomeFiles.toString().split(FileHandler.STR_COMMA); |
| | | int i = -1; |
| | | while(notFound && ++i < fileNames.length) { |
| | | file = new File(fileBase, fName + fileNames[i]); |
| | | if(file.exists()) { |
| | | notFound = false; |
| | | } |
| | | } |
| | | } |
| | | if(notFound) { |