pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1848233 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel: PageLayout.java PageMode.java graphics/state/RenderingIntent.java
Date Wed, 05 Dec 2018 18:42:35 GMT
Author: tilman
Date: Wed Dec  5 18:42:35 2018
New Revision: 1848233

URL: http://svn.apache.org/viewvc?rev=1848233&view=rev
Log:
PDFBOX-4397: avoid duplicate strings

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PageLayout.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PageMode.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/RenderingIntent.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PageLayout.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PageLayout.java?rev=1848233&r1=1848232&r2=1848233&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PageLayout.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PageLayout.java Wed Dec  5
18:42:35 2018
@@ -1,80 +1,71 @@
-/*
- * 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.pdfbox.pdmodel;
-
-/**
- * A name object specifying the page layout shall be used when the document is opened.
- *
- * @author John Hewson
- */
-public enum PageLayout
-{
-    /** Display one page at a time. */
-    SINGLE_PAGE("SinglePage"),
-
-    /**  Display the pages in one column. */
-    ONE_COLUMN("OneColumn"),
-
-    /** Display the pages in two columns), with odd numbered pages on the left. */
-    TWO_COLUMN_LEFT("TwoColumnLeft"),
-
-    /** Display the pages in two columns), with odd numbered pages on the right.  */
-    TWO_COLUMN_RIGHT("TwoColumnRight"),
-
-    /** Display the pages two at a time), with odd-numbered pages on the left. */
-    TWO_PAGE_LEFT("TwoPageLeft"),
-
-    /** Display the pages two at a time), with odd-numbered pages on the right. */
-    TWO_PAGE_RIGHT("TwoPageRight");
-
-    public static PageLayout fromString(String value)
-    {
-        switch (value)
-        {
-            case "SinglePage":
-                return SINGLE_PAGE;
-            case "OneColumn":
-                return ONE_COLUMN;
-            case "TwoColumnLeft":
-                return TWO_COLUMN_LEFT;
-            case "TwoColumnRight":
-                return TWO_COLUMN_RIGHT;
-            case "TwoPageLeft":
-                return TWO_PAGE_LEFT;
-            case "TwoPageRight":
-                return TWO_PAGE_RIGHT;
-            default:
-                throw new IllegalArgumentException(value);
-        }
-    }
-
-    private final String value;
-
-    PageLayout(String value)
-    {
-        this.value = value;
-    }
-
-    /**
-     * Returns the string value, as used in a PDF file.
-     */
-    public String stringValue()
-    {
-        return value;
-    }
-}
+/*
+ * 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.pdfbox.pdmodel;
+
+/**
+ * A name object specifying the page layout shall be used when the document is opened.
+ *
+ * @author John Hewson
+ */
+public enum PageLayout
+{
+    /** Display one page at a time. */
+    SINGLE_PAGE("SinglePage"),
+
+    /**  Display the pages in one column. */
+    ONE_COLUMN("OneColumn"),
+
+    /** Display the pages in two columns), with odd numbered pages on the left. */
+    TWO_COLUMN_LEFT("TwoColumnLeft"),
+
+    /** Display the pages in two columns), with odd numbered pages on the right.  */
+    TWO_COLUMN_RIGHT("TwoColumnRight"),
+
+    /** Display the pages two at a time), with odd-numbered pages on the left. */
+    TWO_PAGE_LEFT("TwoPageLeft"),
+
+    /** Display the pages two at a time), with odd-numbered pages on the right. */
+    TWO_PAGE_RIGHT("TwoPageRight");
+
+    public static PageLayout fromString(String value)
+    {
+        for (PageLayout instance : PageLayout.values())
+        {
+            if (instance.value.equals(value))
+            {
+                return instance;
+            }
+        }
+        throw new IllegalArgumentException(value);
+    }
+
+    private final String value;
+
+    PageLayout(String value)
+    {
+        this.value = value;
+    }
+
+    /**
+     * Returns the string value, as used in a PDF file.
+     */
+    public String stringValue()
+    {
+        return value;
+    }
+}

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PageMode.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PageMode.java?rev=1848233&r1=1848232&r2=1848233&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PageMode.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PageMode.java Wed Dec  5 18:42:35
2018
@@ -44,23 +44,14 @@ public enum PageMode
 
     public static PageMode fromString(String value)
     {
-        switch (value)
+        for (PageMode instance : PageMode.values())
         {
-            case "UseNone":
-                return USE_NONE;
-            case "UseOutlines":
-                return USE_OUTLINES;
-            case "UseThumbs":
-                return USE_THUMBS;
-            case "FullScreen":
-                return FULL_SCREEN;
-            case "UseOC":
-                return USE_OPTIONAL_CONTENT;
-            case "UseAttachments":
-                return USE_ATTACHMENTS;
-            default:
-                throw new IllegalArgumentException(value);
+            if (instance.value.equals(value))
+            {
+                return instance;
+            }
         }
+        throw new IllegalArgumentException(value);
     }
 
     private final String value;

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/RenderingIntent.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/RenderingIntent.java?rev=1848233&r1=1848232&r2=1848233&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/RenderingIntent.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/RenderingIntent.java
Wed Dec  5 18:42:35 2018
@@ -1,80 +1,75 @@
-/*
- * 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.pdfbox.pdmodel.graphics.state;
-
-/**
- * Rendering intent.
- *
- * @author John Hewson
- */
-public enum RenderingIntent
-{
-    /**
-     * Absolute Colorimetric.
-     */
-    ABSOLUTE_COLORIMETRIC("AbsoluteColorimetric"),
-
-    /**
-     * Relative Colorimetric.
-     */
-    RELATIVE_COLORIMETRIC("RelativeColorimetric"),
-
-    /**
-     * Saturation.
-     */
-    SATURATION("Saturation"),
-
-    /**
-     * Perceptual.
-     */
-    PERCEPTUAL("Perceptual");
-
-    public static RenderingIntent fromString(String value)
-    {
-        switch (value)
-        {
-            case "AbsoluteColorimetric":
-                return ABSOLUTE_COLORIMETRIC;
-            case "RelativeColorimetric":
-                return RELATIVE_COLORIMETRIC;
-            case "Saturation":
-                return SATURATION;
-            case "Perceptual":
-                return PERCEPTUAL;
-            default:
-                // "If a conforming reader does not recognize the specified name, 
-                // it shall use the RelativeColorimetric intent by default."
-                return RELATIVE_COLORIMETRIC;
-        }
-    }
-
-    private final String value;
-
-    RenderingIntent(String value)
-    {
-        this.value = value;
-    }
-
-    /**
-     * Returns the string value, as used in a PDF file.
-     */
-    public String stringValue()
-    {
-        return value;
-    }
-}
+/*
+ * 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.pdfbox.pdmodel.graphics.state;
+
+/**
+ * Rendering intent.
+ *
+ * @author John Hewson
+ */
+public enum RenderingIntent
+{
+    /**
+     * Absolute Colorimetric.
+     */
+    ABSOLUTE_COLORIMETRIC("AbsoluteColorimetric"),
+
+    /**
+     * Relative Colorimetric.
+     */
+    RELATIVE_COLORIMETRIC("RelativeColorimetric"),
+
+    /**
+     * Saturation.
+     */
+    SATURATION("Saturation"),
+
+    /**
+     * Perceptual.
+     */
+    PERCEPTUAL("Perceptual");
+
+    public static RenderingIntent fromString(String value)
+    {
+        for (RenderingIntent instance : RenderingIntent.values())
+        {
+            if (instance.value.equals(value))
+            {
+                return instance;
+            }
+        }
+        // "If a conforming reader does not recognize the specified name,
+        // it shall use the RelativeColorimetric intent by default."
+        return RELATIVE_COLORIMETRIC;
+    }
+
+    private final String value;
+
+    RenderingIntent(String value)
+    {
+        this.value = value;
+    }
+
+    /**
+     * Returns the string value, as used in a PDF file.
+     */
+    public String stringValue()
+    {
+        return value;
+    }
+}



Mime
View raw message