Class Document

java.lang.Object
com.independentsoft.office.odf.Document
Direct Known Subclasses:
Chart, Spreadsheet, TextDocument

public abstract class Document extends Object
Represents a document in OpenDocument format.
  • Field Details

    • utf8

      protected Charset utf8
    • outputStream

      protected ZipOutputStream outputStream
    • inputFileTable

      protected FileTable inputFileTable
    • customFileTable

      protected FileTable customFileTable
    • mimeType

      protected String mimeType
    • isTemplate

      protected boolean isTemplate
    • manifest

      protected Manifest manifest
    • metaData

      protected MetaData metaData
    • commonStyles

      protected CommonStyles commonStyles
    • settings

      protected Settings settings
  • Constructor Details

    • Document

      public Document()
  • Method Details

    • open

      public abstract void open(String file) throws IOException, XMLStreamException
      Open.
      Parameters:
      file - the file
      Throws:
      IOException - Signals that an I/O exception has occurred.
      XMLStreamException - the xML stream exception
    • open

      public abstract void open(InputStream stream) throws IOException, XMLStreamException
      Open.
      Parameters:
      stream - the stream
      Throws:
      IOException - Signals that an I/O exception has occurred.
      XMLStreamException - the xML stream exception
    • save

      public abstract void save(String file) throws IOException
      Save.
      Parameters:
      file - the file
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • save

      public abstract void save(String file, boolean overwrite) throws IOException
      Save.
      Parameters:
      file - the file
      overwrite - the overwrite
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • save

      public abstract void save(OutputStream stream) throws IOException
      Save.
      Parameters:
      stream - the stream
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • getBytes

      public abstract byte[] getBytes() throws IOException
      Gets the bytes.
      Returns:
      the bytes
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • getInputStream

      public abstract InputStream getInputStream() throws IOException
      Gets the input stream.
      Returns:
      the input stream
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • saveAsHtml

      public abstract void saveAsHtml(String file) throws IOException
      Saves the document in HTML format.
      Parameters:
      file - The path of the file to save.
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • saveAsHtml

      public abstract void saveAsHtml(String file, boolean overwrite) throws IOException
      Saves the document in HTML format.
      Parameters:
      file - The path of the file to save.
      overwrite - If true, overwrites an existing file.
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • saveAsHtml

      public abstract void saveAsHtml(OutputStream stream) throws IOException
      Saves the document in HTML format.
      Parameters:
      stream - The stream to save to.
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • getHtml

      public abstract String getHtml() throws IOException
      Converts the document to HTML format.
      Returns:
      The HTML representation of the document.
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • openImplementation

      protected void openImplementation(InputStream stream) throws IOException, XMLStreamException
      Throws:
      IOException
      XMLStreamException
    • addFile

      protected void addFile(String filePath, String file) throws IOException
      Throws:
      IOException
    • addManifestEntry

      protected void addManifestEntry(Manifest currentManifest, Manifest originalManifest, String path)
      Adds a manifest:file-entry for a package part written from the in-memory model (image, OLE object, embedded document). Without it the part is unlisted and the package can be reported as corrupt. The original manifest (if any) supplies the exact media-type; otherwise it is derived from the file extension.
    • getPreservedPackageParts

      protected List<String> getPreservedPackageParts(SharedObjects sharedObjects)
      Returns the paths of original package parts that this writer does NOT regenerate (thumbnails, layout-cache, manifest.rdf, unreferenced pictures, ...) so they can be carried over into the saved package instead of being dropped. Directory entries (paths ending in "/") and parts written from the in-memory model are excluded.
    • addPreservedEmbeddedObjectManifestEntries

      protected void addPreservedEmbeddedObjectManifestEntries(Manifest manifest, SharedObjects sharedObjects)
    • addMimeTypeFile

      protected void addMimeTypeFile(String mimeTypeValue) throws IOException
      Throws:
      IOException
    • addFile

      protected void addFile(String filePath, byte[] buffer) throws IOException
      Throws:
      IOException
    • getAttributedTexts

      public List<AttributedText> getAttributedTexts()
      Gets the attributed texts.
      Returns:
      the attributed texts
    • getTexts

      public List<Text> getTexts()
      Gets the texts.
      Returns:
      the texts
    • getText

      public String getText()
      Returns the plain text of the whole document.
      Returns:
      the plain text of the document or an empty string if the document does not contain text
    • getParagraphs

      public List<Paragraph> getParagraphs()
      Gets the paragraphs.
      Returns:
      the paragraphs
    • getHeadings

      public List<Heading> getHeadings()
      Gets the headings.
      Returns:
      the headings
    • getFields

      public List<Field> getFields()
      Gets the fields.
      Returns:
      the fields
    • getLists

      public List<List> getLists()
      Gets the lists.
      Returns:
      the lists
    • getSections

      public List<Section> getSections()
      Gets the sections.
      Returns:
      the sections
    • getTables

      public List<Table> getTables()
      Gets the tables.
      Returns:
      the tables
    • getImages

      public List<Image> getImages()
      Gets the images.
      Returns:
      the images
    • find

      public List<FindResult> find(String text)
      Returns all occurrences of the specified text in the whole document, including tables, headers, footers, notes, annotations, text boxes and shapes.
      Parameters:
      text - the text to find.
      Returns:
      A list of FindResult objects.
    • find

      public List<FindResult> find(String text, FindOptions options)
      Returns all occurrences of the specified text.
      Parameters:
      text - the text to find.
      options - the options of the search.
      Returns:
      A list of FindResult objects.
    • findFirst

      public FindResult findFirst(String text)
      Returns the first occurrence of the specified text or null if the text was not found.
      Parameters:
      text - the text to find.
      Returns:
      A FindResult object or null.
    • findFirst

      public FindResult findFirst(String text, FindOptions options)
      Returns the first occurrence of the specified text or null if the text was not found.
      Parameters:
      text - the text to find.
      options - the options of the search.
      Returns:
      A FindResult object or null.
    • findElements

      public <T> List<T> findElements(Class<T> type)
      Returns all content elements of the specified type, for example all images or all tables, from the whole document.
      Type Parameters:
      T - the type of the content elements.
      Parameters:
      type - the type of the content elements.
      Returns:
      A list of content elements.
    • findElements

      public <T> List<T> findElements(Class<T> type, Predicate<T> match)
      Returns all content elements of the specified type which match the specified condition.
      Type Parameters:
      T - the type of the content elements.
      Parameters:
      type - the type of the content elements.
      match - the condition the content elements have to match.
      Returns:
      A list of content elements.
    • findElements

      public <T> List<T> findElements(Class<T> type, Predicate<T> match, int scope)
      Returns all content elements of the specified type which match the specified condition.
      Type Parameters:
      T - the type of the content elements.
      Parameters:
      type - the type of the content elements.
      match - the condition the content elements have to match.
      scope - the parts of the document to search.
      Returns:
      A list of content elements.
    • replace

      public int replace(String oldText, String newText)
      Replaces all occurrences of the specified oldText with newText in the whole document. The paragraphs, their styles and all other content of the paragraphs remain unchanged.
      Parameters:
      oldText - the string to replace.
      newText - the string that replaces oldText.
      Returns:
      The number of replaced occurrences.
    • replace

      public int replace(String oldText, String newText, FindOptions options)
      Replaces all occurrences of the specified oldText with newText.
      Parameters:
      oldText - the string to replace.
      newText - the string that replaces oldText.
      options - the options of the search.
      Returns:
      The number of replaced occurrences.
    • replace

      public int replace(List<String> oldText, List<String> newText)
      Replaces all occurrences of the specified oldText with newText.
      Parameters:
      oldText - a list of strings to replace.
      newText - a list of strings that replaces oldText.
      Returns:
      The number of replaced occurrences.
    • replace

      public int replace(List<String> oldText, List<String> newText, FindOptions options)
      Replaces all occurrences of the specified oldText with newText.
      Parameters:
      oldText - a list of strings to replace.
      newText - a list of strings that replaces oldText.
      options - the options of the search.
      Returns:
      The number of replaced occurrences.
    • replace

      public int replace(String text, AttributedText attributedText)
      Replaces all occurrences of the specified text with a copy of the specified span. The text before and after the replaced text keeps its formatting.
      Parameters:
      text - the text to replace.
      attributedText - the AttributedText that replaces the text.
      Returns:
      The number of replaced occurrences.
    • replace

      public int replace(String text, AttributedText attributedText, FindOptions options)
      Replaces all occurrences of the specified text with a copy of the specified span.
      Parameters:
      text - the text to replace.
      attributedText - the AttributedText that replaces the text.
      options - the options of the search.
      Returns:
      The number of replaced occurrences.
    • replace

      public int replace(String text, List<AttributedText> attributedTexts, FindOptions options)
      Replaces all occurrences of the specified text with copies of the specified spans.
      Parameters:
      text - the text to replace.
      attributedTexts - the AttributedText objects that replace the text.
      options - the options of the search.
      Returns:
      The number of replaced occurrences.
    • replace

      public int replace(String text, IParagraphContent content)
      Replaces all occurrences of the specified text with a copy of the specified content, for example an image, a tab, a line break, a field or a hyperlink.
      Parameters:
      text - the text to replace.
      content - the content that replaces the text.
      Returns:
      The number of replaced occurrences.
    • replace

      public int replace(String text, IParagraphContent content, FindOptions options)
      Replaces all occurrences of the specified text with a copy of the specified content.
      Parameters:
      text - the text to replace.
      content - the content that replaces the text.
      options - the options of the search.
      Returns:
      The number of replaced occurrences.
    • replaceContent

      public int replaceContent(String text, List<IParagraphContent> content, FindOptions options)
      Replaces all occurrences of the specified text with copies of the specified content.
      Parameters:
      text - the text to replace.
      content - the content that replaces the text.
      options - the options of the search.
      Returns:
      The number of replaced occurrences.
    • replace

      public boolean replace(IContentElement oldElement, IContentElement newElement)
      Replaces the specified content element, for example a span, a paragraph or a table, with another content element. The properties of the replaced element are preserved if the new element has no own properties.
      Parameters:
      oldElement - the content element to replace.
      newElement - the content element that replaces oldElement.
      Returns:
      true if the content element was replaced.
    • replace

      public boolean replace(IContentElement oldElement, IContentElement newElement, FindOptions options)
      Replaces the specified content element with another content element.
      Parameters:
      oldElement - the content element to replace.
      newElement - the content element that replaces oldElement.
      options - the options of the replacement.
      Returns:
      true if the content element was replaced.
    • replace

      public boolean replace(Image image, String filePath) throws IOException
      Replaces the image of the specified image element. The size, the position and all other properties of the frame remain unchanged.
      Parameters:
      image - the image to replace.
      filePath - the path of the new image file.
      Returns:
      true if the image was replaced.
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • replace

      public boolean replace(Image image, String fileName, byte[] buffer)
      Replaces the image of the specified image element. The size, the position and all other properties of the frame remain unchanged.
      Parameters:
      image - the image to replace.
      fileName - the file name of the new image.
      buffer - the new image.
      Returns:
      true if the image was replaced.
    • remove

      public boolean remove(IContentElement element)
      Removes the specified content element from the document.
      Parameters:
      element - the content element to remove.
      Returns:
      true if the content element was removed.
    • getContentElements

      public abstract List<IContentElement> getContentElements()
      Gets the content elements.
      Returns:
      the content elements
    • getInputFileTable

      public FileTable getInputFileTable()
      Gets the input file table.
      Returns:
      the input file table
    • getCustomFileTable

      public FileTable getCustomFileTable()
      Gets the custom file table.
      Returns:
      the custom file table
    • getCommonStyles

      public CommonStyles getCommonStyles()
      Gets the common styles.
      Returns:
      the common styles
    • getGenerator

      public String getGenerator()
      Gets the generator.
      Returns:
      the generator
    • getTitle

      public String getTitle()
      Gets the title.
      Returns:
      the title
    • setTitle

      public void setTitle(String title)
      Sets the title.
      Parameters:
      title - the new title
    • getDescription

      public String getDescription()
      Gets the description.
      Returns:
      the description
    • setDescription

      public void setDescription(String description)
      Sets the description.
      Parameters:
      description - the new description
    • getSubject

      public String getSubject()
      Gets the subject.
      Returns:
      the subject
    • setSubject

      public void setSubject(String subject)
      Sets the subject.
      Parameters:
      subject - the new subject
    • getLanguage

      public String getLanguage()
      Gets the language.
      Returns:
      the language
    • setLanguage

      public void setLanguage(String language)
      Sets the language.
      Parameters:
      language - the new language
    • getKeywords

      public String getKeywords()
      Gets the keywords.
      Returns:
      the keywords
    • setKeywords

      public void setKeywords(String keywords)
      Sets the keywords.
      Parameters:
      keywords - the new keywords
    • getCreator

      public String getCreator()
      Gets the creator.
      Returns:
      the creator
    • setCreator

      public void setCreator(String creator)
      Sets the creator.
      Parameters:
      creator - the new creator
    • getCreationDate

      public Date getCreationDate()
      Gets the creation date.
      Returns:
      the creation date
    • setCreationDate

      public void setCreationDate(Date creationDate)
      Sets the creation date.
      Parameters:
      creationDate - the new creation date
    • getLastModified

      public Date getLastModified()
      Gets the last modified.
      Returns:
      the last modified
    • setLastModified

      public void setLastModified(Date lastModified)
      Sets the last modified.
      Parameters:
      lastModified - the new last modified
    • getEditingCycles

      public int getEditingCycles()
      Gets the editing cycles.
      Returns:
      the editing cycles
    • setEditingCycles

      public void setEditingCycles(int editingCycles)
      Sets the editing cycles.
      Parameters:
      editingCycles - the new editing cycles
    • getEditingDuration

      public String getEditingDuration()
      Gets the editing duration.
      Returns:
      the editing duration
    • setEditingDuration

      public void setEditingDuration(String editingDuration)
      Sets the editing duration.
      Parameters:
      editingDuration - the new editing duration
    • getInitialCreator

      public String getInitialCreator()
      Gets the initial creator.
      Returns:
      the initial creator
    • setInitialCreator

      public void setInitialCreator(String initialCreator)
      Sets the initial creator.
      Parameters:
      initialCreator - the new initial creator
    • getPrintDate

      public Date getPrintDate()
      Gets the prints the date.
      Returns:
      the prints the date
    • setPrintDate

      public void setPrintDate(Date printDate)
      Sets the prints the date.
      Parameters:
      printDate - the new prints the date
    • getPrintedBy

      public String getPrintedBy()
      Gets the printed by.
      Returns:
      the printed by
    • setPrintedBy

      public void setPrintedBy(String printedBy)
      Sets the printed by.
      Parameters:
      printedBy - the new printed by
    • getUserDefinedMetadataElements

      public List<UserDefinedMetadataElement> getUserDefinedMetadataElements()
      Gets the user defined metadata elements.
      Returns:
      the user defined metadata elements
    • getTemplate

      public Template getTemplate()
      Gets the template.
      Returns:
      the template
    • setTemplate

      public void setTemplate(Template template)
      Sets the template.
      Parameters:
      template - the new template
    • getStatistic

      public DocumentStatistic getStatistic()
      Gets the statistic.
      Returns:
      the statistic
    • setStatistic

      public void setStatistic(DocumentStatistic statistic)
      Sets the statistic.
      Parameters:
      statistic - the new statistic
    • getConfigurations

      public List<Configuration> getConfigurations()
      Gets the configurations.
      Returns:
      the configurations
    • isTemplate

      public boolean isTemplate()
      Checks if is template.
      Returns:
      true, if is template
    • setTemplate

      public void setTemplate(boolean isTemplate)
      Sets the template.
      Parameters:
      isTemplate - the new template
    • getFileInputTable

      public FileTable getFileInputTable()
      Gets the file input table.
      Returns:
      the file input table
    • getManifest

      public Manifest getManifest()
      Gets the manifest.
      Returns:
      the manifest
    • getMetaData

      public MetaData getMetaData()
      Gets the meta data.
      Returns:
      the meta data
    • getMimeType

      public String getMimeType()
      Gets the mime type.
      Returns:
      the mime type
    • setMimeType

      public void setMimeType(String mimeType)
      Sets the mime type.
      Parameters:
      mimeType - the new mime type