Merge "Commented out dead/unreachable code (maybe some error in control logic?)"
[aaf/authz.git] / auth / auth-core / src / main / java / org / onap / aaf / auth / rserv / CachingFileAccess.java
index 9af1115..37f3b08 100644 (file)
@@ -24,15 +24,12 @@ package org.onap.aaf.auth.rserv;
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
 import java.io.FileReader;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.Writer;
 import java.nio.ByteBuffer;
-import java.nio.channels.FileChannel;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -52,11 +49,9 @@ import java.util.regex.Pattern;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.onap.aaf.misc.env.Env;
 import org.onap.aaf.misc.env.EnvJAXB;
 import org.onap.aaf.misc.env.LogTarget;
 import org.onap.aaf.misc.env.Store;
-import org.onap.aaf.misc.env.TimeTaken;
 import org.onap.aaf.misc.env.Trans;
 /*
  * CachingFileAccess
@@ -136,6 +131,12 @@ public class CachingFileAccess<TRANS extends Trans> extends HttpCode<TRANS, Void
         typeMap.put("props", "text/plain");
         typeMap.put("jks", "application/octet-stream");
         
+        // Fonts
+        typeMap.put("ttf","font/ttf");
+        typeMap.put("woff","font/woff");
+        typeMap.put("woff2","font/woff2");
+
+        
         timer = new Timer("Caching Cleanup",true);
         timer.schedule(new Cleanup(content,500),60000,60000);
         
@@ -159,10 +160,10 @@ public class CachingFileAccess<TRANS extends Trans> extends HttpCode<TRANS, Void
     @Override
     public void handle(TRANS trans, HttpServletRequest req, HttpServletResponse resp) throws IOException {
         String key = pathParam(req, ":key");
-        String cmd = pathParam(req,":cmd");
-        if (key.equals(clear_command)) {
+        int slash = key.indexOf('/');
+        if(key.length()>2 && slash>=0 && key.substring(0,slash).equals(clear_command)) {
             resp.setHeader("Content-Type",typeMap.get("txt"));
-            if ("clear".equals(cmd)) {
+            if ("clear".equals(key.substring(slash+1))) {
                 content.clear();
                 resp.setStatus(200/*HttpStatus.OK_200*/);
             } else {
@@ -170,7 +171,7 @@ public class CachingFileAccess<TRANS extends Trans> extends HttpCode<TRANS, Void
             }
             return;
         }
-        Content c = load(logT , web_path,cmd!=null && cmd.length()>0?key+'/'+cmd:key, null, checkInterval);
+        Content c = load(logT , web_path,key, null, checkInterval);
         if (c.attachmentOnly) {
             resp.setHeader("Content-disposition", "attachment");
         }
@@ -291,33 +292,6 @@ public class CachingFileAccess<TRANS extends Trans> extends HttpCode<TRANS, Void
         return c;
     }
     
-    public Content loadOrDefault(Trans trans, String targetDir, String targetFileName, String sourcePath, String mediaType) throws IOException {
-        try {
-            return load(trans.info(),targetDir,targetFileName,mediaType,0);
-        } catch (FileNotFoundException e) {
-            String targetPath = targetDir + '/' + targetFileName;
-            TimeTaken tt = trans.start("File doesn't exist; copy " + sourcePath + " to " + targetPath, Env.SUB);
-            try {
-                FileInputStream sourceFIS = new FileInputStream(sourcePath);
-                FileChannel sourceFC = sourceFIS.getChannel();
-                File targetFile = new File(targetPath);
-                targetFile.getParentFile().mkdirs(); // ensure directory exists
-                FileOutputStream targetFOS = new FileOutputStream(targetFile);
-                try {
-                    ByteBuffer bb = ByteBuffer.allocate((int)sourceFC.size());
-                    sourceFC.read(bb);
-                    bb.flip();  // ready for reading
-                    targetFOS.getChannel().write(bb);
-                } finally {
-                    sourceFIS.close();
-                    targetFOS.close();
-                }
-            } finally {
-                tt.done();
-            }
-            return load(trans.info(),targetDir,targetFileName,mediaType,0);
-        }
-    }
 
     public void invalidate(String key) {
         content.remove(key);