org.docx4j.openpackaging.parts.PresentationML.JaxbPmlPart Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of docx4j Show documentation
Show all versions of docx4j Show documentation
docx4j is a library which helps you to work with the Office Open
XML file format as used in docx
documents, pptx presentations, and xlsx spreadsheets.
/*
* Copyright 2007-2008, Plutext Pty Ltd.
*
* This file is part of docx4j.
docx4j is licensed under the Apache License, Version 2.0 (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
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.docx4j.openpackaging.parts.PresentationML;
import java.util.Random;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import org.pptx4j.jaxb.Context;
import org.docx4j.openpackaging.contenttype.ContentTypes;
import org.docx4j.openpackaging.exceptions.InvalidFormatException;
import org.docx4j.openpackaging.exceptions.PartUnrecognisedException;
import org.docx4j.openpackaging.parts.JaxbXmlPart;
import org.docx4j.openpackaging.parts.Part;
import org.docx4j.openpackaging.parts.PartName;
public abstract class JaxbPmlPart extends JaxbXmlPart {
public final static String COMMON_SLIDE_DATA =
""
+ ""
+ ""
+ ""
+ " "
+ " "
+ " "
+ ""
+ ""
+ ""
+ ""
+ ""
+ ""
+ " "
+ " "
+ " "
+ " ";
protected final static String COLOR_MAPPING = "";
protected static Random random = new Random();
public static long getSlideLayoutOrMasterId() {
// See spec 4.8.18 (ST_SlideLayoutId) and 4.8.20 (ST_SlideMasterId)
long val = random.nextInt(2147483647) + 2147483648l;
return val;
}
protected long getSlideId() {
// See spec 4.8.17 (ST_SlideId)
long val = random.nextInt(2147483392) + 256;
return val;
}
public JaxbPmlPart(PartName partName) throws InvalidFormatException {
super(partName);
setJAXBContext(Context.jcPML);
}
public JaxbPmlPart() throws InvalidFormatException {
super(new PartName("/ppt/presentation.xml"));
setJAXBContext(Context.jcPML);
}
public static Part newPartForContentType(String contentType, String partName)
throws InvalidFormatException, PartUnrecognisedException {
if (contentType.equals(ContentTypes.PRESENTATIONML_MAIN)
|| contentType.equals(ContentTypes.PRESENTATIONML_TEMPLATE) ) {
return new MainPresentationPart(new PartName(partName));
} else if (contentType.equals(ContentTypes.PRESENTATIONML_SLIDE)) {
return new SlidePart(new PartName(partName));
} else if (contentType.equals(ContentTypes.PRESENTATIONML_SLIDE_MASTER)) {
return new SlideMasterPart(new PartName(partName));
} else if (contentType.equals(ContentTypes.PRESENTATIONML_SLIDE_LAYOUT)) {
return new SlideLayoutPart(new PartName(partName));
} else if (contentType.equals(ContentTypes.PRESENTATIONML_TABLE_STYLES)) {
return new TableStylesPart(new PartName(partName));
} else if (contentType.equals(ContentTypes.PRESENTATIONML_PRES_PROPS)) {
return new PresentationPropertiesPart(new PartName(partName));
} else if (contentType.equals(ContentTypes.PRESENTATIONML_VIEW_PROPS)) {
return new ViewPropertiesPart(new PartName(partName));
} else if (contentType.equals(ContentTypes.PRESENTATIONML_TAGS)) {
return new TagsPart(new PartName(partName));
} else if (contentType.equals(ContentTypes.PRESENTATIONML_HANDOUT_MASTER)) {
return new HandoutMasterPart(new PartName(partName));
} else if (contentType.equals(ContentTypes.PRESENTATIONML_NOTES_MASTER)) {
return new NotesMasterPart(new PartName(partName));
} else if (contentType.equals(ContentTypes.PRESENTATIONML_NOTES_SLIDE)) {
return new NotesSlidePart(new PartName(partName));
} else {
throw new PartUnrecognisedException("No subclass found for "
+ partName + " (content type '" + contentType + "')");
}
}
// public E unmarshal( java.io.InputStream is ) throws JAXBException {
//
// try {
// setJAXBContext(Context.jcPML);
//
// Unmarshaller u = jc.createUnmarshaller();
// u.setEventHandler(new org.docx4j.jaxb.JaxbValidationEventHandler());
//
// jaxbElement = (E)u.unmarshal( is );
// log.debug( this.getClass().getName() + " unmarshalled" );
//
// } catch (JAXBException e ) {
// log.error(e);
// throw e;
// }
// return jaxbElement;
// }
}