@Override protected OutputStream getOutputStreamImpl() { throw new InvalidOperationException( "Can't use output stream to set properties !"); }
private static ContentType newCorePropertiesPart() { try { return new ContentType(ContentTypes.CORE_PROPERTIES_PART); } catch (InvalidFormatException e) { // Should never happen throw new OpenXML4JRuntimeException( "Package.init() : this exception should never happen, " + "if you read this message please send a mail to the developers team. : " + e.getMessage(), e ); } }
protected XSLFTextRun(XmlObject r, XSLFTextParagraph p){ _r = r; _p = p; if (!(r instanceof CTRegularTextRun || r instanceof CTTextLineBreak || r instanceof CTTextField)) { throw new OpenXML4JRuntimeException("unsupported text run of type "+r.getClass()); } }
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 the specified URI is absolute. * * @param partUri * The URI to check. * @throws InvalidFormatException * Throws if the specified URI is absolute. */ private static void throwExceptionIfAbsoluteUri(URI partUri) throws InvalidFormatException { if (partUri.isAbsolute()) { throw new InvalidFormatException("Absolute URI forbidden: " + partUri); } }
/** * Verifies that the given stream starts with a Zip structure. * * Warning - this will consume the first few bytes of the stream, * you should push-back or reset the stream after use! */ private static void verifyZipHeader(InputStream stream) throws NotOfficeXmlFileException, IOException { InputStream is = FileMagic.prepareToCheckMagic(stream); FileMagic fm = FileMagic.valueOf(is); switch (fm) { case OLE2: throw new OLE2NotOfficeXmlFileException( "The supplied data appears to be in the OLE2 Format. " + "You are calling the part of POI that deals with OOXML "+ "(Office Open XML) Documents. You need to call a different " + "part of POI to process this data (eg HSSF instead of XSSF)"); case XML: throw new NotOfficeXmlFileException( "The supplied data appears to be a raw XML file. " + "Formats such as Office 2003 XML are not supported"); default: // Don't check for a Zip header, as to maintain backwards // compatibility we need to let them seek over junk at the // start before beginning processing. break; } }
/** * Set last modification date. * * @see org.apache.poi.openxml4j.opc.PackageProperties#setModifiedProperty(java.util.Optional) */ public void setModifiedProperty(String modified) { try { this.modified = setDateValue(modified); } catch (InvalidFormatException e) { throw new IllegalArgumentException("modified : " + e.getLocalizedMessage(), e); } }
/** * Wrapper to open a package, which works around shortcomings in java's this() constructor calls * * @param path the path to the document * @return the new OPCPackage * * @exception IOException if there was a problem opening the document */ public static OPCPackage openPackage(String path) throws IOException { try { return OPCPackage.open(path); } catch (InvalidFormatException e) { throw new IOException(e.toString(), 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 !"); }
/** * Set last printed date. * * @see org.apache.poi.openxml4j.opc.PackageProperties#setLastPrintedProperty(java.util.Optional) */ public void setLastPrintedProperty(String lastPrinted) { try { this.lastPrinted = setDateValue(lastPrinted); } catch (InvalidFormatException e) { throw new IllegalArgumentException("lastPrinted : " + e.getLocalizedMessage(), e); } }
@Override protected InputStream getInputStreamImpl() { throw new InvalidOperationException("Operation not authorized. This part may only be manipulated using the getters and setters on PackagePropertiesPart"); }
@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 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!"); } }
/** * 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!"); } }
@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 !!!"); }