Examples of PackagePropertiesPart


Examples of org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart

  public PackageProperties getPackageProperties()
      throws InvalidFormatException {
    this.throwExceptionIfWriteOnly();
    // If no properties part has been found then we create one
    if (this.packageProperties == null) {
      this.packageProperties = new PackagePropertiesPart(this,
          PackagingURIHelper.CORE_PROPERTIES_PART_NAME);
    }
    return this.packageProperties;
  }
View Full Code Here

Examples of org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart

  // TODO Load element with XMLBeans or dynamic table
  // TODO Check every element/namespace for compliance
  public PackagePart unmarshall(UnmarshallContext context, InputStream in)
      throws InvalidFormatException, IOException {
    PackagePropertiesPart coreProps = new PackagePropertiesPart(context
        .getPackage(), context.getPartName());

    // If the input stream is null then we try to get it from the
    // package.
    if (in == null) {
      if (context.getZipEntry() != null) {
        in = ((ZipPackage) context.getPackage()).getZipArchive()
            .getInputStream(context.getZipEntry());
      } else if (context.getPackage() != null) {
        // Try to retrieve the part inputstream from the URI
        ZipEntry zipEntry = ZipHelper
            .getCorePropertiesZipEntry((ZipPackage) context
                .getPackage());
        in = ((ZipPackage) context.getPackage()).getZipArchive()
            .getInputStream(zipEntry);
      } else
        throw new IOException(
            "Error while trying to get the part input stream.");
    }

    Document xmlDoc;
    try {
      xmlDoc = DocumentHelper.readDocument(in);

      /* Check OPC compliance */

      // Rule M4.2, M4.3, M4.4 and M4.5/
      checkElementForOPCCompliance(xmlDoc.getDocumentElement());

      /* End OPC compliance */

        } catch (SAXException e) {
            throw new IOException(e.getMessage());
        }

        coreProps.setCategoryProperty(loadCategory(xmlDoc));
    coreProps.setContentStatusProperty(loadContentStatus(xmlDoc));
    coreProps.setContentTypeProperty(loadContentType(xmlDoc));
    coreProps.setCreatedProperty(loadCreated(xmlDoc));
    coreProps.setCreatorProperty(loadCreator(xmlDoc));
    coreProps.setDescriptionProperty(loadDescription(xmlDoc));
    coreProps.setIdentifierProperty(loadIdentifier(xmlDoc));
    coreProps.setKeywordsProperty(loadKeywords(xmlDoc));
    coreProps.setLanguageProperty(loadLanguage(xmlDoc));
    coreProps.setLastModifiedByProperty(loadLastModifiedBy(xmlDoc));
    coreProps.setLastPrintedProperty(loadLastPrinted(xmlDoc));
    coreProps.setModifiedProperty(loadModified(xmlDoc));
    coreProps.setRevisionProperty(loadRevision(xmlDoc));
    coreProps.setSubjectProperty(loadSubject(xmlDoc));
    coreProps.setTitleProperty(loadTitle(xmlDoc));
    coreProps.setVersionProperty(loadVersion(xmlDoc));

    return coreProps;
  }
View Full Code Here

Examples of org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart

            extractMetadata(extractor.getCustomProperties(), metadata);
        }
    }

    private void extractMetadata(CoreProperties properties, Metadata metadata) {
        PackagePropertiesPart propsHolder = properties
                .getUnderlyingProperties();

        addProperty(metadata, OfficeOpenXMLCore.CATEGORY, propsHolder.getCategoryProperty());
        addProperty(metadata, OfficeOpenXMLCore.CONTENT_STATUS, propsHolder
                .getContentStatusProperty());
        addProperty(metadata, TikaCoreProperties.CREATED, propsHolder
                .getCreatedProperty());
        addProperty(metadata, TikaCoreProperties.CREATOR, propsHolder
                .getCreatorProperty());
        addProperty(metadata, TikaCoreProperties.DESCRIPTION, propsHolder
                .getDescriptionProperty());
        addProperty(metadata, TikaCoreProperties.IDENTIFIER, propsHolder
                .getIdentifierProperty());
        addProperty(metadata, TikaCoreProperties.KEYWORDS, propsHolder
                .getKeywordsProperty());
        addProperty(metadata, TikaCoreProperties.LANGUAGE, propsHolder
                .getLanguageProperty());
        addProperty(metadata, TikaCoreProperties.MODIFIER, propsHolder
                .getLastModifiedByProperty());
        addProperty(metadata, TikaCoreProperties.PRINT_DATE, propsHolder
                .getLastPrintedProperty());
        addProperty(metadata, Metadata.LAST_MODIFIED, propsHolder
                .getModifiedProperty());
        addProperty(metadata, TikaCoreProperties.MODIFIED, propsHolder
              .getModifiedProperty());
        addProperty(metadata, OfficeOpenXMLCore.REVISION, propsHolder
                .getRevisionProperty());
        // TODO: Move to OO subject in Tika 2.0
        addProperty(metadata, TikaCoreProperties.TRANSITION_SUBJECT_TO_OO_SUBJECT,
                propsHolder.getSubjectProperty());
        addProperty(metadata, TikaCoreProperties.TITLE, propsHolder.getTitleProperty());
        addProperty(metadata, OfficeOpenXMLCore.VERSION, propsHolder.getVersionProperty());
       
        // Legacy Tika-1.0 style stats
        // TODO Remove these in Tika 2.0
        addProperty(metadata, Metadata.CATEGORY, propsHolder.getCategoryProperty());
        addProperty(metadata, Metadata.CONTENT_STATUS, propsHolder
                .getContentStatusProperty());
        addProperty(metadata, Metadata.REVISION_NUMBER, propsHolder
                .getRevisionProperty());
        addProperty(metadata, Metadata.VERSION, propsHolder.getVersionProperty());
    }
View Full Code Here

Examples of org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart

  // TODO Load element with XMLBeans or dynamic table
  // TODO Check every element/namespace for compliance
  public PackagePart unmarshall(UnmarshallContext context, InputStream in)
      throws InvalidFormatException, IOException {
    PackagePropertiesPart coreProps = new PackagePropertiesPart(context
        .getPackage(), context.getPartName());

    // If the input stream is null then we try to get it from the
    // package.
    if (in == null) {
      if (context.getZipEntry() != null) {
        in = ((ZipPackage) context.getPackage()).getZipArchive()
            .getInputStream(context.getZipEntry());
      } else if (context.getPackage() != null) {
        // Try to retrieve the part inputstream from the URI
        ZipEntry zipEntry = ZipHelper
            .getCorePropertiesZipEntry((ZipPackage) context
                .getPackage());
        in = ((ZipPackage) context.getPackage()).getZipArchive()
            .getInputStream(zipEntry);
      } else
        throw new IOException(
            "Error while trying to get the part input stream.");
    }

    Document xmlDoc;
    try {
      xmlDoc = SAXHelper.readSAXDocument(in);

      /* Check OPC compliance */

      // Rule M4.2, M4.3, M4.4 and M4.5/
      checkElementForOPCCompliance(xmlDoc.getRootElement());

      /* End OPC compliance */

    } catch (DocumentException e) {
      throw new IOException(e.getMessage());
    }

    coreProps.setCategoryProperty(loadCategory(xmlDoc));
    coreProps.setContentStatusProperty(loadContentStatus(xmlDoc));
    coreProps.setContentTypeProperty(loadContentType(xmlDoc));
    coreProps.setCreatedProperty(loadCreated(xmlDoc));
    coreProps.setCreatorProperty(loadCreator(xmlDoc));
    coreProps.setDescriptionProperty(loadDescription(xmlDoc));
    coreProps.setIdentifierProperty(loadIdentifier(xmlDoc));
    coreProps.setKeywordsProperty(loadKeywords(xmlDoc));
    coreProps.setLanguageProperty(loadLanguage(xmlDoc));
    coreProps.setLastModifiedByProperty(loadLastModifiedBy(xmlDoc));
    coreProps.setLastPrintedProperty(loadLastPrinted(xmlDoc));
    coreProps.setModifiedProperty(loadModified(xmlDoc));
    coreProps.setRevisionProperty(loadRevision(xmlDoc));
    coreProps.setSubjectProperty(loadSubject(xmlDoc));
    coreProps.setTitleProperty(loadTitle(xmlDoc));
    coreProps.setVersionProperty(loadVersion(xmlDoc));

    return coreProps;
  }
View Full Code Here

Examples of org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart

    POIXMLProperties props = workbook.getProperties();
    assertNotNull(props);
    //the Application property must be set for new workbooks, see Bugzilla #47559
    assertEquals("Apache POI", props.getExtendedProperties().getUnderlyingProperties().getApplication());

    PackagePropertiesPart opcProps = props.getCoreProperties().getUnderlyingProperties();
    assertNotNull(opcProps);

    opcProps.setTitleProperty("Testing Bugzilla #47460");
    assertEquals("Apache POI", opcProps.getCreatorProperty().getValue());
    opcProps.setCreatorProperty("poi-dev@poi.apache.org");

    workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook);
    assertEquals("Apache POI", workbook.getProperties().getExtendedProperties().getUnderlyingProperties().getApplication());
    opcProps = workbook.getProperties().getCoreProperties().getUnderlyingProperties();
    assertEquals("Testing Bugzilla #47460", opcProps.getTitleProperty().getValue());
    assertEquals("poi-dev@poi.apache.org", opcProps.getCreatorProperty().getValue());
  }
View Full Code Here

Examples of org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart

        df.setTimeZone(TimeZone.getTimeZone("UTC"));
        String strDate = "2007-05-12T08:00:00Z";
        Date date = df.parse(strDate);

        OPCPackage pkg = new ZipPackage();
        PackagePropertiesPart props = (PackagePropertiesPart)pkg.getPackageProperties();

        // created
        assertEquals("", props.getCreatedPropertyString());
        assertNull(props.getCreatedProperty().getValue());
        props.setCreatedProperty((String)null);
        assertEquals("", props.getCreatedPropertyString());
        assertNull(props.getCreatedProperty().getValue());
        props.setCreatedProperty(new Nullable<Date>());
        assertEquals("", props.getCreatedPropertyString());
        assertNull(props.getCreatedProperty().getValue());
        props.setCreatedProperty(new Nullable<Date>(date));
        assertEquals(strDate, props.getCreatedPropertyString());
        assertEquals(date, props.getCreatedProperty().getValue());
        props.setCreatedProperty(strDate);
        assertEquals(strDate, props.getCreatedPropertyString());
        assertEquals(date, props.getCreatedProperty().getValue());

        // lastPrinted
        assertEquals("", props.getLastPrintedPropertyString());
        assertNull(props.getLastPrintedProperty().getValue());
        props.setLastPrintedProperty((String)null);
        assertEquals("", props.getLastPrintedPropertyString());
        assertNull(props.getLastPrintedProperty().getValue());
        props.setLastPrintedProperty(new Nullable<Date>());
        assertEquals("", props.getLastPrintedPropertyString());
        assertNull(props.getLastPrintedProperty().getValue());
        props.setLastPrintedProperty(new Nullable<Date>(date));
        assertEquals(strDate, props.getLastPrintedPropertyString());
        assertEquals(date, props.getLastPrintedProperty().getValue());
        props.setLastPrintedProperty(strDate);
        assertEquals(strDate, props.getLastPrintedPropertyString());
        assertEquals(date, props.getLastPrintedProperty().getValue());

        // modified
        assertNull(props.getModifiedProperty().getValue());
        props.setModifiedProperty((String)null);
        assertNull(props.getModifiedProperty().getValue());
        props.setModifiedProperty(new Nullable<Date>());
        assertNull(props.getModifiedProperty().getValue());
        props.setModifiedProperty(new Nullable<Date>(date));
        assertEquals(strDate, props.getModifiedPropertyString());
        assertEquals(date, props.getModifiedProperty().getValue());
        props.setModifiedProperty(strDate);
        assertEquals(strDate, props.getModifiedPropertyString());
        assertEquals(date, props.getModifiedProperty().getValue());
    }
View Full Code Here

Examples of org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart

        assertTrue("Core/Doc Relationship not found in " + p.getRelationships(), foundDocRel);
        assertTrue("Core Props Relationship not found in " + p.getRelationships(), foundCorePropRel);
        assertTrue("Ext Props Relationship not found in " + p.getRelationships(), foundExtPropRel);

        // Get the Core Properties
        PackagePropertiesPart props = (PackagePropertiesPart)p.getPackageProperties();
       
        // Check
        assertEquals("Stefan Kopf", props.getCreatorProperty().getValue());
    }
View Full Code Here

Examples of org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart

    POIXMLProperties props = workbook.getProperties();
    assertNotNull(props);
    //the Application property must be set for new workbooks, see Bugzilla #47559
    assertEquals("Apache POI", props.getExtendedProperties().getUnderlyingProperties().getApplication());

    PackagePropertiesPart opcProps = props.getCoreProperties().getUnderlyingProperties();
    assertNotNull(opcProps);

    opcProps.setTitleProperty("Testing Bugzilla #47460");
    assertEquals("Apache POI", opcProps.getCreatorProperty().getValue());
    opcProps.setCreatorProperty("poi-dev@poi.apache.org");

    workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook);
    assertEquals("Apache POI", workbook.getProperties().getExtendedProperties().getUnderlyingProperties().getApplication());
    opcProps = workbook.getProperties().getCoreProperties().getUnderlyingProperties();
    assertEquals("Testing Bugzilla #47460", opcProps.getTitleProperty().getValue());
    assertEquals("poi-dev@poi.apache.org", opcProps.getCreatorProperty().getValue());
  }
View Full Code Here

Examples of org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart

      pkg.contentTypeManager.addContentType(
          PackagingURIHelper.createPartName("/default.xml"),
          ContentTypes.PLAIN_OLD_XML);

      // Initialise some PackageBase properties
      pkg.packageProperties = new PackagePropertiesPart(pkg,
          PackagingURIHelper.CORE_PROPERTIES_PART_NAME);
      pkg.packageProperties.setCreatorProperty("Generated by Apache POI OpenXML4J");
      pkg.packageProperties.setCreatedProperty(new Nullable<Date>(new Date()));
    } catch (InvalidFormatException e) {
      // Should never happen
View Full Code Here

Examples of org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart

  public PackageProperties getPackageProperties()
      throws InvalidFormatException {
    this.throwExceptionIfWriteOnly();
    // If no properties part has been found then we create one
    if (this.packageProperties == null) {
      this.packageProperties = new PackagePropertiesPart(this,
          PackagingURIHelper.CORE_PROPERTIES_PART_NAME);
    }
    return this.packageProperties;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.