org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureNode Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pdfbox Show documentation
Show all versions of pdfbox Show documentation
The Apache PDFBox library is an open source Java tool for working with PDF documents.
/*
* 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.pdfbox.pdmodel.documentinterchange.logicalstructure;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.pdfbox.cos.COSArray;
import org.apache.pdfbox.cos.COSBase;
import org.apache.pdfbox.cos.COSDictionary;
import org.apache.pdfbox.cos.COSInteger;
import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.cos.COSObject;
import org.apache.pdfbox.pdmodel.common.COSArrayList;
import org.apache.pdfbox.pdmodel.common.COSObjectable;
/**
* A node in the structure tree.
*
* @author Johannes Koch
*/
public abstract class PDStructureNode implements COSObjectable
{
/**
* Creates a node in the structure tree. Can be either a structure tree root,
* or a structure element.
*
* @param node the node dictionary
* @return the structure node
*/
public static PDStructureNode create(COSDictionary node)
{
String type = node.getNameAsString(COSName.TYPE);
if ("StructTreeRoot".equals(type))
{
return new PDStructureTreeRoot(node);
}
if ((type == null) || "StructElem".equals(type))
{
return new PDStructureElement(node);
}
throw new IllegalArgumentException("Dictionary must not include a Type entry with a value that is neither StructTreeRoot nor StructElem.");
}
private final COSDictionary dictionary;
/**
* {@inheritDoc}
*/
public COSDictionary getCOSObject()
{
return dictionary;
}
/**
* Constructor.
*
* @param type the type
*/
protected PDStructureNode(String type)
{
this.dictionary = new COSDictionary();
this.dictionary.setName(COSName.TYPE, type);
}
/**
* Constructor for an existing structure node.
*
* @param dictionary The existing dictionary.
*/
protected PDStructureNode(COSDictionary dictionary)
{
this.dictionary = dictionary;
}
/**
* Returns the type.
*
* @return the type
*/
public String getType()
{
return this.getCOSObject().getNameAsString(COSName.TYPE);
}
/**
* Returns a list of objects for the kids (K).
*
* @return a list of objects for the kids
*/
public List