Java tutorial
/* Copyright 2010-2014 Norconex Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.norconex.importer.handler.transformer; import java.io.InputStream; import java.io.OutputStream; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; import com.norconex.commons.lang.config.IXMLConfigurable; import com.norconex.importer.doc.ImporterMetadata; import com.norconex.importer.handler.AbstractImporterHandler; import com.norconex.importer.handler.ImporterHandlerException; /** * Base class for transformers. * <br><br> * * Subclasses inherit this {@link IXMLConfigurable} configuration: * <pre> * <restrictTo caseSensitive="[false|true]" * field="(name of header/metadata field name to match)"> * (regular expression of value to match) * </restrictTo> * <!-- multiple "restrictTo" tags allowed (only one needs to match) --> * </pre> * @author Pascal Essiembre * @since 2.0.0 */ public abstract class AbstractDocumentTransformer extends AbstractImporterHandler implements IDocumentTransformer { public AbstractDocumentTransformer() { super("transformer"); } @Override public final void transformDocument(String reference, InputStream input, OutputStream output, ImporterMetadata metadata, boolean parsed) throws ImporterHandlerException { if (!isApplicable(reference, metadata, parsed)) { return; } transformApplicableDocument(reference, input, output, metadata, parsed); } protected abstract void transformApplicableDocument(String reference, InputStream input, OutputStream output, ImporterMetadata metadata, boolean parsed) throws ImporterHandlerException; @Override public boolean equals(final Object other) { if (!(other instanceof AbstractDocumentTransformer)) { return false; } return new EqualsBuilder().appendSuper(super.equals(other)).isEquals(); } @Override public int hashCode() { return new HashCodeBuilder().appendSuper(super.hashCode()).toHashCode(); } }