protected DocumentReader makeDocumentReader(CoreSession session, DocumentModel doc, boolean exportAsTree, boolean exportAsZip) { DocumentReader documentReader; if (exportAsTree) { documentReader = new DocumentTreeReader(session, doc, false); if (!exportAsZip) { ((DocumentTreeReader) documentReader).setInlineBlobs(true); } } else { documentReader = new SingleDocumentReader(session, doc); } return documentReader; }
@Override public ExportedDocument read() throws IOException { if (zipFile != null) { return readZip(); } else { return readOrderedStream(); } }
@Override public void close() { super.close(); session = null; doc = null; }
@Override public void importSnapshot(CoreSession session, InputStream is) throws IOException { String importPath = persister.getDistributionRoot(session).getPathAsString(); DocumentReader reader = new NuxeoArchiveReader(is); DocumentWriter writer = new DocumentModelWriter(session, importPath); DocumentPipe pipe = new DocumentPipeImpl(10); pipe.setReader(reader); pipe.setWriter(writer); pipe.run(); reader.close(); writer.close(); }
protected DocumentWriter makeDocumentWriter(OutputStream outputStream, boolean exportAsTree, boolean exportAsZip) throws IOException { DocumentWriter documentWriter; if (exportAsZip) { documentWriter = new NuxeoArchiveWriter(outputStream); } else { if (exportAsTree) { documentWriter = new XMLDocumentTreeWriter(outputStream); } else { documentWriter = new XMLDocumentWriter(outputStream); } } return documentWriter; } }
private void initialize() throws IOException { ZipEntry entry = in.getNextEntry(); if (NuxeoArchiveReader.isMarkerEntry(entry)) { delegate = new NuxeoArchiveReader(in, false); } else { // not a nuxeo archive file File root = null; try { root = Framework.createTempFile("nuxeo-import-", ".unzip"); Framework.trackFile(root, root); root.delete(); root.mkdirs(); extract(in, entry, root); while ((entry = in.getNextEntry()) != null) { extract(in, entry, root); } } finally { in.close(); } delegate = new XMLDirectoryReader(root); } }
@Override public DocumentTranslationMap write(ExportedDocument[] docs) throws IOException { initWriter(); out.write("<documents>".getBytes()); out.flush(); DocumentTranslationMap map = super.write(docs); writer.flush(); out.write("</documents>".getBytes()); return map; }
/** * Create a {@link NuxeoArchiveReader} from a {@link File}. * <p> * This constructor is different from others because it allows the input zip file to have been generated by an other * engine that {@link NuxeoArchiveWriter}. * <p> * In particular, you can use this constructor on a Zip Archive that was manually modified. * * @param file a Zip archive */ public NuxeoArchiveReader(File file) throws IOException { this.zipFile = new ZipFile(file); buildOrderedZipIndex(); checkMarker(); }
public NuxeoArchiveWriter(ZipOutputStream out, int compressionLevel) throws IOException { this.out = out; this.out.setLevel(compressionLevel); setComment(""); // write the marker entry writeMarker(); }
/** * Protected constructor used by {@link ZipReader}. Must not close the stream when done. */ protected NuxeoArchiveReader(ZipInputStream in, boolean checkMarker) throws IOException { this.in = in; inMustBeClosed = !checkMarker; if (checkMarker) { checkMarker(); } }
public ZipReader(InputStream in) throws IOException { this.in = new ZipInputStream(in); initialize(); }
@Override // the zip entry order is the same as one used when creating the zip public ExportedDocument read() throws IOException { Enumeration<? extends ZipEntry> entries = zip.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (entry.isDirectory()) { return createDocument(entry); } } return null; }
private void checkMarker() throws IOException { if (zipFile == null) { ZipEntry entry = in.getNextEntry(); if (entry == null) { throw new IOException("Not a valid Nuxeo Archive - no marker file found (unexpected end of zip)"); } if (!isMarkerEntry(entry)) { throw new IOException("Not a valid Nuxeo Archive - no marker file found"); } } else { if (!zipIndex.contains(ExportConstants.MARKER_FILE)) { throw new IOException("Not a valid Nuxeo Archive - no marker file found"); } } }
public static DocumentsListReader createDocumentsListReader(CoreSession session, Collection<DocumentRef> docRefsList) { List<DocumentModel> list = new ArrayList<DocumentModel>(); for (DocumentRef docRef : docRefsList) { DocumentModel doc = session.getDocument(docRef); list.add(doc); } return new DocumentsListReader(session, list); }
@Override public DocumentTranslationMap write(ExportedDocument xdoc) throws IOException { if (xdoc.getDocument() == null) { // not a valid doc -> this may be a regular folder for example the // root of the tree return null; } Path path = xdoc.getPath(); // if (path.isEmpty() || path.isRoot()) { // return; // TODO avoid to import the root // } path = root.append(path); // compute target path return doWrite(xdoc, path); }
@Override public DocumentTranslationMap write(ExportedDocument doc) throws IOException { initWriter(); writer.write(doc.getDocument()); // out.write(doc.getDocument().asXML().getBytes()); // 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; }
@Override public DocumentTranslationMap write(Collection<ExportedDocument> docs) throws IOException { initWriter(); out.write("<documents>".getBytes()); out.flush(); DocumentTranslationMap map = super.write(docs); writer.flush(); out.write("</documents>".getBytes()); return map; }
@Override public void close() { super.close(); iterator = null; }
@Override public void close() { super.close(); iterator.reset(); iterator = null; }
@Override public void close() { super.close(); iterator.reset(); iterator = null; }