All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.poi.hwpf.model.FSPATable Maven / Gradle / Ivy

Go to download

The Apache Commons Codec package contains simple encoder and decoders for various formats such as Base64 and Hexadecimal. In addition to these widely used encoders and decoders, the codec package also maintains a collection of phonetic encoding utilities.

There is a newer version: 62
Show newest version
/* ====================================================================
   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

       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.
==================================================================== */

package org.apache.poi.hwpf.model;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.poi.hwpf.model.types.FSPAAbstractType;
import org.apache.poi.util.Internal;

/**
 * This class holds all the FSPA (File Shape Address) structures.
 */
@Internal
public final class FSPATable
{

    private final Map _byStart = new LinkedHashMap<>();

    public FSPATable( byte[] tableStream, FileInformationBlock fib,
            FSPADocumentPart part )
    {
        int offset = fib.getFSPAPlcfOffset( part );
        int length = fib.getFSPAPlcfLength( part );

        PlexOfCps plex = new PlexOfCps(tableStream, offset, length, FSPAAbstractType.getSize() );
        for ( int i = 0; i < plex.length(); i++ )
        {
            GenericPropertyNode property = plex.getProperty( i );
            _byStart.put(property.getStart(), property );
        }
    }

    @Deprecated
    public FSPATable( byte[] tableStream, int fcPlcspa, int lcbPlcspa,
            List tpt )
    {
        // Will be 0 if no drawing objects in document
        if ( fcPlcspa == 0 )
            return;

        PlexOfCps plex = new PlexOfCps( tableStream, fcPlcspa, lcbPlcspa,
                FSPA.FSPA_SIZE );
        for ( int i = 0; i < plex.length(); i++ )
        {
            GenericPropertyNode property = plex.getProperty( i );
            _byStart.put(property.getStart(), property );
        }
    }

    public FSPA getFspaFromCp( int cp )
    {
        GenericPropertyNode propertyNode = _byStart.get(cp);
        if ( propertyNode == null )
        {
            return null;
        }
        return new FSPA( propertyNode.getBytes(), 0 );
    }

    public FSPA[] getShapes()
    {
        List result = new ArrayList<>(_byStart.size());
        for ( GenericPropertyNode propertyNode : _byStart.values() )
        {
            result.add( new FSPA( propertyNode.getBytes(), 0 ) );
        }
        return result.toArray(new FSPA[0]);
    }

    public String toString() {
        StringBuilder buf = new StringBuilder();
        buf.append( "[FPSA PLC size=" ).append( _byStart.size() ).append( "]\n" );

        for ( Map.Entry entry : _byStart.entrySet() ) {
            Integer i = entry.getKey();
            buf.append( "  " ).append(i).append( " => \t" );

            try {
                FSPA fspa = getFspaFromCp(i);
                buf.append(fspa);
            } catch ( Exception exc ) {
                buf.append( exc.getMessage() );
            }
            buf.append( "\n" );
        }
        buf.append( "[/FSPA PLC]" );
        return buf.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy