package izyndoc;

import com.jacob.com.*;

/**
 * <p>Title: WordDocCustomProps</p>
 * <p>Description: Manipulate the CustomDocumentProperties collection of
 * a Word document.</p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: Izyn Technologies</p>
 * @author Richard Norton
 * @version 1.0
 */

public class WordDocCustomProps extends com.jacob.com.Dispatch
{
  private final static Integer MSOPROPERTYTYPESTRING = new Integer(4);
  private final static Boolean FALSE = new Boolean(false);


  /**
   * Constructor.
   *
   * @param dispatchCustomProps Dispatch
   */
  public WordDocCustomProps(Dispatch dispatchCustomProps)
  {
    //TAKE OVER THE IDispatch POINTER
    this.m_pDispatch = dispatchCustomProps.m_pDispatch;
    //NULL OUT THE INPUT POINTER
    dispatchCustomProps.m_pDispatch = 0;
  }

  /**
   * Get number of CustomDocumentProperties.
   *
   * @return int
   */
  public int getCustomPropsCount()
  {
    return Dispatch.get(this, "Count").toInt();
  }

  /**
   * Add a custom property.
   *
   * @param customPropName String
   * @param customPropValue String
   * @return Dispatch
   */
  public Dispatch addCustomProperty(String customPropName
                                       , String customPropValue)
  {
    return Dispatch.callN(this, "Add", new Variant[]{
                          new Variant(customPropName)
                          , new Variant(FALSE)
                          , new Variant(MSOPROPERTYTYPESTRING)
                          , new Variant(customPropValue)
                              }).toDispatch();
  }

  /**
   * Get a custom property.
   *
   * @param customPropsPos int
   * @return Dispatch
   */
  public Dispatch getCustomProperty(int customPropsPos)
  {
    return
      Dispatch.call(this, "Item", new Variant(customPropsPos)).toDispatch();
  }

  /**
   * Get a custom property.
   *
   * @param customPropsName String
   * @return Dispatch null if custom property name is not valid
   */
  public Dispatch getCustomProperty(String customPropsName)
  {
    try
    {
      return
        Dispatch.call(this, "Item", new Variant(customPropsName)).toDispatch();
    }
    catch (Exception e)
    {
      return null;
    }
  }
}
