use of org.apache.pdfbox.preflight.PreflightConfiguration in project pdfbox by apache.
the class PreflightStreamEngine method checkSetColorSpaceOperators.
/**
* This method validates if the ColorSpace used as operand is consistent with
* the color space defined in OutputIntent dictionaries.
*
* @param operator
* @param arguments
* @throws IOException
*/
protected void checkSetColorSpaceOperators(Operator operator, List<COSBase> arguments) throws IOException {
if (!("CS".equals(operator.getName()) || "cs".equals(operator.getName()))) {
return;
}
String colorSpaceName;
if (arguments.get(0) instanceof COSString) {
colorSpaceName = (arguments.get(0)).toString();
} else if (arguments.get(0) instanceof COSName) {
colorSpaceName = ((COSName) arguments.get(0)).getName();
} else {
registerError("The operand " + arguments.get(0) + " for colorSpace operator " + operator.getName() + " doesn't have the expected type", ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY);
return;
}
ColorSpaceHelper csHelper = null;
ColorSpaces cs = null;
try {
cs = ColorSpaces.valueOf(colorSpaceName);
} catch (IllegalArgumentException e) {
/*
* The color space is unknown. Try to access the resources dictionary, the color space can be a reference.
*/
PDColorSpace pdCS = this.getResources().getColorSpace(COSName.getPDFName(colorSpaceName));
if (pdCS != null) {
cs = ColorSpaces.valueOf(pdCS.getName());
PreflightConfiguration cfg = context.getConfig();
ColorSpaceHelperFactory csFact = cfg.getColorSpaceHelperFact();
csHelper = csFact.getColorSpaceHelper(context, pdCS, ColorSpaceRestriction.NO_RESTRICTION);
}
}
if (cs == null) {
registerError("The ColorSpace " + colorSpaceName + " is unknown", ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY);
return;
}
if (csHelper == null) {
PDColorSpace pdCS = PDColorSpace.create(COSName.getPDFName(colorSpaceName));
PreflightConfiguration cfg = context.getConfig();
ColorSpaceHelperFactory csFact = cfg.getColorSpaceHelperFact();
csHelper = csFact.getColorSpaceHelper(context, pdCS, ColorSpaceRestriction.NO_RESTRICTION);
}
csHelper.validate();
}
use of org.apache.pdfbox.preflight.PreflightConfiguration in project pdfbox by apache.
the class PreflightStreamEngine method getColorSpaceHelper.
private ColorSpaceHelper getColorSpaceHelper(PDColorSpace pdCS) {
PreflightConfiguration cfg = context.getConfig();
ColorSpaceHelperFactory csFact = cfg.getColorSpaceHelperFact();
return csFact.getColorSpaceHelper(context, pdCS, ColorSpaceRestriction.ONLY_DEVICE);
}
use of org.apache.pdfbox.preflight.PreflightConfiguration in project pdfbox by apache.
the class TestPreflightConfiguration method testGetValidationProcess_MissingProcess.
@Test(expected = MissingValidationProcessException.class)
public void testGetValidationProcess_MissingProcess() throws Exception {
PreflightConfiguration configuration = PreflightConfiguration.createPdfA1BConfiguration();
configuration.getInstanceOfProcess("unknownProcess");
}
use of org.apache.pdfbox.preflight.PreflightConfiguration in project pdfbox by apache.
the class TestPreflightConfiguration method testReplaceValidationProcess.
@Test
public void testReplaceValidationProcess() throws Exception {
PreflightConfiguration configuration = PreflightConfiguration.createPdfA1BConfiguration();
String processName = "mock-process";
configuration.replaceProcess(processName, MockProcess.class);
assertEquals(MockProcess.class, configuration.getInstanceOfProcess(processName).getClass());
configuration.replaceProcess(processName, MockProcess2.class);
assertEquals(MockProcess2.class, configuration.getInstanceOfProcess(processName).getClass());
}
use of org.apache.pdfbox.preflight.PreflightConfiguration in project pdfbox by apache.
the class ContextHelper method callValidation.
/**
* Put the element to check on the top of the ValidationPath and call the validation method on the Process.
*
* @param context
* (mandatory) the preflight context that contains all required information
* @param element
* @param processName
* the process to instantiate and to compute
* @throws ValidationException
*/
private static void callValidation(PreflightContext context, Object element, String processName) throws ValidationException {
PreflightPath validationPath = context.getValidationPath();
if (hasRecursion(context, element, validationPath)) {
return;
}
boolean needPop = validationPath.pushObject(element);
PreflightConfiguration config = context.getConfig();
ValidationProcess process = config.getInstanceOfProcess(processName);
process.validate(context);
if (needPop) {
validationPath.pop();
}
}
Aggregations