001: /*
002: * Copyright 2006 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
007: * BI Platform. The Initial Developer is Pentaho Corporation.
008: *
009: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
011: * the license for the specific language governing your rights and limitations.
012: *
013: * @created Jul 25, 2005
014: * @author James Dixon
015: *
016: */
017:
018: package org.pentaho.core.solution;
019:
020: import java.io.File;
021:
022: import org.apache.commons.lang.StringUtils;
023: import org.pentaho.messages.Messages;
024:
025: public class ActionResource implements IActionResource {
026:
027: private String name;
028:
029: private String mimeType;
030:
031: private String address;
032:
033: private int sourceType;
034:
035: public ActionResource(String name, int sourceType, String mimeType,
036: String address) {
037:
038: this .name = name;
039: this .mimeType = mimeType;
040: this .sourceType = sourceType;
041: this .address = address;
042: }
043:
044: public ActionResource(String name, int sourceType, String mimeType,
045: String solutionName, String solutionPath, String location) {
046:
047: this (name, sourceType, mimeType, null);
048: if (sourceType == IActionResource.SOLUTION_FILE_RESOURCE) {
049: address = getLocationInSolution(solutionName, solutionPath,
050: location);
051: } else {
052: address = location;
053: }
054: }
055:
056: // TODO sbarkdull, refactor, this method probably belongs in filebased...SolutionRepository,
057: // and/or could possibly work with FileSolutionFile, or be incorporated in that class
058: private static String getLocationInSolution(String solutionName,
059: String solutionPath, String location) {
060: if (StringUtils.isEmpty(location)) {
061: return (null);
062: }
063: if (location.charAt(0) == '\\' || location.charAt(0) == '/') {
064: return solutionName + File.separator + location;
065: } else if (location.startsWith("..", 0)) { //$NON-NLS-1$
066: // TODO: support relative paths...
067: assert false : Messages
068: .getErrorString("ActionResource.ERROR_0001_FEATURE_NOT_IMPLEMENTED"); //$NON-NLS-1$
069: return null;
070: } else {
071: if ("".equals(solutionPath)) { //$NON-NLS-1$
072: return solutionName + File.separator + location;
073: }
074: return solutionName + File.separator + solutionPath
075: + File.separator + location;
076: }
077: }
078:
079: public static int getResourceType(String sourceTypeName) {
080: if ("solution-file".equals(sourceTypeName)) { //$NON-NLS-1$
081: return IActionResource.SOLUTION_FILE_RESOURCE;
082: } else if ("file".equals(sourceTypeName)) { //$NON-NLS-1$
083: return IActionResource.FILE_RESOURCE;
084: } else if ("url".equals(sourceTypeName)) { //$NON-NLS-1$
085: return IActionResource.URL_RESOURCE;
086: } else if ("xml".equals(sourceTypeName)) { //$NON-NLS-1$
087: return IActionResource.XML;
088: } else if ("string".equals(sourceTypeName)) { //$NON-NLS-1$
089: return IActionResource.STRING;
090: } else
091: return UNKNOWN_RESOURCE;
092: }
093:
094: /*
095: * (non-Javadoc)
096: *
097: * @see org.pentaho.core.solution.IActionResource#getName()
098: */
099: public String getName() {
100: return name;
101: }
102:
103: /*
104: * (non-Javadoc)
105: *
106: * @see org.pentaho.core.solution.IActionResource#getMimeType()
107: */
108: public String getMimeType() {
109: return mimeType;
110: }
111:
112: /*
113: * (non-Javadoc)
114: *
115: * @see org.pentaho.core.solution.IActionResource#getSourceType()
116: */
117: public int getSourceType() {
118: return sourceType;
119: }
120:
121: public String getAddress() {
122: return address;
123: }
124:
125: }
|