com.hfg.xml.msofficexml.xlsx.part.SsmlCommentsPart 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.xlsx.part;
import com.hfg.xml.XMLTag;
import com.hfg.xml.msofficexml.OfficeOpenXMLContentType;
import com.hfg.xml.msofficexml.xlsx.SsmlRelationshipType;
import com.hfg.xml.msofficexml.xlsx.Xlsx;
import com.hfg.xml.msofficexml.xlsx.spreadsheetml.SsmlWorksheet;
import com.hfg.xml.msofficexml.xlsx.spreadsheetml.SsmlXML;
import com.hfg.xml.msofficexml.xlsx.spreadsheetml.SsmlXMLTag;
import com.hfg.xml.msofficexml.xlsx.spreadsheetml.XlsxComment;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
/*
taylora% more xl/drawings/vmlDrawing1.vml
1, 15, 0, 2, 2, 64, 2, 3
False
0
0
Alex Taylor Alex Taylor:
A message from beyond
*/
public class SsmlCommentsPart extends XlsxPart
{
private static int sIndexSrc = 1;
private SsmlWorksheet mParentWorksheet;
private SsmlComments mCommentsTag;
private XMLTag mCommentListTag;
private XMLTag mAuthorsTag;
private int mIndex = sIndexSrc++;
private Map mAuthorMap;
//---------------------------------------------------------------------------
public SsmlCommentsPart(SsmlWorksheet inParentWorksheet)
{
super(inParentWorksheet.getParentDoc());
mParentWorksheet = inParentWorksheet;
// Register the content type
mParentWorksheet.getParentDoc().getContentTypesPart().addOverride(this, SsmlContentType.COMMENTS);
// Register the relationship
mParentWorksheet.getParentWorksheetPart().getWorksheetRelationshipPart().addRelationship(SsmlRelationshipType.COMMENTS, this);
mCommentsTag = new SsmlComments(mParentWorksheet.getParentDoc());
setRootNode(mCommentsTag);
mCommentListTag = new XMLTag(SsmlXML.COMMENT_LIST);
mCommentsTag.addSubtag(mCommentListTag);
// A boilerplate VML drawing part is also needed
//TODO
}
//---------------------------------------------------------------------------
@Override
public OfficeOpenXMLContentType getContentType()
{
return SsmlContentType.COMMENTS;
}
//---------------------------------------------------------------------------
@Override
public File getFile()
{
return new File(SsmlXML.XL_DIR, "comments" + mIndex + ".xml");
}
//---------------------------------------------------------------------------
public SsmlCommentsPart addComment(XlsxComment inComment)
{
SsmlComment commentTag = new SsmlComment(getParentDoc());
commentTag.setAttribute(SsmlXML.REF_RANGE_ATT, inComment.getCellRef());
commentTag.setAttribute(SsmlXML.AUTHOR_ID_ATT, getAuthorIdx(inComment.getAuthor()));
commentTag.addSubtag(new SsmlCommentText(getParentDoc(), inComment.getText()));
mCommentListTag.addSubtag(commentTag);
return this;
}
//---------------------------------------------------------------------------
private int getAuthorIdx(String inAuthor)
{
if (null == mAuthorMap)
{
mAuthorMap = new HashMap(10);
mAuthorsTag = new XMLTag(SsmlXML.AUTHORS);
mCommentsTag.addSubtag(mAuthorsTag);
}
Integer index = mAuthorMap.get(inAuthor);
if (null == index)
{
// New author
index = mAuthorMap.size();
mAuthorMap.put(inAuthor, index);
mAuthorsTag.addSubtag(new XMLTag(SsmlXML.AUTHOR).setContent(inAuthor));
}
return index;
}
private class SsmlComments extends SsmlXMLTag
{
//---------------------------------------------------------------------------
public SsmlComments(Xlsx inXlsx)
{
super(SsmlXML.COMMENTS, inXlsx);
}
}
private class SsmlComment extends SsmlXMLTag
{
//---------------------------------------------------------------------------
public SsmlComment(Xlsx inXlsx)
{
super(SsmlXML.COMMENT, inXlsx);
}
}
private class SsmlCommentText extends SsmlXMLTag
{
//---------------------------------------------------------------------------
public SsmlCommentText(Xlsx inXlsx, SsmlXMLTag inTextTag)
{
super(SsmlXML.COMMENT_TEXT, inXlsx);
addSubtag(inTextTag);
}
}
}