@Override protected InputStream getInputStreamImpl() { throw new InvalidOperationException("Operation not authorized. This part may only be manipulated using the getters and setters on PackagePropertiesPart"); }
void register(final PackagePartCollection partList) throws InvalidFormatException { if (contentType == null) { throw new InvalidFormatException("The part " + partName.getURI().getPath() + " does not have any " + "content type ! Rule: Package require content types when retrieving a part from a package. [M.1.14]"); } if (partList.containsKey(partName)) { throw new InvalidFormatException( "A part with the name '"+partName+"' already exist : Packages shall not contain equivalent part names " + "and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]"); } try { partList.put(partName, new ZipPackagePart(ZipPackage.this, zipArchiveEntry, partName, contentType, false)); } catch (InvalidOperationException e) { throw new InvalidFormatException(e.getMessage(), e); } }
continue; } catch (InvalidOperationException invoe) { throw new InvalidFormatException(invoe.getMessage(), invoe);
@Override protected OutputStream getOutputStreamImpl() { throw new InvalidOperationException( "Can't use output stream to set properties !"); }
void register(final PackagePartCollection partList) throws InvalidFormatException { if (contentType == null) { throw new InvalidFormatException("The part " + partName.getURI().getPath() + " does not have any " + "content type ! Rule: Package require content types when retrieving a part from a package. [M.1.14]"); } if (partList.containsKey(partName)) { throw new InvalidFormatException( "A part with the name '"+partName+"' already exist : Packages shall not contain equivalent part names " + "and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]"); } try { partList.put(partName, new ZipPackagePart(ZipPackage.this, zipArchiveEntry, partName, contentType, false)); } catch (InvalidOperationException e) { throw new InvalidFormatException(e.getMessage(), e); } }
/** * Throws an exception if this package part is a relationship part. * * @throws InvalidOperationException * If this part is a relationship part. */ private void throwExceptionIfRelationship() throws InvalidOperationException { if (this._isRelationshipPart) throw new InvalidOperationException( "Can do this operation on a relationship part !"); }
@Override public boolean save(OutputStream zos) { throw new InvalidOperationException("Operation not authorized. This part may only be manipulated using the getters and setters on PackagePropertiesPart"); }
@Override public boolean load(InputStream ios) { throw new InvalidOperationException("Operation not authorized. This part may only be manipulated using the getters and setters on PackagePropertiesPart"); }
/** * Throws an exception if the package access mode is in read only mode * (PackageAccess.Read). * * @throws InvalidOperationException * Throws if a writing operation is done on a read only package. * @see org.apache.poi.openxml4j.opc.PackageAccess */ void throwExceptionIfReadOnly() throws InvalidOperationException { if (packageAccess == PackageAccess.READ) { throw new InvalidOperationException( "Operation not allowed, document open in read only mode!"); } }
/** * Throws an exception if the package access mode is in write only mode * (PackageAccess.Write). This method is call when other methods need write * right. * * @throws InvalidOperationException if a read operation is done on a write only package. * @see org.apache.poi.openxml4j.opc.PackageAccess */ void throwExceptionIfWriteOnly() throws InvalidOperationException { if (packageAccess == PackageAccess.WRITE) { throw new InvalidOperationException( "Operation not allowed, document open in write only mode!"); } }
@Override @NotImplemented public boolean load(InputStream ios) { throw new InvalidOperationException("Method not implemented !"); }
private static ZipEntrySource openZipEntrySourceStream(ZipArchiveThresholdInputStream zis) throws InvalidOperationException { // Acquire the final level resource. If this is acquired successfully, the zip package was read successfully from the input stream try { // open the zip entry source stream return new ZipInputStreamZipEntrySource(zis); } catch (IOException e) { throw new InvalidOperationException("Could not open the specified zip entry source stream", e); } }
@Override @NotImplemented public void close() { throw new InvalidOperationException("Method not implemented !"); }
@Override @NotImplemented public void flush() { throw new InvalidOperationException("Method not implemented !"); } }
/** * Validates the package compliance with the OPC specifications. * * @return <b>true</b> if the package is valid else <b>false</b> */ @NotImplemented public boolean validatePackage(OPCPackage pkg) throws InvalidFormatException { throw new InvalidOperationException("Not implemented yet !!!"); }
/** * Creates a new package. * * @param file * Path of the document. * @return A newly created PackageBase ready to use. */ public static OPCPackage create(File file) { if (file == null || (file.exists() && file.isDirectory())) { throw new IllegalArgumentException("file"); } if (file.exists()) { throw new InvalidOperationException( "This package (or file) already exists : use the open() method or delete the file."); } // Creates a new package OPCPackage pkg = new ZipPackage(); pkg.originalPackagePath = file.getAbsolutePath(); configurePackage(pkg); return pkg; }
/** * Check rule [M1.11]: a package implementer shall neither create nor * recognize a part with a part name derived from another part name by * appending segments to it. * * @param partName name of part * @param part part to put * @return the previous value associated with {@code partName}, or * {@code null} if there was no mapping for {@code partName}. * @exception InvalidOperationException * Throws if you try to add a part with a name derived from * another part name. */ public PackagePart put(final PackagePartName partName, final PackagePart part) { final String ppName = partName.getName(); final StringBuilder concatSeg = new StringBuilder(); // split at slash, but keep leading slash final String delim = "(?=["+PackagingURIHelper.FORWARD_SLASH_STRING+".])"; for (String seg : ppName.split(delim)) { concatSeg.append(seg); if (registerPartNameStr.contains(concatSeg.toString())) { throw new InvalidOperationException( "You can't add a part with a part name derived from another part ! [M1.11]"); } } registerPartNameStr.add(ppName); return packagePartLookup.put(ppName, part); }
private static ZipEntrySource openZipEntrySourceStream(File file) throws InvalidOperationException { final FileInputStream fis; // Acquire a resource that is needed to read the next level of openZipEntrySourceStream try { // open the file input stream fis = new FileInputStream(file); // NOSONAR } catch (final FileNotFoundException e) { // If the source cannot be acquired, abort (no resources to free at this level) throw new InvalidOperationException("Can't open the specified file input stream from file: '" + file + "'", e); } // If an error occurs while reading the next level of openZipEntrySourceStream, free the acquired resource try { // read from the file input stream return openZipEntrySourceStream(fis); } catch (final InvalidOperationException|UnsupportedFileFormatException e) { // abort: close the zip input stream IOUtils.closeQuietly(fis); throw e; } catch (final Exception e) { // abort: close the file input stream IOUtils.closeQuietly(fis); throw new InvalidOperationException("Failed to read the file input stream from file: '" + file + "'", e); } }
throw new InvalidOperationException( "You can't call save(File) to save to the currently open " + "file. To save to the current file, please just call close()"
private static ZipEntrySource openZipEntrySourceStream(FileInputStream fis) throws InvalidOperationException { final ZipArchiveThresholdInputStream zis; // Acquire a resource that is needed to read the next level of openZipEntrySourceStream try { // open the zip input stream zis = ZipHelper.openZipStream(fis); // NOSONAR } catch (final IOException e) { // If the source cannot be acquired, abort (no resources to free at this level) throw new InvalidOperationException("Could not open the file input stream", e); } // If an error occurs while reading the next level of openZipEntrySourceStream, free the acquired resource try { // read from the zip input stream return openZipEntrySourceStream(zis); } catch (final InvalidOperationException|UnsupportedFileFormatException e) { // abort: close the zip input stream IOUtils.closeQuietly(zis); throw e; } catch (final Exception e) { // abort: close the zip input stream IOUtils.closeQuietly(zis); throw new InvalidOperationException("Failed to read the zip entry source stream", e); } }