Skip to content

Commit cc7d3f4

Browse files
author
Evgeniy Prudnikov
committed
Option to remove AGPL log message
DEVSIX-6378
1 parent 040086f commit cc7d3f4

14 files changed

+579
-2
lines changed

commons/src/main/java/com/itextpdf/commons/actions/EventManager.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ This file is part of the iText (R) project.
2222
*/
2323
package com.itextpdf.commons.actions;
2424

25+
import com.itextpdf.commons.actions.processors.UnderAgplProductProcessorFactory;
2526
import com.itextpdf.commons.exceptions.AggregatedException;
2627

2728
import java.util.ArrayList;
@@ -51,6 +52,16 @@ public static EventManager getInstance() {
5152
return INSTANCE;
5253
}
5354

55+
/**
56+
* Deliberately turns off the warning message about AGPL usage.
57+
*
58+
* <p>
59+
* <b> Important note. Calling of this method means that the terms of AGPL license are met. </b>
60+
*/
61+
public static void acknowledgeAgplUsageDisableWarningMessage() {
62+
ProductProcessorFactoryKeeper.setProductProcessorFactory(new UnderAgplProductProcessorFactory());
63+
}
64+
5465
/**
5566
* Handles the event.
5667
*

commons/src/main/java/com/itextpdf/commons/actions/ProductEventHandler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ This file is part of the iText (R) project.
2525
import com.itextpdf.commons.actions.confirmations.ConfirmEvent;
2626
import com.itextpdf.commons.actions.confirmations.ConfirmedEventWrapper;
2727
import com.itextpdf.commons.actions.contexts.UnknownContext;
28-
import com.itextpdf.commons.actions.processors.DefaultITextProductEventProcessor;
2928
import com.itextpdf.commons.actions.processors.ITextProductEventProcessor;
3029
import com.itextpdf.commons.actions.sequence.SequenceId;
3130
import com.itextpdf.commons.exceptions.ProductEventHandlerRepeatException;
@@ -97,7 +96,7 @@ ITextProductEventProcessor getActiveProcessor(String productName) {
9796
}
9897

9998
if (ProductNameConstant.PRODUCT_NAMES.contains(productName)) {
100-
processor = new DefaultITextProductEventProcessor(productName);
99+
processor = ProductProcessorFactoryKeeper.getProductProcessorFactory().createProcessor(productName);
101100
processors.put(productName, processor);
102101
return processor;
103102
} else {
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2022 iText Group NV
4+
Authors: iText Software.
5+
6+
This program is offered under a commercial and under the AGPL license.
7+
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
8+
9+
AGPL licensing:
10+
This program is free software: you can redistribute it and/or modify
11+
it under the terms of the GNU Affero General Public License as published by
12+
the Free Software Foundation, either version 3 of the License, or
13+
(at your option) any later version.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU Affero General Public License for more details.
19+
20+
You should have received a copy of the GNU Affero General Public License
21+
along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
package com.itextpdf.commons.actions;
24+
25+
import com.itextpdf.commons.actions.processors.DefaultProductProcessorFactory;
26+
import com.itextpdf.commons.actions.processors.IProductProcessorFactory;
27+
28+
/**
29+
* Helper class which allow to change used product processor factory instance.
30+
*/
31+
final class ProductProcessorFactoryKeeper {
32+
private static final IProductProcessorFactory DEFAULT_FACTORY = new DefaultProductProcessorFactory();
33+
private static IProductProcessorFactory productProcessorFactory = DEFAULT_FACTORY;
34+
35+
private ProductProcessorFactoryKeeper() {
36+
// do nothing
37+
}
38+
39+
/**
40+
* Sets product processor factory instance.
41+
*
42+
* @param productProcessorFactory the instance to be set
43+
*/
44+
static void setProductProcessorFactory(IProductProcessorFactory productProcessorFactory) {
45+
ProductProcessorFactoryKeeper.productProcessorFactory = productProcessorFactory;
46+
}
47+
48+
/**
49+
* Restores default factory.
50+
*/
51+
static void restoreDefaultProductProcessorFactory() {
52+
ProductProcessorFactoryKeeper.productProcessorFactory = DEFAULT_FACTORY;
53+
}
54+
55+
/**
56+
* Gets reporting product processor factory instance.
57+
*
58+
* @return the product processor factory instance
59+
*/
60+
static IProductProcessorFactory getProductProcessorFactory() {
61+
return productProcessorFactory;
62+
}
63+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2022 iText Group NV
4+
Authors: iText Software.
5+
6+
This program is offered under a commercial and under the AGPL license.
7+
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
8+
9+
AGPL licensing:
10+
This program is free software: you can redistribute it and/or modify
11+
it under the terms of the GNU Affero General Public License as published by
12+
the Free Software Foundation, either version 3 of the License, or
13+
(at your option) any later version.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU Affero General Public License for more details.
19+
20+
You should have received a copy of the GNU Affero General Public License
21+
along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
package com.itextpdf.commons.actions.processors;
24+
25+
/**
26+
* Default factory class to construct {@link ITextProductEventProcessor} instance.
27+
*/
28+
public class DefaultProductProcessorFactory implements IProductProcessorFactory {
29+
30+
/**
31+
* Creates default product processor using a product name.
32+
*
33+
* @param productName the product which will be handled by this processor
34+
*
35+
* @return current {@link ITextProductEventProcessor} instance
36+
*/
37+
@Override
38+
public ITextProductEventProcessor createProcessor(String productName) {
39+
return new DefaultITextProductEventProcessor(productName);
40+
}
41+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2022 iText Group NV
4+
Authors: iText Software.
5+
6+
This program is offered under a commercial and under the AGPL license.
7+
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
8+
9+
AGPL licensing:
10+
This program is free software: you can redistribute it and/or modify
11+
it under the terms of the GNU Affero General Public License as published by
12+
the Free Software Foundation, either version 3 of the License, or
13+
(at your option) any later version.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU Affero General Public License for more details.
19+
20+
You should have received a copy of the GNU Affero General Public License
21+
along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
package com.itextpdf.commons.actions.processors;
24+
25+
/**
26+
* Class represents a factory for {@link ITextProductEventProcessor} objects.
27+
*/
28+
public interface IProductProcessorFactory {
29+
/**
30+
* Creates product processor using a product name.
31+
*
32+
* @param productName the product which will be handled by this processor
33+
*
34+
* @return the processor instance
35+
*/
36+
ITextProductEventProcessor createProcessor(String productName);
37+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2022 iText Group NV
4+
Authors: iText Software.
5+
6+
This program is offered under a commercial and under the AGPL license.
7+
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
8+
9+
AGPL licensing:
10+
This program is free software: you can redistribute it and/or modify
11+
it under the terms of the GNU Affero General Public License as published by
12+
the Free Software Foundation, either version 3 of the License, or
13+
(at your option) any later version.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU Affero General Public License for more details.
19+
20+
You should have received a copy of the GNU Affero General Public License
21+
along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
package com.itextpdf.commons.actions.processors;
24+
25+
import com.itextpdf.commons.actions.AbstractProductProcessITextEvent;
26+
27+
/**
28+
* The class defines an under APGL strategy of product event processing.
29+
*/
30+
public class UnderAgplITextProductEventProcessor extends AbstractITextProductEventProcessor{
31+
/**
32+
* Creates a new instance of under AGPL processor for the provided product.
33+
*
34+
* @param productName the product which will be handled by this processor
35+
*/
36+
public UnderAgplITextProductEventProcessor(String productName) {
37+
super(productName);
38+
}
39+
40+
@Override
41+
public void onEvent(AbstractProductProcessITextEvent event) {
42+
// do nothing
43+
}
44+
45+
@Override
46+
public String getUsageType() {
47+
return "AGPL";
48+
}
49+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2022 iText Group NV
4+
Authors: iText Software.
5+
6+
This program is offered under a commercial and under the AGPL license.
7+
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
8+
9+
AGPL licensing:
10+
This program is free software: you can redistribute it and/or modify
11+
it under the terms of the GNU Affero General Public License as published by
12+
the Free Software Foundation, either version 3 of the License, or
13+
(at your option) any later version.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU Affero General Public License for more details.
19+
20+
You should have received a copy of the GNU Affero General Public License
21+
along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
package com.itextpdf.commons.actions.processors;
24+
25+
/**
26+
* Factory class to construct {@link ITextProductEventProcessor} instance under AGPL license.
27+
*/
28+
public class UnderAgplProductProcessorFactory implements IProductProcessorFactory {
29+
30+
/**
31+
* Creates under AGPL product processor using a product name.
32+
*
33+
* @param productName the product which will be handled by this processor
34+
*
35+
* @return current {@link ITextProductEventProcessor} instance
36+
*/
37+
@Override
38+
public ITextProductEventProcessor createProcessor(String productName) {
39+
return new UnderAgplITextProductEventProcessor(productName);
40+
}
41+
}

commons/src/test/java/com/itextpdf/commons/actions/EventManagerTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ This file is part of the iText (R) project.
2222
*/
2323
package com.itextpdf.commons.actions;
2424

25+
import com.itextpdf.commons.actions.processors.DefaultProductProcessorFactory;
26+
import com.itextpdf.commons.actions.processors.IProductProcessorFactory;
27+
import com.itextpdf.commons.actions.processors.UnderAgplProductProcessorFactory;
2528
import com.itextpdf.commons.actions.sequence.SequenceId;
2629
import com.itextpdf.commons.ecosystem.ITextTestEvent;
2730
import com.itextpdf.commons.ecosystem.TestConfigurationEvent;
@@ -33,13 +36,19 @@ This file is part of the iText (R) project.
3336
import com.itextpdf.test.annotations.type.UnitTest;
3437

3538
import java.util.List;
39+
import org.junit.After;
3640
import org.junit.Assert;
3741
import org.junit.Test;
3842
import org.junit.experimental.categories.Category;
3943

4044
@Category(UnitTest.class)
4145
public class EventManagerTest extends ExtendedITextTest {
4246

47+
@After
48+
public void afterEach() {
49+
ProductProcessorFactoryKeeper.restoreDefaultProductProcessorFactory();
50+
}
51+
4352
@Test
4453
@LogMessages(messages = {
4554
@LogMessage(messageTemplate = TestConfigurationEvent.MESSAGE)
@@ -106,7 +115,15 @@ public void configureHandlersTest() {
106115
Assert.assertFalse(eventManager.isRegistered(handler));
107116

108117
Assert.assertFalse(eventManager.unregister(handler));
118+
}
109119

120+
@Test
121+
public void turningOffAgplTest() {
122+
IProductProcessorFactory defaultProductProcessorFactory = ProductProcessorFactoryKeeper.getProductProcessorFactory();
123+
Assert.assertTrue(defaultProductProcessorFactory instanceof DefaultProductProcessorFactory);
124+
EventManager.acknowledgeAgplUsageDisableWarningMessage();
125+
IProductProcessorFactory underAgplProductProcessorFactory1 = ProductProcessorFactoryKeeper.getProductProcessorFactory();
126+
Assert.assertTrue(underAgplProductProcessorFactory1 instanceof UnderAgplProductProcessorFactory);
110127
}
111128

112129
private static class ThrowArithmeticExpHandler implements IEventHandler {

0 commit comments

Comments
 (0)