public class POIXMLDocumentPart
extends java.lang.Object
Each POIXMLDocumentPart keeps a reference to the underlying a PackagePart
.
Modifier and Type | Class and Description |
---|---|
static class |
POIXMLDocumentPart.RelationPart
The RelationPart is a cached relationship between the document, which contains the RelationPart, and one of its referenced child document parts.
(RelationPart 是包含 RelationPart 的文档与其引用的子文档部分之一之间的缓存关系。)
|
Constructor and Description |
---|
POIXMLDocumentPart()
Creates new POIXMLDocumentPart - called by client code to create new parts from scratch.
|
POIXMLDocumentPart(OPCPackage pkg)
Construct POIXMLDocumentPart representing a "core document" package part.
|
POIXMLDocumentPart(OPCPackage pkg, java.lang.String coreDocumentRel)
Construct POIXMLDocumentPart representing a custom "core document" package part.
|
POIXMLDocumentPart(PackagePart part)
Creates an POIXMLDocumentPart representing the given package part and relationship.
|
POIXMLDocumentPart(POIXMLDocumentPart parent, PackagePart part)
Creates an POIXMLDocumentPart representing the given package part, relationship and parent Called by
read(POIXMLFactory, java.util.Map) when reading in an existing file.
|
Modifier and Type | Method and Description |
---|---|
static void |
_invokeOnDocumentRead(POIXMLDocumentPart part)
Deprecated.
(已弃用。)
|
POIXMLDocumentPart.RelationPart |
addRelation(java.lang.String relId, POIXMLRelation relationshipType, POIXMLDocumentPart part)
Add a new child POIXMLDocumentPart
(添加新的子 POIXMLDocumentPart)
|
protected void |
commit()
Save the content in the underlying package part.
(将内容保存在底层包部分中。)
|
POIXMLDocumentPart |
createRelationship(POIXMLRelation descriptor, POIXMLFactory factory)
Create a new child POIXMLDocumentPart
(创建一个新的子 POIXMLDocumentPart)
|
POIXMLDocumentPart |
createRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx)
Create a new child POIXMLDocumentPart
(创建一个新的子 POIXMLDocumentPart)
|
POIXMLDocumentPart.RelationPart |
createRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx, boolean noRelation)
Create a new child POIXMLDocumentPart
(创建一个新的子 POIXMLDocumentPart)
|
int |
getNextPartNumber(POIXMLRelation descriptor, int minIdx)
Identifies the next available part number for a part of the given type, if possible, otherwise -1 if none are available.
(如果可能,标识给定类型的部件的下一个可用部件号,否则 -1 如果没有可用的部件号。)
|
PackagePart |
getPackagePart()
Provides access to the underlying PackagePart
(提供对底层 PackagePart 的访问)
|
POIXMLDocumentPart |
getParent()
Returns the parent POIXMLDocumentPart.
(返回父 POIXMLDocumentPart。)
|
POIXMLDocumentPart |
getRelationById(java.lang.String id)
Returns the target
POIXMLDocumentPart , where a
PackageRelationship is set from the
PackagePart of this
POIXMLDocumentPart to the
PackagePart of the target
POIXMLDocumentPart with a
PackageRelationship.getId() matching the given parameter value.
(返回目标 POIXMLDocumentPart,其中 PackageRelationship 设置为此 POIXMLDocumentPart 的 PackagePart 到目标 POIXMLDocumentPart 的 PackagePart,PackageRelationship.getId() 匹配给定的参数值。)
|
java.lang.String |
getRelationId(POIXMLDocumentPart part)
Returns the first
PackageRelationship.getId() of the
PackageRelationship , that sources from the
PackagePart of this
POIXMLDocumentPart to the
PackagePart of the given parameter value.
(返回 PackageRelationship 的第一个 PackageRelationship.getId(),它从这个 POIXMLDocumentPart 的 PackagePart 到给定参数值的 PackagePart。)
|
POIXMLDocumentPart.RelationPart |
getRelationPartById(java.lang.String id)
Returns the target
POIXMLDocumentPart.RelationPart , where a
PackageRelationship is set from the
PackagePart of this
POIXMLDocumentPart to the
PackagePart of the target
POIXMLDocumentPart with a
PackageRelationship.getId() matching the given parameter value.
(返回目标 POIXMLDocumentPart.RelationPart,其中 PackageRelationship 设置为此 POIXMLDocumentPart 的 PackagePart 到目标 POIXMLDocumentPart 的 PackagePart,PackageRelationship.getId() 匹配给定的参数值。)
|
java.util.List<POIXMLDocumentPart.RelationPart> |
getRelationParts()
Returns the list of child relations for this POIXMLDocumentPart
(返回此 POIXMLDocumentPart 的子关系列表)
|
java.util.List<POIXMLDocumentPart> |
getRelations()
Returns the list of child relations for this POIXMLDocumentPart
(返回此 POIXMLDocumentPart 的子关系列表)
|
protected PackagePart |
getTargetPart(PackageRelationship rel)
Get the PackagePart that is the target of a relationship from this Part.
(从此 Part 中获取作为关系目标的 PackagePart。)
|
boolean |
isCommitted()
to check whether embedded part is already committed
(检查嵌入部分是否已经提交)
|
protected void |
onDocumentCreate()
Fired when a new package part is created
(创建新的包部件时触发)
|
protected void |
onDocumentRead()
Fired when a package part is read
(读取包部分时触发)
|
protected void |
onDocumentRemove()
Fired when a package part is about to be removed from the package
(当一个包部分即将从包中移除时触发)
|
protected void |
onSave(java.util.Set<PackagePart> alreadySaved)
Save changes in the underlying OOXML package.
(保存底层 OOXML 包中的更改。)
|
protected void |
prepareForCommit()
Ensure that a memory based package part does not have lingering data from previous commit() calls.
(确保基于内存的包部分没有来自先前 commit() 调用的延迟数据。)
|
protected void |
read(POIXMLFactory factory, java.util.Map<PackagePart,POIXMLDocumentPart> context)
Iterate through the underlying PackagePart and create child POIXMLFactory instances using the specified factory
(遍历底层的 PackagePart 并使用指定的工厂创建子 POIXMLFactory 实例)
|
protected void |
rebase(OPCPackage pkg)
When you open something like a theme, call this to re-base the XML Document onto the core child of the current core document
(当您打开主题之类的内容时,调用它以将 XML 文档重新定位到当前核心文档的核心子文档)
|
protected void |
removeRelation(POIXMLDocumentPart part)
Remove the relation to the specified part in this package and remove the part, if it is no longer needed.
(删除与此包中指定部分的关系,如果不再需要,则删除该部分。)
|
protected boolean |
removeRelation(POIXMLDocumentPart part, boolean removeUnusedParts)
Remove the relation to the specified part in this package and remove the part, if it is no longer needed and flag is set to true.
(删除与此包中指定部分的关系并删除该部分,如果不再需要并且标志设置为 true。)
|
protected void |
removeRelation(java.lang.String partId)
Remove the relation to the specified part in this package and remove the part, if it is no longer needed.
(删除与此包中指定部分的关系,如果不再需要,则删除该部分。)
|
void |
setCommitted(boolean isCommitted)
setter method to set embedded part is committed
(设置嵌入部分的 setter 方法已提交)
|
java.lang.String |
toString() |
public POIXMLDocumentPart(OPCPackage pkg)
pkg
- the OPCPackage containing this document
(pkg - 包含此文档的 OPCPackage)
public POIXMLDocumentPart(OPCPackage pkg, java.lang.String coreDocumentRel)
pkg
- the OPCPackage containing this document
(pkg - 包含此文档的 OPCPackage)
coreDocumentRel
- the relation type of this document
(coreDocumentRel - 此文档的关系类型)
public POIXMLDocumentPart()
public POIXMLDocumentPart(PackagePart part)
read(POIXMLFactory, java.util.Map)
when reading in an existing file.
(创建一个表示给定包部分和关系的 POIXMLDocumentPart。读取现有文件时由 read(POIXMLFactory, java.util.Map) 调用。)
part
- - The package part that holds xml data representing this sheet.
(part - 包含代表此工作表的 xml 数据的包部分。)
read(POIXMLFactory, java.util.Map)
public POIXMLDocumentPart(POIXMLDocumentPart parent, PackagePart part)
read(POIXMLFactory, java.util.Map)
when reading in an existing file.
(创建一个 POIXMLDocumentPart 表示给定的包部分、关系和父级 在读取现有文件时由 read(POIXMLFactory, java.util.Map) 调用。)
parent
- - Parent part
(parent - - 父部分)
part
- - The package part that holds xml data representing this sheet.
(part - 包含代表此工作表的 xml 数据的包部分。)
read(POIXMLFactory, java.util.Map)
public boolean isCommitted()
public void setCommitted(boolean isCommitted)
isCommitted
- boolean value
(isCommitted - 布尔值)
protected final void rebase(OPCPackage pkg) throws InvalidFormatException
pkg
- the package to be rebased
(pkg - 要变基的包)
InvalidFormatException
- if there was an error in the core document relation
(InvalidFormatException - 如果核心文档关系中存在错误)
java.lang.IllegalStateException
- if there are more than one core document relations
(java.lang.IllegalStateException - 如果有多个核心文档关系)
public final PackagePart getPackagePart()
public final java.util.List<POIXMLDocumentPart> getRelations()
public final java.util.List<POIXMLDocumentPart.RelationPart> getRelationParts()
public final POIXMLDocumentPart getRelationById(java.lang.String id)
POIXMLDocumentPart
, where a
PackageRelationship
is set from the
PackagePart
of this
POIXMLDocumentPart
to the
PackagePart
of the target
POIXMLDocumentPart
with a
PackageRelationship.getId()
matching the given parameter value.
(返回目标 POIXMLDocumentPart,其中 PackageRelationship 设置为此 POIXMLDocumentPart 的 PackagePart 到目标 POIXMLDocumentPart 的 PackagePart,PackageRelationship.getId() 匹配给定的参数值。)
id
- The relation id to look for
(id - 要查找的关系 id)
public final POIXMLDocumentPart.RelationPart getRelationPartById(java.lang.String id)
POIXMLDocumentPart.RelationPart
, where a
PackageRelationship
is set from the
PackagePart
of this
POIXMLDocumentPart
to the
PackagePart
of the target
POIXMLDocumentPart
with a
PackageRelationship.getId()
matching the given parameter value.
(返回目标 POIXMLDocumentPart.RelationPart,其中 PackageRelationship 设置为此 POIXMLDocumentPart 的 PackagePart 到目标 POIXMLDocumentPart 的 PackagePart,PackageRelationship.getId() 匹配给定的参数值。)
id
- The relation id to look for
(id - 要查找的关系 id)
public final java.lang.String getRelationId(POIXMLDocumentPart part)
PackageRelationship.getId()
of the
PackageRelationship
, that sources from the
PackagePart
of this
POIXMLDocumentPart
to the
PackagePart
of the given parameter value.
There can be multiple references to the given POIXMLDocumentPart
and only the first in the order of creation is returned.
part
- The
POIXMLDocumentPart
for which the according relation-id shall be found.
(part - 应为其找到相应关系 ID 的 POIXMLDocumentPart。)
PackageRelationship.getId()
or null, if parts are not related.
(PackageRelationship.getId() 的值或 null,如果部分不相关。)
public final POIXMLDocumentPart.RelationPart addRelation(java.lang.String relId, POIXMLRelation relationshipType, POIXMLDocumentPart part)
relId
- the preferred relation id, when null the next free relation id will be used
(relId - 首选关系 id,当为 null 时,将使用下一个空闲关系 id)
relationshipType
- the package relationship type
(relationshipType - 包关系类型)
part
- the child to add
(part - 要添加的孩子)
protected final void removeRelation(POIXMLDocumentPart part)
If there are multiple relationships to the same part, this will only remove the first relationship in the order of creation. The removal via the part id (removeRelation(String)
is preferred.
part
- the part which relation is to be removed from this document
(part - 要从此文档中删除关系的部分)
protected final boolean removeRelation(POIXMLDocumentPart part, boolean removeUnusedParts)
If there are multiple relationships to the same part, this will only remove the first relationship in the order of creation. The removal via the part id (removeRelation(String, boolean)
is preferred.
part
- The related part, to which the relation shall be removed.
(part - 应删除关系的相关部分。)
removeUnusedParts
- true, if the part shall be removed from the package if not needed any longer.
(removeUnusedParts - true,如果不再需要该部件应从包中移除。)
protected final void removeRelation(java.lang.String partId)
If there are multiple relationships to the same part, this will only remove the first relationship in the order of creation. The removal via the part id (removeRelation(POIXMLDocumentPart)
is preferred.
partId
- the part id which relation is to be removed from this document
(partId - 要从此文档中删除关系的部件 ID)
public final POIXMLDocumentPart getParent()
null
for the root element.
(父 POIXMLDocumentPart 或根元素为 null。)
public java.lang.String toString()
toString
in class
java.lang.Object
protected void commit() throws java.io.IOException
Sub-classes should override and add logic to marshal the "model" into Ooxml4J.
For example, the code saving a generic XML entry may look as follows:
protected void commit() throws IOException { PackagePart part = getPackagePart(); OutputStream out = part.getOutputStream(); XmlObject bean = getXmlBean(); //the "model" which holds changes in memory bean.save(out, DEFAULT_XML_OPTIONS); out.close(); }(将内容保存在底层包部分中。默认实现是空的,这意味着包部分保持不变。子类应覆盖并添加逻辑以将“模型”编组到 Ooxml4J。例如,保存通用 XML 条目的代码可能如下所示: protected void commit() throws IOException { PackagePart part = getPackagePart();输出流输出 = part.getOutputStream(); XmlObject bean = getXmlBean(); //保存内存变化的“模型” bean.save(out, DEFAULT_XML_OPTIONS); out.close(); })
java.io.IOException
- a subclass may throw an IOException if the changes can't be committed
(java.io.IOException - 如果无法提交更改,子类可能会抛出 IOException)
protected final void onSave(java.util.Set<PackagePart> alreadySaved) throws java.io.IOException
commit()
for each package part
(保存底层 OOXML 包中的更改。递归地为每个包部分触发 commit())
alreadySaved
- context set containing already visited nodes
(alreadySaved - 包含已访问节点的上下文集)
java.io.IOException
- a related part may throw an IOException if the changes can't be saved
(java.io.IOException - 如果无法保存更改,相关部分可能会抛出 IOException)
protected void prepareForCommit()
Note: This is overwritten for some objects, as *PictureData seem to store the actual content in the part directly without keeping a copy like all others therefore we need to handle them differently.
(确保基于内存的包部分没有来自先前 commit() 调用的延迟数据。注意:这对于某些对象会被覆盖,因为 *PictureData 似乎直接将实际内容存储在部件中,而不像所有其他对象一样保留副本,因此我们需要以不同方式处理它们。)public final POIXMLDocumentPart createRelationship(POIXMLRelation descriptor, POIXMLFactory factory)
descriptor
- the part descriptor
(描述符 - 部分描述符)
factory
- the factory that will create an instance of the requested relation
(factory - 将创建所请求关系实例的工厂)
PartAlreadyExistsException
- If rule M1.12 is not verified : Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names.
(PartAlreadyExistsException - 如果未验证规则 M1.12:包不应包含等效的部件名称,并且包实现者不应创建或识别具有等效部件名称的包。)
public final POIXMLDocumentPart createRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx)
descriptor
- the part descriptor
(描述符 - 部分描述符)
factory
- the factory that will create an instance of the requested relation
(factory - 将创建所请求关系实例的工厂)
idx
- part number
(idx - 部件号)
PartAlreadyExistsException
- If rule M1.12 is not verified : Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names.
(PartAlreadyExistsException - 如果未验证规则 M1.12:包不应包含等效的部件名称,并且包实现者不应创建或识别具有等效部件名称的包。)
@Internal public final int getNextPartNumber(POIXMLRelation descriptor, int minIdx)
createRelationship(POIXMLRelation, POIXMLFactory, int)
or
createRelationship(POIXMLRelation, POIXMLFactory, int, boolean)
without naming clashes. If parts with other types are already claiming a name for this relationship type (eg a
XSSFRelation.CHART
using the drawing part namespace normally used by
XSSFRelation.DRAWINGS
), those will be considered when finding the next spare number.
(如果可能,标识给定类型的部件的下一个可用部件号,否则 -1 如果没有可用的部件号。然后可以将找到的(有效)索引安全地提供给 createRelationship(POIXMLRelation, POIXMLFactory, int) 或 createRelationship(POIXMLRelation, POIXMLFactory, int, boolean) 而不会发生命名冲突。如果具有其他类型的部件已经为此关系类型声明了一个名称(例如,使用 XSSFRelation.DRAWINGS 通常使用的绘图部件命名空间的 XSSFRelation.CHART),则在查找下一个备用编号时将考虑这些名称。)
descriptor
- The relationship type to find the part number for
(描述符 - 查找部件号的关系类型)
minIdx
- The minimum free index to assign, use -1 for any
(minIdx - 要分配的最小空闲索引,使用 -1 表示任何)
public final POIXMLDocumentPart.RelationPart createRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx, boolean noRelation)
descriptor
- the part descriptor
(描述符 - 部分描述符)
factory
- the factory that will create an instance of the requested relation
(factory - 将创建所请求关系实例的工厂)
idx
- part number
(idx - 部件号)
noRelation
- if true, then no relationship is added.
(noRelation - 如果为真,则不添加任何关系。)
PartAlreadyExistsException
- If rule M1.12 is not verified : Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names.
(PartAlreadyExistsException - 如果未验证规则 M1.12:包不应包含等效的部件名称,并且包实现者不应创建或识别具有等效部件名称的包。)
protected void read(POIXMLFactory factory, java.util.Map<PackagePart,POIXMLDocumentPart> context) throws OpenXML4JException
factory
- the factory object that creates POIXMLFactory instances
(factory - 创建 POIXMLFactory 实例的工厂对象)
context
- context map containing already visited noted keyed by targetURI
(context - 包含已访问的由 targetURI 键控的注释的上下文映射)
OpenXML4JException
- thrown when a related part can't be read
(OpenXML4JException - 当无法读取相关部分时抛出)
protected PackagePart getTargetPart(PackageRelationship rel) throws InvalidFormatException
rel
- The relationship
(rel - 关系)
InvalidFormatException
- thrown if the related part has is erroneous
(InvalidFormatException - 如果相关部分有错误则抛出)
protected void onDocumentCreate() throws java.io.IOException
java.io.IOException
- a subclass may throw an IOException on document creation
(java.io.IOException - 子类可能会在创建文档时抛出 IOException)
protected void onDocumentRead() throws java.io.IOException
java.io.IOException
- a subclass may throw an IOException when a document is read
(java.io.IOException - 读取文档时子类可能会抛出 IOException)
protected void onDocumentRemove() throws java.io.IOException
java.io.IOException
- a subclass may throw an IOException when a document is removed
(java.io.IOException - 删除文档时子类可能会抛出 IOException)
@Internal @Deprecated public static void _invokeOnDocumentRead(POIXMLDocumentPart part) throws java.io.IOException
This method only exists to allow access to protected onDocumentRead()
from XWPFDocument
without reflection. It should be removed.
part
- the part which is to be read
(part - 要读取的部分)
java.io.IOException
- if the part can't be read
(java.io.IOException - 如果该部分无法读取)
Copyright 2021 The Apache Software Foundation or its licensors, as applicable.