String resolvedPartUri = part.getPartName().getName().substring(1); if (part.getRelationshipsPart()!= null && part.getRelationshipsPart().getJaxbElement()!=null && part.getRelationshipsPart().getJaxbElement().getRelationship()!=null && part.getRelationshipsPart().getJaxbElement().getRelationship().size()>0) { RelationshipsPart rrp = part.getRelationshipsPart(); log.debug("Found relationships " + rrp.getPartName() ); String relPart = PartName.getRelationshipsPartName(resolvedPartUri);
if (source.setPartShortcut(part, relationshipType ) ) { log.debug("Convenience method established from " + source.getPartName() + " to " + part.getPartName()); part.getSourceRelationships().add(r); + " to " + part.getPartName()); || part instanceof DefaultXmlPart) { part.setRelationshipType(relationshipType);
/** * Create a notes slide and add it to slide relationships * * @param sourcePart * @param partName * @return the notes slide * @throws InvalidFormatException * @throws JAXBException */ public static NotesSlidePart createNotesSlidePart(Part sourcePart, PartName partName) throws Exception { String proposedRelId = sourcePart.getRelationshipsPart().getNextId(); NotesSlidePart notesSlidePart = new NotesSlidePart(partName); notesSlidePart.getSourceRelationships().add(sourcePart.addTargetPart(notesSlidePart, proposedRelId)); notesSlidePart.setJaxbElement(NotesSlidePart.createNotes()); return notesSlidePart; }
protected static Part copyPart(Part part, OpcPackage targetPackage, boolean deepCopy) throws Docx4JException { Part ret = null; try { ret = part.getClass().getConstructor(PartName.class).newInstance(part.getPartName()); } catch (Exception e) { throw new Docx4JException("Error cloning part of class " + part.getClass().getName(), e); } ret.setRelationshipType(part.getRelationshipType()); ret.setContentType(new ContentType(part.getContentType())); if (targetPackage != null) { ret.setPackage(targetPackage); } if (deepCopy) { deepCopyContent(part, ret); } else { shallowCopyContent(part, ret); } return ret; }
for (Relationship r : getSourceRelationships()) { log.warn("source rel of " + this.getPartName().getName() + " has no parent rels element"); log.warn("source rel of " + this.getPartName().getName() + " not present in parent rels element"); if (this.getPackage()==null) { log.warn(this.getPartName().getName() + " not attached to any package"); } else { this.getPackage().getParts().remove(getPartName());
protected static Part deepCopyPart(OpcPackage opcPackage, Base targetParent, Part sourcePart, Set<String> relationshipTypes) throws Docx4JException { //check if already handled Part ret = opcPackage.getParts().get(sourcePart.getPartName()); if (ret == null) { // ret = copyPart(sourcePart, opcPackage, ((relationshipTypes == null) || relationshipTypes.contains(sourcePart.getRelationshipType())) ); opcPackage.getParts().put(ret); targetParent.setPartShortcut(ret, ret.getRelationshipType()); } return ret; }
parentPart.setRelationships(null); } else { removedParts.addAll( parentPart.getRelationshipsPart().removePart( new PartName(xmlpart.getName())) ); newRP = parentPart.getRelationshipsPart(true); newRP = parentPart.getRelationshipsPart(true); newPart.setOwningRelationshipPart(parentPart.getRelationshipsPart()); newPart.getSourceRelationships().add( parentPart.getRelationshipsPart().getRel(new PartName(a.getPart().getName()))); otherPackage.getParts().put(newPart); newPart.setPackage( otherPackage );
PartName partName = part.getPartName(); log.debug("Loading part " + partName.getName() ); part.setOwningRelationshipPart(this); part.getSourceRelationships().add(sourceRelationship); part.setPackage( getPackage() );
public void put(Part part) { if (get(part.getPartName()) != null) { log.info("Overwriting existing part " + part.getPartName()); } else { log.debug("put part " + part.getPartName()); } parts.put(part.getPartName(), part); }
protected void handleImageRel(ConversionImageHandler imageHandler, String imgRelId, Part sourcePart) { Relationship rel = sourcePart.getRelationshipsPart().getRelationshipByID(imgRelId); Part part = null; String uri = null; boolean ignoreImage = false; setID(imgRelId); part = sourcePart.getRelationshipsPart().getPart(rel); /* a part == null is ok if it is an external image, * and hasn't been loaded (loadExternalTargets == false) * but the relationship can be external, * but the part avaiable (loadExternalTargets == true) */ if ((part != null) && (!(part instanceof BinaryPart))) { log.error("Invalid part type id: " + imgRelId + ", class = " + part.getClass().getName()); ignoreImage = true; } if (!ignoreImage) { uri = handlePart(imageHandler, this, rel, (BinaryPart)part); if (uri != null) { this.setSrc(uri); } } }
for (Relationship relationship : part.getSourceRelationships()) { if (relationship.getType().endsWith("worksheet")) { String sheetId = relationship.getId(); if (part.getRelationshipsPart() != null) { traverse(part, part.getRelationshipsPart());
log.info("Renaming part " + this.getPartName().getName() + " to " + newName.getName() ); this.getPackage().getParts().remove(this.getPartName() ); URI relativizeAgainst = this.getOwningRelationshipPart().getSourceURI(); log.debug("Relativising target " + tobeRelativized + " against source " + relativizeAgainst); this.setPartName(newName); this.getPackage().getParts().put(this);
public static void printInfo(String parentName, Relationship r, Part p, StringBuilder sb, String indent) { if (p.getSourceRelationships().size()>0 ) { relationshipType = p.getSourceRelationships().get(0).getType(); sb.append("\n" + indent + "Part " + p.getPartName() + " [" + p.getClass().getName() + "] " + relationshipType ); } else { sb.append("\n" + indent + parentName + "'s " + r.getId() + " is " + p.getPartName() + " [" + p.getClass().getName() + "] " + relationshipType );
PartName newPartName = part.getPartName(); log.info("adding part with proposed name: " + newPartName.getName()); String proposedName = part.getPartName().getName(); log.debug("Detected duplicate partname: " + proposedName ); if (proposedName.indexOf(".")>0) { "." + part.getPartName().getExtension(), this.getPackage().getParts().getParts() ); } else { part.setPartName(newPartName); // access directly log.debug(".. renamed to " + newPartName ); URI tobeRelativized = part.getPartName().getURI(); URI relativizeAgainst = sourceP.getPartName().getURI(); existsAlready.setType( part.getRelationshipType() ); rel.setType( part.getRelationshipType() ); String ext = part.getPartName().getExtension(); if ( part.getContentType().equals( ContentTypes.IMAGE_JPEG) ) { ctm.addDefaultContentType(ext,ContentTypes.IMAGE_JPEG ); } else if ( part.getContentType().equals( ContentTypes.EXTENSION_GIF ) ) { ctm.addDefaultContentType(ext, ContentTypes.EXTENSION_GIF); } else if ( part.getContentType().equals( ContentTypes.EXTENSION_PNG ) ) { ctm.addDefaultContentType(ext, ContentTypes.IMAGE_PNG);
public static org.docx4j.xmlPackage.Part createRawBinaryPart(Part part) throws Docx4JException { String resolvedPartUri = part.getPartName().getName(); // Don't drop leading "/" for XmlPackage representation. // It is needed if Word is to consume the result. //String resolvedPartUri = part.getPartName().getName().substring(1); org.docx4j.xmlPackage.Part partResult = factory.createPart(); partResult.setName(resolvedPartUri); partResult.setContentType( part.getContentType() ); try { partResult.setCompression("store"); partResult.setBinaryData( ((BinaryPart)part).getBytes() ); } catch (Exception e ) { throw new Docx4JException("Failed to put binary part", e); } log.debug( "PUT SUCCESS: " + resolvedPartUri); return partResult; }
part.getPartName().getName().substring(1) ); part.setRelationships(rrp); } else { log.debug("No relationships " + relPart );
"docx4j " + Version.getDocx4jVersion()); if (cp.getCreator()==null && part.getPackage().isNew() ) { org.docx4j.docProps.core.dc.elements.ObjectFactory of = new org.docx4j.docProps.core.dc.elements.ObjectFactory(); cp.setCreator(of.createSimpleLiteral() ); log.error("PROBLEM - No suitable part found for: " + part.getPartName()); e.printStackTrace(); log.error(e.getMessage(), e); throw new Docx4JException("Problem saving part " + part.getPartName(), e);
part.setContentType( new ContentType(contentType) ); log.debug(o.getClass().getName()); PartName name = part.getPartName();
@Override public Object getValueAt(int row, int column) { Part part = getRow(row); // Gets the part in question switch(column) { case 0: return part.getPartName(part); // lowercase "part" case 1: return part.getMake(); // lowercase "part" case 2: return part.getPartNumber(); // lowercase "part" //... do you see what I'm trying to do here? // continue to do this for all your other "Part.whateverMethod("
protected String addPropertiesPart(WordprocessingMLPackage pkgOut, Part customXmlDataStoragePart, String ns) throws InvalidFormatException { CustomXmlDataStoragePropertiesPart part = new CustomXmlDataStoragePropertiesPart(); org.docx4j.customXmlProperties.ObjectFactory of = new org.docx4j.customXmlProperties.ObjectFactory(); DatastoreItem dsi = of.createDatastoreItem(); String newItemId = "{" + UUID.randomUUID().toString().toUpperCase() + "}"; dsi.setItemID(newItemId); if (ns!=null) { SchemaRefs srefs = of.createSchemaRefs(); dsi.setSchemaRefs(srefs); SchemaRef sref = of.createSchemaRefsSchemaRef(); sref.setUri(ns); srefs.getSchemaRef().add(sref); } part.setJaxbElement(dsi); customXmlDataStoragePart.addTargetPart(part, AddPartBehaviour.RENAME_IF_NAME_EXISTS); pkgOut.getCustomXmlDataStorageParts().put(newItemId.toLowerCase(), (CustomXmlPart)customXmlDataStoragePart); return newItemId; }