@Override public String toString() { return getName(); }
public static String generateUniqueName(Base sourcePart, String proposedRelId, String directoryPrefix, String after_, String ext) { // In order to ensure unique part name, // idea is to use the relId, which ought to be unique // Also need partName, since images for different parts are stored in a common dir String sourcepartName = sourcePart.getPartName().getName(); int beginIndex = sourcepartName.lastIndexOf("/")+1; int endIndex = sourcepartName.lastIndexOf("."); String partPrefix = sourcepartName.substring(beginIndex, endIndex); return directoryPrefix + partPrefix + "_" + after_ + "_" + proposedRelId + "." + ext; }
public void setContentType(ContentType contentType) { log.debug("\nSet contentType " + contentType + " on part " + this.getPartName().getName() +"\n\n"); this.contentType = contentType; }
public void saveRawXmlPart(ZipOutputStream out, Part part) throws Docx4JException { // This is a neater signature and should be used where possible! String partName = part.getPartName().getName().substring(1); saveRawXmlPart(out, part, partName); }
protected void saveRawBinaryPart(ZipOutputStream out, Part part) throws Docx4JException { // Drop the leading '/' String resolvedPartUri = part.getPartName().getName().substring(1); try { // Add ZIP entry to output stream. out.putNextEntry(new ZipEntry(resolvedPartUri)); out.write( ((BinaryPart)part).getBytes() ); // Complete the entry out.closeEntry(); } catch (Exception e ) { throw new Docx4JException("Failed to put binary part", e); } log.info( "success writing part: " + resolvedPartUri); }
public String getRelationshipType() { if (relationshipType == null ) { // 20091029, since we now have sourceRelationship, // there is little point in also have relationshipType, // except for a part which isn't yet connected to // a package via a relationship. if (this.sourceRelationships.size()==0) { log.warn(this.getPartName().getName() + " has no source rel set"); return null; } else { // It ought to be the same in each source rel return this.sourceRelationships.get(0).getType(); } } else { return relationshipType; } } public void setRelationshipType(String relationshipType) {
public void saveCustomXmlDataStoragePart(CustomXmlDataStoragePart part) throws Docx4JException { String targetName = part.getPartName().getName().substring(1); String filePath = dir.getPath() + dir.separator + targetName; File file = new File(filePath); file.getParentFile().mkdirs(); try { FileOutputStream fos = new FileOutputStream(file); part.getData().writeDocument( fos ); fos.close(); } catch (Exception e) { throw new Docx4JException("Error marshalling CustomXmlDataStoragePart " + part.getPartName(), e); } }
public void debug() { System.out.println("- Additions -------"); for (Alteration a : partsAdded) { System.out.println(a.getPart().getName() + " @ " + a.getSourcePartName().getName() ); } System.out.println("- Modifications -------"); for (Alteration a : partsModified) { System.out.println(a.getPart().getName() + " @ " + a.getSourcePartName().getName() ); } System.out.println("- Deletions -------"); for (Alteration a : partsDeleted) { System.out.println(a.getPart().getName() + " @ " + a.getSourcePartName().getName() ); } }
private void debugListParts(WordprocessingMLPackage pkg1) { // List the parts by walking the rels tree RelationshipsPart rp = pkg1.getRelationshipsPart(); StringBuilder sb = new StringBuilder(); PartsList.printInfo(rp.getPartName().getName(), null, rp, sb, ""); PartsList.traverseRelationships(pkg1, rp, sb, " "); System.out.println(sb.toString()); }
public void setDocument(InputStream is) throws Docx4JException { try { DocumentBuilder documentBuilder = XmlUtils.getNewDocumentBuilder(); doc = documentBuilder.parse(is); } catch (Exception e) { throw new Docx4JException("Problems parsing InputStream for part " + this.getPartName().getName(), e); } }
public static void handlePkg(OpcPackage opcPackage, boolean printContentTypes) { if (printContentTypes) printContentTypes(opcPackage); // List the parts by walking the rels tree RelationshipsPart rp = opcPackage.getRelationshipsPart(); StringBuilder sb = new StringBuilder(); printInfo(rp.getPartName().getName(), null, rp, sb, ""); traverseRelationships(opcPackage, rp, sb, " "); System.out.println(sb.toString()); // opcPackage.save( new File(System.getProperty("user.dir") + "/OUT_chart_drawing.xlsx")); }
public void scramble(JaxbXmlPart p) { log.info("\n\n Scrambling " + p.getPartName().getName()); new TraversalUtil(p.getJaxbElement(), latinizer); }
public void detectDmlVml(JaxbXmlPart p) { log.info("\n\n Inspecting " + p.getPartName().getName()); dmlVmlAnalyzer.reinit(); dmlVmlAnalyzer.setPart(p); new TraversalUtil(p.getJaxbElement(), dmlVmlAnalyzer); result.unsafeObjectsByPart.put(p, dmlVmlAnalyzer.unsafeObjects); if (dmlVmlAnalyzer.unsafeObjects.size()>0){ result.anyUnsafeObjects = true; } result.inventoryObjectsByPart.put(p, dmlVmlAnalyzer.inventoryObjects); if (!result.containsVML) { result.containsVML = dmlVmlAnalyzer.containsVML; } result.fieldsPresent = this.dmlVmlAnalyzer.fieldsPresent; }
/** * @param partName * @param contentType * @since 6.1.0 */ public void addOverrideContentType(PartName partName, String contentType) { CTOverride defaultCT = ctFactory.createCTOverride(); defaultCT.setPartName(partName.getName()); defaultCT.setContentType(contentType); overrideContentType.put(partName.getURI(), defaultCT); }
/** * Workaround for the fact that Xalan doesn't let us pass an AtomicInteger into an extension * function. Instead, it converts it into an int, which means the object in our * bookmarkIdCounter parameter isn't updated. * * So here we wrap the AtomicInteger in a class, * * @author jharrop * */ public static class BookmarkCounter { protected AtomicInteger bookmarkId; BookmarkCounter(AtomicInteger bookmarkId) { this.bookmarkId = bookmarkId; } }
public SlideMasterPart getSlideMasterPart() { if (master!=null) { return master; } Relationship masterRel = getRelationshipsPart().getRelationshipByType( Namespaces.PRESENTATIONML_SLIDE_MASTER); if (masterRel==null) { log.warn(this.getPartName().getName() + " has no master!"); } else { master = (SlideMasterPart)getRelationshipsPart().getPart(masterRel); } return master; }
@Override public PartName getPartName() { // Calculate rels part name dynamically where possible; // this ensures it is named appropriately // if its source part's name changes // (eg AddPartBehaviour.RENAME_IF_NAME_EXISTS) if (this.getSourceP()!=null && (!(this.getSourceP() instanceof OpcPackage))) { try { return new PartName(PartName.getRelationshipsPartName( sourceP.getPartName().getName() )); } catch (InvalidFormatException e) { throw new RuntimeException(e); } } else { return super.getPartName(); } }
public void saveCustomXmlDataStoragePart(CustomXmlDataStoragePart part) throws Docx4JException { String targetName = part.getPartName().getName().substring(1); try { // Add ZIP entry to output stream. zos.putArchiveEntry(new ZipArchiveEntry(targetName)); part.getData().writeDocument( zos ); // Complete the entry zos.closeArchiveEntry(); } catch (Exception e) { throw new Docx4JException("Error marshalling CustomXmlDataStoragePart " + part.getPartName(), e); } }
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; }
/** * Constructor. Creates an appropriately named .rels XML document. * * Often invoked via sourceP.getRelationshipsPart(true) // create rels part * * @param sourceP * Source part for these relationships * * @throws InvalidFormatException * If the specified URI is not valid. */ public RelationshipsPart(Base sourceP) throws InvalidFormatException { super(new PartName(PartName.getRelationshipsPartName( sourceP.getPartName().getName() )) ); // though we won't be using that, since it is dynamic this.sourceP = sourceP; init(); sourceP.setRelationships(this); // TODO - use setRelationships from here // like this in other constructors // in this class. org.docx4j.relationships.ObjectFactory factory = new org.docx4j.relationships.ObjectFactory(); jaxbElement = factory.createRelationships(); }