1 13 package org.pentaho.core.repository.content; 14 15 import java.util.Map ; 16 17 import org.apache.commons.logging.Log; 18 import org.apache.commons.logging.LogFactory; 19 import org.pentaho.core.repository.IContentItem; 20 import org.pentaho.core.repository.IContentLocation; 21 import org.pentaho.core.repository.IContentRepository; 22 import org.pentaho.core.session.IPentahoSession; 23 import org.pentaho.core.solution.IOutputDef; 24 import org.pentaho.core.solution.IOutputHandler; 25 import org.pentaho.core.system.PentahoSystem; 26 import org.pentaho.messages.Messages; 27 28 public class ContentRepositoryOutputHandler implements IOutputHandler { 29 30 public static final String DefaultMimeType = "application/octet-stream"; public static final String BackgroundFolder = "background"; public static final String DefaultExtension = ".bin"; 34 private boolean contentGenerated; 35 private IContentItem outputContentItem; 36 private int outputType = OUTPUT_TYPE_DEFAULT; 37 private String location; 38 private String contentGUID; 39 private String solution; 40 private String mimeType; 41 private String extension; 42 private int writeMode = IContentItem.WRITEMODE_OVERWRITE; 43 private IPentahoSession userSession; 44 45 46 public ContentRepositoryOutputHandler(String location, 47 String contentGUID, 48 String solution, 49 IPentahoSession session) { 50 this(location, contentGUID, solution, DefaultMimeType, DefaultExtension, session); 51 } 52 53 public ContentRepositoryOutputHandler(String location, 54 String contentGUID, 55 String solution, 56 String mimeType, 57 String extension, 58 IPentahoSession session) { 59 60 this.contentGUID = contentGUID; 61 this.location = location; 62 this.solution = solution; 63 this.mimeType = mimeType; 64 this.extension = extension; 65 userSession = session; 66 } 67 68 public void setMimeType(String value) { 69 mimeType = value; 70 } 71 72 public void setExtension(String value) { 73 extension = value; 74 } 75 76 public String getMimeType() { 77 return mimeType; 78 } 79 80 public String getExtension() { 81 return extension; 82 } 83 84 public void setWriteMode(int value) { 85 writeMode = value; 86 } 87 88 public int getWriteMode() { 89 return writeMode; 90 } 91 92 public Log getLogger() { 93 return LogFactory.getLog(ContentRepositoryOutputHandler.class); 94 } 95 96 public boolean allowFeedback() { 97 return false; 98 } 99 100 public boolean contentDone() { 101 return contentGenerated; 102 } 103 104 public IContentItem getFeedbackContentItem() { 105 return null; 106 } 107 108 109 public IContentItem getOutputContentItem(String objectName, String contentName) { 110 return getOutputContentItem( objectName, contentName, contentGUID, null); 111 } 112 113 public IContentItem getOutputContentItem(String objectName, String contentName, String title, String url) { 114 contentGenerated = true; 115 if (outputContentItem == null) { 116 IContentRepository contentRepository = PentahoSystem.getContentRepository(userSession); 118 if (contentRepository == null) { 119 getLogger().error(Messages.getErrorString("RuntimeContext.ERROR_0024_NO_CONTENT_REPOSITORY")); return null; 121 } 122 IContentLocation contentLocation = null; 124 try { 125 contentLocation = contentRepository.getContentLocationByPath(location); 126 } catch (Exception ex) { 127 } 129 if (contentLocation == null) { 130 contentLocation = contentRepository.newContentLocation(location, contentName, contentName, solution, true); 131 } 132 133 if (contentLocation == null) { 134 getLogger().error(Messages.getErrorString("RuntimeContext.ERROR_0025_INVALID_CONTENT_LOCATION")); return null; 136 } 137 138 IContentItem contentItem = null; 140 try { 141 contentItem = contentLocation.getContentItemByName(contentGUID); 142 } catch (Exception ex) { 143 } 145 if (contentItem == null) { 146 149 contentItem = contentLocation.newContentItem(contentGUID, contentGUID, title, extension, mimeType, url, writeMode); 150 } 151 outputContentItem = contentItem; 152 } 153 return outputContentItem; 154 } 155 156 public IOutputDef getOutputDef(String name) { 157 return null; 159 } 160 161 public Map getOutputDefs() { 162 return null; 164 } 165 166 public int getOutputPreference() { 167 return outputType; 169 } 170 171 public void setContentItem(IContentItem content, String objectName, 172 String contentName) { 173 outputContentItem = content; 174 } 175 176 public void setOutput(String name, Object value) { 177 if (IOutputHandler.CONTENT.equalsIgnoreCase(name)) { 178 if ( value instanceof IContentItem ) { 179 outputContentItem = (IContentItem)value; 180 contentGenerated = true; 181 } 182 } 183 } 184 185 public void setOutputPreference(int value) { 186 this.outputType = value; 187 } 188 189 } 190 | Popular Tags |