blob: bb42f9167fd4fbf897dbce3775b2055f9db13505 [file] [log] [blame]
//------------------------------------------------------------------------------
// Copyright (c) 2005, 2006 IBM Corporation and others.
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// which accompanies this distribution, and is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// Contributors:
// IBM Corporation - initial implementation
//------------------------------------------------------------------------------
package org.eclipse.epf.publishing.services;
import java.io.File;
import java.text.MessageFormat;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.epf.common.utils.Timer;
import org.eclipse.epf.library.services.FileNameCache;
import org.eclipse.epf.publishing.PublishingPlugin;
import org.eclipse.epf.uma.MethodConfiguration;
/**
* Abstract publishing manager class.
* use the org.eclipse.epf.publishing.ui.publishers extension point to extend this class
* if you need to customize the publishing.
*
* @author Jinhua Xi
* @since 1.0
*
*/
public abstract class AbstractPublishManager {
protected static boolean debug = PublishingPlugin.getDefault().isDebugging();
protected String pubDir;
protected MethodConfiguration config;
protected PublishOptions options;
protected AbstractViewBuilder viewBuilder;
protected boolean sucess = false;
/**
* default constructor
*
*/
public AbstractPublishManager() {
}
/**
* initilize the publishing manager
*
* @param pubDir String
* @param config MethodConfiguration
* @param options PublishOptions
*/
public void init(String pubDir, MethodConfiguration config, PublishOptions options) {
this.pubDir = pubDir;
if ( !this.pubDir.endsWith(File.separator) ) {
this.pubDir += File.separator;
}
this.config = config;
this.options = options;
this.viewBuilder = createViewBuilder();
// clear the file name cache
FileNameCache.getInstance().clear();
}
/**
* get the publishing view builder.
* The view builder is responsible to build the publishing views and contents.
*
* @return AbstractViewBuilder
*/
public AbstractViewBuilder getViewBuilder() {
return this.viewBuilder;
}
public ISiteGenerator getSiteGenerator() {
return viewBuilder.getSiteGenerator();
}
/**
* do publishing. The publishing process is defined in three steps.
* prePublish to do some preparation before the actual publishing
* doPublish to publish the views and contents
* postPublish to do some cleanup work after publish.
* Extended classes can override these methods to achieve additional publishing results.
*
* @param monitor IProgressMonitor
* @throws PublishingServiceException
*/
public void publish(IProgressMonitor monitor) throws PublishingServiceException {
if ( options != null ) {
options.validate();
}
Timer t = null;
if ( debug ) {
t = new Timer();
}
try {
prePublish(monitor);
doPublish(monitor);
postPublish(monitor);
sucess = true;
} catch (Exception e) {
throw new PublishingServiceException(e);
} finally {
if (debug && t != null ) {
t.stop();
System.out
.println(MessageFormat
.format(
"Time taken to publish configuration ''{0}'': {1} secs", //$NON-NLS-1$
new Object[] { config.getName(),
Long.toString(t.getTime()/1000) }));
}
}
}
/**
* dispose the object. Once disposed, the object is not valid any more.
*
*/
public void dispose() {
if ( viewBuilder != null ) {
viewBuilder.dispose();
viewBuilder = null;
}
}
/**
* abstract method to get the url to the published site
* @return String the url
*/
public abstract String getPublishedUrl();
/**
* abstract method to get the url to the publish report
* @return String
*/
public abstract String getPublishReportUrl();
protected abstract AbstractViewBuilder createViewBuilder();
protected abstract void prePublish(IProgressMonitor monitor) throws Exception;
protected abstract void doPublish(IProgressMonitor monitor) throws Exception;
protected abstract void postPublish(IProgressMonitor monitor) throws Exception;
}