com.helger.pdflayout.IPDDocumentCustomizer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ph-pdf-layout Show documentation
Show all versions of ph-pdf-layout Show documentation
Library for creating nicely layouted PDF documents based on PDFBox
/**
* Copyright (C) 2014-2016 Philip Helger (www.helger.com)
* philip[at]helger[dot]com
*
* 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.helger.pdflayout;
import java.io.IOException;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.apache.pdfbox.pdmodel.PDDocument;
import com.helger.commons.ValueEnforcer;
/**
* Callback interface for PDF customization
*
* @author Philip Helger
*/
@FunctionalInterface
public interface IPDDocumentCustomizer
{
/**
* Customize the passed {@link PDDocument}.
*
* @param aDoc
* The document to be customized. Never null
.
* @throws IOException
* in case something goes wrong
*/
void customizeDocument (@Nonnull PDDocument aDoc) throws IOException;
/**
* Invoke this customizer and afterwards the provided customizer.
*
* @param aNextCustomizer
* The customizer to be invoked after this customizer. May not be
* null
.
* @return A new, non-null
customizer.
*/
@Nonnull
@CheckReturnValue
default IPDDocumentCustomizer and (@Nonnull final IPDDocumentCustomizer aNextCustomizer)
{
ValueEnforcer.notNull (aNextCustomizer, "NextCustomizer");
return aDoc -> {
this.customizeDocument (aDoc);
aNextCustomizer.customizeDocument (aDoc);
};
}
/**
* Create a customizer that invokes both customizers if they are
* non-null
.
*
* @param aCustomizer1
* The first customizer to be invoked. May be null
.
* @param aCustomizer2
* The second customizer to be invoked after the first customizer (if
* present). May be null
.
* @return null
if both parameters are null
.
*/
@Nullable
@CheckReturnValue
static IPDDocumentCustomizer and (@Nullable final IPDDocumentCustomizer aCustomizer1,
@Nullable final IPDDocumentCustomizer aCustomizer2)
{
if (aCustomizer1 != null)
{
if (aCustomizer2 != null)
return aCustomizer1.and (aCustomizer2);
return aCustomizer1;
}
// May be null
return aCustomizer2;
}
}