Example #1
0
 @Override
 public DocumentTranslationMap write(ExportedDocument doc) throws IOException {
   String path = doc.getPath().toString();
   writeDocument(path, doc);
   // keep location unchanged
   DocumentLocation oldLoc = doc.getSourceLocation();
   String oldServerName = oldLoc.getServerName();
   DocumentRef oldDocRef = oldLoc.getDocRef();
   DocumentTranslationMap map = new DocumentTranslationMapImpl(oldServerName, oldServerName);
   map.put(oldDocRef, oldDocRef);
   return map;
 }
Example #2
0
  protected void writeDocument(String path, ExportedDocument doc) throws IOException {

    if (path.equals("/") || path.length() == 0) {
      path = "";
    } else { // avoid adding a root entry
      path += '/';
      ZipEntry entry = new ZipEntry(path);
      // store the number of child as an extra info on the entry
      entry.setExtra(new DWord(doc.getFilesCount()).getBytes());
      out.putNextEntry(entry);
      out.closeEntry();
      // System.out.println(">> add entry: "+entry.getName());
    }

    // write metadata
    ZipEntry entry = new ZipEntry(path + ExportConstants.DOCUMENT_FILE);
    out.putNextEntry(entry);
    try {
      writeXML(doc.getDocument(), out);
    } finally {
      out.closeEntry();
      // System.out.println(">> add entry: "+entry.getName());
    }

    // write external documents
    for (Map.Entry<String, Document> ext : doc.getDocuments().entrySet()) {
      String fileName = ext.getKey() + ".xml";
      entry = new ZipEntry(path + fileName);
      out.putNextEntry(entry);
      try {
        writeXML(ext.getValue(), out);
      } finally {
        out.closeEntry();
      }
    }

    // write blobs
    Map<String, Blob> blobs = doc.getBlobs();
    for (Map.Entry<String, Blob> blobEntry : blobs.entrySet()) {
      String fileName = blobEntry.getKey();
      entry = new ZipEntry(path + fileName);
      out.putNextEntry(entry);
      try (InputStream in = blobEntry.getValue().getStream()) {
        IOUtils.copy(in, out);
      }
      // DO NOT CALL out.close(), we want to keep writing to it
      out.closeEntry();
    }
  }
Example #3
0
  private ExportedDocument createDocument(ZipEntry dirEntry) throws IOException {
    ExportedDocument xdoc = new ExportedDocumentImpl();
    String dirPath = dirEntry.getName();
    // TODO -> some processing on the path?
    xdoc.setPath(new Path(dirPath).removeTrailingSeparator());
    // read the main document
    ZipEntry entry = zip.getEntry(dirPath + ExportConstants.DOCUMENT_FILE);
    InputStream in = zip.getInputStream(entry);
    try {
      Document doc = readXML(in);
      doc.setDocument(doc);
    } finally {
      in.close();
    }

    return null;
  }
  @Test
  public void testBlobFilenamePresent() throws Exception {
    createDocs();

    ExportedDocument exportedDoc = new ExportedDocumentImpl(docToExport, true);
    assertEquals("File", exportedDoc.getType());

    session.removeDocument(docToExport.getRef());
    session.save();
    assertEquals(0, session.getChildren(workspace.getRef()).size());

    DocumentWriter writer = new DocumentModelWriter(session, rootDocument.getPathAsString());
    writer.write(exportedDoc);

    DocumentModelList children = session.getChildren(workspace.getRef());
    assertEquals(1, children.size());
    DocumentModel importedDocument = children.get(0);
    Blob blob = (Blob) importedDocument.getProperty("file", "content");
    assertEquals("dummyBlob.txt", blob.getFilename());
  }