@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } DocumentLocation other = (DocumentLocation) obj; if (docRef == null) { if (other.getDocRef() != null) { return false; } } else if (!docRef.equals(other.getDocRef())) { return false; } if (serverName == null) { if (other.getServerName() != null) { return false; } } else if (!serverName.equals(other.getServerName())) { return false; } return true; }
protected static String getDocumentPart(String requestedURL) { String docPart = ""; DocumentViewCodecManager documentViewCodecManager = Framework.getService(DocumentViewCodecManager.class); DocumentView docView = documentViewCodecManager.getDocumentViewFromUrl(requestedURL, false, null); if (docView != null) { DocumentLocation docLoc = docView.getDocumentLocation(); if (docLoc != null) { String serverName = docLoc.getServerName(); if (serverName != null) { docPart += serverName; IdRef idRef = docLoc.getIdRef(); PathRef pathRef = docLoc.getPathRef(); if (idRef != null) { docPart += "/id/" + idRef; } else if (pathRef != null) { docPart += "/path" + pathRef; } } } } return docPart; }
@Override public Resource getResource(Serializable object, Map<String, Object> context) { if (object instanceof DocumentModel) { DocumentModel doc = (DocumentModel) object; String localName = doc.getRepositoryName() + '/' + doc.getId(); return new QNameResourceImpl(namespace, localName); } else if (object instanceof DocumentLocation) { DocumentLocation docLoc = (DocumentLocation) object; String localName = docLoc.getServerName() + '/' + docLoc.getIdRef().toString(); return new QNameResourceImpl(namespace, localName); } else { throw new IllegalArgumentException(String.format("cannot build resource for '%s'", object)); } }
protected DocumentModel loadDocument() throws DocumentNotFoundException { final DocumentRef docRef = getDocument().getDocRef(); DocumentModel doc = session.getDocument(docRef); doc.putContextData(DublinCoreListener.DISABLE_DUBLINCORE_LISTENER, true); return doc; }
@Override public String getUrlFromDocumentView(DocumentView docView) { DocumentLocation docLoc = docView.getDocumentLocation(); if (docLoc != null) { List<String> items = new ArrayList<String>(); items.add(getPrefix()); IdRef docRef = docLoc.getIdRef(); if (docRef == null) { return null; } items.add(docRef.toString()); String uri = Joiner.on("/").join(items); return URIUtils.addParametersToURIQuery(uri, docView.getParameters()); } return null; }
if (docView.getDocumentLocation().getIdRef() != null) { DocumentIdCodec idCodec = new DocumentIdCodec(); return idCodec.getUrlFromDocumentView(docView); List<String> items = new ArrayList<>(); items.add(getPrefix()); items.add(docLoc.getServerName()); PathRef docRef = docLoc.getPathRef(); if (null == docView.getDocumentLocation().getIdRef()) { log.error("The DocumentLocation did not contains the RefId."); return uriWithParam;
@Override public String getUrlFromDocumentView(DocumentView docView) { DocumentLocation docLoc = docView.getDocumentLocation(); if (docLoc != null) { List<String> items = new ArrayList<>(); items.add(getPrefix()); items.add(docLoc.getServerName()); IdRef docRef = docLoc.getIdRef(); if (docRef == null) { return null; } items.add(docRef.toString()); String viewId = docView.getViewId(); if (viewId != null) { items.add(viewId); } String uri = String.join("/", items); return URIUtils.addParametersToURIQuery(uri, docView.getParameters()); } return null; }
@Override public List<PublishedDocument> getExistingPublishedDocument(DocumentLocation docLoc) { List<PublishedDocument> publishedDocuments = super.getExistingPublishedDocument(docLoc); DocumentModel sourceDocument = coreSession.getDocument(docLoc.getDocRef()); if (sourceDocument.isProxy()) { // If on a proxy, we want all the others proxy pointing to the same // version if (!sourceDocument.hasFacet(RENDITION_FACET) && !sourceDocument.hasSchema(RENDITION_SCHEMA)) { return publishedDocuments; } DocumentRef docRef = new IdRef( (String) sourceDocument.getPropertyValue(Constants.RENDITION_SOURCE_ID_PROPERTY)); publishedDocuments.addAll(getPublishedDocumentsFromProxyDocument(docRef, sourceDocument)); } else { publishedDocuments.addAll(getPublishedDocumentsFromLiveDocument(docLoc.getDocRef())); } return publishedDocuments; }
@Override protected void doWork() { ElasticSearchIndexing esi = Framework.getService(ElasticSearchIndexing.class); openSystemSession(); int bucketSize = Math.min(documentCount, getBucketSize()); List<String> ids = new ArrayList<>(bucketSize); for (DocumentLocation doc : getDocuments()) { ids.add(doc.getIdRef().value); if ((ids.size() % bucketSize) == 0) { esi.indexNonRecursive(getIndexingCommands(session, ids)); ids.clear(); TransactionHelper.commitOrRollbackTransaction(); TransactionHelper.startTransaction(); } } if (!ids.isEmpty()) { esi.indexNonRecursive(getIndexingCommands(session, ids)); ids.clear(); } if (syncAlias) { log.warn(String.format("Re-indexing job: %s completed.", getSchedulePath().getParentPath())); ElasticSearchAdmin esa = Framework.getService(ElasticSearchAdmin.class); esa.syncSearchAndWriteAlias(esa.getIndexNameForRepository(repositoryName)); } }
@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 String getUrlFromDocumentView(DocumentView docView) { DocumentLocation docLoc = docView.getDocumentLocation(); String filepath = docView.getParameter(FILE_PROPERTY_PATH_KEY); String filename = docView.getParameter(FILENAME_KEY); if (docLoc != null && filepath != null && filename != null) { StringBuilder buf = new StringBuilder(); buf.append(getPrefix()); buf.append("/"); buf.append(docLoc.getServerName()); buf.append("/"); buf.append(docLoc.getDocRef().toString()); buf.append("/"); buf.append(filepath); buf.append("/"); buf.append(URIUtils.quoteURIPathToken(filename)); String uri = buf.toString(); Map<String, String> requestParams = new HashMap<>(docView.getParameters()); requestParams.remove(FILE_PROPERTY_PATH_KEY); requestParams.remove(FILENAME_KEY); return URIUtils.addParametersToURIQuery(uri, requestParams); } return null; }
@Override @Begin(id = "#{conversationIdGenerator.currentOrNewMainConversationId}", join = true) public String navigateToURL(String documentUrl) { final DocumentLocation docLoc; try { docLoc = DocumentLocator.parseDocRef(documentUrl); } catch (BadDocumentUriException e) { log.error("Cannot get document ref from uri " + documentUrl + ". " + e.getMessage(), e); return null; } final DocumentRef docRef = docLoc.getDocRef(); RepositoryLocation repLoc = new RepositoryLocation(docLoc.getServerName()); return navigateTo(repLoc, docRef); }
@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; }
@Override public DocumentTranslationMap write(ExportedDocument doc) throws IOException { OutputFormat format = AbstractDocumentWriter.createPrettyPrint(); XMLWriter writer = null; try { writer = new XMLWriter(out, format); writer.write(doc.getDocument()); } finally { if (writer != null) { writer.close(); } } // 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; }
private DocumentTranslationMap doWrite(ExportedDocument xdoc, Path targetPath) { DocumentModel previousDoc = null; PathRef pathRef = new PathRef(targetPath.toString()); if (session.exists(pathRef)) { previousDoc = session.getDocument(pathRef); } DocumentModel doc; if (previousDoc == null) { doc = createDocument(xdoc, targetPath); } else { doc = updateDocument(xdoc, previousDoc); } DocumentLocation source = xdoc.getSourceLocation(); DocumentTranslationMap map = new DocumentTranslationMapImpl(source.getServerName(), doc.getRepositoryName()); if (source.getDocRef() != null && source.getDocRef().reference() != null) { map.put(source.getDocRef(), doc.getRef()); } return map; }
@Override public DocumentTranslationMap write(ExportedDocument xdoc) throws IOException { Path path = xdoc.getPath(); if (path.isEmpty() || path.isRoot()) { return null; // TODO avoid to import the root } path = root.append(path); // compute target path DocumentModel doc = createDocument(xdoc, path); DocumentLocation source = xdoc.getSourceLocation(); DocumentTranslationMap map = new DocumentTranslationMapImpl(source.getServerName(), doc.getRepositoryName()); map.put(source.getDocRef(), doc.getRef()); return map; }
@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; } DocumentModel doc = null; String id = xdoc.getId(); try { doc = session.getDocument(new IdRef(id)); } catch (DocumentNotFoundException e) { log.error("Cannot update document. No such document: " + id); return null; } doc = updateDocument(xdoc, doc); DocumentLocation source = xdoc.getSourceLocation(); DocumentTranslationMap map = new DocumentTranslationMapImpl(source.getServerName(), doc.getRepositoryName()); map.put(source.getDocRef(), doc.getRef()); return map; }
/** * @since 5.7 */ public void downloadThumbnail(DocumentView docView) { if (docView != null) { DocumentLocation docLoc = docView.getDocumentLocation(); if (documentManager == null) { RepositoryLocation loc = new RepositoryLocation(docLoc.getServerName()); navigationContext.setCurrentServerLocation(loc); documentManager = navigationContext.getOrCreateDocumentManager(); } DocumentModel doc = documentManager.getDocument(docLoc.getDocRef()); if (doc != null) { ThumbnailAdapter thumbnailDoc = doc.getAdapter(ThumbnailAdapter.class); Blob thumbnail = thumbnailDoc.getThumbnail(documentManager); if (thumbnail == null) { return; } ComponentUtils.download(doc, null, thumbnail, thumbnail.getFilename(), "thumbnail"); } } } }
RepositoryLocation loc = new RepositoryLocation(docLoc.getServerName()); navigationContext.setCurrentServerLocation(loc); documentManager = navigationContext.getOrCreateDocumentManager(); DocumentModel doc = documentManager.getDocument(docLoc.getDocRef()); if (doc == null) { return;
String newRepo = targetLocation.getServerName(); if (!repo.equals(newRepo)) { DocumentTranslationMap map = new DocumentTranslationMapImpl(repo, repo); DocumentModel sourceDoc = session.getDocument(source); DocumentModel destDoc = session.copy(source, targetLocation.getDocRef(), null); roots.add(destDoc.getRef());