Skip to content

Commit

Permalink
Added PDF creator to set on generated PDF docs
Browse files Browse the repository at this point in the history
  • Loading branch information
torakiki committed Dec 5, 2015
1 parent e9dacd5 commit c041179
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.pdfsam.support.RequireUtils.requireNotBlank;
import static org.pdfsam.support.RequireUtils.requireNotNull;

import org.pdfsam.ConfigurableProperty;
import org.pdfsam.Pdfsam;
import org.pdfsam.PdfsamEdition;
import org.springframework.core.env.Environment;
Expand All @@ -33,12 +34,15 @@
public class PdfsamCommunity implements Pdfsam {
private Environment env;
private String name;
private String shortName;

public PdfsamCommunity(String name, Environment env) {
public PdfsamCommunity(String name, String shortName, Environment env) {
requireNotBlank(name, "Application name cannot be blank");
requireNotBlank(shortName, "Application short name cannot be blank");
requireNotNull(env, "Environment cannot be null");
this.env = env;
this.name = name;
this.shortName = shortName;
}

public PdfsamEdition edition() {
Expand All @@ -49,12 +53,15 @@ public String name() {
return name;
}

public String property(org.pdfsam.ConfigurableProperty prop, String defaultValue) {
public String shortName() {
return shortName;
}

public String property(ConfigurableProperty prop, String defaultValue) {
return env.getProperty(prop.prop, defaultValue);
}

public String property(org.pdfsam.ConfigurableProperty prop) {
public String property(ConfigurableProperty prop) {
return env.getProperty(prop.prop, EMPTY);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,6 @@ public Image logo512() throws IOException {

@Bean
public Pdfsam pdfsam() {
return new PdfsamCommunity("PDF Split and Merge Basic Edition", env);
return new PdfsamCommunity("PDF Split and Merge Basic Edition", "PDFsam Basic", env);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,21 @@
public class PdfsamCommunityTest {
@Test(expected = IllegalArgumentException.class)
public void blankName() {
new PdfsamCommunity(" ", mock(Environment.class));
new PdfsamCommunity(" ", "something", mock(Environment.class));
}

@Test(expected = IllegalArgumentException.class)
public void blankShortName() {
new PdfsamCommunity("Something", " ", mock(Environment.class));
}

@Test(expected = IllegalArgumentException.class)
public void nullEnv() {
new PdfsamCommunity("name", null);
new PdfsamCommunity("name", "short", null);
}

@Test
public void edition() {
assertEquals(PdfsamEdition.COMMUNITY, new PdfsamCommunity("name", mock(Environment.class)).edition());
assertEquals(PdfsamEdition.COMMUNITY, new PdfsamCommunity("name", "short", mock(Environment.class)).edition());
}
}
5 changes: 5 additions & 0 deletions pdfsam-core/src/main/java/org/pdfsam/Pdfsam.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public interface Pdfsam {
*/
String name();

/**
* @return application short name
*/
String shortName();

/**
* @param prop
* @param defaultValue
Expand Down
9 changes: 8 additions & 1 deletion pdfsam-gui/src/main/java/org/pdfsam/PdfsamApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public void init() {
UserContext userContext = new DefaultUserContext();
System.setProperty(EventStudio.MAX_QUEUE_SIZE_PROP, Integer.toString(userContext.getNumberOfLogRows()));
LOG.info("Starting PDFsam");
System.setProperty(Sejda.UNETHICAL_READ_PROPERTY_NAME, "true");
cleanUserContextIfNeeded(userContext);
String localeString = userContext.getLocale();
if (isNotBlank(localeString)) {
Expand Down Expand Up @@ -119,6 +118,7 @@ public void start(Stage primaryStage) {
ApplicationContextHolder.getContext();
startLogAppender();
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionLogger());
initSejda();
cleanIfNeeded();
primaryStage.setScene(initScene());
primaryStage.getIcons().addAll(ApplicationContextHolder.getContext().getBeansOfType(Image.class).values());
Expand All @@ -139,6 +139,13 @@ public void start(Stage primaryStage) {
DurationFormatUtils.formatDurationWords(STOPWATCH.getTime(), true, true)));
}

private void initSejda() {
Pdfsam pdfsam = ApplicationContextHolder.getContext().getBean(Pdfsam.class);
System.out.println("here");
Sejda.CREATOR = pdfsam.shortName() + " v" + pdfsam.property(ConfigurableProperty.VERSION);
System.setProperty(Sejda.UNETHICAL_READ_PROPERTY_NAME, "true");
}

private void startLogAppender() {
LogMessageBroadcaster broadcaster = ApplicationContextHolder.getContext().getBean(LogMessageBroadcaster.class);
broadcaster.start();
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
<logback.version>1.1.3</logback.version>
<jdepend.version>2.9.1</jdepend.version>
<hibernate-validator.version>4.2.0.Final</hibernate-validator.version>
<sejda.version>2.0.0-alpha17</sejda.version>
<sejda.version>2.0.0-alpha25-SNAPSHOT</sejda.version>
<eventstudio.version>1.0.5</eventstudio.version>
<org.springframework.version>4.2.1.RELEASE</org.springframework.version>
<fontawesomefx.version>8.6</fontawesomefx.version>
Expand Down

0 comments on commit c041179

Please sign in to comment.