diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2015-10-04 00:35:30 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2015-10-04 00:35:30 +0000 |
commit | 012cfb107cc9b72f962085c284467a8907f48794 (patch) | |
tree | df90bbeaf051cb2bc68bf3410ce0b9b6b99275e3 /src/ooxml/java | |
parent | 6d5e89298648e480c29747ba878cc0ea35f263a3 (diff) | |
download | poi-012cfb107cc9b72f962085c284467a8907f48794.tar.gz poi-012cfb107cc9b72f962085c284467a8907f48794.zip |
sonar fixes
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1706648 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml/java')
-rw-r--r-- | src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java | 12 | ||||
-rw-r--r-- | src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideShow.java | 124 |
2 files changed, 66 insertions, 70 deletions
diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java index 26331fbccf..1d957e5a59 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java @@ -559,20 +559,18 @@ public final class PackagePropertiesPart extends PackagePart implements * @throws InvalidFormatException * Throws if the date format isnot valid. */ - private Nullable<Date> setDateValue(String s) throws InvalidFormatException { - if (s == null || s.equals("")) { + private Nullable<Date> setDateValue(String dateStr) throws InvalidFormatException { + if (dateStr == null || dateStr.equals("")) { return new Nullable<Date>(); } - if (!s.endsWith("Z")) { - s += "Z"; - } + String dateTzStr = dateStr.endsWith("Z") ? dateStr : (dateStr + "Z"); SimpleDateFormat df = new SimpleDateFormat(DEFAULT_DATEFORMAT, Locale.ROOT); df.setTimeZone(LocaleUtil.TIMEZONE_UTC); - Date d = df.parse(s, new ParsePosition(0)); + Date d = df.parse(dateTzStr, new ParsePosition(0)); if (d == null) { df = new SimpleDateFormat(ALTERNATIVE_DATEFORMAT, Locale.ROOT); df.setTimeZone(LocaleUtil.TIMEZONE_UTC); - d = df.parse(s, new ParsePosition(0)); + d = df.parse(dateTzStr, new ParsePosition(0)); } if (d == null) { throw new InvalidFormatException("Date not well formated"); diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideShow.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideShow.java index 6d17cbb4c7..79a5bd6d75 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideShow.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideShow.java @@ -6,7 +6,7 @@ (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, @@ -46,90 +46,90 @@ import org.openxmlformats.schemas.presentationml.x2006.main.SldMasterDocument; /** * Experimental class to do low level processing of pptx files. - * + * * Most users should use the higher level {@link XMLSlideShow} instead. - * + * * If you are using these low level classes, then you * will almost certainly need to refer to the OOXML * specifications from * http://www.ecma-international.org/publications/standards/Ecma-376.htm - * + * * WARNING - APIs expected to change rapidly */ public class XSLFSlideShow extends POIXMLDocument { private PresentationDocument presentationDoc; - /** - * The embedded OLE2 files in the OPC package - */ - private List<PackagePart> embedds; + /** + * The embedded OLE2 files in the OPC package + */ + private List<PackagePart> embedds; - @SuppressWarnings("deprecation") + @SuppressWarnings("deprecation") public XSLFSlideShow(OPCPackage container) throws OpenXML4JException, IOException, XmlException { super(container); - + if(getCorePart().getContentType().equals(XSLFRelation.THEME_MANAGER.getContentType())) { - rebase(getPackage()); + rebase(getPackage()); } - + presentationDoc = PresentationDocument.Factory.parse(getCorePart().getInputStream()); - - embedds = new LinkedList<PackagePart>(); - for (CTSlideIdListEntry ctSlide : getSlideReferences().getSldIdArray()) { - PackagePart corePart = getCorePart(); - PackagePart slidePart = corePart.getRelatedPart( - corePart.getRelationship(ctSlide.getId2())); - for(PackageRelationship rel : slidePart.getRelationshipsByType(OLE_OBJECT_REL_TYPE)) - embedds.add(slidePart.getRelatedPart(rel)); // TODO: Add this reference to each slide as well + embedds = new LinkedList<PackagePart>(); + for (CTSlideIdListEntry ctSlide : getSlideReferences().getSldIdArray()) { + PackagePart corePart = getCorePart(); + PackagePart slidePart = corePart.getRelatedPart(corePart.getRelationship(ctSlide.getId2())); + + for(PackageRelationship rel : slidePart.getRelationshipsByType(OLE_OBJECT_REL_TYPE)) { + // TODO: Add this reference to each slide as well + embedds.add(slidePart.getRelatedPart(rel)); + } - for(PackageRelationship rel : slidePart.getRelationshipsByType(PACK_OBJECT_REL_TYPE)) - embedds.add(slidePart.getRelatedPart(rel)); + for (PackageRelationship rel : slidePart.getRelationshipsByType(PACK_OBJECT_REL_TYPE)) { + embedds.add(slidePart.getRelatedPart(rel)); + } } } public XSLFSlideShow(String file) throws OpenXML4JException, IOException, XmlException { this(openPackage(file)); } - + /** * Returns the low level presentation base object */ - @Internal + @Internal public CTPresentation getPresentation() { return presentationDoc.getPresentation(); } - + /** * Returns the references from the presentation to its * slides. * You'll need these to figure out the slide ordering, * and to get at the actual slides themselves */ - @Internal + @Internal public CTSlideIdList getSlideReferences() { - if(! getPresentation().isSetSldIdLst()) { - getPresentation().setSldIdLst( - CTSlideIdList.Factory.newInstance() - ); - } - return getPresentation().getSldIdLst(); + if(! getPresentation().isSetSldIdLst()) { + getPresentation().setSldIdLst(CTSlideIdList.Factory.newInstance()); + } + return getPresentation().getSldIdLst(); } - + /** * Returns the references from the presentation to its * slide masters. - * You'll need these to get at the actual slide + * You'll need these to get at the actual slide * masters themselves */ - @Internal + @Internal public CTSlideMasterIdList getSlideMasterReferences() { return getPresentation().getSldMasterIdLst(); } - + public PackagePart getSlideMasterPart(CTSlideMasterIdListEntry master) throws IOException, XmlException { try { - PackagePart corePart = getCorePart(); + PackagePart corePart = getCorePart(); return corePart.getRelatedPart( corePart.getRelationship(master.getId2()) ); @@ -141,7 +141,7 @@ public class XSLFSlideShow extends POIXMLDocument { * Returns the low level slide master object from * the supplied slide master reference */ - @Internal + @Internal public CTSlideMaster getSlideMaster(CTSlideMasterIdListEntry master) throws IOException, XmlException { PackagePart masterPart = getSlideMasterPart(master); SldMasterDocument masterDoc = @@ -151,10 +151,8 @@ public class XSLFSlideShow extends POIXMLDocument { public PackagePart getSlidePart(CTSlideIdListEntry slide) throws IOException, XmlException { try { - PackagePart corePart = getCorePart(); - return corePart.getRelatedPart( - corePart.getRelationship(slide.getId2()) - ); + PackagePart corePart = getCorePart(); + return corePart.getRelatedPart(corePart.getRelationship(slide.getId2())); } catch(InvalidFormatException e) { throw new XmlException(e); } @@ -163,7 +161,7 @@ public class XSLFSlideShow extends POIXMLDocument { * Returns the low level slide object from * the supplied slide reference */ - @Internal + @Internal public CTSlide getSlide(CTSlideIdListEntry slide) throws IOException, XmlException { PackagePart slidePart = getSlidePart(slide); SldDocument slideDoc = @@ -178,13 +176,13 @@ public class XSLFSlideShow extends POIXMLDocument { public PackagePart getNodesPart(CTSlideIdListEntry parentSlide) throws IOException, XmlException { PackageRelationshipCollection notes; PackagePart slidePart = getSlidePart(parentSlide); - + try { notes = slidePart.getRelationshipsByType(XSLFRelation.NOTES.getRelation()); } catch(InvalidFormatException e) { throw new IllegalStateException(e); } - + if(notes.size() == 0) { // No notes for this slide return null; @@ -192,9 +190,9 @@ public class XSLFSlideShow extends POIXMLDocument { if(notes.size() > 1) { throw new IllegalStateException("Expecting 0 or 1 notes for a slide, but found " + notes.size()); } - + try { - return slidePart.getRelatedPart(notes.getRelationship(0)); + return slidePart.getRelatedPart(notes.getRelationship(0)); } catch(InvalidFormatException e) { throw new IllegalStateException(e); } @@ -203,32 +201,32 @@ public class XSLFSlideShow extends POIXMLDocument { * Returns the low level notes object for the given * slide, as found from the supplied slide reference */ - @Internal + @Internal public CTNotesSlide getNotes(CTSlideIdListEntry slide) throws IOException, XmlException { PackagePart notesPart = getNodesPart(slide); if(notesPart == null) return null; - + NotesDocument notesDoc = NotesDocument.Factory.parse(notesPart.getInputStream()); - + return notesDoc.getNotes(); } - + /** * Returns all the comments for the given slide */ - @Internal + @Internal public CTCommentList getSlideComments(CTSlideIdListEntry slide) throws IOException, XmlException { PackageRelationshipCollection commentRels; PackagePart slidePart = getSlidePart(slide); - + try { commentRels = slidePart.getRelationshipsByType(XSLFRelation.COMMENTS.getRelation()); } catch(InvalidFormatException e) { throw new IllegalStateException(e); } - + if(commentRels.size() == 0) { // No comments for this slide return null; @@ -236,12 +234,12 @@ public class XSLFSlideShow extends POIXMLDocument { if(commentRels.size() > 1) { throw new IllegalStateException("Expecting 0 or 1 comments for a slide, but found " + commentRels.size()); } - + try { PackagePart cPart = slidePart.getRelatedPart( commentRels.getRelationship(0) ); - CmLstDocument commDoc = + CmLstDocument commDoc = CmLstDocument.Factory.parse(cPart.getInputStream()); return commDoc.getCmLst(); } catch(InvalidFormatException e) { @@ -249,12 +247,12 @@ public class XSLFSlideShow extends POIXMLDocument { } } - /** - * Get the document's embedded files. - */ - @Override - public List<PackagePart> getAllEmbedds() throws OpenXML4JException { - return embedds; - } + /** + * Get the document's embedded files. + */ + @Override + public List<PackagePart> getAllEmbedds() throws OpenXML4JException { + return embedds; + } } |