Skip to content

Commit

Permalink
document metadata handling
Browse files Browse the repository at this point in the history
(doc-title, doc-author, doc-language, doc-subject, doc-creator)
  • Loading branch information
fugerit79 committed Oct 7, 2023
1 parent c26aa1c commit 773f901
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- document metadata handling (doc-title, doc-author, doc-language, doc-subject, doc-creator)

### Changed

- fj-doc version set to 3.1.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.function.Consumer;

import org.fugerit.java.core.cfg.ConfigRuntimeException;
import org.fugerit.java.core.lang.helpers.StringUtils;
Expand All @@ -28,6 +29,7 @@
import org.fugerit.java.doc.base.model.DocPhrase;
import org.fugerit.java.doc.base.model.DocStyle;
import org.fugerit.java.doc.base.model.DocTable;
import org.fugerit.java.doc.base.typehelper.generic.GenericConsts;
import org.fugerit.java.doc.base.xml.DocModelUtils;

import com.lowagie.text.Anchor;
Expand Down Expand Up @@ -345,12 +347,25 @@ private void handleFooter( DocBase docBase, PdfHelper pdfHelper, OpenPdfHelper d
}
}

private void applyIfNotEmpty( String value, Consumer<String> c ) {
if ( StringUtils.isNotEmpty( value ) ) {
c.accept(value);
}
}

/* (non-Javadoc)
* @see org.fugerit.java.doc.base.DocHandler#handleDoc(org.fugerit.java.doc.base.DocBase)
*/
public void handleDoc(DocBase docBase) throws DocumentException, IOException {
Properties info = docBase.getInfo();

// set document metadata
applyIfNotEmpty( docBase.getStableInfo().getProperty( GenericConsts.INFO_KEY_DOC_TITLE ) , s -> this.document.addTitle( s ) );
applyIfNotEmpty( docBase.getStableInfo().getProperty( GenericConsts.INFO_KEY_DOC_AUTHOR ) , s -> this.document.addAuthor( s ) );
applyIfNotEmpty( docBase.getStableInfo().getProperty( GenericConsts.INFO_KEY_DOC_SUBJECT ) , s -> this.document.addSubject( s ) );
applyIfNotEmpty( docBase.getStableInfo().getProperty( GenericConsts.INFO_KEY_DOC_CREATOR ) , s -> this.document.addCreator( s ) );
applyIfNotEmpty( docBase.getStableInfo().getProperty( GenericConsts.INFO_KEY_DOC_LANGUAGE ) , s -> this.document.setDocumentLanguage( s ) );

String defaultFontName = info.getProperty( DOC_DEFAULT_FONT_NAME, "helvetica" );
String defaultFontSize = info.getProperty( DOC_DEFAULT_FONT_SIZE, "10" );
String defaultFontStyle = info.getProperty( DOC_DEFAULT_FONT_STYLE, "normal" );
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/xml/default_doc_alt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<info name="doc-title">Basic example</info>
<info name="doc-subject">fj doc venus sample source xml</info>
<info name="doc-author">fugerit79</info>
<info name="doc-creator">Fugerit Venus OpenPDF DocTypeHandler</info>
<info name="doc-language">en</info>
<!-- font must be loaded -->
<info name="page-orient">horizontal</info>
Expand Down

0 comments on commit 773f901

Please sign in to comment.