org.sejda.sambox.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 sambox Show documentation
Show all versions of sambox Show documentation
An Apache PDFBox fork intended to be used as PDF processor for Sejda and PDFsam
related projects
/*
* 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.sejda.sambox.pdmodel.documentinterchange.logicalstructure;
import static java.util.Objects.nonNull;
import java.util.ArrayList;
import java.util.List;
import org.sejda.sambox.cos.COSArray;
import org.sejda.sambox.cos.COSArrayList;
import org.sejda.sambox.cos.COSBase;
import org.sejda.sambox.cos.COSDictionary;
import org.sejda.sambox.cos.COSInteger;
import org.sejda.sambox.cos.COSName;
import org.sejda.sambox.cos.COSObjectable;
/**
* A node in the structure tree.
*
* @author Johannes Koch
*/
public abstract class PDStructureNode implements COSObjectable
{
private final COSDictionary 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;
}
/**
* 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.");
}
@Override
public COSDictionary getCOSObject()
{
return 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