当前位置: 首页>>代码示例>>Java>>正文


Java MgnlContext类代码示例

本文整理汇总了Java中info.magnolia.context.MgnlContext的典型用法代码示例。如果您正苦于以下问题:Java MgnlContext类的具体用法?Java MgnlContext怎么用?Java MgnlContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MgnlContext类属于info.magnolia.context包,在下文中一共展示了MgnlContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import info.magnolia.context.MgnlContext; //导入依赖的package包/类
@Override
public void execute(final InstallContext installContext) throws TaskExecutionException {
    try {
        final Session session = MgnlContext.getJCRSession(NewsRepositoryConstants.COLLABORATION);

        final Node rootNode = session.getRootNode();
        final int numberOfMovedNodes = processNewsItems(installContext, rootNode, 0);

        if (numberOfMovedNodes > 0) {
            installContext.info("Nested news items were found and have been un-nested.");
            installContext.info("Note: If present, duplicate news items now have a name that ends with '-duplicate'.");
            installContext.info("Please check all news items and re-publish if needed.");
        }
    } catch (RepositoryException e) {
        throw new TaskExecutionException("Error while un-nesting event nodes", e);
    }
}
 
开发者ID:tricode,项目名称:magnolia-news,代码行数:18,代码来源:FindAndMoveNestedNewsTask.java

示例2: NewsRenderableDefinition

import info.magnolia.context.MgnlContext; //导入依赖的package包/类
@Inject
public NewsRenderableDefinition(Node content, RD definition, RenderingModel<?> parent, TemplatingFunctions templatingFunctions) {
    super(content, definition, parent);
    this.templatingFunctions = templatingFunctions;

    filter = new HashMap<>();
    final Iterator<Map.Entry<String, String>> it = MgnlContext.getWebContext().getParameters().entrySet().iterator();
    while (it.hasNext()) {
        final Map.Entry<String, String> pairs = it.next();
        if (WHITELISTED_PARAMETERS.contains(pairs.getKey()) && StringUtils.isNotEmpty(pairs.getValue())) {
            filter.put(pairs.getKey(), pairs.getValue());
            LOGGER.debug("Added to filter: {}", pairs.getKey());
        }
        it.remove(); // avoids a ConcurrentModificationException
    }
}
 
开发者ID:tricode,项目名称:magnolia-news,代码行数:17,代码来源:NewsRenderableDefinition.java

示例3: execute

import info.magnolia.context.MgnlContext; //导入依赖的package包/类
@Override
public String execute() {

    if (content != null) {
        String uuid;
        try {
            uuid = content.getIdentifier();
            // Fetch pre-executed search results
            searchResult = MgnlContext.getAttribute(ResultsAreaRenderableDefinition.SEARCH_RESULT_ATTRIBUTE_PREFIX + uuid);
            // Check if search result are available and remove from context for later executions of the results area
            if (searchResult != null) {
                MgnlContext.removeAttribute(ResultsAreaRenderableDefinition.SEARCH_RESULT_ATTRIBUTE_PREFIX + uuid);
            }
        } catch (RepositoryException e) {
            log.debug("Error obtaining uuid during execute of component model", e);
        }

    }
    // No search results, execute new search!
    if (searchResult == null) {
        executeSearch();
    }

    return super.execute();
}
 
开发者ID:gtenham,项目名称:magnolia-templating,代码行数:26,代码来源:ResultsRenderableDefinition.java

示例4: getComponentTotal

import info.magnolia.context.MgnlContext; //导入依赖的package包/类
/**
 * Get total results count for single component.
 *
 * @param node
 * @return total component results count
 */
public int getComponentTotal(Node node) {
    int total = 0;
    ResultsRenderableDefinition model = getComponentModel(node);

    if (model != null) {
        model.executeSearch();

        try {
            MgnlContext.setAttribute(SEARCH_RESULT_ATTRIBUTE_PREFIX + node.getIdentifier(), model.getSearchResult());
        } catch (RepositoryException e) {
            log.debug("Error getting node identifier during during set of MgnlContext attribute", e);
        }
        total = model.getTotalCount();
    }
    return total;
}
 
开发者ID:gtenham,项目名称:magnolia-templating,代码行数:23,代码来源:ResultsAreaRenderableDefinition.java

示例5: BlogRenderableDefinition

import info.magnolia.context.MgnlContext; //导入依赖的package包/类
@Inject
public BlogRenderableDefinition(Node content, RD definition, RenderingModel<?> parent, TemplatingFunctions templatingFunctions) {
    super(content, definition, parent);
    this.templatingFunctions = templatingFunctions;

    filter = Maps.newHashMap();

    final Iterator<Entry<String, String>> it = MgnlContext.getWebContext().getParameters().entrySet().iterator();
    while (it.hasNext()) {
        final Map.Entry<String, String> pairs = it.next();
        if (WHITELISTED_PARAMETERS.contains(pairs.getKey()) && StringUtils.isNotEmpty(pairs.getValue())) {
            filter.put(pairs.getKey(), pairs.getValue());
            LOGGER.debug("Added to filter: {}", pairs.getKey());
        }
        it.remove(); // avoids a ConcurrentModificationException
    }
}
 
开发者ID:tricode,项目名称:magnolia-blog,代码行数:18,代码来源:BlogRenderableDefinition.java

示例6: testPrintDoubleQuoted2

import info.magnolia.context.MgnlContext; //导入依赖的package包/类
/**
 * jsonfn.from(content).add(".*").inline().print()
 *
 * ==> { "foo" : "that\\'s it", ... }
 */
@Test
public void testPrintDoubleQuoted2() throws Exception {
    // GIVEN
    Session session = MgnlContext.getInstance().getJCRSession("website");
    Node node = session.getNode("/home/section2/article/mgnl:apex");
    node.setProperty("description",
            "<p><span style=\"line-height:1.6em\">l&auml;ngsten produzierten Profikameras &uuml;berhaupt.</span></p><p><span style=\"line-height:1.6em\">Mit der F3 !</span></p>");
    // WHEN
    String json = JsonTemplatingFunctions.from(node).add("description").inline().print();
    // THEN
    assertThat(json, startsWith("{"));
    assertThat(json, containsString(
            "\"description\":\"<p><span style=\\\"line-height:1.6em\\\">l&auml;ngsten produzierten Profikameras &uuml;berhaupt.</span></p><p><span style=\\\"line-height:1.6em\\\">Mit der F3 !</span></p>\""));
    assertThat(json, endsWith("}"));
}
 
开发者ID:rah003,项目名称:neat-jsonfn,代码行数:21,代码来源:JsonBuilderTest.java

示例7: testFlattenOutputByTypesOfSingleNode

import info.magnolia.context.MgnlContext; //导入依赖的package包/类
/**
 * to output all stuff from root, jcr:xxx node types should be skipped:
 *
 * jsonfn.from(root).add(".*").print()
 *
 * ==> { "foo" : "hahaha", "a" :"x", b: 1234, "bar" : "meh", ... }
 */
@Test
public void testFlattenOutputByTypesOfSingleNode() throws Exception {
    Session session = MgnlContext.getInstance().getJCRSession("website");
    session.getNode("/home").addNode("test_above_apex", "mgnl:folder").addNode("apex_under_test", "mgnl:apex");
    // WHEN
    String json = JsonTemplatingFunctions.from(session.getNode("/")).down(2).allowOnlyNodeTypes(".*apex").add("@name", "@nodeType", "@path", "@depth").print();
    // THEN
    assertThat(json, startsWith("["));
    assertThat(json.substring(1, json.length() - 1), not(containsString("[")));
    assertThat(json, endsWith("]"));
    assertThat(json, not(containsString("mgnl:folder")));
    assertThat(json, not(containsString("apex_under_test")));
    assertThat(json, containsString("mgnl:apex"));

}
 
开发者ID:rah003,项目名称:neat-jsonfn,代码行数:23,代码来源:JsonBuilderTest.java

示例8: testSubNodePropertyListingWithExclusionOfParent

import info.magnolia.context.MgnlContext; //导入依赖的package包/类
/**
 * Lists specified properties only for sub nodes but not for the parent nodes. Issue #21.
 *
 */
@Test
public void testSubNodePropertyListingWithExclusionOfParent() throws Exception {
    Session session = MgnlContext.getInstance().getJCRSession("website");
    // GIVEN

    Node node = session.getNode("/home/section2/article/mgnl:apex/alias");
    node.addNode("tab0","mgnl:content");
    node.addNode("tab1","mgnl:content");
    node.addNode("tab2","mgnl:content");
    session.save();
    // WHEN
    String json = JsonTemplatingFunctions.from(session.getNode("/home/section2/article/mgnl:apex/alias"))
            .down(1).add( "tab(.+)['@id']").inline().print();
    // THEN
    assertThat(json, startsWith("{"));
    assertThat(json, containsString("\"tab1\":{\"@id\""));
    assertThat(json, not(containsString("},\"@id\":")));
    assertThat(json, containsString("},\"tab2\":{\"@id\":"));
    assertThat(json, endsWith("}"));
}
 
开发者ID:rah003,项目名称:neat-jsonfn,代码行数:25,代码来源:JsonBuilderTest.java

示例9: testSubNodeWithSamePropertyAsOneOfAncestors

import info.magnolia.context.MgnlContext; //导入依赖的package包/类
/**
 * Lists specified properties only for parent nodes but not for the subnodes. Issue #16.
 *
 */
@Test
public void testSubNodeWithSamePropertyAsOneOfAncestors() throws Exception {
    Session session = MgnlContext.getInstance().getJCRSession("website");
    // GIVEN

    Node node = session.getNode("/home/section2/article/mgnl:apex/alias");
    node.setProperty("abstract", "foo");
    Node child = node.addNode("linkInternal","mgnl:content");
    child.setProperty("abstract", "foo");
    session.save();
    // WHEN
    String json = JsonTemplatingFunctions.from(session.getNode("/home/section2/article/mgnl:apex/alias"))
            .down(3).add("alias['abstract']").exclude("linkInternal['abstract']").inline().print();
    // THEN
    assertThat(json, startsWith("{"));
    assertThat(json, containsString("{\"abstract\":\"foo\"}"));
    assertThat(json, endsWith("}"));
}
 
开发者ID:rah003,项目名称:neat-jsonfn,代码行数:23,代码来源:JsonBuilderTest.java

示例10: testSubNodeWithSystemPropertyNameAsOneOfAncestors

import info.magnolia.context.MgnlContext; //导入依赖的package包/类
/**
 * Lists specified properties only for parent nodes but not for the subnodes. Issue #16.
 *
 */
@Test
public void testSubNodeWithSystemPropertyNameAsOneOfAncestors() throws Exception {
    Session session = MgnlContext.getInstance().getJCRSession("website");
    // GIVEN

    Node node = session.getNode("/home/section2/article/mgnl:apex/alias");
    node.setProperty("abstract", "foo");
    Node child = node.addNode("linkInternal","mgnl:content");
    child.setProperty("abstract", "foo");
    session.save();
    // WHEN
    String json = JsonTemplatingFunctions.from(session.getNode("/home/section2/article/mgnl:apex/alias"))
            .down(3).add("alias['@id']").exclude("linkInternal['@id']").inline().print();
    // THEN
    assertThat(json, startsWith("{"));
    assertThat(json, containsString("{\"@id\":\""));
    assertEquals(json.split("id").length, 2);
    assertThat(json, endsWith("}"));
}
 
开发者ID:rah003,项目名称:neat-jsonfn,代码行数:24,代码来源:JsonBuilderTest.java

示例11: testPerformance

import info.magnolia.context.MgnlContext; //导入依赖的package包/类
/**
 * Test performance.
 */
@Test
public void testPerformance() throws Exception {
    Session session = MgnlContext.getInstance().getJCRSession("website");
    for (int i = 0; i < 100; i++) {
        session.getWorkspace().copy("/home/section", "/home/section0" + i);
    }
    session.save();
    int count = 10;
    long stamp = System.currentTimeMillis();
    for (int i = 0; i < count; i++) {
        // WHEN
        singleRun();
    }
    long res = System.currentTimeMillis() - stamp;
    res = res / count;
    assertTrue(res < 4000);
}
 
开发者ID:rah003,项目名称:neat-jsonfn,代码行数:21,代码来源:JsonBuilderTest.java

示例12: singleRun

import info.magnolia.context.MgnlContext; //导入依赖的package包/类
private void singleRun() throws Exception {
    Session session = MgnlContext.getInstance().getJCRSession("website");
    NodeIterator iter = session.getNode("/home").getNodes();
    String json = "[]";
    int count = 0;
    while (iter.hasNext()) {
        count++;
        Node n = iter.nextNode();
        json = JsonTemplatingFunctions.appendFrom(json, n)
                .add("name",
                        "link",
                        "linkText",
                        "displayName",
                        "partnerInContentApp",
                        "@path",
                        "mgnl:created",
                        "mgnl:activationStatus")
                .expand("categoriesFilter", "category")
                .expand("image", "dam")
                .binaryLinkRendition("zoom")
                .maskChar(':', '_')
                .wrapForI18n()
                .inline().print();
    }

}
 
开发者ID:rah003,项目名称:neat-jsonfn,代码行数:27,代码来源:JsonBuilderTest.java

示例13: generateCell

import info.magnolia.context.MgnlContext; //导入依赖的package包/类
@Override
public Object generateCell(Table source, Object itemId, Object columnId) {
    Item item = source.getItem(itemId);
    Property property = (item == null) ? null : item.getItemProperty(columnId);

    if (property != null) {
        Node supplierPage = null;
        try {
            supplierPage = MgnlContext.getJCRSession(RepositoryConstants.WEBSITE).getNodeByIdentifier(property.toString());
        } catch (RepositoryException e) {
            LOGGER.error("Cannot fetch supplier page", e);
        }
        return PropertyUtil.getString(supplierPage, "title");
    }
    return null;
}
 
开发者ID:magnoliales,项目名称:magnolia-handlebars,代码行数:17,代码来源:SupplierPageColumnFormatter.java

示例14: queryForVanityUrlNode

import info.magnolia.context.MgnlContext; //导入依赖的package包/类
/**
 * Query for a vanity url node.
 *
 * @param vanityUrl vanity url from request
 * @param siteName  site name from aggegation state
 * @return first vanity url node of result or null, if nothing found
 */
public Node queryForVanityUrlNode(final String vanityUrl, final String siteName) {
    Node node = null;

    try {
        Session jcrSession = MgnlContext.getJCRSession(VanityUrlModule.WORKSPACE);
        QueryManager queryManager = jcrSession.getWorkspace().getQueryManager();
        Query query = queryManager.createQuery(QUERY, JCR_SQL2);
        query.bindValue(PN_VANITY_URL, new StringValue(vanityUrl));
        query.bindValue(PN_SITE, new StringValue(siteName));
        QueryResult queryResult = query.execute();
        NodeIterator nodes = queryResult.getNodes();
        if (nodes.hasNext()) {
            node = nodes.nextNode();
        }
    } catch (RepositoryException e) {
        LOGGER.error("Error message.", e);
    }

    return node;
}
 
开发者ID:aperto,项目名称:magnolia-vanity-url,代码行数:28,代码来源:VanityUrlService.java

示例15: getBaseCaption

import info.magnolia.context.MgnlContext; //导入依赖的package包/类
@Override
protected String getBaseCaption(DetailLocation location) {
    String baseCaption = super.getBaseCaption(location);
    String nodePath = location.getNodePath();
    try {
        Session jcrSession = MgnlContext.getJCRSession(VanityUrlModule.WORKSPACE);
        if (jcrSession.nodeExists(nodePath)) {
            Node node = jcrSession.getNode(nodePath);
            // get specific node version if needed
            if (isNotBlank(location.getVersion())) {
                node = _versionManager.getVersion(node, location.getVersion());
            }
            String vanityUrl = getString(node, PN_VANITY_URL);
            if (isNotBlank(vanityUrl)) {
                baseCaption = vanityUrl;
            }
        } else {
            baseCaption = _i18n.translate("vanityUrl.detail.caption.newVanityUrl");
        }
    } catch (RepositoryException e) {
        LOGGER.warn("Could not set sub app tab caption for item : {}", nodePath, e);
    }
    return baseCaption;
}
 
开发者ID:aperto,项目名称:magnolia-vanity-url,代码行数:25,代码来源:VanityUrlDetailSubApp.java


注:本文中的info.magnolia.context.MgnlContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。