Skip to content

Commit

Permalink
[RELEASE] iText 7 7.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
iText-CI committed Dec 20, 2021
2 parents c4daee4 + c2fb4f6 commit fe4462b
Show file tree
Hide file tree
Showing 1,453 changed files with 7,652 additions and 2,093 deletions.
2 changes: 1 addition & 1 deletion barcodes/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.itextpdf</groupId>
<artifactId>root</artifactId>
<version>7.2.0</version>
<version>7.2.1</version>
</parent>
<artifactId>barcodes</artifactId>
<name>iText 7 - barcodes</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public void barcode417XObjectTest() throws IOException, InterruptedException {
barcode.setCode(text);
PdfFormXObject xObject = barcode.createFormXObject(document);

canvas.addXObject(xObject, 10, 650);
canvas.addXObjectAt(xObject, 10, 650);

document.close();

Expand Down
2 changes: 1 addition & 1 deletion commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.itextpdf</groupId>
<artifactId>root</artifactId>
<version>7.2.0</version>
<version>7.2.1</version>
</parent>
<artifactId>commons</artifactId>
<name>iText 7 - commons</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ This file is part of the iText (R) project.
import com.itextpdf.commons.actions.confirmations.ConfirmEvent;
import com.itextpdf.commons.actions.confirmations.ConfirmedEventWrapper;
import com.itextpdf.commons.actions.contexts.UnknownContext;
import com.itextpdf.commons.exceptions.UnknownProductException;
import com.itextpdf.commons.logs.CommonsLogMessageConstant;
import com.itextpdf.commons.actions.processors.DefaultITextProductEventProcessor;
import com.itextpdf.commons.actions.processors.ITextProductEventProcessor;
import com.itextpdf.commons.actions.sequence.SequenceId;
import com.itextpdf.commons.exceptions.ProductEventHandlerRepeatException;
import com.itextpdf.commons.exceptions.UnknownProductException;
import com.itextpdf.commons.logs.CommonsLogMessageConstant;
import com.itextpdf.commons.utils.MessageFormatUtil;

import java.util.ArrayList;
Expand All @@ -47,7 +48,11 @@ This file is part of the iText (R) project.
*/
final class ProductEventHandler extends AbstractContextBasedEventHandler {
static final ProductEventHandler INSTANCE = new ProductEventHandler();

private static final Logger LOGGER = LoggerFactory.getLogger(ProductEventHandler.class);
// The constant has the following value for two reasons. First, to avoid the infinite loop.
// Second, to retry event processing several times for technical reasons.
private static final int MAX_EVENT_RETRY_COUNT = 4;

private final ConcurrentHashMap<String, ITextProductEventProcessor> processors = new ConcurrentHashMap<>();
private final WeakHashMap<SequenceId, List<AbstractProductProcessITextEvent>> events = new WeakHashMap<>();
Expand All @@ -63,24 +68,17 @@ private ProductEventHandler() {
*/
@Override
protected void onAcceptedEvent(AbstractContextBasedITextEvent event) {
if (! (event instanceof AbstractProductProcessITextEvent)) {
return;
}
final AbstractProductProcessITextEvent productEvent = (AbstractProductProcessITextEvent) event;
final String productName = productEvent.getProductName();
final ITextProductEventProcessor productEventProcessor = getActiveProcessor(productName);
if (productEventProcessor == null) {
throw new UnknownProductException(
MessageFormatUtil.format(UnknownProductException.UNKNOWN_PRODUCT, productName));
}
productEventProcessor.onEvent(productEvent);
if (productEvent.getSequenceId() != null) {
if (productEvent instanceof ConfirmEvent) {
wrapConfirmedEvent((ConfirmEvent) productEvent, productEventProcessor);
} else {
addEvent(productEvent.getSequenceId(), productEvent);
for (int i = 0; i < MAX_EVENT_RETRY_COUNT; i++) {
try {
tryProcessEvent(event);
// process succeeded
return;
} catch (ProductEventHandlerRepeatException repeatException) {
// ignore this exception to retry the processing
}
}
// the final processing retry
tryProcessEvent(event);
}

ITextProductEventProcessor addProcessor(ITextProductEventProcessor processor) {
Expand Down Expand Up @@ -138,6 +136,29 @@ void addEvent(SequenceId id, AbstractProductProcessITextEvent event) {
}
}

private void tryProcessEvent(AbstractContextBasedITextEvent event) {
if (! (event instanceof AbstractProductProcessITextEvent)) {
return;
}
final AbstractProductProcessITextEvent productEvent = (AbstractProductProcessITextEvent) event;
final String productName = productEvent.getProductName();
final ITextProductEventProcessor productEventProcessor = getActiveProcessor(productName);
if (productEventProcessor == null) {
throw new UnknownProductException(
MessageFormatUtil.format(UnknownProductException.UNKNOWN_PRODUCT, productName));
}

productEventProcessor.onEvent(productEvent);

if (productEvent.getSequenceId() != null) {
if (productEvent instanceof ConfirmEvent) {
wrapConfirmedEvent((ConfirmEvent) productEvent, productEventProcessor);
} else {
addEvent(productEvent.getSequenceId(), productEvent);
}
}
}

private void wrapConfirmedEvent(ConfirmEvent event, ITextProductEventProcessor productEventProcessor) {
synchronized (events) {
final List<AbstractProductProcessITextEvent> eventsList = events.get(event.getSequenceId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ This file is part of the iText (R) project.
public final class CommonsProductData {
static final String COMMONS_PUBLIC_PRODUCT_NAME = "Commons";
static final String COMMONS_PRODUCT_NAME = "commons";
static final String COMMONS_VERSION = "7.2.0";
static final String COMMONS_VERSION = "7.2.1";
static final int COMMONS_COPYRIGHT_SINCE = 2000;
static final int COMMONS_COPYRIGHT_TO = 2021;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public final class ProductData {
private final String publicProductName;
private final String productName;
private final String version;
private final String minimalCompatibleLicenseKeyVersion;
private final int sinceCopyrightYear;
private final int toCopyrightYear;

Expand All @@ -45,9 +46,25 @@ public final class ProductData {
*/
public ProductData(String publicProductName, String productName, String version, int sinceCopyrightYear,
int toCopyrightYear) {
this(publicProductName, productName, version, null, sinceCopyrightYear, toCopyrightYear);
}

/**
* Creates a new instance of product data.
*
* @param publicProductName is a product name
* @param productName is a technical name of the product
* @param version is a version of the product
* @param minimalCompatibleLicenseKeyVersion is a minimal compatible version of licensekey library
* @param sinceCopyrightYear is the first year of a product development
* @param toCopyrightYear is a last year of a product development
*/
public ProductData(String publicProductName, String productName, String version,
String minimalCompatibleLicenseKeyVersion, int sinceCopyrightYear, int toCopyrightYear) {
this.publicProductName = publicProductName;
this.productName = productName;
this.version = version;
this.minimalCompatibleLicenseKeyVersion = minimalCompatibleLicenseKeyVersion;
this.sinceCopyrightYear = sinceCopyrightYear;
this.toCopyrightYear = toCopyrightYear;
}
Expand Down Expand Up @@ -97,6 +114,15 @@ public int getToCopyrightYear() {
return toCopyrightYear;
}

/**
* Getter for the minimal compatible licensekey version.
*
* @return minimal compatible version of licensekey library.
*/
public String getMinCompatibleLicensingModuleVersion() {
return minimalCompatibleLicenseKeyVersion;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public void onEvent(AbstractProductProcessITextEvent event) {
if (isNeededToLogMessage) {
String message = new String(MESSAGE_FOR_LOGGING, StandardCharsets.ISO_8859_1);
LOGGER.info(message);
// System out added with purpose. This is not a debug code
System.out.println(message);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2021 iText Group NV
Authors: iText Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.itextpdf.commons.exceptions;

/**
* The class represents a signal to the event handler that it is necessary to repeat the handling of the current event.
*/
public final class ProductEventHandlerRepeatException extends ITextException {
/**
* Creates a new instance of {@link ProductEventHandlerRepeatException} based on message.
*
* @param message the detail message
*/
public ProductEventHandlerRepeatException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ This file is part of the iText (R) project.
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;

/**
* This file is a helper class for internal usage only.
Expand Down Expand Up @@ -146,6 +147,11 @@ public static String format(Date date, String pattern) {
return initParserSDF(pattern).format(date);
}

public static long getCurrentTimeZoneOffset() {
TimeZone tz = TimeZone.getDefault();
return tz.getOffset(getCurrentTimeDate().getTime());
}

private static DateFormat initParserSDF(String pattern) {
final SimpleDateFormat parserSDF = new SimpleDateFormat(pattern);
parserSDF.setCalendar(new GregorianCalendar());
Expand Down
74 changes: 74 additions & 0 deletions commons/src/main/java/com/itextpdf/commons/utils/ProcessInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2021 iText Group NV
Authors: iText Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.itextpdf.commons.utils;

/**
* Class contains a process information, such as process exit code and process output.
*/
public final class ProcessInfo {

private final int exitCode;
private final String processStdOutput;
private final String processErrOutput;

/**
* Create a new instance, containing a process information,
* such as process exit code, process standard and error outputs.
*
* @param exitCode exit code of the process.
* @param processStdOutput the standard output of the process.
* @param processErrOutput the error output of the process.
*/
public ProcessInfo(int exitCode, String processStdOutput, String processErrOutput) {
this.exitCode = exitCode;
this.processStdOutput = processStdOutput;
this.processErrOutput = processErrOutput;
}

/**
* Getter for a process exit code.
*
* @return Returns a process exit code.
*/
public int getExitCode() {
return exitCode;
}

/**
* Getter for a standard process output.
*
* @return Returns a process standard output string.
*/
public String getProcessStdOutput() {
return processStdOutput;
}

/**
* Getter for an error process output.
*
* @return Returns a process error output string.
*/
public String getProcessErrOutput() {
return processErrOutput;
}
}
19 changes: 18 additions & 1 deletion commons/src/main/java/com/itextpdf/commons/utils/SystemUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ This file is part of the iText (R) project.
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -130,6 +131,14 @@ public static StringBuilder runProcessAndCollectErrors(String execPath, String p
return printProcessErrorsOutput(runProcess(execPath, params, null));
}

public static ProcessInfo runProcessAndGetProcessInfo(String command, String params) throws IOException,
InterruptedException {
Process p = runProcess(command, params, null);
String processStdOutput = printProcessStandardOutput(p).toString();
String processErrOutput = printProcessErrorsOutput(p).toString();
return new ProcessInfo(p.waitFor(), processStdOutput, processErrOutput);
}

static Process runProcess(String execPath, String params, String workingDirPath) throws IOException {
List<String> cmdList = prepareProcessArguments(execPath, params);
String[] cmdArray = cmdList.toArray(new String[0]);
Expand Down Expand Up @@ -181,8 +190,16 @@ static String getProcessOutput(Process p) throws IOException {
}

static StringBuilder printProcessErrorsOutput(Process p) throws IOException {
return printProcessOutput(p.getErrorStream());
}

static StringBuilder printProcessStandardOutput(Process p) throws IOException {
return printProcessOutput(p.getInputStream());
}

private static StringBuilder printProcessOutput(InputStream processStream) throws IOException {
StringBuilder builder = new StringBuilder();
BufferedReader bre = new BufferedReader(new InputStreamReader(p.getErrorStream()));
BufferedReader bre = new BufferedReader(new InputStreamReader(processStream));
String line;
while ((line = bre.readLine()) != null) {
System.out.println(line);
Expand Down
Loading

0 comments on commit fe4462b

Please sign in to comment.