2004-04-09 09:05:39 -04:00
|
|
|
/* ====================================================================
|
2006-12-22 14:18:16 -05:00
|
|
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
contributor license agreements. See the NOTICE file distributed with
|
|
|
|
this work for additional information regarding copyright ownership.
|
|
|
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
(the "License"); you may not use this file except in compliance with
|
|
|
|
the License. You may obtain a copy of the License at
|
2004-04-09 09:05:39 -04:00
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
==================================================================== */
|
|
|
|
|
2003-08-30 05:13:53 -04:00
|
|
|
package org.apache.poi.hpsf;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Adds writing capability to the {@link Property} class.</p>
|
2004-06-22 12:11:39 -04:00
|
|
|
*
|
2003-08-30 05:13:53 -04:00
|
|
|
* <p>Please be aware that this class' functionality will be merged into the
|
|
|
|
* {@link Property} class at a later time, so the API will change.</p>
|
|
|
|
*
|
|
|
|
* @author Rainer Klute <a
|
|
|
|
* href="mailto:klute@rainer-klute.de"><klute@rainer-klute.de></a>
|
|
|
|
* @since 2003-08-03
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
public class MutableProperty extends Property
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Creates an empty property. It must be filled using the set method to
|
|
|
|
* be usable.</p>
|
|
|
|
*/
|
|
|
|
public MutableProperty()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-09-04 16:15:24 -04:00
|
|
|
/**
|
|
|
|
* <p>Creates a <code>MutableProperty</code> as a copy of an existing
|
|
|
|
* <code>Property</code>.</p>
|
2004-06-22 12:11:39 -04:00
|
|
|
*
|
2003-09-04 16:15:24 -04:00
|
|
|
* @param p The property to copy.
|
|
|
|
*/
|
|
|
|
public MutableProperty(final Property p)
|
|
|
|
{
|
|
|
|
setID(p.getID());
|
|
|
|
setType(p.getType());
|
|
|
|
setValue(p.getValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-30 05:13:53 -04:00
|
|
|
/**
|
|
|
|
* <p>Sets the property's ID.</p>
|
|
|
|
*
|
|
|
|
* @param id the ID
|
|
|
|
*/
|
|
|
|
public void setID(final long id)
|
|
|
|
{
|
|
|
|
this.id = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Sets the property's type.</p>
|
|
|
|
*
|
|
|
|
* @param type the property's type
|
|
|
|
*/
|
|
|
|
public void setType(final long type)
|
|
|
|
{
|
|
|
|
this.type = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Sets the property's value.</p>
|
|
|
|
*
|
|
|
|
* @param value the property's value
|
|
|
|
*/
|
|
|
|
public void setValue(final Object value)
|
|
|
|
{
|
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Writes the property to an output stream.</p>
|
2004-06-22 12:11:39 -04:00
|
|
|
*
|
2003-08-30 05:13:53 -04:00
|
|
|
* @param out The output stream to write to.
|
2003-12-02 12:46:01 -05:00
|
|
|
* @param codepage The codepage to use for writing non-wide strings
|
2003-08-30 05:13:53 -04:00
|
|
|
* @return the number of bytes written to the stream
|
2004-06-22 12:11:39 -04:00
|
|
|
*
|
2003-08-30 05:13:53 -04:00
|
|
|
* @exception IOException if an I/O error occurs
|
|
|
|
* @exception WritingNotSupportedException if a variant type is to be
|
|
|
|
* written that is not yet supported
|
|
|
|
*/
|
2003-12-02 12:46:01 -05:00
|
|
|
public int write(final OutputStream out, final int codepage)
|
2003-08-30 05:13:53 -04:00
|
|
|
throws IOException, WritingNotSupportedException
|
|
|
|
{
|
|
|
|
int length = 0;
|
|
|
|
long variantType = getType();
|
2004-08-31 16:42:12 -04:00
|
|
|
|
|
|
|
/* Ensure that wide strings are written if the codepage is Unicode. */
|
|
|
|
if (codepage == Constants.CP_UNICODE && variantType == Variant.VT_LPSTR)
|
|
|
|
variantType = Variant.VT_LPWSTR;
|
|
|
|
|
2003-08-30 05:13:53 -04:00
|
|
|
length += TypeWriter.writeUIntToStream(out, variantType);
|
2003-12-02 12:46:01 -05:00
|
|
|
length += VariantSupport.write(out, variantType, getValue(), codepage);
|
2003-08-30 05:13:53 -04:00
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|