Package org.apache.poi.hpsf

Examples of org.apache.poi.hpsf.CustomProperties


                    final PropertySet ps = new PropertySet(dis);
                    dsi = new DocumentSummaryInformation(ps);
                }
                else
                    dsi = PropertySetFactory.newDocumentSummaryInformation();
                final CustomProperties cps = dsi.getCustomProperties();

                if (cps == null)
                    /* The document does not have custom properties. */
                    return;

                for (final Iterator i = cps.entrySet().iterator(); i.hasNext();)
                {
                    final Map.Entry e = (Entry) i.next();
                    final CustomProperty cp = (CustomProperty) e.getValue();
                    cp.getName();
                    cp.getValue();
View Full Code Here


        final String KEY = "Schl\u00fcssel \u00e4";
        final String VALUE_1 = "Wert 1";
        final String VALUE_2 = "Wert 2";

        CustomProperty cp;
        CustomProperties cps = new CustomProperties();
        assertEquals(0, cps.size());

        /* After adding a custom property the size must be 1 and it must be
         * possible to extract the custom property from the map. */
        cps.put(KEY, VALUE_1);
        assertEquals(1, cps.size());
        Object v1 = cps.get(KEY);
        assertEquals(VALUE_1, v1);

        /* After adding a custom property with the same name the size must still
         * be one. */
        cps.put(KEY, VALUE_2);
        assertEquals(1, cps.size());
        Object v2 = cps.get(KEY);
        assertEquals(VALUE_2, v2);

        /* Removing the custom property must return the remove property and
         * reduce the size to 0. */
        cp = (CustomProperty) cps.remove(KEY);
        assertEquals(KEY, cp.getName());
        assertEquals(VALUE_2, cp.getValue());
        assertEquals(0, cps.size());
    }
View Full Code Here

        final String NAME_1 = "Schl\u00fcssel \u00e4";
        final String VALUE_1 = "Wert 1";
        final Map dictionary = new HashMap();

        DocumentSummaryInformation dsi = PropertySetFactory.newDocumentSummaryInformation();
        CustomProperties cps;
        MutableSection s;

        /* A document summary information set stream by default does have custom properties. */
        cps = dsi.getCustomProperties();
        assertEquals(null, cps);

        /* Test an empty custom properties set. */
        s = new MutableSection();
        s.setFormatID(SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID[1]);
        // s.setCodepage(Constants.CP_UNICODE);
        dsi.addSection(s);
        cps = dsi.getCustomProperties();
        assertEquals(0, cps.size());

        /* Add a custom property. */
        MutableProperty p = new MutableProperty();
        p.setID(ID_1);
        p.setType(Variant.VT_LPWSTR);
        p.setValue(VALUE_1);
        s.setProperty(p);
        dictionary.put(Long.valueOf(ID_1), NAME_1);
        s.setDictionary(dictionary);
        cps = dsi.getCustomProperties();
        assertEquals(1, cps.size());
        assertTrue(cps.isPure());

        /* Add another custom property. */
        s.setProperty(ID_2, Variant.VT_LPWSTR, VALUE_1);
        dictionary.put(Long.valueOf(ID_2), NAME_1);
        s.setDictionary(dictionary);
        cps = dsi.getCustomProperties();
        assertEquals(1, cps.size());
        assertFalse(cps.isPure());
    }
View Full Code Here

    // Normal properties
    text.append( getPropertiesText(dsi) );

    // Now custom ones
    CustomProperties cps = dsi == null ? null : dsi.getCustomProperties();
    if(cps != null) {
      Iterator<String> keys = cps.nameSet().iterator();
      while(keys.hasNext()) {
        String key = keys.next();
        String val = getPropertyValueText( cps.get(key) );
        text.append(key + " = " + val + "\n");
      }
    }

    // All done
View Full Code Here

    // Normal properties
    text.append( getPropertiesText(dsi) );

    // Now custom ones
    CustomProperties cps = dsi == null ? null : dsi.getCustomProperties();
    if(cps != null) {
      Iterator<String> keys = cps.nameSet().iterator();
      while(keys.hasNext()) {
        String key = keys.next();
        String val = getPropertyValueText( cps.get(key) );
        text.append(key + " = " + val + "\n");
      }
    }

    // All done
View Full Code Here

    // Normal properties
    text.append( getPropertiesText(dsi) );
   
    // Now custom ones
    CustomProperties cps = dsi.getCustomProperties();
    Iterator keys = cps.keySet().iterator();
    while(keys.hasNext()) {
      String key = (String)keys.next();
      String val = getPropertyValueText( cps.get(key) );
      text.append(key + " = " + val + "\n");
    }
   
    // All done
    return text.toString();
View Full Code Here

        System.out.println("Category changed to " + dsi.getCategory() + ".");

        /* Read the custom properties. If there are no custom properties yet,
         * the application has to create a new CustomProperties object. It will
         * serve as a container for custom properties. */
        CustomProperties customProperties = dsi.getCustomProperties();
        if (customProperties == null)
            customProperties = new CustomProperties();

        /* Insert some custom properties into the container. */
        customProperties.put("Key 1", "Value 1");
        customProperties.put("Schl\u00fcssel 2", "Wert 2");
        customProperties.put("Sample Number", new Integer(12345));
        customProperties.put("Sample Boolean", Boolean.TRUE);
        customProperties.put("Sample Date", new Date());

        /* Read a custom property. */
        Object value = customProperties.get("Sample Number");

        /* Write the custom properties back to the document summary
         * information. */
        dsi.setCustomProperties(customProperties);

View Full Code Here

    // Normal properties
    text.append( getPropertiesText(dsi) );

    // Now custom ones
    CustomProperties cps = dsi == null ? null : dsi.getCustomProperties();
    if(cps != null) {
      Iterator<String> keys = cps.nameSet().iterator();
      while(keys.hasNext()) {
        String key = keys.next();
        String val = getPropertyValueText( cps.get(key) );
        text.append(key + " = " + val + "\n");
      }
    }

    // All done
View Full Code Here

    si.setComments("xxxCommentsxxx");
    si.setKeywords("xxxKeyWordsxxx");
    si.setSubject("xxxSubjectxxx");

    // Custom Properties (in DocumentSummaryInformation
    CustomProperties customProperties = dsi.getCustomProperties();
    if (customProperties == null) {
      customProperties = new CustomProperties();
    }

    /* Insert some custom properties into the container. */
    customProperties.put("Key1", "Value1");
    customProperties.put("Schl\u00fcssel2", "Wert2");
    customProperties.put("Sample Integer", new Integer(12345));
    customProperties.put("Sample Boolean", Boolean.TRUE);
    Date date = new Date();
    customProperties.put("Sample Date", date);
    customProperties.put("Sample Double", new Double(-1.0001));
    customProperties.put("Sample Negative Integer", new Integer(-100000));

    dsi.setCustomProperties(customProperties);

    // start reading
    closeAndReOpen();

    // testing
    assertNotNull(dsi);
    assertNotNull(si);

    assertEquals("Category", "xxxCategoryxxx", dsi.getCategory());
    assertEquals("Company", "xxxCompanyxxx", dsi.getCompany());
    assertEquals("Manager", "xxxManagerxxx", dsi.getManager());

    assertEquals("", "xxxAuthorxxx", si.getAuthor());
    assertEquals("", "xxxTitlexxx", si.getTitle());
    assertEquals("", "xxxCommentsxxx", si.getComments());
    assertEquals("", "xxxKeyWordsxxx", si.getKeywords());
    assertEquals("", "xxxSubjectxxx", si.getSubject());

    /*
     * Read the custom properties. If there are no custom properties yet,
     * the application has to create a new CustomProperties object. It will
     * serve as a container for custom properties.
     */
    customProperties = dsi.getCustomProperties();
    if (customProperties == null) {
      fail();
    }

    /* Insert some custom properties into the container. */
    String a1 = (String) customProperties.get("Key1");
    assertEquals("Key1", "Value1", a1);
    String a2 = (String) customProperties.get("Schl\u00fcssel2");
    assertEquals("Schl\u00fcssel2", "Wert2", a2);
    Integer a3 = (Integer) customProperties.get("Sample Integer");
    assertEquals("Sample Number", new Integer(12345), a3);
    Boolean a4 = (Boolean) customProperties.get("Sample Boolean");
    assertEquals("Sample Boolean", Boolean.TRUE, a4);
    Date a5 = (Date) customProperties.get("Sample Date");
    assertEquals("Custom Date:", date, a5);

    Double a6 = (Double) customProperties.get("Sample Double");
    assertEquals("Custom Float", new Double(-1.0001), a6);

    Integer a7 = (Integer) customProperties.get("Sample Negative Integer");
    assertEquals("Neg", new Integer(-100000), a7);
  }
View Full Code Here

    si.setTitle(title);
    si.setAuthor(author);
    si.setComments(comments);
    si.setKeywords(keywords);
    si.setSubject(subject);
    CustomProperties customProperties = dsi.getCustomProperties();
    if (customProperties == null) {
      customProperties = new CustomProperties();
    }

    /* Insert some custom properties into the container. */
    customProperties.put(k1, p1);
    customProperties.put(k2, p2);
    customProperties.put("Sample Number", new Integer(12345));
    customProperties.put("Sample Boolean", Boolean.TRUE);
    Date date = new Date();
    customProperties.put("Sample Date", date);

    dsi.setCustomProperties(customProperties);

    closeAndReOpen();

    assertNotNull(dsi);
    assertNotNull(si);
    /*
     * Change the category to "POI example". Any former category value will
     * be lost. If there has been no category yet, it will be created.
     */
    assertEquals("Category", category, dsi.getCategory());
    assertEquals("Company", company, dsi.getCompany());
    assertEquals("Manager", manager, dsi.getManager());

    assertEquals("", author, si.getAuthor());
    assertEquals("", title, si.getTitle());
    assertEquals("", comments, si.getComments());
    assertEquals("", keywords, si.getKeywords());
    assertEquals("", subject, si.getSubject());

    /*
     * Read the custom properties. If there are no custom properties yet,
     * the application has to create a new CustomProperties object. It will
     * serve as a container for custom properties.
     */
    customProperties = dsi.getCustomProperties();
    if (customProperties == null) {
      fail();
    }

    /* Insert some custom properties into the container. */
    String a1 = (String) customProperties.get(k1);
    assertEquals("Key1", p1, a1);
    String a2 = (String) customProperties.get(k2);
    assertEquals("Schl\u00fcssel2", p2, a2);
    Integer a3 = (Integer) customProperties.get("Sample Number");
    assertEquals("Sample Number", new Integer(12345), a3);
    Boolean a4 = (Boolean) customProperties.get("Sample Boolean");
    assertEquals("Sample Boolean", Boolean.TRUE, a4);
    Date a5 = (Date) customProperties.get("Sample Date");
    assertEquals("Custom Date:", date, a5);

  }
View Full Code Here

TOP

Related Classes of org.apache.poi.hpsf.CustomProperties

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.