From dae854c33ec803eeda524ad165ee9ce00be58cdd Mon Sep 17 00:00:00 2001 From: Tilman Hausherr Date: Tue, 12 Dec 2023 13:44:11 +0000 Subject: [PATCH] PDFBOX-5660: code cleanup, by Axel Howind git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1914568 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/pdfbox/debugger/PDFDebugger.java | 4 +- .../debugger/stringpane/StringPane.java | 2 +- .../examples/signature/CreateSignature.java | 2 +- .../signature/CreateVisibleSignature.java | 2 +- .../signature/CreateVisibleSignature2.java | 2 +- .../org/apache/fontbox/ttf/WGL4Names.java | 263 +++++++++--------- .../org/apache/pdfbox/cos/COSDocument.java | 4 +- .../apache/pdfbox/text/PDFTextStripper.java | 2 +- 8 files changed, 140 insertions(+), 141 deletions(-) diff --git a/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java b/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java index 412eb6d74da..4db58a91ee8 100644 --- a/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java +++ b/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java @@ -1208,7 +1208,7 @@ private String convertToString( Object selectedNode ) } if (selectedNode instanceof COSName) { - return "" + ((COSName) selectedNode).getName(); + return ((COSName) selectedNode).getName(); } if (selectedNode instanceof COSString) { @@ -1259,7 +1259,7 @@ private String convertToString( Object selectedNode ) } if (selectedNode instanceof XrefEntry) { - return ((XrefEntry) selectedNode).toString(); + return selectedNode.toString(); } return null; } diff --git a/debugger/src/main/java/org/apache/pdfbox/debugger/stringpane/StringPane.java b/debugger/src/main/java/org/apache/pdfbox/debugger/stringpane/StringPane.java index 2a7fcd5ded6..350dd7ea57f 100644 --- a/debugger/src/main/java/org/apache/pdfbox/debugger/stringpane/StringPane.java +++ b/debugger/src/main/java/org/apache/pdfbox/debugger/stringpane/StringPane.java @@ -68,7 +68,7 @@ private String getTextString(COSString cosString) break; } } - return "" + text; + return text; } public JTabbedPane getPane() diff --git a/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateSignature.java b/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateSignature.java index 7397fdc7938..5d502c23d6a 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateSignature.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateSignature.java @@ -219,7 +219,7 @@ public static void main(String[] args) throws IOException, GeneralSecurityExcept private static void usage() { System.err.println("usage: java " + CreateSignature.class.getName() + " " + - " \n" + "" + + " \n" + "options:\n" + " -tsa sign timestamp using the given TSA server\n" + " -e sign using external signature creation scenario"); diff --git a/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature.java b/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature.java index 3f8cdd91755..4f389cb6457 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature.java @@ -469,7 +469,7 @@ public static void main(String[] args) throws KeyStoreException, CertificateExce private static void usage() { System.err.println("Usage: java " + CreateVisibleSignature.class.getName() - + " \n" + "" + + + " \n" + "options:\n" + " -tsa sign timestamp using the given TSA server\n"+ " -e sign using external signature creation scenario"); diff --git a/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature2.java b/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature2.java index 1c325a2ed83..51b519746fd 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature2.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature2.java @@ -583,7 +583,7 @@ public static void main(String[] args) throws KeyStoreException, CertificateExce private static void usage() { System.err.println("Usage: java " + CreateVisibleSignature2.class.getName() - + " \n" + "" + + + " \n" + "options:\n" + " -tsa sign timestamp using the given TSA server\n"+ " -e sign using external signature creation scenario"); diff --git a/fontbox/src/main/java/org/apache/fontbox/ttf/WGL4Names.java b/fontbox/src/main/java/org/apache/fontbox/ttf/WGL4Names.java index 7170f83d9bc..e021d20ced2 100644 --- a/fontbox/src/main/java/org/apache/fontbox/ttf/WGL4Names.java +++ b/fontbox/src/main/java/org/apache/fontbox/ttf/WGL4Names.java @@ -1,132 +1,131 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.fontbox.ttf; - -import java.util.HashMap; -import java.util.Map; - -/** - * Windows Glyph List 4 (WGL4) names for Mac glyphs. - */ -public final class WGL4Names -{ - /** - * The number of standard mac glyph names. - */ - public static final int NUMBER_OF_MAC_GLYPHS = 258; - - /** - * The 258 standard mac glyph names a used in 'post' format 1 and 2. - */ - private static final String[] MAC_GLYPH_NAMES = new String[] - { - ".notdef",".null", "nonmarkingreturn", "space", "exclam", "quotedbl", - "numbersign", "dollar", "percent", "ampersand", "quotesingle", - "parenleft", "parenright", "asterisk", "plus", "comma", "hyphen", - "period", "slash", "zero", "one", "two", "three", "four", "five", - "six", "seven", "eight", "nine", "colon", "semicolon", "less", - "equal", "greater", "question", "at", "A", "B", "C", "D", "E", "F", - "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", - "T", "U", "V", "W", "X", "Y", "Z", "bracketleft", "backslash", - "bracketright", "asciicircum", "underscore", "grave", "a", "b", - "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", - "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "braceleft", - "bar", "braceright", "asciitilde", "Adieresis", "Aring", - "Ccedilla", "Eacute", "Ntilde", "Odieresis", "Udieresis", "aacute", - "agrave", "acircumflex", "adieresis", "atilde", "aring", - "ccedilla", "eacute", "egrave", "ecircumflex", "edieresis", - "iacute", "igrave", "icircumflex", "idieresis", "ntilde", "oacute", - "ograve", "ocircumflex", "odieresis", "otilde", "uacute", "ugrave", - "ucircumflex", "udieresis", "dagger", "degree", "cent", "sterling", - "section", "bullet", "paragraph", "germandbls", "registered", - "copyright", "trademark", "acute", "dieresis", "notequal", "AE", - "Oslash", "infinity", "plusminus", "lessequal", "greaterequal", - "yen", "mu", "partialdiff", "summation", "product", "pi", - "integral", "ordfeminine", "ordmasculine", "Omega", "ae", "oslash", - "questiondown", "exclamdown", "logicalnot", "radical", "florin", - "approxequal", "Delta", "guillemotleft", "guillemotright", - "ellipsis", "nonbreakingspace", "Agrave", "Atilde", "Otilde", "OE", - "oe", "endash", "emdash", "quotedblleft", "quotedblright", - "quoteleft", "quoteright", "divide", "lozenge", "ydieresis", - "Ydieresis", "fraction", "currency", "guilsinglleft", - "guilsinglright", "fi", "fl", "daggerdbl", "periodcentered", - "quotesinglbase", "quotedblbase", "perthousand", "Acircumflex", - "Ecircumflex", "Aacute", "Edieresis", "Egrave", "Iacute", - "Icircumflex", "Idieresis", "Igrave", "Oacute", "Ocircumflex", - "apple", "Ograve", "Uacute", "Ucircumflex", "Ugrave", "dotlessi", - "circumflex", "tilde", "macron", "breve", "dotaccent", "ring", - "cedilla", "hungarumlaut", "ogonek", "caron", "Lslash", "lslash", - "Scaron", "scaron", "Zcaron", "zcaron", "brokenbar", "Eth", "eth", - "Yacute", "yacute", "Thorn", "thorn", "minus", "multiply", - "onesuperior", "twosuperior", "threesuperior", "onehalf", - "onequarter", "threequarters", "franc", "Gbreve", "gbreve", - "Idotaccent", "Scedilla", "scedilla", "Cacute", "cacute", "Ccaron", - "ccaron", "dcroat" - }; - - /** - * The indices of the standard mac glyph names. - */ - private static final Map MAC_GLYPH_NAMES_INDICES; - - static - { - MAC_GLYPH_NAMES_INDICES = new HashMap<>(NUMBER_OF_MAC_GLYPHS); - for (int i = 0; i < NUMBER_OF_MAC_GLYPHS; ++i) - { - MAC_GLYPH_NAMES_INDICES.put(MAC_GLYPH_NAMES[i],i); - } - } - - private WGL4Names() - { - } - - /** - * Returns the index of the glyph with the given name. - * - * @param name the name of the glyph - * @return the index of the given glyph name or null for an invalid glyph name - */ - public static Integer getGlyphIndex(String name) - { - return MAC_GLYPH_NAMES_INDICES.get(name); - } - - /** - * Returns the name of the glyph at the given index. - * - * @param index the index of the glyph - * @return the name of the glyph at the given index or null fo an invalid glyph index - */ - public static String getGlyphName(int index) - { - return index >= 0 && index < NUMBER_OF_MAC_GLYPHS ? MAC_GLYPH_NAMES[index] : null; - } - - /** - * Returns a new array with all glyph names. - * - * @return the array with all glyph names - */ - public static String[] getAllNames() - { - String[] glyphNames = new String[NUMBER_OF_MAC_GLYPHS]; - System.arraycopy(MAC_GLYPH_NAMES, 0, glyphNames, 0, NUMBER_OF_MAC_GLYPHS); - return glyphNames; - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.fontbox.ttf; + +import java.util.HashMap; +import java.util.Map; + +/** + * Windows Glyph List 4 (WGL4) names for Mac glyphs. + */ +public final class WGL4Names +{ + /** + * The number of standard mac glyph names. + */ + public static final int NUMBER_OF_MAC_GLYPHS = 258; + + /** + * The 258 standard mac glyph names a used in 'post' format 1 and 2. + */ + private static final String[] MAC_GLYPH_NAMES = { + ".notdef",".null", "nonmarkingreturn", "space", "exclam", "quotedbl", + "numbersign", "dollar", "percent", "ampersand", "quotesingle", + "parenleft", "parenright", "asterisk", "plus", "comma", "hyphen", + "period", "slash", "zero", "one", "two", "three", "four", "five", + "six", "seven", "eight", "nine", "colon", "semicolon", "less", + "equal", "greater", "question", "at", "A", "B", "C", "D", "E", "F", + "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", + "T", "U", "V", "W", "X", "Y", "Z", "bracketleft", "backslash", + "bracketright", "asciicircum", "underscore", "grave", "a", "b", + "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", + "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "braceleft", + "bar", "braceright", "asciitilde", "Adieresis", "Aring", + "Ccedilla", "Eacute", "Ntilde", "Odieresis", "Udieresis", "aacute", + "agrave", "acircumflex", "adieresis", "atilde", "aring", + "ccedilla", "eacute", "egrave", "ecircumflex", "edieresis", + "iacute", "igrave", "icircumflex", "idieresis", "ntilde", "oacute", + "ograve", "ocircumflex", "odieresis", "otilde", "uacute", "ugrave", + "ucircumflex", "udieresis", "dagger", "degree", "cent", "sterling", + "section", "bullet", "paragraph", "germandbls", "registered", + "copyright", "trademark", "acute", "dieresis", "notequal", "AE", + "Oslash", "infinity", "plusminus", "lessequal", "greaterequal", + "yen", "mu", "partialdiff", "summation", "product", "pi", + "integral", "ordfeminine", "ordmasculine", "Omega", "ae", "oslash", + "questiondown", "exclamdown", "logicalnot", "radical", "florin", + "approxequal", "Delta", "guillemotleft", "guillemotright", + "ellipsis", "nonbreakingspace", "Agrave", "Atilde", "Otilde", "OE", + "oe", "endash", "emdash", "quotedblleft", "quotedblright", + "quoteleft", "quoteright", "divide", "lozenge", "ydieresis", + "Ydieresis", "fraction", "currency", "guilsinglleft", + "guilsinglright", "fi", "fl", "daggerdbl", "periodcentered", + "quotesinglbase", "quotedblbase", "perthousand", "Acircumflex", + "Ecircumflex", "Aacute", "Edieresis", "Egrave", "Iacute", + "Icircumflex", "Idieresis", "Igrave", "Oacute", "Ocircumflex", + "apple", "Ograve", "Uacute", "Ucircumflex", "Ugrave", "dotlessi", + "circumflex", "tilde", "macron", "breve", "dotaccent", "ring", + "cedilla", "hungarumlaut", "ogonek", "caron", "Lslash", "lslash", + "Scaron", "scaron", "Zcaron", "zcaron", "brokenbar", "Eth", "eth", + "Yacute", "yacute", "Thorn", "thorn", "minus", "multiply", + "onesuperior", "twosuperior", "threesuperior", "onehalf", + "onequarter", "threequarters", "franc", "Gbreve", "gbreve", + "Idotaccent", "Scedilla", "scedilla", "Cacute", "cacute", "Ccaron", + "ccaron", "dcroat" + }; + + /** + * The indices of the standard mac glyph names. + */ + private static final Map MAC_GLYPH_NAMES_INDICES; + + static + { + MAC_GLYPH_NAMES_INDICES = new HashMap<>(NUMBER_OF_MAC_GLYPHS); + for (int i = 0; i < NUMBER_OF_MAC_GLYPHS; ++i) + { + MAC_GLYPH_NAMES_INDICES.put(MAC_GLYPH_NAMES[i],i); + } + } + + private WGL4Names() + { + } + + /** + * Returns the index of the glyph with the given name. + * + * @param name the name of the glyph + * @return the index of the given glyph name or null for an invalid glyph name + */ + public static Integer getGlyphIndex(String name) + { + return MAC_GLYPH_NAMES_INDICES.get(name); + } + + /** + * Returns the name of the glyph at the given index. + * + * @param index the index of the glyph + * @return the name of the glyph at the given index or null fo an invalid glyph index + */ + public static String getGlyphName(int index) + { + return index >= 0 && index < NUMBER_OF_MAC_GLYPHS ? MAC_GLYPH_NAMES[index] : null; + } + + /** + * Returns a new array with all glyph names. + * + * @return the array with all glyph names + */ + public static String[] getAllNames() + { + String[] glyphNames = new String[NUMBER_OF_MAC_GLYPHS]; + System.arraycopy(MAC_GLYPH_NAMES, 0, glyphNames, 0, NUMBER_OF_MAC_GLYPHS); + return glyphNames; + } +} diff --git a/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java b/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java index 024e9f1425e..838eca05e49 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java @@ -251,13 +251,13 @@ public List getObjectsByType(COSName type) */ public List getObjectsByType(COSName type1, COSName type2) { - List originKeys = new ArrayList(xrefTable.keySet()); + List originKeys = new ArrayList<>(xrefTable.keySet()); List retval = getObjectsByType(originKeys, type1, type2); // there might be some additional objects if the brute force parser was triggered // due to a broken cross reference table/stream if (originKeys.size() < xrefTable.size()) { - List additionalKeys = new ArrayList(xrefTable.keySet()); + List additionalKeys = new ArrayList<>(xrefTable.keySet()); additionalKeys.removeAll(originKeys); retval.addAll(getObjectsByType(additionalKeys, type1, type2)); } diff --git a/pdfbox/src/main/java/org/apache/pdfbox/text/PDFTextStripper.java b/pdfbox/src/main/java/org/apache/pdfbox/text/PDFTextStripper.java index fb7527f8fcc..8ee7ae441a0 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/text/PDFTextStripper.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/text/PDFTextStripper.java @@ -113,7 +113,7 @@ public class PDFTextStripper extends LegacyPDFStreamEngine /** * The platform's line separator. */ - protected final String LINE_SEPARATOR = System.lineSeparator(); + protected static final String LINE_SEPARATOR = System.lineSeparator(); private String lineSeparator = LINE_SEPARATOR; private String wordSeparator = " ";