com.hfg.xml.msofficexml.docx.wordprocessingml.WmlSubDoc Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com_hfg Show documentation
Show all versions of com_hfg Show documentation
com.hfg xml, html, svg, and bioinformatics utility library
package com.hfg.xml.msofficexml.docx.wordprocessingml;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import com.hfg.xml.msofficexml.RelationshipType;
import com.hfg.xml.msofficexml.docx.Docx;
import com.hfg.xml.msofficexml.OfficeOpenXMLTag;
import com.hfg.xml.msofficexml.docx.RelationshipXML;
import com.hfg.xml.msofficexml.part.OfficeXMLPart;
public class WmlSubDoc extends OfficeOpenXMLTag
{
private OfficeXMLPart mPart;
private static int sIdSrc = 1;
//##########################################################################
// CONSTRUCTORS
//##########################################################################
//---------------------------------------------------------------------------
public WmlSubDoc(Docx inDocx)
{
super(WmlXML.SUB_DOC, inDocx);
}
//##########################################################################
// PUBLIC METHODS
//##########################################################################
//---------------------------------------------------------------------------
@Override
public Docx getParentDoc()
{
return (Docx) super.getParentDoc();
}
//---------------------------------------------------------------------------
public WmlSubDoc setDocument(Docx inValue)
{
String baseFilename = "subDoc" + sIdSrc++;
mPart = new SubDocPart(inValue);
mPart.setFile(new File(WmlXML.WORD_DIR, baseFilename + ".docx"));
// Add the relationship
String relationshipId = getParentDoc().getMainDocPartRelationshipPart().addRelationship(RelationshipType.SUB_DOCUMENT, new File(mPart.getFile().getName()));
setAttribute(RelationshipXML.ID_ATT, relationshipId);
return this;
}
//##########################################################################
// INNER CLASS
//##########################################################################
private class SubDocPart extends OfficeXMLPart
{
private Docx mDocx;
//------------------------------------------------------------------------
public SubDocPart(Docx inDocx)
{
super(inDocx);
getParentDoc().addPart(this);
mDocx = inDocx;
}
//------------------------------------------------------------------------
@Override
public void toXML(OutputStream inStream)
{
try
{
mDocx.write(inStream);
}
catch (IOException e)
{
throw new RuntimeException("Problem writing subdocument!", e);
}
}
}
}