|
From: <tr...@us...> - 2003-08-01 02:39:31
|
Update of /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/pipeline
In directory sc8-pr-cvs1:/tmp/cvs-serv9832
Modified Files:
Tag: branch_1_0
PipelineStage.java
Log Message:
Index: PipelineStage.java
===================================================================
RCS file: /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/pipeline/PipelineStage.java,v
retrieving revision 1.9
retrieving revision 1.9.4.1
diff -C2 -d -r1.9 -r1.9.4.1
*** PipelineStage.java 9 May 2003 12:25:16 -0000 1.9
--- PipelineStage.java 1 Aug 2003 02:39:27 -0000 1.9.4.1
***************
*** 54,67 ****
implements IPipelineStage {
! /** constant: output document mime type */
! public final static String OUTPUT_TYPE = "outType";
! /** constant: intput document mime type */
! public final static String INPUT_TYPE = "inType";
/** constant: name of the document in this stage */
! public static final String DOCUMENT_NAME = "docName";
/** constant: should fail if an error occurs */
- public static final String FAIL_ON_ERROR = "failOnError";
- /** constant: should fail if an error occurs */
public static final String ERROR_STAGE = "errorStage";
/** constant: is stage ignored */
--- 54,67 ----
implements IPipelineStage {
! /** constant: output document mime type */
! public final static String OUTPUT_TYPE = "outType";
! /** constant: intput document mime type */
! public final static String INPUT_TYPE = "inType";
/** constant: name of the document in this stage */
! public static final String DOCUMENT_NAME = "docName";
! /** constant: should fail if an error occurs */
! public static final String FAIL_ON_ERROR = "failOnError";
/** constant: should fail if an error occurs */
public static final String ERROR_STAGE = "errorStage";
/** constant: is stage ignored */
***************
*** 175,179 ****
*
* @return journal
! * @throws com.babeldoc.core.pipeline.PipelineException
*/
public IJournal getJournal()
--- 175,179 ----
*
* @return journal
! * @throws PipelineException
*/
public IJournal getJournal()
***************
*** 256,260 ****
try {
String value = getMyConfiguration().get(key).getValue();
! return templatization ? templatize(this.getDocument(), this.getTicket(),value) : value;
} catch (Exception e) {
//getLog().logWarn("Error resolving " + this.getName() + "." + key);
--- 256,260 ----
try {
String value = getMyConfiguration().get(key).getValue();
! return templatization ? templatize(this.getDocument(), this.getTicket(), value) : value;
} catch (Exception e) {
//getLog().logWarn("Error resolving " + this.getName() + "." + key);
***************
*** 328,348 ****
public NameValuePair[] getOptionList(String[] keys, boolean templatization) {
NameValuePair[] nvpairs = null;
! PipelineStageConfig config = getMyConfiguration();
! for (int i = 0; i < keys.length; ++i) {
! config = config.get(keys[i]);
! }
!
! if (config != null) {
! ArrayList array = new ArrayList();
! for (Iterator configKeys = config.keys().iterator(); configKeys.hasNext();) {
! String name = (String) configKeys.next();
! String value = templatization ? templatize(this.getDocument(),
! this.getTicket(), config.get(name).getValue()) :
! config.get(name).getValue();
! array.add(new NameValuePair(name, value));
! }
! nvpairs = (NameValuePair[]) (array.toArray(new NameValuePair[0]));
}
return nvpairs;
}
--- 328,348 ----
public NameValuePair[] getOptionList(String[] keys, boolean templatization) {
NameValuePair[] nvpairs = null;
! PipelineStageConfig config = getMyConfiguration();
! for (int i = 0; i < keys.length; ++i) {
! config = config.get(keys[i]);
! }
! if (config != null) {
! ArrayList array = new ArrayList();
! for (Iterator configKeys = config.keys().iterator(); configKeys.hasNext();) {
! String name = (String) configKeys.next();
! String value = templatization ? templatize(this.getDocument(),
! this.getTicket(), config.get(name).getValue()) :
! config.get(name).getValue();
! array.add(new NameValuePair(name, value));
}
+
+ nvpairs = (NameValuePair[]) (array.toArray(new NameValuePair[0]));
+ }
return nvpairs;
}
***************
*** 352,356 ****
*
* @return
- * @throws com.babeldoc.core.pipeline.PipelineException
*/
protected PipelineStageConfig getMyConfiguration() {
--- 352,355 ----
***************
*** 366,371 ****
*/
public boolean hasOption(String key) {
! String name = this.getOptions(key);
! return name != null;
}
--- 365,370 ----
*/
public boolean hasOption(String key) {
! String name = this.getOptions(key);
! return name != null;
}
***************
*** 378,383 ****
*/
public boolean hasOption(String key, String subkey) {
! String name = this.getOptions(key, subkey);
! return name != null;
}
--- 377,382 ----
*/
public boolean hasOption(String key, String subkey) {
! String name = this.getOptions(key, subkey);
! return name != null;
}
***************
*** 489,495 ****
-
-
-
/**
* Update the status
--- 488,491 ----
***************
*** 509,567 ****
! /**
! * ProcessPipelineStage. This method gets called from the process method that calls the
! * the pipeline stage and handles the errors
! *
! * @param name
! * @param pstage
! * @return array
! * @throws PipelineException
! */
! public PipelineStageResult[] processStage()
! throws PipelineException {
! PipelineStageResult[] psResults = null;
! try {
! // If the stage is not ignored, process usually
! if (!this.isIgnored()) {
! //set name for this document if provided
! this.getDocument().setName(this.getOptions(DOCUMENT_NAME));
! //set mime-type
! this.getDocument().setMimeType(this.getOptions(INPUT_TYPE));
! psResults = this.process();
!
! //Set output type if given
! if (psResults != null) {
! String outputType = this.getOptions(OUTPUT_TYPE);
! for (int i = 0; i < psResults.length; i++) {
! psResults[i].document.setMimeType(outputType);
! }
! }
! this.updateJournalStatus(JournalStatus.SUCCESS);
! } else {
! //stage is ignored. Ignore it!
! this.processIgnored();
! this.updateJournalStatus(JournalStatus.IGNORED);
! }
! } catch (PipelineException pe) {
! // If an error gets caught - handle the error. if the handler returns a
! //false flag then get the process ignored to get the next stage etc.
! if (!this.getErrorHandler().handlePipelineStageError(this, pe)) {
! try {
! psResults = this.processOnError();
! } catch (PipelineException e) {
! // Throw the Exception that caused the problem, not the one that
! // resulted as due to processing the problem
! throw pe;
! }
! } else {
! // Throw the Exception that caused the problem.
! throw pe;
! }
! }
! return psResults;
! }
--- 505,560 ----
! /**
! * ProcessPipelineStage. This method gets called from the process method that calls the
! * the pipeline stage and handles the errors
! *
! * @return array
! * @throws PipelineException
! */
! public PipelineStageResult[] processStage()
! throws PipelineException {
! PipelineStageResult[] psResults = null;
! try {
! // If the stage is not ignored, process usually
! if (!this.isIgnored()) {
! //set name for this document if provided
! this.getDocument().setName(this.getOptions(DOCUMENT_NAME));
! //set mime-type
! this.getDocument().setMimeType(this.getOptions(INPUT_TYPE));
! psResults = this.process();
! //Set output type if given
! if (psResults != null) {
! String outputType = this.getOptions(OUTPUT_TYPE);
! for (int i = 0; i < psResults.length; i++) {
! psResults[i].document.setMimeType(outputType);
! }
! }
! this.updateJournalStatus(JournalStatus.SUCCESS);
! } else {
! //stage is ignored. Ignore it!
! psResults = this.processIgnored();
! this.updateJournalStatus(JournalStatus.IGNORED);
! }
! } catch (PipelineException pe) {
! // If an error gets caught - handle the error. if the handler returns a
! //false flag then get the process ignored to get the next stage etc.
! if (!this.getErrorHandler().handlePipelineStageError(this, pe)) {
! try {
! psResults = this.processOnError();
! } catch (PipelineException e) {
! // Throw the Exception that caused the problem, not the one that
! // resulted as due to processing the problem
! throw pe;
! }
! } else {
! // Throw the Exception that caused the problem.
! throw pe;
! }
! }
+ return psResults;
+ }
***************
*** 572,639 ****
* @return
*/
! private IPipelineStageErrorHandler getErrorHandler()
! throws PipelineException {
! String errorHandler = this.getOptions(ERROR_HANDLER);
! if (errorHandler != null ) {
! try {
! return (IPipelineStageErrorHandler)ServiceFactory.getService(errorHandler);
! } catch (ServiceException se){
! throw new PipelineException(se.getMessage(), se);
! }
! }
! return new DefaultPipelineStageErrorHandler();
! }
! /**
! * Should processing document in this pipeline stage be skipped
! *
! * @return true - skip processing
! */
! public boolean isIgnored() {
! if (hasOption(IGNORED)) {
! return "true".equalsIgnoreCase(this.getOptions(IGNORED));
! } else {
! return false;
! }
! }
! /**
! * Must this pipeline stage track its data object?
! *
! * @return true - track the document
! */
! public boolean isTracked() {
! if (hasOption(TRACKED)) {
! return "true".equalsIgnoreCase(this.getOptions(TRACKED));
! } else {
! return false;
! }
! }
! public abstract PipelineStageResult[] process() throws PipelineException;
! /**
! * Default error Handler this stage which is in error. The default processing
! * updates the journal with a fail flag. Logs an error and returns a true fatality
! * flag.
! *
! * @param stage
! * @param pe
! * @return fatality flag - stop the pipeline processing if true
! */
! public boolean handlePipelineStageError(IPipelineStage stage,
! PipelineException pe) {
! JournalStatus status = JournalStatus.FAIL;
! ((PipelineStage) stage).setAdditionalInfo(pe.toString());
! ((PipelineStage) stage).updateJournalStatus(status);
! //add message to document
! stage.getDocument().addMessage(pe.toString());
! boolean stop = ((PipelineStage) stage).getFailOnError();
! LogService.getInstance().logError(com.babeldoc.core.I18n.get("019009",
! stage.getName(),
! pe.toString()), null);
! return stop;
! }
}
--- 565,633 ----
* @return
*/
! private IPipelineStageErrorHandler getErrorHandler()
! throws PipelineException {
! String errorHandler = this.getOptions(ERROR_HANDLER);
! if (errorHandler != null) {
! try {
! return (IPipelineStageErrorHandler) ServiceFactory.getService(errorHandler);
! } catch (ServiceException se) {
! throw new PipelineException(se.getMessage(), se);
! }
! }
! return new DefaultPipelineStageErrorHandler();
! }
! /**
! * Should processing document in this pipeline stage be skipped
! *
! * @return true - skip processing
! */
! public boolean isIgnored() {
! if (hasOption(IGNORED)) {
! return "true".equalsIgnoreCase(this.getOptions(IGNORED));
! } else {
! return false;
! }
! }
! /**
! * Must this pipeline stage track its data object?
! *
! * @return true - track the document
! */
! public boolean isTracked() {
! if (hasOption(TRACKED)) {
! return "true".equalsIgnoreCase(this.getOptions(TRACKED));
! } else {
! return false;
! }
! }
! public abstract PipelineStageResult[] process() throws PipelineException;
! /**
! * Default error Handler this stage which is in error. The default processing
! * updates the journal with a fail flag. Logs an error and returns a true fatality
! * flag.
! *
! * @param stage
! * @param pe
! * @return fatality flag - stop the pipeline processing if true
! */
! public boolean handlePipelineStageError(IPipelineStage stage,
! PipelineException pe) {
! JournalStatus status = JournalStatus.FAIL;
! ((PipelineStage) stage).setAdditionalInfo(pe.toString());
! ((PipelineStage) stage).updateJournalStatus(status);
! //add message to document
! stage.getDocument().addMessage(pe.toString());
!
! boolean stop = ((PipelineStage) stage).getFailOnError();
! LogService.getInstance().logError(com.babeldoc.core.I18n.get("019009",
! stage.getName(),
! pe.toString()), null);
! return stop;
! }
}
|