Package org.openxml4j.opc

Examples of org.openxml4j.opc.PackageRelationship


   * @throws OpenXML4JException
   *             Throws if internal error occurs.
   */
  public static ZipEntry getCorePropertiesZipEntry(ZipPackage pkg)
      throws OpenXML4JException {
    PackageRelationship corePropsRel = pkg.getRelationshipsByType(
        PackageRelationshipTypes.CORE_PROPERTIES).getRelationship(0);

    if (corePropsRel == null)
      return null;

    return new ZipEntry(corePropsRel.getTargetURI().getPath());
  }
View Full Code Here


   * Creates a new XSSFReader, for the given package
   */
  public XSSFReader(Package pkg) throws IOException, OpenXML4JException {
    this.pkg = pkg;
   
        PackageRelationship coreDocRelationship = this.pkg.getRelationshipsByType(
                PackageRelationshipTypes.CORE_DOCUMENT).getRelationship(0);
   
        // Get the part that holds the workbook
        workbookPart = this.pkg.getPart(coreDocRelationship);
  }
View Full Code Here

   * Returns an InputStream to read the contents of the
   *  specified Sheet.
   * @param relId The relationId of the sheet, from a r:id on the workbook
   */
  public InputStream getSheet(String relId) throws IOException, InvalidFormatException {
        PackageRelationship rel = workbookPart.getRelationship(relId);
        if(rel == null) {
          throw new IllegalArgumentException("No Sheet found with r:id " + relId);
        }
       
        PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
        PackagePart sheet = pkg.getPart(relName);
        if(sheet == null) {
          throw new IllegalArgumentException("No data found for Sheet with r:id " + relId);
        }
        return sheet.getInputStream();
View Full Code Here

    public boolean hasNext() {
      return sheetRels.hasNext();
    }

    public InputStream next() {
      PackageRelationship sheet = sheetRels.next();
      try {
            PackagePartName relName = PackagingURIHelper.createPartName(sheet.getTargetURI());
        PackagePart sheetPkg = pkg.getPart(relName);
        return sheetPkg.getInputStream();
      } catch(IOException e) {
        throw new RuntimeException(e);
      } catch(InvalidFormatException ife) {
View Full Code Here

   * Generates the relation if required
   */
  protected void generateRelationIfNeeded(PackagePart sheetPart) {
    if(needsRelationToo()) {
      // Generate the relation
      PackageRelationship rel =
        sheetPart.addExternalRelationship(location, XSSFRelation.SHEET_HYPERLINKS.getRelation());
     
      // Update the r:id
      ctHyperlink.setId(rel.getId());
    }
  }
View Full Code Here

   
    protected POIXMLDocument(Package pkg) throws IOException {
      try {
        this.pkg = pkg;
       
          PackageRelationship coreDocRelationship = this.pkg.getRelationshipsByType(
                  PackageRelationshipTypes.CORE_DOCUMENT).getRelationship(0);
     
          // Get core part
          this.corePart = this.pkg.getPart(coreDocRelationship);

          // Verify it's there
          if(corePart == null) {
            throw new IllegalArgumentException("No core part found for this document! Nothing with " + coreDocRelationship.getRelationshipType() + " present as a relation.");
          }
        } catch (OpenXML4JException e) {
            throw new IOException(e.toString());
      }
    }
View Full Code Here

      return null;
    }
    if(rels.size() > 1) {
      throw new IllegalArgumentException("Found " + rels.size() + " relations for the type " + relationType + ", should only ever be one!");
    }
    PackageRelationship rel = rels.getRelationship(0);
    return getTargetPart(rel);
  }
View Full Code Here

    // TODO: make me optional/separated in private function
    try  {
      Iterator <PackageRelationship> relIter =
        getCorePart().getRelationshipsByType(HYPERLINK_RELATION_TYPE).iterator();
      while(relIter.hasNext()) {
        PackageRelationship rel = relIter.next();
        hyperlinks.add(new XWPFHyperlink(rel.getId(), rel.getTargetURI().toString()));
      }
    } catch(Exception e) {
      throw new OpenXML4JException(e.getLocalizedMessage());
    }
View Full Code Here

  public InputStream getContents(PackagePart corePart) throws IOException, InvalidFormatException {
        PackageRelationshipCollection prc =
          corePart.getRelationshipsByType(REL);
        Iterator<PackageRelationship> it = prc.iterator();
        if(it.hasNext()) {
            PackageRelationship rel = it.next();
            PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
            PackagePart part = corePart.getPackage().getPart(relName);
            return part.getInputStream();
        } else {
          log.log(POILogger.WARN, "No part " + DEFAULT_NAME + " found");
          return null;
View Full Code Here

  public XSSFModel load(PackagePart corePart) throws Exception {
        PackageRelationshipCollection prc =
          corePart.getRelationshipsByType(REL);
        Iterator<PackageRelationship> it = prc.iterator();
        if(it.hasNext()) {
            PackageRelationship rel = it.next();
            PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
            PackagePart part = corePart.getPackage().getPart(relName);
            return create(part, rel);
        } else {
          log.log(POILogger.WARN, "No part " + DEFAULT_NAME + " found");
          return null;
View Full Code Here

TOP

Related Classes of org.openxml4j.opc.PackageRelationship

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.