OpenpackagingFactory.java
package pro.verron.officestamper.utils.openpackaging;
import org.docx4j.openpackaging.exceptions.InvalidFormatException;
import org.docx4j.openpackaging.parts.PartName;
import pro.verron.officestamper.utils.UtilsException;
/// Utility class for creating Open Packaging objects.
///
/// This class provides helper methods to create instances of docx4j Open Packaging objects, wrapping checked exceptions
/// in runtime [UtilsException] for easier handling.
public class OpenpackagingFactory {
private OpenpackagingFactory() {
throw new UtilsException("Utility class shouldn't be instantiated");
}
/// Creates a new PartName instance from the given string representation.
///
/// This method wraps the checked [InvalidFormatException] that can occur when creating a PartName in a runtime
/// [UtilsException].
///
/// @param partName the string representation of the part name
///
/// @return a new PartName instance
///
/// @throws UtilsException if the part name string is invalid
public static PartName newPartName(String partName) {
try {
return new PartName(partName);
} catch (InvalidFormatException e) {
throw new UtilsException(e);
}
}
}