From 82f28cc18b9371c81f3e6fa147080371a00443f5 Mon Sep 17 00:00:00 2001 From: Tobias Kellner Date: Sat, 15 Mar 2014 00:25:37 +0100 Subject: Don't use raw types! Also check casts where possible --- .../placeholder/SignaturePlaceholderContext.java | 4 +-- .../placeholder/SignaturePlaceholderExtractor.java | 30 ++++++++++++---------- .../pdfas/lib/impl/stamping/StamperFactory.java | 8 +++--- .../egiz/pdfas/lib/impl/stamping/TableFactory.java | 8 +++--- .../pdfas/lib/impl/verify/VerifierDispatcher.java | 8 +++--- .../java/at/gv/egiz/sl/util/BKUSLConnector.java | 9 +++---- 6 files changed, 36 insertions(+), 31 deletions(-) (limited to 'pdf-as-lib/src/main/java/at/gv') diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/SignaturePlaceholderContext.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/SignaturePlaceholderContext.java index f09202ae..3c8a6d76 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/SignaturePlaceholderContext.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/SignaturePlaceholderContext.java @@ -54,7 +54,7 @@ package at.gv.egiz.pdfas.lib.impl.placeholder; */ public class SignaturePlaceholderContext { - private ThreadLocal sigHolder = new ThreadLocal(); + private ThreadLocal sigHolder = new ThreadLocal(); private static SignaturePlaceholderContext instance = new SignaturePlaceholderContext(); @@ -72,7 +72,7 @@ public class SignaturePlaceholderContext { * @return */ public static SignaturePlaceholderData getSignaturePlaceholderData(){ - return (SignaturePlaceholderData)instance.sigHolder.get(); + return instance.sigHolder.get(); } /** diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/SignaturePlaceholderExtractor.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/SignaturePlaceholderExtractor.java index 52e25781..816ca04f 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/SignaturePlaceholderExtractor.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/SignaturePlaceholderExtractor.java @@ -59,6 +59,7 @@ import java.util.Vector; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.pdfbox.cos.COSBase; import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.exceptions.WrappedIOException; import org.apache.pdfbox.pdmodel.PDDocument; @@ -107,7 +108,7 @@ public class SignaturePlaceholderExtractor extends PDFStreamEngine { public static final int PLACEHOLDER_MATCH_MODE_MODERATE = 1; public static final int PLACEHOLDER_MATCH_MODE_LENIENT = 2; - private List placeholders = new Vector(); + private List placeholders = new Vector(); private int currentPage = 0; private SignaturePlaceholderExtractor(String placeholderId, int placeholderMatchMode) throws IOException { @@ -143,8 +144,8 @@ public class SignaturePlaceholderExtractor extends PDFStreamEngine { } catch (IOException e2) { throw new PDFIOException("error.pdf.io.04", e2); } - List pages = doc.getDocumentCatalog().getAllPages(); - Iterator iter = pages.iterator(); + List pages = doc.getDocumentCatalog().getAllPages(); + Iterator iter = pages.iterator(); int pageNr = 0; while (iter.hasNext()) { pageNr++; @@ -185,7 +186,7 @@ public class SignaturePlaceholderExtractor extends PDFStreamEngine { } private static SignaturePlaceholderData matchPlaceholderDocument( - List placeholders, String placeholderId, int matchMode) throws PlaceholderExtractionException { + List placeholders, String placeholderId, int matchMode) throws PlaceholderExtractionException { if (matchMode == PLACEHOLDER_MATCH_MODE_STRICT) throw new PlaceholderExtractionException("error.pdf.stamp.09"); @@ -195,24 +196,24 @@ public class SignaturePlaceholderExtractor extends PDFStreamEngine { for (int i = 0; i < placeholders.size(); i++) { - SignaturePlaceholderData spd = (SignaturePlaceholderData)placeholders.get(i); + SignaturePlaceholderData spd = placeholders.get(i); if (spd.getId() == null) return spd; } if (matchMode == PLACEHOLDER_MATCH_MODE_LENIENT) - return (SignaturePlaceholderData)placeholders.get(0); + return placeholders.get(0); return null; } - private static SignaturePlaceholderData matchPlaceholderPage(List placeholders, + private static SignaturePlaceholderData matchPlaceholderPage(List placeholders, String placeholderId, int matchMode) { if (placeholders.size() == 0) return null; for (int i = 0; i < placeholders.size(); i++) { - SignaturePlaceholderData data = (SignaturePlaceholderData)placeholders.get(i); + SignaturePlaceholderData data = placeholders.get(i); if (placeholderId != null && placeholderId.equals(data.getId())) return data; if (placeholderId == null && data.getId() == null) @@ -225,13 +226,14 @@ public class SignaturePlaceholderExtractor extends PDFStreamEngine { this.currentPage = pageNr; } - protected void processOperator( PDFOperator operator, List arguments ) throws IOException + @Override + protected void processOperator(PDFOperator operator, List arguments) throws IOException { String operation = operator.getOperation(); if( operation.equals( "Do" ) ) { COSName objectName = (COSName)arguments.get( 0 ); - Map xobjects = getResources().getXObjects(); + Map xobjects = getResources().getXObjects(); PDXObject xobject = (PDXObject)xobjects.get( objectName.getName() ); if( xobject instanceof PDXObjectImage ) { @@ -278,7 +280,7 @@ public class SignaturePlaceholderExtractor extends PDFStreamEngine { } else { - super.processOperator( operator, arguments ); + super.processOperator(operator, arguments); } } @@ -311,8 +313,8 @@ public class SignaturePlaceholderExtractor extends PDFStreamEngine { Result result; long before = System.currentTimeMillis(); try { - Hashtable hints = new Hashtable(); - Vector formats = new Vector(); + Hashtable> hints = new Hashtable>(); + Vector formats = new Vector(); formats.add(BarcodeFormat.QR_CODE); hints.put(DecodeHintType.POSSIBLE_FORMATS, formats); result = new MultiFormatReader().decode(bitmap, hints); @@ -326,7 +328,7 @@ public class SignaturePlaceholderExtractor extends PDFStreamEngine { if (text.startsWith(QR_PLACEHOLDER_IDENTIFIER)) { String[] data = text.split(";"); if (data.length > 1) { - for (int i = 1; i < data.length; i++) { + for (int i = 1; i < data.length; i++) { String kvPair = data[i]; String[] kv = kvPair.split("="); if (kv.length != 2) { diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/StamperFactory.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/StamperFactory.java index 42dee32d..ffed4da6 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/StamperFactory.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/StamperFactory.java @@ -33,9 +33,11 @@ public class StamperFactory { public static IPDFStamper createDefaultStamper(ISettings settings) throws PdfAsException { try { - Class cls = (Class) - Class.forName(DEFAULT_STAMPER_CLASS); - IPDFStamper stamper = cls.newInstance(); + Class cls = Class.forName(DEFAULT_STAMPER_CLASS); + Object st = cls.newInstance(); + if (!(st instanceof IPDFStamper)) + throw new ClassCastException(); + IPDFStamper stamper = (IPDFStamper) st; stamper.setSettings(settings); return stamper; } catch (Throwable e) { diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/TableFactory.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/TableFactory.java index 429aa6d0..8f945414 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/TableFactory.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/TableFactory.java @@ -66,7 +66,7 @@ public class TableFactory implements IProfileConstants { /** * Reference from signature key to there corresponding value */ - private static Hashtable sigEntries_ = new Hashtable(8); + private static Hashtable sigEntries_ = new Hashtable(8); static { setDefaultStyles(); @@ -151,7 +151,7 @@ public class TableFactory implements IProfileConstants { { // analyse the row definition String[] elems = table_def_string.split("\\|"); - ArrayList row = new ArrayList(); + ArrayList row = new ArrayList(); for (int elem_idx = 0; elem_idx < elems.length; elem_idx++) { String elem = elems[elem_idx]; @@ -268,7 +268,7 @@ public class TableFactory implements IProfileConstants { SignatureEntry sigEntry = null; if (sigEntries_.containsKey(key)) { - sigEntry = (SignatureEntry) sigEntries_.get(key); + sigEntry = sigEntries_.get(key); value = sigEntry.getValue(); } /* @@ -305,7 +305,7 @@ public class TableFactory implements IProfileConstants { String caption = null; if (sigEntries_.containsKey(key)) { - caption = ((SignatureEntry) sigEntries_.get(key)).getCaption(); + caption = sigEntries_.get(key).getCaption(); if (caption == null) { caption = key; diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/verify/VerifierDispatcher.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/verify/VerifierDispatcher.java index 509494b2..4fb883a3 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/verify/VerifierDispatcher.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/verify/VerifierDispatcher.java @@ -69,9 +69,11 @@ public class VerifierDispatcher { try { for (int i = 0; i < currentClasses.length; i++) { String clsName = currentClasses[i]; - Class cls = (Class) Class - .forName(clsName); - IVerifyFilter filter = cls.newInstance(); + Class cls = Class.forName(clsName); + Object f = cls.newInstance(); + if (!(f instanceof IVerifyFilter)) + throw new ClassCastException(); + IVerifyFilter filter = (IVerifyFilter) f; filter.setConfiguration((Configuration) settings); List entries = filter.getFiters(); Iterator it = entries.iterator(); diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BKUSLConnector.java b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BKUSLConnector.java index 9545b32f..c0a0b8aa 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BKUSLConnector.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BKUSLConnector.java @@ -104,10 +104,9 @@ public class BKUSLConnector extends BaseSLConnector { } } - @SuppressWarnings("rawtypes") public InfoboxReadResponseType sendInfoboxReadRequest( InfoboxReadRequestType request) throws PdfAsException { - JAXBElement element = null; + JAXBElement element = null; String slRequest; try { slRequest = SLMarschaller.marshalToString(of @@ -116,7 +115,7 @@ public class BKUSLConnector extends BaseSLConnector { String slResponse = performHttpRequestToBKU(slRequest); - element = (JAXBElement) SLMarschaller + element = (JAXBElement) SLMarschaller .unmarshalFromString(slResponse); } catch (JAXBException e) { @@ -146,7 +145,7 @@ public class BKUSLConnector extends BaseSLConnector { public CreateCMSSignatureResponseType sendCMSRequest( CreateCMSSignatureRequestType request) throws PdfAsException { - JAXBElement element = null; + JAXBElement element = null; String slRequest; try { slRequest = SLMarschaller.marshalToString(of @@ -155,7 +154,7 @@ public class BKUSLConnector extends BaseSLConnector { String slResponse = performHttpRequestToBKU(slRequest); - element = (JAXBElement) SLMarschaller + element = (JAXBElement) SLMarschaller .unmarshalFromString(slResponse); } catch (JAXBException e) { throw new PDFIOException("error.pdf.io.03", e); -- cgit v1.2.3