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 Jun 21, 2005
014: * @author James Dixon
015: *
016: */
017:
018: package org.pentaho.core.repository;
019:
020: import java.io.File;
021: import java.io.FileNotFoundException;
022: import java.io.IOException;
023: import java.io.InputStream;
024: import java.io.Reader;
025: import java.util.List;
026: import javax.activation.DataSource;
027: import org.dom4j.Document;
028: import org.dom4j.Node;
029: import org.pentaho.core.session.IPentahoSession;
030: import org.pentaho.core.solution.IActionResource;
031: import org.pentaho.core.solution.IActionSequence;
032: import org.pentaho.core.solution.ISolutionFile;
033: import org.pentaho.core.solution.SolutionReposUtil.ISolutionFilter;
034: import org.pentaho.messages.Messages;
035: import org.pentaho.util.logging.ILogger;
036:
037: /**
038: * Defines methods for getting information out of a location holding the Pentaho
039: * solutions.
040: *
041: * @author jdixon
042: *
043: */
044:
045: public interface ISolutionRepository extends ILogger {
046:
047: public static final int ACTION_EXECUTE = 1; //Document being requested for execution
048: public static final int ACTION_ADMIN = 2; //Document being requested for administration
049:
050: public static final int ACTION_SUBSCRIBE = 3;
051: public static final int ACTION_CREATE = 4;
052: public static final int ACTION_UPDATE = 5;
053: public static final int ACTION_DELETE = 6;
054:
055: public static final int FILE_EXISTS = 1;
056:
057: public static final int FILE_ADD_FAILED = 2;
058: public static final int FILE_ADD_SUCCESSFUL = 3;
059: public static final int FILE_ADD_INVALID_PUBLISH_PASSWORD = 4;
060: public static final int FILE_ADD_INVALID_USER_CREDENTIALS = 5;
061:
062: public static final String[] FILE_STATUS_MSG = {
063: "", // item 0 does not exist//$NON-NLS-1$
064: Messages
065: .getString("ISolutionRepository.ERROR_0001_FILE_EXISTS"),//$NON-NLS-1$
066: Messages
067: .getString("ISolutionRepository.ERROR_0002_FILE_ADD_FAILED"),//$NON-NLS-1$
068: Messages
069: .getString("ISolutionRepository.STATUS_0003_FILE_ADD_SUCCESSFUL"),//$NON-NLS-1$
070: Messages
071: .getString("ISolutionRepository.ERROR_0004_FILE_ADD_INVALID_PUBLISH_PASSWORD"),//$NON-NLS-1$
072: Messages
073: .getString("ISolutionRepository.ERROR_0005_FILE_ADD_INVALID_USER_CREDENTIALS") //$NON-NLS-1$
074: };
075:
076: /**
077: * Retrieves the action sequence from the repository. Should return <code>null</code> if the
078: * requested action seqeuence is not found.
079: * @param solutionName The name of the solution - like the root folder
080: * @param actionPath The relative path (from the solution) of where the file is stored
081: * @param actionName The name of the action sequence
082: * @param loggingLevel The level at which to log messages
083: * @param actionOperation Whether the action sequence is being retrieved for administration or execution
084: * @return
085: */
086: public IActionSequence getActionSequence(String solutionName,
087: String actionPath, String actionName, int loggingLevel,
088: int actionOperation);
089:
090: /**
091: * Initializes the solution repository with the user session
092: * @param session The current user session
093: */
094: public void init(IPentahoSession session);
095:
096: /**
097: * Gets an XML <tt>Document</tt> representing all the solutions and all the files within all the solutions
098: * @param actionOperation Indicates what the list will be used for - execution or administration
099: * @return Document
100: */
101: public Document getSolutions(int actionOperation);
102:
103: /**
104: * Gets an XML <tt>Document</tt> representing all the files within a certain path within a solution
105: * @param solutionName The name of the solution to get
106: * @param pathName The path from which to retrieve
107: * @param actionOperation Indicates what the list will be used for - execution or administration
108: * @return Document
109: */
110: public Document getSolutions(String solutionName, String pathName,
111: int actionOperation, boolean visibleOnly);
112:
113: /**
114: * Returns an XML document that represents the parent/child relationship of the current solution repository
115: *
116: * @param actionOperation
117: * @return an XML document
118: */
119: public Document getSolutionStructure(int actionOperation);
120:
121: /**
122: * Returns a list of documents located in the solution and path.
123: *
124: * @param solution - The solution to use
125: * @param path - The path within the solution
126: * @param subDirectories - Should this recursively process sub-directories?
127: * @param visibleOnly - Only include action sequences marked as visible
128: * @param actionOperation - Type of action operation to be performed
129: *
130: * @return - An XML document that represents the documents
131: */
132: //public Document getActionSequences(String solution, String path, boolean subDirectories, boolean visibleOnly, int actionOperation);
133: /**
134: * Loads or reloads a solution repository after a structure change.
135: *
136: * @param session - The session associated with this solution repository
137: * @param loggingLevel - The requested level of logging
138: */
139: public void reloadSolutionRepository(IPentahoSession session,
140: int loggingLevel);
141:
142: public String getRepositoryName();
143:
144: /**
145: * Removes the file (fileName) from the path defined by the solution and path.
146: *
147: * @param solution
148: * @param path
149: * @param fileName
150: * @return - boolean indicating success
151: */
152: public boolean removeSolutionFile(String solution, String path,
153: String fileName);
154:
155: public boolean removeSolutionFile(String solutionPath);
156:
157: /**
158: * Adds a solution to the solution repository defined by the url that is built by
159: * concatenating baseUrl, path, and fileName. The fileName that is added has its
160: * data populated by the data from File (on disk).
161: *
162: * @param baseUrl
163: * @param path
164: * @param fileName
165: * @param fi
166: * @param overwrite
167: * @return - int indicating status of return
168: */
169: public int addSolutionFile(String baseUrl, String path,
170: String fileName, File f, boolean overwrite);
171:
172: /**
173: * Adds a solution to the solution repository defined by the url that is built by
174: * concatenating baseUrl, path, and fileName. The fileName that is added has its
175: * data populated by the data.
176: *
177: * @param baseUrl
178: * @param path
179: * @param fileName
180: * @param data
181: * @param overwrite
182: * @return - int indicating status of return
183: */
184: public int addSolutionFile(String baseUrl, String path,
185: String fileName, byte[] data, boolean overwrite);
186:
187: /**
188: * Returns a long that represents the last time this file was modified
189: *
190: * @param path
191: */
192: public long getSolutionFileLastModified(String path);
193:
194: /**
195: * Returns an appropriate class loader for a specific path
196: *
197: * @param path
198: * @return - A ClassLoader
199: */
200: public ClassLoader getClassLoader(String path);
201:
202: public Document getFullSolutionTree(int actionOperation,
203: ISolutionFilter filter);
204:
205: /**
206: * Returns an XML document that defines the entire solution tree. This general purpose method
207: * return all files/folders in the solution in an easily understood XML document.
208: *
209: * @param actionOperation
210: * @return
211: */
212: public Document getSolutionTree(int actionOperation);
213:
214: /**
215: * @param actionOperation
216: * @param filter an implementation of a ISolutionFilter that determines which files will be returned
217: * @return Document representing the solution tree
218: */
219: public Document getSolutionTree(int actionOperation,
220: ISolutionFilter filter);
221:
222: /*
223: * The following method do not use the solution, path, action model for resolving resource location.
224: * Instead where indicated a complete path should be provided.
225: */
226:
227: /**
228: * Returns a true if the specified resource exists.
229: *
230: * @param solutionPath - path to the resource
231: * @return - boolean true if resource exists
232: */
233: public boolean resourceExists(String solutionPath);
234:
235: /**
236: * Returns the size of the specfied resource. If resource doesn't exit
237: * a -1 is returned
238: *
239: * @param solutionPath - path to the resource
240: * @return - long value of the size
241: */
242: public long resourceSize(String solutionPath);
243:
244: /**
245: * Given a IActionResource this method returns a InputStream that references the
246: * content of the actionResource.
247: *
248: * @param actionResource - resource to create a stream for.
249: * @param getLocalizedResource - flag to use to check if we should attempt to get a localized version of the resource
250: * @return - InputStream that contains the data of the actionResource
251: * @throws FileNotFoundException
252: */
253: public InputStream getResourceInputStream(
254: IActionResource actionResource, boolean getLocalizedResource)
255: throws FileNotFoundException;
256:
257: /**
258: * Returns an InputStream that contains the data of the resource defined by the
259: * solutionPath.
260: *
261: * @param solutionPath - location of a resource.
262: * @return - InputStream that represents the data of the resource.
263: * @throws FileNotFoundException
264: */
265: public InputStream getResourceInputStream(String solutionPath,
266: boolean getLocalizedResource) throws FileNotFoundException;
267:
268: /**
269: * See getResourceInputStream(IActionResource actionResource). Identical method
270: * except returns results as a Reader. Exceptions are thrown if io error or file is not
271: * found.
272: *
273: * @param actionResource
274: * @return
275: * @throws FileNotFoundException
276: * @throws IOException
277: */
278: public Reader getResourceReader(IActionResource actionResource)
279: throws FileNotFoundException, IOException;
280:
281: /**
282: * See getResourceInputStream(String solutionPath). Identical method
283: * except returns results as a Reader. Exceptions are thrown if io error or file is not
284: * found.
285: *
286: * @param solutionPath
287: * @return
288: * @throws FileNotFoundException
289: * @throws IOException
290: */
291: public Reader getResourceReader(String solutionPath)
292: throws FileNotFoundException, IOException;
293:
294: /**
295: * See getResourceInputStream(IActionResource actionResource). Identical method
296: * except returns results as a String. Exception is thrown if io error.
297: *
298: * @param actionResource
299: * @return
300: * @throws IOException
301: */
302: public String getResourceAsString(IActionResource actionResource)
303: throws IOException;
304:
305: /**
306: * See getResourceInputStream(String solutionPath). Identical method
307: * except returns results as a String. Exception is thrown if io error.
308: *
309: * @param solutionPath
310: * @return
311: * @throws IOException
312: */
313: public String getResourceAsString(String solutionPath)
314: throws IOException;
315:
316: /**
317: * See getResourceInputBytes(String solutionPath). Identical method
318: * except returns results as a byte array. Exception is thrown if io error.
319: *
320: * @param solutionPath
321: * @return
322: * @throws IOException
323: */
324: public byte[] getResourceAsBytes(String solutionPath,
325: boolean getLocalizedResource) throws IOException;
326:
327: /**
328: * See getResourceInputBytes(String solutionPath). Identical method
329: * except returns results as a byte array. Exception is thrown if io error.
330: *
331: * @param solutionPath
332: * @return
333: * @throws IOException
334: */
335: public byte[] getResourceAsBytes(IActionResource actionResource,
336: boolean getLocalizedResource) throws IOException;
337:
338: /**
339: * See getResourceInputStream(String solutionPath). Identical method
340: * except returns results as a DataSource.
341: *
342: * @param solutionPath
343: * @return
344: * @throws FileNotFoundException
345: */
346: public DataSource getResourceDataSource(String solutionPath)
347: throws FileNotFoundException;
348:
349: /**
350: * See getResourceInputStream(IActionResource actionResource). Identical method
351: * except returns results as a DataSource.
352: *
353: * @param solutionPath
354: * @return
355: * @throws FileNotFoundException
356: */
357: public DataSource getResourceDataSource(
358: IActionResource actionResource)
359: throws FileNotFoundException;
360:
361: /**
362: * See getResourceInputStream(String solutionPath). Identical method
363: * except returns results as a Document.
364: *
365: * @param solutionPath
366: * @return
367: */
368: public Document getResourceAsDocument(String solutionPath)
369: throws IOException;
370:
371: /**
372: * See getResourceInputStream(IActionResource actionResource). Identical method
373: * except returns results as a Document.
374: *
375: * @param solutionPath
376: * @return
377: */
378: public Document getResourceAsDocument(IActionResource actionResource)
379: throws IOException;
380:
381: /**
382: *
383: * @return
384: * An array of Strings where each string is the fully qualified path of
385: * every *.xaction contained in the repository.
386: */
387:
388: public String[] getAllActionSequences();
389:
390: /**
391: * Allows the caller to provide a List that will contain all log messages generated by the Solution Repository
392: * represented by this interface
393: *
394: * @param messages a List that String messages will be appended to
395: */
396: public void setMessages(List messages);
397:
398: /**
399: * Return the message list, if any, that all log messages generated by this Solution Repository
400: * are being appended to
401: *
402: * @return List of String messages
403: */
404: public List getMessages();
405:
406: /**
407: * Get an XML document that describes the structure of the solution repository.
408: * Returns the document used to construct the navigation UI. Also used
409: * by WAQR and jpivot to construct the repository browswer
410: *
411: * @param solution String The name of the solution. If this is empty (null or ""), and path
412: * is empty, return the root of the document. Otherwise return a document that
413: * starts at the node specified by the solution and path in the solution
414: * @param path String The path of the interested folder. See notes for
415: * parameter <param>solution</param>.
416: * @param actionOperation String
417: * @return Document XML document that describes the structure of the solution repository.
418: */
419: public Document getNavigationUIDocument(String solution,
420: String path, int actionOperation);
421:
422: /**
423: * Interprets the XSL name coming in against the document to see if there are any
424: * repository-specific changes based on display type associated with the XSL name
425: * @param doc
426: * @param inputXSLName
427: * @return Actual XSL name to use
428: */
429: public String getXSLName(Document doc, String solution,
430: String inputXSLName);
431:
432: /**
433: * This method resets the caches used by the solution repository.
434: */
435: public void resetRepository();
436:
437: /**
438: * @param path the solution path to the desired resource
439: * @return the ISolutionFile for the given path
440: */
441: public ISolutionFile getFileByPath(String path);
442:
443: /**
444: * @return the ISolutionFile for the root of the repository
445: */
446: public ISolutionFile getRootFolder();
447:
448: public void localizeDoc(Node document, ISolutionFile file);
449:
450: /**
451: * @return wether or not the concrete versions of this interface support ACLS
452: */
453: public boolean supportsACLS();
454:
455: public ISolutionFile getSolutionFile(IActionResource actionResource);
456:
457: }
|