1 17 18 package org.pentaho.core.solution; 19 20 import java.io.File ; 21 22 public class ActionResource implements IActionResource { 23 24 private String name; 25 26 private String mimeType; 27 28 private String address; 29 30 private int sourceType; 31 32 public ActionResource(String name, int sourceType, String mimeType, String address) { 33 34 this.name = name; 35 this.mimeType = mimeType; 36 this.sourceType = sourceType; 37 this.address = address; 38 } 39 40 public ActionResource(String name, int sourceType, String mimeType, String solutionName, String solutionPath, String location) { 41 42 this.name = name; 43 this.mimeType = mimeType; 44 this.sourceType = sourceType; 45 if (sourceType == IActionResource.SOLUTION_FILE_RESOURCE) { 46 address = getLocationInSolution(solutionName, solutionPath, location); 47 } else { 48 address = location; 49 } 50 } 51 52 public String getLocationInSolution(String solutionName, String solutionPath, String location) { 53 if ( (location == null) || (location.length() == 0) ) { 54 return( null ); 55 } 56 if (location.charAt(0) == '\\' || location.charAt(0) == '/') { 57 return solutionName + File.separator + location; 58 } else if (location.startsWith("..", 0)) { return null; 61 } else { 62 if ("".equals(solutionPath)) { return solutionName + File.separator + location; 64 } 65 return solutionName + File.separator + solutionPath + File.separator + location; 66 } 67 } 68 69 public static int getResourceType(String sourceTypeName) { 70 if ("solution-file".equals(sourceTypeName)) { return IActionResource.SOLUTION_FILE_RESOURCE; 72 } else if ("file".equals(sourceTypeName)) { return IActionResource.FILE_RESOURCE; 74 } else if ("url".equals(sourceTypeName)) { return IActionResource.URL_RESOURCE; 76 } else if ("xml".equals(sourceTypeName)) { return IActionResource.XML; 78 } else if ("string".equals(sourceTypeName)) { return IActionResource.STRING; 80 } else 81 return UNKNOWN_RESOURCE; 82 } 83 84 89 public String getName() { 90 return name; 92 } 93 94 99 public String getMimeType() { 100 return mimeType; 102 } 103 104 109 public int getSourceType() { 110 return sourceType; 112 } 113 114 public String getAddress() { 115 return address; 117 } 118 119 } 120 | Popular Tags |