@Override public boolean isVisible() { final Action action = new AccessMenuPluginAction(getWorkspaceModel().getObject()); return Brix.get().getAuthorizationStrategy().isActionAuthorized(action); } }
private T loadNode(String id) { if (id != null) { JcrSession session = Brix.get().getCurrentSession(workspaceName); if (id.startsWith("/")) { return (T) session.getItem(id); } else { return (T) session.getNodeByIdentifier(id); } } else { return null; } } }
public static SnapshotPlugin get(Brix brix) { return (SnapshotPlugin) brix.getPlugin(ID); }
public Workspace getObject() { if (workspace == null && workspaceId != null) { workspace = Brix.get().getWorkspaceManager().getWorkspace(workspaceId); } return workspace; } }
public void restoreSnapshot(Workspace snapshotWorkspace, Workspace targetWorkspace) { JcrSession sourceSession = brix.getCurrentSession(snapshotWorkspace.getId()); JcrSession targetSession = brix.getCurrentSession(targetWorkspace.getId()); brix.clone(sourceSession, targetSession); brix.initWorkspace(targetWorkspace, brix.getCurrentSession(targetWorkspace.getId())); }
@Override public boolean isVisible() { final Action action = new AccessSitePluginAction(getWorkspaceModel().getObject()); final boolean granted = Brix.get().getAuthorizationStrategy().isActionAuthorized(action); if (granted) { JcrSession session = Brix.get().getCurrentSession(getWorkspaceModel().getObject().getId()); SitePlugin sp = SitePlugin.get(); return sp.canEditNode(sp.getGlobalContainer(session), Context.ADMINISTRATION); } return false; } }
public List<org.brixcms.workspace.Workspace> filterVisibleWorkspaces( List<org.brixcms.workspace.Workspace> workspaces, Context context) { if (workspaces == null) { return Collections.emptyList(); } else { List<org.brixcms.workspace.Workspace> result = new ArrayList<org.brixcms.workspace.Workspace>( workspaces.size()); for (org.brixcms.workspace.Workspace w : workspaces) { Action action = new ViewWorkspaceAction(context, w); if (getAuthorizationStrategy().isActionAuthorized(action)) { result.add(w); } } return result; } }
/** * Convenience method for obtaining Brix instance. This is the preferred way to obtain the instance. * * @return brix instance */ public Brix getBrix() { return Brix.get(); }
private void buildChildren() { children = new ArrayList<JcrTreeNode>(); JcrSession session = Brix.get().getCurrentSession(workspaceId); BrixNode root = (BrixNode) session.getItem(Brix.get().getRootPath()); JcrNodeIterator iterator = root.getNodes(); while (iterator.hasNext()) { BrixNode node = (BrixNode) iterator.nextNode(); if (node instanceof TreeAwareNode) { JcrTreeNode treeNode = ((TreeAwareNode) node).getTreeNode(node); if (treeNode != null) { children.add(treeNode); } } } Collections.sort(children, new Comparator<JcrTreeNode>() { public int compare(JcrTreeNode o1, JcrTreeNode o2) { return o1.getClass().getName().compareTo(o2.getClass().getName()); } }); }
private List<WorkspaceEntry> loadWorkspaces() { Brix brix = Brix.get(); List<WorkspaceEntry> workspaces = new ArrayList<WorkspaceEntry>(); Workspace currentWorkspace = getCurrentWorkspaceId() != null ? brix.getWorkspaceManager() .getWorkspace(getCurrentWorkspaceId()) : null; for (Plugin p : brix.getPlugins()) { List<Workspace> filtered = brix.filterVisibleWorkspaces(p.getWorkspaces( currentWorkspace, true), Context.PRESENTATION); for (Workspace w : filtered) { WorkspaceEntry we = new WorkspaceEntry(); we.id = w.getId(); we.visibleName = p.getUserVisibleName(w, true); workspaces.add(we); } } return workspaces; }
public void createPrototype(Workspace originalWorkspace, String prototypeName) { Workspace workspace = brix.getWorkspaceManager().createWorkspace(); workspace.setAttribute(Brix.WORKSPACE_ATTRIBUTE_TYPE, WORKSPACE_TYPE); setPrototypeName(workspace, prototypeName); JcrSession originalSession = brix.getCurrentSession(originalWorkspace.getId()); JcrSession destSession = brix.getCurrentSession(workspace.getId()); brix.clone(originalSession, destSession); }
private List<Workspace> getAvailableWorkspaces() { Brix brix = Brix.get(); List<Workspace> workspaces = new ArrayList<Workspace>(); Workspace current = getModelObject(); for (Plugin p : brix.getPlugins()) { List<Workspace> filtered = brix.filterVisibleWorkspaces( p.getWorkspaces(current, false), Context.ADMINISTRATION); for (Workspace w : filtered) { workspaces.add(w); } } if (!workspaces.contains(current) && current != null) { workspaces.add(current); } return workspaces; }
public void initRepository() { List<RepositoryInitializer> initializers = new ArrayList<RepositoryInitializer>(); initializers.addAll(config.getRegistry().lookupCollection(RepositoryInitializer.POINT)); initializers.addAll(config.getRegistry().lookupCollection(JcrNodeWrapperFactory.POINT)); try { JcrSession s = getCurrentSession(null); for (RepositoryInitializer initializer : initializers) { initializer.initializeRepository(this, s); } s.save(); s.logout(); } catch (RepositoryException e) { throw new RuntimeException("Couldn't initialize repository", e); } for (Workspace w : getWorkspaceManager().getWorkspaces()) { JcrSession s = getCurrentSession(w.getId()); initWorkspace(w, s); s.logout(); } }
public void createPrototype(List<JcrNode> nodes, String prototypeName) { if (nodes.isEmpty()) { throw new IllegalStateException("Node list can not be empty."); } Workspace workspace = brix.getWorkspaceManager().createWorkspace(); workspace.setAttribute(Brix.WORKSPACE_ATTRIBUTE_TYPE, WORKSPACE_TYPE); setPrototypeName(workspace, prototypeName); JcrSession destSession = brix.getCurrentSession(workspace.getId()); JcrUtil.cloneNodes(nodes, destSession.getRootNode()); destSession.save(); }
@Override public void onSubmit() { List<FileUpload> uploadList = upload.getModelObject(); if (uploadList != null) { for (FileUpload u : uploadList) { try { InputStream s = u.getInputStream(); String id = ManageSnapshotsPanel.this.getModelObject().getId(); Brix brix = getBrix(); JcrSession session = brix.getCurrentSession(id); if (session.itemExists(brix.getRootPath())) { session.getItem(brix.getRootPath()).remove(); session.save(); } session.importXML("/", s, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING); session.save(); brix.initWorkspace(ManageSnapshotsPanel.this.getModelObject(), session); getSession().info(ManageSnapshotsPanel.this.getString("restoreSuccessful")); } catch (IOException e) { throw new BrixException(e); } } } } });
protected void checkAccess() { BrixNode node = getModelObject(); if (!SitePlugin.get().canViewNode(node, Context.PRESENTATION)) { throw Brix.get().getForbiddenException(); } }
public Workspace getSiteWorkspace(String name, String state) { Map<String, String> attributes = new HashMap<String, String>(); attributes.put(Brix.WORKSPACE_ATTRIBUTE_TYPE, WORKSPACE_TYPE); attributes.put(WORKSPACE_ATTRIBUTE_NAME, name); if (state != null) { attributes.put(WORKSPACE_ATTRIBUTE_STATE, state); } List<Workspace> res = brix.getWorkspaceManager().getWorkspacesFiltered(attributes); return res.isEmpty() ? null : res.get(0); }
public void publish(Workspace workspace, String targetState) { if (workspace == null) { throw new IllegalArgumentException("Argument 'workspace' may not be null."); } if (targetState == null) { throw new IllegalArgumentException("Argument 'targetState' may not be null."); } SitePlugin sitePlugin = SitePlugin.get(); if (!sitePlugin.isSiteWorkspace(workspace)) { throw new IllegalStateException("Workspace must be a Site workspace."); } if (targetState.equals(sitePlugin.getWorkspaceState(workspace))) { throw new IllegalStateException("Cannot publish workspace to same state it is already."); } String name = sitePlugin.getWorkspaceName(workspace); Workspace target = sitePlugin.getSiteWorkspace(name, targetState); if (target == null) { target = sitePlugin.createSite(name, targetState); } JcrSession sourceSession = brix.getCurrentSession(workspace.getId()); JcrSession targetSession = brix.getCurrentSession(target.getId()); brix.clone(sourceSession, targetSession); }
private BrixNode getRootNode(String workspaceId, boolean createIfNotExist) { JcrSession session = brix.getCurrentSession(workspaceId); if (session.itemExists(getRootPath()) == false) { if (createIfNotExist) { BrixNode parent = (BrixNode) session.getItem(brix.getRootPath()); parent.addNode(ROOT_NODE_NAME, "nt:unstructured"); } else { return null; } } return (BrixNode) session.getItem(getRootPath()); }