/** * Enabling package access * @return backing Node */ protected Node getNode() { return super.getNode(); }
/** * Enabling package access * @return backing Node */ protected Node getNode() { return super.getNode(); }
protected String[] getStringsProperty(String relPath) throws RepositoryException { String[] result = null; if (hasNode() && getNode().hasProperty(relPath)) { Value[] values = getNode().getProperty(relPath).getValues(); result = new String[values.length]; int i = 0; for (Value v : values) { result[i++] = v.getString(); } } return result; }
public Document duplicate(Document offspring) throws WorkflowException, MappingException, RepositoryException, RemoteException { Node source = offspring.getNode(rootSession); return duplicate(source, COPY_OF +source.getName()); }
public void delete(Document document) throws WorkflowException, MappingException, RepositoryException, RemoteException { String path = subject.getPath().substring(1); Node folderNode = (path.equals("") ? rootSession.getRootNode() : rootSession.getRootNode().getNode(path)); Node documentNode = document.getNode(rootSession); if (documentNode.getPath().startsWith(folderNode.getPath()+"/")) { delete(folderNode, documentNode); } }
public Document duplicate(Document offspring, Map<String,String> arguments) throws WorkflowException, MappingException, RepositoryException, RemoteException { Node source = offspring.getNode(rootSession); String targetName = arguments.get("name"); return duplicate(source, targetName); }
/** * Returns the ensured to be checked out backing Node of this Document, either directly if available and already * tied to the provided Session or else retrieved from the provided Session based on its {@link #getIdentity()}. * @param session The session for which to return the backing Node * @return the ensured to be checked out backing Node of this Document or null if this Document doesn't contain a identity */ public Node getCheckedOutNode(Session session) throws RepositoryException { Node node = getNode(session); if (node != null) { JcrUtils.ensureIsCheckedOut(node); } return node; }
protected Date getDateProperty(String relPath) throws RepositoryException { Calendar cal = null; if (hasNode()) { cal = JcrUtils.getDateProperty(getNode(), relPath, null); } return cal != null ? cal.getTime() : null; }
/** * Create a draft variant node for a document represented by handle node. * * @param workflow Editable workflow for the desired document * @param session JCR session for obtaining the draft node * @return JCR draft node or nothing, wrapped in an Optional */ public static Optional<Node> createDraft(final EditableWorkflow workflow, final Session session) { try { final Document document = workflow.obtainEditableInstance(); return Optional.of(document.getNode(session)); } catch (WorkflowException | RepositoryException | RemoteException e) { log.warn("Failed to obtain draft for user '{}'.", session.getUserID(), e); } return Optional.empty(); }
@Override public boolean isModified() throws WorkflowException, MappingException, RepositoryException, RemoteException { final HippoSession session = (HippoSession) context.getUserSession(); final Node node = document.getNode(session); return session.pendingChanges(node, "nt:base", true).hasNext(); }
@Override protected Node doExecute(Node node) throws Exception { GalleryWorkflow workflow = getGalleryWorkflow(node); String nodeName = "asset"; do { nodeName += random.nextInt(10); } while (node.hasNode(nodeName)); Document document = workflow.createGalleryItem(nodeName, "hippogallery:exampleAssetSet"); node.getSession().refresh(false); Node assetNode = document.getNode(node.getSession()); InputStream istream = getClass().getClassLoader().getResourceAsStream("org/onehippo/repository/concurrent/action/Hippo.pdf"); makeImage(assetNode, istream, "application/pdf"); node.getSession().save(); return assetNode; }
private Node getDocumentNode(Session session, Document document) { if (document == null || document.getIdentity() == null) { log.error("Cannot retrieve workflow for null document"); return null; } try { return document.getNode(session); } catch (ItemNotFoundException e) { log.error("Document not found {}", e.getMessage()); } catch (RepositoryException e) { log.error("Unexpected error {}", e.getMessage(), e); } return null; }
/** * Get the containing folder of a document. * * @param document either a document, a handle or a folder * @param session the session to use to get the containing folder for * @return the folder containing this document or the root document * @throws RepositoryException */ public static Document getContainingFolder(Document document, Session session) throws RepositoryException { return new Document(getContainingFolder(document.getNode(session))); }
protected Boolean getBooleanProperty(String relPath) throws RepositoryException { return hasNode() ? JcrUtils.getBooleanProperty(getNode(), relPath, null) : null; }
protected String getStringProperty(String relPath) throws RepositoryException { return hasNode() ? JcrUtils.getStringProperty(getNode(), relPath, null) : null; }
protected Long getLongProperty(String relPath) throws RepositoryException { return hasNode() ? JcrUtils.getLongProperty(getNode(), relPath, null) : null; }
protected Node getNodeProperty(String relPath) throws RepositoryException { return hasNode() ? JcrUtils.getNodeProperty(getNode(), relPath, null) : null; }
public Document copyFrom(Document offspring, Document targetFolder, String targetName, Map<String,String> arguments) throws WorkflowException, MappingException, RepositoryException, RemoteException { if (targetName == null || targetName.equals("")) { throw new WorkflowException("No target name given"); } String path = subject.getPath().substring(1); Node folder = (path.equals("") ? rootSession.getRootNode() : rootSession.getRootNode().getNode(path)); Node destination = targetFolder.getNode(rootSession); Node source = offspring.getNode(rootSession); if (folder.isSame(destination)) { //throw new WorkflowException("Cannot copy document to same folder, use duplicate instead"); return duplicate(source, targetName); } if (source.getAncestor(folder.getDepth()).isSame(folder)) { return ((EmbedWorkflow)workflowContext.getWorkflow("embedded", new Document(destination))).copyTo(new Document(subject), offspring, targetName, arguments); } return null; }
public void addTranslation(String language, Document document) throws WorkflowException, RepositoryException, RemoteException { HippoTranslatedNode translatedNode = new HippoTranslatedNode(rootSubject); if (translatedNode.hasTranslation(language)) { throw new WorkflowException("Language already exists"); } Node copiedDocNode = document.getNode(rootSession); JcrUtils.ensureIsCheckedOut(copiedDocNode); if (!copiedDocNode.isNodeType(HippoTranslationNodeType.NT_TRANSLATED)) { copiedDocNode.addMixin(HippoTranslationNodeType.NT_TRANSLATED); } copiedDocNode.setProperty(HippoTranslationNodeType.LOCALE, language); copiedDocNode.setProperty(HippoTranslationNodeType.ID, userSubject.getProperty(HippoTranslationNodeType.ID) .getString()); rootSession.save(); rootSession.refresh(false); }
private Document getTranslatedVariant(final Document translatedDocument) throws RepositoryException { final Node translatedNode = translatedDocument.getNode(UserSession.get().getJcrSession()); if (translatedNode.isNodeType(NT_HANDLE)) { Node variant = null; for (Node node : new NodeIterable(translatedNode.getNodes(translatedNode.getName()))) { variant = node; final String state = JcrUtils.getStringProperty(translatedNode, HIPPOSTD_STATE, null); if (UNPUBLISHED.equals(state)) { break; } } return variant != null ? new Document(variant) : null; } return translatedDocument; }