* @see org.apache.poi.openxml4j.opc.RelationshipSource#isRelationshipExists(org.apache.poi.openxml4j.opc.PackageRelationship)
*/
public boolean isRelationshipExists(PackageRelationship rel) {
- return _relationships.getRelationshipByID(rel.getId()) != null;
+ return rel != null && _relationships.getRelationshipByID(rel.getId()) != null;
}
/**
* The relationship to add.
*/
public void addRelationship(PackageRelationship relPart) {
+ if (relPart == null || relPart.getId() == null || relPart.getId().isEmpty()) {
+ throw new IllegalArgumentException("invalid relationship part/id");
+ }
relationshipsByID.put(relPart.getId(), relPart);
relationshipsByType.put(relPart.getRelationshipType(), relPart);
}
PackageRelationship rel = new PackageRelationship(container,
sourcePart, targetUri, targetMode, relationshipType, id);
- relationshipsByID.put(rel.getId(), rel);
- relationshipsByType.put(rel.getRelationshipType(), rel);
+ addRelationship(rel);
if (targetMode == TargetMode.INTERNAL){
internalRelationshipsByTargetName.put(targetUri.toASCIIString(), rel);
}
@Override
public String getAddress() {
- String id = _link.getId();
+ final String id = _link.getId();
if (id == null || id.isEmpty()) {
return _link.getAction();
}
- URI targetURI = _sheet.getPackagePart().getRelationship(id).getTargetURI();
-
- return targetURI.toASCIIString();
+ final PackageRelationship rel = _sheet.getPackagePart().getRelationship(id);
+ if (rel == null) {
+ return null;
+ }
+
+ final URI targetURI = rel.getTargetURI();
+ return (targetURI == null) ? null : targetURI.toASCIIString();
}
@Override
import org.apache.poi.sl.usermodel.PictureShape;
import org.apache.poi.sl.usermodel.Placeholder;
import org.apache.poi.util.Beta;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
@Beta
public class XSLFPictureShape extends XSLFSimpleShape
implements PictureShape<XSLFShape,XSLFTextParagraph> {
+ private static final POILogger LOG = POILogFactory.getLogger(XSLFPictureShape.class);
+
private XSLFPictureData _data;
/*package*/ XSLFPictureShape(CTPicture shape, XSLFSheet sheet) {
XSLFPictureShape p = (XSLFPictureShape)sh;
String blipId = p.getBlipId();
+ if (blipId == null) {
+ LOG.log(POILogger.WARN, "unable to copy invalid picture shape");
+ return;
+ }
+
String relId = getSheet().importBlip(blipId, p.getSheet().getPackagePart());
CTPicture ct = (CTPicture)getXmlObject();
PackagePart blipPart;
try {
blipPart = packagePart.getRelatedPart(blipRel);
- } catch (InvalidFormatException e){
+ } catch (Exception e){
throw new POIXMLException(e);
}
XSLFPictureData data = new XSLFPictureData(blipPart);
import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint;
import org.apache.poi.sl.usermodel.TextRun;
import org.apache.poi.util.Beta;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
import org.apache.poi.xslf.model.CharacterPropertyFetcher;
import org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties;
import org.apache.xmlbeans.XmlObject;
import org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor;
import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle;
import org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBodyProperties;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextField;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextFont;
*/
@Beta
public class XSLFTextRun implements TextRun {
+ private static final POILogger LOG = POILogFactory.getLogger(XSLFTextRun.class);
+
private final XmlObject _r;
private final XSLFTextParagraph _p;
@Override
public void setFontColor(PaintStyle color) {
if (!(color instanceof SolidPaint)) {
- throw new IllegalArgumentException("Currently only SolidPaint is supported!");
+ LOG.log(POILogger.WARN, "Currently only SolidPaint is supported!");
+ return;
}
SolidPaint sp = (SolidPaint)color;
Color c = DrawPaint.applyColorTransform(sp.getSolidColor());
@Override
public Double getFontSize(){
double scale = 1;
- CTTextNormalAutofit afit = getParentParagraph().getParentShape().getTextBodyPr().getNormAutofit();
- if(afit != null) {
- scale = (double)afit.getFontScale() / 100000;
+ final XSLFTextShape ps = getParentParagraph().getParentShape();
+ if (ps != null) {
+ final CTTextBodyProperties tbp = ps.getTextBodyPr();
+ if (tbp != null) {
+ CTTextNormalAutofit afit = tbp.getNormAutofit();
+ if (afit != null && afit.isSetFontScale()) {
+ scale = afit.getFontScale() / 100000.;
+ }
+ }
}
- CharacterPropertyFetcher<Double> fetcher = new CharacterPropertyFetcher<Double>(_p.getIndentLevel()){
+ final CharacterPropertyFetcher<Double> fetcher = new CharacterPropertyFetcher<Double>(_p.getIndentLevel()){
@Override
public boolean fetch(CTTextCharacterProperties props){
if (props != null && props.isSetSz()) {