KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > core > solution > ActionResource


1 /*
2  * Copyright 2006 Pentaho Corporation. All rights reserved.
3  * This software was developed by Pentaho Corporation and is provided under the terms
4  * of the Mozilla Public License, Version 1.1, or any later version. You may not use
5  * this file except in compliance with the license. If you need a copy of the license,
6  * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
7  * BI Platform. The Initial Developer is Pentaho Corporation.
8  *
9  * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11  * the license for the specific language governing your rights and limitations.
12  *
13  * @created Jul 25, 2005
14  * @author James Dixon
15  *
16  */

17
18 package org.pentaho.core.solution;
19
20 import java.io.File JavaDoc;
21
22 public class ActionResource implements IActionResource {
23
24     private String JavaDoc name;
25
26     private String JavaDoc mimeType;
27
28     private String JavaDoc address;
29
30     private int sourceType;
31
32     public ActionResource(String JavaDoc name, int sourceType, String JavaDoc mimeType, String JavaDoc address) {
33
34         this.name = name;
35         this.mimeType = mimeType;
36         this.sourceType = sourceType;
37         this.address = address;
38     }
39
40     public ActionResource(String JavaDoc name, int sourceType, String JavaDoc mimeType, String JavaDoc solutionName, String JavaDoc solutionPath, String JavaDoc 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 JavaDoc getLocationInSolution(String JavaDoc solutionName, String JavaDoc solutionPath, String JavaDoc 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)) { //$NON-NLS-1$
59
// TODO: support relative paths...
60
return null;
61         } else {
62             if ("".equals(solutionPath)) { //$NON-NLS-1$
63
return solutionName + File.separator + location;
64             }
65             return solutionName + File.separator + solutionPath + File.separator + location;
66         }
67     }
68
69     public static int getResourceType(String JavaDoc sourceTypeName) {
70         if ("solution-file".equals(sourceTypeName)) { //$NON-NLS-1$
71
return IActionResource.SOLUTION_FILE_RESOURCE;
72         } else if ("file".equals(sourceTypeName)) { //$NON-NLS-1$
73
return IActionResource.FILE_RESOURCE;
74         } else if ("url".equals(sourceTypeName)) { //$NON-NLS-1$
75
return IActionResource.URL_RESOURCE;
76         } else if ("xml".equals(sourceTypeName)) { //$NON-NLS-1$
77
return IActionResource.XML;
78         } else if ("string".equals(sourceTypeName)) { //$NON-NLS-1$
79
return IActionResource.STRING;
80         } else
81             return UNKNOWN_RESOURCE;
82     }
83
84     /*
85      * (non-Javadoc)
86      *
87      * @see org.pentaho.core.solution.IActionResource#getName()
88      */

89     public String JavaDoc getName() {
90         // TODO Auto-generated method stub
91
return name;
92     }
93
94     /*
95      * (non-Javadoc)
96      *
97      * @see org.pentaho.core.solution.IActionResource#getMimeType()
98      */

99     public String JavaDoc getMimeType() {
100         // TODO Auto-generated method stub
101
return mimeType;
102     }
103
104     /*
105      * (non-Javadoc)
106      *
107      * @see org.pentaho.core.solution.IActionResource#getSourceType()
108      */

109     public int getSourceType() {
110         // TODO Auto-generated method stub
111
return sourceType;
112     }
113
114     public String JavaDoc getAddress() {
115         // TODO Auto-generated method stub
116
return address;
117     }
118
119 }
120
Popular Tags