@Test public void testGetActive() throws Exception { List<BBCode> bbcodes = new ArrayList<BBCode>(); bbcodes.add(createBBCode("foo", "replacement", "description", "example", false, true)); bbcodes.add(createBBCode("foo", "replacement", "description", "example", true, false)); bbcodes.add(createBBCode("foo2", "replacement", "description", "example", true, true)); bbcodes.add(createBBCode("foo3", "replacement", "description", "example", false, true)); bbcodes.add(createBBCode("foo4", "replacement", "description", "example", false, true)); bbcodeService.save(bbcodes); List<String> actual = bbcodeService.getActive(); assertEquals(bbcodes.size() - 1, actual.size()); AssertUtils.assertContains(actual, "foo", "foo2=", "foo3", "foo4"); }
public List<String> getActive() throws Exception { SessionProvider sProvider = SessionProvider.createSystemProvider(); if (activeBBCodesCache.isEmpty()) { try { Node bbCodeHome = getBBcodeHome(sProvider); if (bbCodeHome == null) { return activeBBCodesCache; } QueryManager qm = bbCodeHome.getSession().getWorkspace().getQueryManager(); StringBuilder pathQuery = new StringBuilder(); pathQuery.append("/jcr:root").append(bbCodeHome.getPath()).append("/element(*,").append(BBCODE_NODE_TYPE).append(")[@exo:isActive='true']"); Query query = qm.createQuery(pathQuery.toString(), Query.XPATH); QueryResult result = query.execute(); NodeIterator iter = result.getNodes(); String tagName = ""; synchronized (activeBBCodesCache) { while (iter.hasNext()) { Node bbcNode = iter.nextNode(); tagName = bbcNode.getName(); activeBBCodesCache.add(tagName); } } } finally { sProvider.close(); } } return activeBBCodesCache; }
BBCodeServiceImpl implements Startable, BBCodeService, ManagementAware { public List<String> getActive() throws Exception { SessionProvider sProvider = SessionProvider.createSystemProvider(); if (activeBBCodesCache.isEmpty()) { try { Node bbCodeHome = getBBcodeHome(sProvider); if (bbCodeHome == null) { return activeBBCodesCache; } QueryManager qm = bbCodeHome.getSession().getWorkspace().getQueryManager(); StringBuilder pathQuery = new StringBuilder(); pathQuery.append("/jcr:root").append(bbCodeHome.getPath()).append("/element(*,").append(BBCODE_NODE_TYPE).append(")[@exo:isActive='true']"); Query query = qm.createQuery(pathQuery.toString(), Query.XPATH); QueryResult result = query.execute(); NodeIterator iter = result.getNodes(); String tagName = ""; synchronized (activeBBCodesCache) { while (iter.hasNext()) { Node bbcNode = iter.nextNode(); tagName = bbcNode.getName(); activeBBCodesCache.add(tagName); } } } finally { sProvider.close(); } } return activeBBCodesCache; } }
BBCodeServiceImpl implements Startable, BBCodeService, ManagementAware { public List<String> getActive() throws Exception { SessionProvider sProvider = SessionProvider.createSystemProvider(); if (activeBBCodesCache.isEmpty()) { try { Node bbCodeHome = getBBcodeHome(sProvider); if (bbCodeHome == null) { return activeBBCodesCache; } QueryManager qm = bbCodeHome.getSession().getWorkspace().getQueryManager(); StringBuilder pathQuery = new StringBuilder(); pathQuery.append("/jcr:root").append(bbCodeHome.getPath()).append("/element(*,").append(BBCODE_NODE_TYPE).append(")[@exo:isActive='true']"); Query query = qm.createQuery(pathQuery.toString(), Query.XPATH); QueryResult result = query.execute(); NodeIterator iter = result.getNodes(); String tagName = ""; synchronized (activeBBCodesCache) { while (iter.hasNext()) { Node bbcNode = iter.nextNode(); tagName = bbcNode.getName(); activeBBCodesCache.add(tagName); } } } finally { sProvider.close(); } } return activeBBCodesCache; } BBCodeServiceImpl();  BBCodeServiceImpl(KSDataLocation dataLocator); }
BBCodeServiceImpl implements Startable, BBCodeService, ManagementAware { public List<String> getActive() throws Exception { SessionProvider sProvider = SessionProvider.createSystemProvider(); if (activeBBCodesCache.isEmpty()) { try { Node bbCodeHome = getBBcodeHome(sProvider); if (bbCodeHome == null) { return activeBBCodesCache; } QueryManager qm = bbCodeHome.getSession().getWorkspace().getQueryManager(); StringBuilder pathQuery = new StringBuilder(); pathQuery.append("/jcr:root").append(bbCodeHome.getPath()).append("/element(*,").append(BBCODE_NODE_TYPE).append(")[@exo:isActive='true']"); Query query = qm.createQuery(pathQuery.toString(), Query.XPATH); QueryResult result = query.execute(); NodeIterator iter = result.getNodes(); String tagName = ""; synchronized (activeBBCodesCache) { while (iter.hasNext()) { Node bbcNode = iter.nextNode(); tagName = bbcNode.getName(); activeBBCodesCache.add(tagName); } } } finally { sProvider.close(); } } return activeBBCodesCache; } BBCodeServiceImpl();  BBCodeServiceImpl(KSDataLocation dataLocator); void registerBBCodePlugin(BBCodePlugin plugin); void initDefaultBBCodes(); void save(List<BBCode> bbcodes); List<BBCode> getAll(); List<String> getActive(); BBCode findById(String id); void delete(String bbcodeId); void start(); void stop(); void setContext(ManagementContext context); KSDataLocation getDataLocator(); void setDataLocator(KSDataLocation dataLocator); List<BBCodePlugin> getPlugins(); void setPlugins(List<BBCodePlugin> plugins); }
BBCodeServiceImpl implements Startable, BBCodeService, ManagementAware { public List<String> getActive() throws Exception { SessionProvider sProvider = SessionProvider.createSystemProvider(); if (activeBBCodesCache.isEmpty()) { try { Node bbCodeHome = getBBcodeHome(sProvider); if (bbCodeHome == null) { return activeBBCodesCache; } QueryManager qm = bbCodeHome.getSession().getWorkspace().getQueryManager(); StringBuilder pathQuery = new StringBuilder(); pathQuery.append("/jcr:root").append(bbCodeHome.getPath()).append("/element(*,").append(BBCODE_NODE_TYPE).append(")[@exo:isActive='true']"); Query query = qm.createQuery(pathQuery.toString(), Query.XPATH); QueryResult result = query.execute(); NodeIterator iter = result.getNodes(); String tagName = ""; synchronized (activeBBCodesCache) { while (iter.hasNext()) { Node bbcNode = iter.nextNode(); tagName = bbcNode.getName(); activeBBCodesCache.add(tagName); } } } finally { sProvider.close(); } } return activeBBCodesCache; } BBCodeServiceImpl();  BBCodeServiceImpl(KSDataLocation dataLocator); void registerBBCodePlugin(BBCodePlugin plugin); void initDefaultBBCodes(); void save(List<BBCode> bbcodes); List<BBCode> getAll(); List<String> getActive(); BBCode findById(String id); void delete(String bbcodeId); void start(); void stop(); void setContext(ManagementContext context); KSDataLocation getDataLocator(); void setDataLocator(KSDataLocation dataLocator); List<BBCodePlugin> getPlugins(); void setPlugins(List<BBCodePlugin> plugins); final static String BBCODE_NODE_TYPE; final static String BBCODE_HOME_NODE_TYPE; }