ContentRepositoryOutputHandler.java
| Index Score | ||
|---|---|---|
![]() |
![]() |
org.pentaho.core.repository.content |
![]() |
![]() |
Pentaho |
View: Reasons, Metrics, Source Code
These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.
/*
* Copyright 2006 Pentaho Corporation. All rights reserved.
* This software was developed by Pentaho Corporation and is provided under the terms
* of the Mozilla Public License, Version 1.1, or any later version. You may not use
* this file except in compliance with the license. If you need a copy of the license,
* please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
* BI Platform. The Initial Developer is Pentaho Corporation.
*
* Software distributed under the Mozilla Public License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
* the license for the specific language governing your rights and limitations.
*/
package org.pentaho.core.repository.content;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.pentaho.core.repository.IContentItem;
import org.pentaho.core.repository.IContentLocation;
import org.pentaho.core.repository.IContentRepository;
import org.pentaho.core.runtime.IRuntimeContext;
import org.pentaho.core.session.IPentahoSession;
import org.pentaho.core.solution.IOutputDef;
import org.pentaho.core.solution.IOutputHandler;
import org.pentaho.core.solution.MimeTypeListener;
import org.pentaho.core.system.PentahoSystem;
import org.pentaho.messages.Messages;
public class ContentRepositoryOutputHandler implements IOutputHandler {
private static final byte[] lock = new byte[0];
public static final String DefaultMimeType = "application/octet-stream"; //$NON-NLS-1$
public static final String BackgroundFolder = "background"; //$NON-NLS-1$
public static final String DefaultExtension = ".bin"; //$NON-NLS-1$
private boolean contentGenerated;
private IContentItem outputContentItem;
private int outputType = OUTPUT_TYPE_DEFAULT;
private String location;
private String contentGUID;
// private String solution;
private String mimeType;
private String extension;
private int writeMode = IContentItem.WRITEMODE_OVERWRITE;
private IPentahoSession userSession;
protected IRuntimeContext runtimeContext;
public ContentRepositoryOutputHandler(String location, String contentGUID, String solution, IPentahoSession session) {
this(location, contentGUID, solution, DefaultMimeType, DefaultExtension, session);
}
public ContentRepositoryOutputHandler(String location, String contentGUID, String solution, String mimeType,
String extension, IPentahoSession session) {
this.contentGUID = contentGUID;
this.location = location;
//this.solution = solution;
this.mimeType = mimeType;
this.extension = extension;
userSession = session;
}
public void setSession(IPentahoSession session) {
this.userSession = session;
}
public IPentahoSession getSession() {
return userSession;
}
public void setMimeType(String value) {
mimeType = value;
}
public void setExtension(String value) {
extension = value;
}
public String getMimeType() {
return mimeType;
}
public String getExtension() {
return extension;
}
public void setWriteMode(int value) {
writeMode = value;
}
public int getWriteMode() {
return writeMode;
}
public Log getLogger() {
return LogFactory.getLog(ContentRepositoryOutputHandler.class);
}
public boolean allowFeedback() {
return false;
}
public boolean contentDone() {
return contentGenerated;
}
public IContentItem getFeedbackContentItem() {
return null;
}
public IContentItem getOutputContentItem(String objectName, String contentName, String solution, String instanceId,
String inMimeType) {
return getOutputContentItem(objectName, contentName, contentGUID, null, solution, instanceId, inMimeType);
}
public IContentItem getOutputContentItem(String objectName, String contentName, String title, String url,
String solution, String instanceId, String inMimeType) {
contentGenerated = true;
if (outputContentItem == null) {
if (inMimeType != null) {
this.setMimeType(inMimeType);
}
// We need to create one now because someone is asking for it.
IContentRepository contentRepository = PentahoSystem.getContentRepository(userSession);
if (contentRepository == null) {
getLogger().error(Messages.getErrorString("RuntimeContext.ERROR_0024_NO_CONTENT_REPOSITORY")); //$NON-NLS-1$
return null;
}
IContentItem contentItem = null;
//
// Synchronizing solves a nasty race condition when
// multiple simultaneous threads ask Hibernate if a
// specific Location/Item exists. In all cases, the
// answer will be no, so they all create the corresponding
// object and tell Hibernate to save it. The end-result is
// exceptions thrown from the database for key-constraint violations.
// Synchronizing down to the create of the item will make sure
// that all pending saves get persistent.
//
synchronized(lock) {
// Find the location if it's already there.
IContentLocation contentLocation = null;
try {
contentLocation = contentRepository.getContentLocationByPath(location);
} catch (Exception ex) {
// ignored
}
if (contentLocation == null) {
contentLocation = contentRepository.newContentLocation(location, contentName, contentName, solution, true);
}
if (contentLocation == null) {
getLogger().error(Messages.getErrorString("RuntimeContext.ERROR_0025_INVALID_CONTENT_LOCATION")); //$NON-NLS-1$
return null;
}
// Get the content item from the location - if it's there.
try {
contentItem = contentLocation.getContentItemByName(contentGUID);
} catch (Exception ex) {
// Ignored
}
if (contentItem == null) {
// Create a contentItem with the ID that came from the contentGUID.
// This must be a GUID or conflicts in the repository will happen.
contentItem = contentLocation.newContentItem(contentGUID, contentGUID, title, extension, mimeType, url,
writeMode);
}
outputContentItem = contentItem;
}
}
return outputContentItem;
}
public IOutputDef getOutputDef(String name) {
// TODO Auto-generated method stub
return null;
}
public Map getOutputDefs() {
// TODO Auto-generated method stub
return null;
}
public int getOutputPreference() {
// TODO Auto-generated method stub
return outputType;
}
public void setContentItem(IContentItem content, String objectName, String contentName) {
outputContentItem = content;
}
public void setOutput(String name, Object value) {
if (IOutputHandler.CONTENT.equalsIgnoreCase(name)) {
if (value instanceof IContentItem) {
outputContentItem = (IContentItem) value;
contentGenerated = true;
}
}
}
public void setOutputPreference(int value) {
this.outputType = value;
}
public MimeTypeListener getMimeTypeListener() {
return null;
}
public void setMimeTypeListener(MimeTypeListener mimeTypeListener) {
// ignored
}
public void setRuntimeContext(IRuntimeContext runtimeContext) {
this.runtimeContext = runtimeContext;
}
}
The table below shows all metrics for ContentRepositoryOutputHandler.java.




