Hi, we tried to load some stencils in Visio 2013 format, but got a NullpointerException. sadly we cannot find out what happened, since we do not have the sources for your library.
Here is the code - necessary ressources are attached:
package test.visio.aspose;
import com.aspose.diagram.;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import static org.junit.Assert.;
public class AsposeExportTest
{
private Diagram diagram;
private Page drawingPage;
private int shapeCount = 0;
@Before
public void prepare() throws Exception
{
createDocument(getClass().getResourceAsStream(“template.vtx”), 210, 297, “test”);
}
protected void createDocument(final InputStream templateFileStream,
final int width, final int height, final String configName)
throws Exception
{
diagram = new Diagram(templateFileStream);
final DocumentProperties dProps = diagram.getDocumentProps();
dProps.setCreator(replaceSpecialChars(System.getProperty(“user.name”)));
dProps.setTimeCreated(new DateTime(new Date()));
dProps.setSubject(configName);
XForm xform = diagram.getPages().get(0).getPageSheet().getXForm();
xform.getWidth().setValue(width);
xform.getHeight().setValue(height);
xform = diagram.getPages().get(1).getPageSheet().getXForm();
xform.getWidth().setValue(width);
xform.getHeight().setValue(height);
for (int i = 0; i < diagram.getPages().getCount(); i++)
{
final Page page = diagram.getPages().get(i);
if (page.getBackground() == 1)
{
continue;
}
drawingPage = page;
break;
}
if (drawingPage == null)
{
throw new IllegalArgumentException(“No drawing page available in template” );
}
}
public void load2010Masters() throws Exception
{
initMasters(getClass().getResourceAsStream(“Miscellaneous_2010.vsx”));
}
public void load2013Masters() throws Exception
{
initMasters(getClass().getResourceAsStream(“Miscellaneous_2013.vsx”));
}
protected void initMasters( final InputStream stencil ) throws Exception {
final Diagram stencilDiagram = new Diagram( stencil );
final Iterator iterator = stencilDiagram.getMasters().iterator();
while( iterator.hasNext() ) {
final Master master = iterator.next();
if(“Theme Effects”.equals(master.getName())) {
diagram.getMasters().remove( master );
}
else {
master.setID(getNextId());
diagram.getMasters().add(master);
}
}
}
private int getNextId()
{
return shapeCount++;
}
public String replaceSpecialChars(final String string) {
return string.replaceAll( “<”, “" ).replaceAll( “>”, "” ).replaceAll( “&”, “" ).replaceAll( “”", "” ).replaceAll( “’”, “_” );
}
}
Best regards
Gerald Koch