This is an automated email from the ASF dual-hosted git repository. fanningpj pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/poi.git
The following commit(s) were added to refs/heads/trunk by this push: new 061d6a3d0f more parsers 061d6a3d0f is described below commit 061d6a3d0ffa52346c0af3a22fbda35ce6ed11ba Author: PJ Fanning <pjfann...@users.noreply.github.com> AuthorDate: Wed Aug 20 18:34:09 2025 +0100 more parsers --- .../main/java/org/apache/poi/hslf/HSLFParser.java | 61 ++++++++++++++++++++++ .../org/apache/poi/hslf/HSLFReadException.java | 56 ++++++++++++++++++++ .../main/java/org/apache/poi/hwpf/HWPFParser.java | 60 +++++++++++++++++++++ .../org/apache/poi/hwpf/HWPFReadException.java | 56 ++++++++++++++++++++ .../main/java/org/apache/poi/hssf/HSSFParser.java | 61 ++++++++++++++++++++++ .../org/apache/poi/hssf/HSSFReadException.java | 56 ++++++++++++++++++++ 6 files changed, 350 insertions(+) diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/HSLFParser.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/HSLFParser.java new file mode 100644 index 0000000000..b6e35df4f3 --- /dev/null +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/HSLFParser.java @@ -0,0 +1,61 @@ +/* ==================================================================== + 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.poi.hslf; + +import java.io.IOException; +import java.io.InputStream; + +import org.apache.poi.hslf.usermodel.HSLFSlideShow; +import org.apache.poi.util.ExceptionUtil; + +/** + * Methods that wrap {@link HSLFSlideShow} parsing functionality. + * One difference is that the methods in this class try to + * throw {@link HSLFReadException} or {@link IOException} instead of {@link RuntimeException}. + * You can still get an {@link Error}s like an {@link OutOfMemoryError}. + * + * @since POI 5.5.0 + */ +public final class HSLFParser { + + private HSLFParser() { + // Prevent instantiation + } + + /** + * Parse the given InputStream and return a new {@link HSLFSlideShow} instance. + * + * @param stream the data to parse (will be closed after parsing) + * @return a new {@link HSLFSlideShow} instance + * @throws HSLFReadException if an error occurs while reading the file + * @throws IOException if an I/O error occurs while reading the file + */ + public static HSLFSlideShow parse(InputStream stream) throws HSLFReadException, IOException { + try { + return new HSLFSlideShow(stream); + } catch (IOException e) { + throw e; + } catch (Error | RuntimeException e) { + if (ExceptionUtil.isFatal(e)) { + throw e; + } + throw new HSLFReadException("Exception reading HSLFSlideShow", e); + } catch (Exception e) { + throw new HSLFReadException("Exception reading HSLFSlideShow", e); + } + } +} diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/HSLFReadException.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/HSLFReadException.java new file mode 100644 index 0000000000..75312472ac --- /dev/null +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/HSLFReadException.java @@ -0,0 +1,56 @@ +/* ==================================================================== + 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.poi.hslf; + +import org.apache.poi.POIException; + +/** + * An exception that indicates a problem reading a ppt file. + * <p>This exception is only used by some new methods. + * Historically, POI has used {@link RuntimeException} for most of its + * exceptions, but this is not a good practice. This class is a checked + * class that extends {@link Exception} so needs to be explicitly + * caught or declared in the method signature.</p> + * @since POI 5.5.0 + */ +public class HSLFReadException extends POIException { + private static final long serialVersionUID = 1L; + + /** + * Create a new {@code HSLFReadException} with + * the {@code String} specified as an error message. + * + * @param msg The error message for the exception. + */ + public HSLFReadException(String msg) { + super(msg); + } + + /** + * Create a new {@code HSLFReadException} with + * the {@code String} specified as an error message and the cause. + * + * @param msg The error message for the exception. + * @param cause the cause (which is saved for later retrieval by the + * {@link #getCause()} method). (A {@code null} value is + * permitted, and indicates that the cause is nonexistent or + * unknown.) + */ + public HSLFReadException(String msg, Throwable cause) { + super(msg, cause); + } +} diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/HWPFParser.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/HWPFParser.java new file mode 100644 index 0000000000..0799748481 --- /dev/null +++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/HWPFParser.java @@ -0,0 +1,60 @@ +/* ==================================================================== + 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.poi.hwpf; + +import java.io.IOException; +import java.io.InputStream; + +import org.apache.poi.util.ExceptionUtil; + +/** + * Methods that wrap {@link HWPFDocument} parsing functionality. + * One difference is that the methods in this class try to + * throw {@link HWPFReadException} or {@link IOException} instead of {@link RuntimeException}. + * You can still get an {@link Error}s like an {@link OutOfMemoryError}. + * + * @since POI 5.5.0 + */ +public final class HWPFParser { + + private HWPFParser() { + // Prevent instantiation + } + + /** + * Parse the given InputStream and return a new {@link HWPFDocument} instance. + * + * @param stream the data to parse (will be closed after parsing) + * @return a new {@link HWPFDocument} instance + * @throws HWPFReadException if an error occurs while reading the file + * @throws IOException if an I/O error occurs while reading the file + */ + public static HWPFDocument parse(InputStream stream) throws HWPFReadException, IOException { + try { + return new HWPFDocument(stream); + } catch (IOException e) { + throw e; + } catch (Error | RuntimeException e) { + if (ExceptionUtil.isFatal(e)) { + throw e; + } + throw new HWPFReadException("Exception reading HWPFDocument", e); + } catch (Exception e) { + throw new HWPFReadException("Exception reading HWPFDocument", e); + } + } +} diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/HWPFReadException.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/HWPFReadException.java new file mode 100644 index 0000000000..ec3ce80bc4 --- /dev/null +++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/HWPFReadException.java @@ -0,0 +1,56 @@ +/* ==================================================================== + 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.poi.hwpf; + +import org.apache.poi.POIException; + +/** + * An exception that indicates a problem reading a doc file. + * <p>This exception is only used by some new methods. + * Historically, POI has used {@link RuntimeException} for most of its + * exceptions, but this is not a good practice. This class is a checked + * class that extends {@link Exception} so needs to be explicitly + * caught or declared in the method signature.</p> + * @since POI 5.5.0 + */ +public class HWPFReadException extends POIException { + private static final long serialVersionUID = 1L; + + /** + * Create a new {@code HWPFReadException} with + * the {@code String} specified as an error message. + * + * @param msg The error message for the exception. + */ + public HWPFReadException(String msg) { + super(msg); + } + + /** + * Create a new {@code HWPFReadException} with + * the {@code String} specified as an error message and the cause. + * + * @param msg The error message for the exception. + * @param cause the cause (which is saved for later retrieval by the + * {@link #getCause()} method). (A {@code null} value is + * permitted, and indicates that the cause is nonexistent or + * unknown.) + */ + public HWPFReadException(String msg, Throwable cause) { + super(msg, cause); + } +} diff --git a/poi/src/main/java/org/apache/poi/hssf/HSSFParser.java b/poi/src/main/java/org/apache/poi/hssf/HSSFParser.java new file mode 100644 index 0000000000..14bdeecfd6 --- /dev/null +++ b/poi/src/main/java/org/apache/poi/hssf/HSSFParser.java @@ -0,0 +1,61 @@ +/* ==================================================================== + 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.poi.hssf; + +import java.io.IOException; +import java.io.InputStream; + +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.util.ExceptionUtil; + +/** + * Methods that wrap {@link HSSFWorkbook} parsing functionality. + * One difference is that the methods in this class try to + * throw {@link HSSFReadException} or {@link IOException} instead of {@link RuntimeException}. + * You can still get an {@link Error}s like an {@link OutOfMemoryError}. + * + * @since POI 5.5.0 + */ +public final class HSSFParser { + + private HSSFParser() { + // Prevent instantiation + } + + /** + * Parse the given InputStream and return a new {@link HSSFWorkbook} instance. + * + * @param stream the data to parse (will be closed after parsing) + * @return a new {@link HSSFWorkbook} instance + * @throws HSSFReadException if an error occurs while reading the file + * @throws IOException if an I/O error occurs while reading the file + */ + public static HSSFWorkbook parse(InputStream stream) throws HSSFReadException, IOException { + try { + return new HSSFWorkbook(stream); + } catch (IOException e) { + throw e; + } catch (Error | RuntimeException e) { + if (ExceptionUtil.isFatal(e)) { + throw e; + } + throw new HSSFReadException("Exception reading HSSFWorkbook", e); + } catch (Exception e) { + throw new HSSFReadException("Exception reading HSSFWorkbook", e); + } + } +} diff --git a/poi/src/main/java/org/apache/poi/hssf/HSSFReadException.java b/poi/src/main/java/org/apache/poi/hssf/HSSFReadException.java new file mode 100644 index 0000000000..1bc2ae207a --- /dev/null +++ b/poi/src/main/java/org/apache/poi/hssf/HSSFReadException.java @@ -0,0 +1,56 @@ +/* ==================================================================== + 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.poi.hssf; + +import org.apache.poi.POIException; + +/** + * An exception that indicates a problem reading an xls file. + * <p>This exception is only used by some new methods. + * Historically, POI has used {@link RuntimeException} for most of its + * exceptions, but this is not a good practice. This class is a checked + * class that extends {@link Exception} so needs to be explicitly + * caught or declared in the method signature.</p> + * @since POI 5.5.0 + */ +public class HSSFReadException extends POIException { + private static final long serialVersionUID = 1L; + + /** + * Create a new {@code HSSFReadException} with + * the {@code String} specified as an error message. + * + * @param msg The error message for the exception. + */ + public HSSFReadException(String msg) { + super(msg); + } + + /** + * Create a new {@code HSSFReadException} with + * the {@code String} specified as an error message and the cause. + * + * @param msg The error message for the exception. + * @param cause the cause (which is saved for later retrieval by the + * {@link #getCause()} method). (A {@code null} value is + * permitted, and indicates that the cause is nonexistent or + * unknown.) + */ + public HSSFReadException(String msg, Throwable cause) { + super(msg, cause); + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@poi.apache.org For additional commands, e-mail: commits-h...@poi.apache.org