Skip to content

Commit

Permalink
misc trivial
Browse files Browse the repository at this point in the history
  • Loading branch information
plutext committed Jul 31, 2014
1 parent 849ba4e commit 4df7490
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 10 deletions.
Expand Up @@ -218,7 +218,7 @@ public void setStyles(Styles newStyles) {
// cellPStyles = new HashSet<String>();

for (Style s : newStyles.getStyle()) {
System.out.println(s.getStyleId());
// System.out.println(s.getStyleId());
allStyles.put(s.getStyleId(), s);
}
}
Expand Down Expand Up @@ -303,7 +303,7 @@ private String getCellPStyle(String styleVal, boolean pStyleIsDefault) {
Style basedOn = null;
String currentStyle = styleVal;
do {
System.out.println("Getting " + currentStyle);
// System.out.println("Getting " + currentStyle);
Style thisStyle = allStyles.get(currentStyle);
hierarchy.add(thisStyle);
if (thisStyle.getBasedOn()!=null) {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/docx4j/openpackaging/io3/Load3.java
Expand Up @@ -335,6 +335,10 @@ private void getPart(OpcPackage pkg, RelationshipsPart rp,
part.setRelationshipType(relationshipType);
}
rp.loadPart(part, r);
// That loads a pre-existing target part into the package
// (but does not load its contents as such; that is
// done elsewhere).

pkg.handled.put(resolvedPartUri, resolvedPartUri);


Expand Down Expand Up @@ -431,6 +435,9 @@ public Part getRawPart(
} else if (part instanceof org.docx4j.openpackaging.parts.WordprocessingML.BinaryPart) {

log.debug("Detected BinaryPart " + part.getClass().getName() );

// Note that this is done lazily, since the below lines are commented out

// is = partStore.loadPart( resolvedPartUri);
// ((BinaryPart)part).setBinaryData(is);

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/docx4j/openpackaging/parts/JaxbXmlPart.java
Expand Up @@ -118,6 +118,14 @@ public E getContents() throws Docx4JException {
InputStream is = null;
if (jaxbElement==null) {
PartStore partStore = this.getPackage().getSourcePartStore();
if (partStore==null) {
log.warn("No PartStore defined for this package (it was probably created, not loaded). " );
log.warn(partName.getName() + ": did you initialise its contents to something?");
return null;
// or we could create it, with a bit of effort;
// as to which see http://stackoverflow.com/questions/1090458/instantiating-a-generic-class-in-java
}

try {
String name = this.partName.getName();

Expand Down
Expand Up @@ -356,7 +356,9 @@ public void resetIdAllocator() {
// ----------------------------------------------------------

/**
* Loads a pre-existing target part.
* Loads a pre-existing target part into the package
* (but does not load its contents as such; that is
* done elsewhere).
*
* The target part is assumed to be specified already in this
* relationship part.
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/org/docx4j/samples/PartsList.java
Expand Up @@ -26,11 +26,8 @@

import javax.xml.bind.JAXBElement;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.docx4j.XmlUtils;
import org.docx4j.openpackaging.contenttype.ContentTypeManager;
import org.docx4j.openpackaging.exceptions.Docx4JException;
import org.docx4j.openpackaging.packages.OpcPackage;
import org.docx4j.openpackaging.parts.DefaultXmlPart;
import org.docx4j.openpackaging.parts.JaxbXmlPart;
Expand All @@ -39,6 +36,8 @@
import org.docx4j.openpackaging.parts.WordprocessingML.VbaDataPart;
import org.docx4j.openpackaging.parts.relationships.RelationshipsPart;
import org.docx4j.relationships.Relationship;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class PartsList extends AbstractSample {
Expand Down Expand Up @@ -75,6 +74,9 @@ public static void main(String[] args) throws Exception {

System.out.println(sb.toString());

// opcPackage.save( new File(System.getProperty("user.dir") + "/OUT_chart_drawing.xlsx"));


}

/**
Expand All @@ -100,13 +102,13 @@ public static void printInfo(Part p, StringBuilder sb, String indent) {
// System.out.println("//" + p.getPartName() );
// System.out.println("public final static String XX =");
// System.out.println("\"" + relationshipType + "\";");

if (p instanceof JaxbXmlPart) {
Object o = ((JaxbXmlPart)p).getJaxbElement();
if (o instanceof javax.xml.bind.JAXBElement) {
sb.append(" containing JaxbElement:" + XmlUtils.JAXBElementDebug((JAXBElement)o) );
} else {
sb.append(" containing JaxbElement:" + o.getClass().getName() );
sb.append(" containing:" + o.getClass().getName() );
}
} else if (p instanceof DefaultXmlPart) {
try {
Expand All @@ -115,7 +117,7 @@ public static void printInfo(Part p, StringBuilder sb, String indent) {
if (o instanceof javax.xml.bind.JAXBElement) {
sb.append(" containing JaxbElement:" + XmlUtils.JAXBElementDebug((JAXBElement)o) );
} else {
sb.append(" containing JaxbElement:" + o.getClass().getName() );
sb.append(" containing:" + o.getClass().getName() );
}
} catch (Exception e) {
// TODO Auto-generated catch block
Expand Down
Expand Up @@ -70,7 +70,7 @@ public static void main(String[] args) throws Exception {

// Create and add shape
Shape sample = ((Shape)XmlUtils.unmarshalString(SAMPLE_SHAPE, Context.jcPML) );
slidePart.getJaxbElement().getCSld().getSpTree().getSpOrGrpSpOrGraphicFrame().add(sample);
slidePart.getContents().getCSld().getSpTree().getSpOrGrpSpOrGraphicFrame().add(sample);

// All done: save it
presentationMLPackage.save(new java.io.File(outputfilepath));
Expand Down

0 comments on commit 4df7490

Please sign in to comment.