Example usage for org.apache.commons.lang StringUtils removeStart

List of usage examples for org.apache.commons.lang StringUtils removeStart

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils removeStart.

Prototype

public static String removeStart(String str, String remove) 

Source Link

Document

Removes a substring only if it is at the begining of a source string, otherwise returns the source string.

Usage

From source file:org.onehippo.forge.content.exim.repository.jaxrs.ContentEximExportService.java

private int exportBinaries(Logger procLogger, ProcessStatus processStatus, ExecutionParams params,
        DefaultBinaryExportTask exportTask, Result result, int batchCount, FileObject baseFolder)
        throws Exception {
    final String baseFolderUrlPrefix = baseFolder.getURL().toString() + "/";
    final AntPathMatcher pathMatcher = new AntPathMatcher();

    for (ResultItem item : result.getItems()) {
        if (isStopRequested(baseFolder)) {
            procLogger.info("Stop requested by file at {}/{}", baseFolder.getName().getPath(),
                    STOP_REQUEST_FILE_REL_PATH);
            break;
        }/* w w w  . j  a v a  2  s  .c  o m*/

        ContentMigrationRecord record = null;

        try {
            String handlePath = item.getPath();

            if (!isBinaryPathIncluded(pathMatcher, params, handlePath)) {
                continue;
            }

            if (!HippoNodeUtils.isBinaryPath(handlePath)) {
                continue;
            }

            if (!exportTask.getDocumentManager().getSession().nodeExists(handlePath)) {
                continue;
            }

            Node handle = exportTask.getDocumentManager().getSession().getNode(handlePath);
            Node variant = HippoNodeUtils.getFirstVariantNode(handle);

            if (variant == null) {
                continue;
            }

            String variantPath = variant.getPath();
            record = exportTask.beginRecord(variant.getIdentifier(), variantPath);

            ContentNode contentNode = exportTask.exportBinarySetToContentNode(variant);
            record.setProcessed(true);

            ContentNodeUtils.replaceDocbasesByPaths(exportTask.getDocumentManager().getSession(), contentNode,
                    ContentNodeUtils.MIRROR_DOCBASES_XPATH);

            Set<String> docbasePropNames = params.getDocbasePropNames();
            if (CollectionUtils.isNotEmpty(docbasePropNames)) {
                for (String docbasePropName : docbasePropNames) {
                    ContentNodeUtils.replaceDocbasePropertiesByPaths(
                            exportTask.getDocumentManager().getSession(), contentNode,
                            "properties[@itemName='" + docbasePropName + "']");
                }
            }

            ContentNodeUtils.removeUrlPrefixInJcrDataValues(contentNode, baseFolderUrlPrefix);

            applyTagContentProperties(contentNode, params.getBinaryTags());

            String relPath = StringUtils
                    .removeStart(ContentPathUtils.removeIndexNotationInNodePath(variantPath), "/");
            FileObject file = baseFolder.resolveFile(relPath + ".json");
            record.setAttribute("file", file.getName().getPath());
            exportTask.writeContentNodeToJsonFile(contentNode, file);

            procLogger.debug("Exported document from {} to {}.", handlePath, file.getName().getPath());
            record.setSucceeded(true);
        } catch (Exception e) {
            procLogger.error("Failed to process record: {}", record, e);
            if (record != null) {
                record.setErrorMessage(e.toString());
            }
        } finally {
            if (record != null) {
                exportTask.endRecord();
                result.incrementTotalBinaryCount();
                if (record.isSucceeded()) {
                    result.incrementSucceededBinaryCount();
                } else {
                    result.incrementFailedBinaryCount();
                }
                if (processStatus != null) {
                    processStatus.setProgress(result.getProgress());
                }
            }
            ++batchCount;
            if (batchCount % params.getBatchSize() == 0) {
                exportTask.getDocumentManager().getSession().refresh(false);
                if (params.getThrottle() > 0) {
                    Thread.sleep(params.getThrottle());
                }
            }
        }
    }

    exportTask.getDocumentManager().getSession().refresh(false);

    return batchCount;
}

From source file:org.onehippo.forge.content.exim.repository.jaxrs.ContentEximExportService.java

private int exportDocuments(Logger procLogger, ProcessStatus processStatus, ExecutionParams params,
        WorkflowDocumentVariantExportTask exportTask, Result result, int batchCount, FileObject baseFolder,
        Set<String> referredBinaryPaths) throws Exception {
    final String baseFolderUrlPrefix = baseFolder.getURL().toString() + "/";
    final AntPathMatcher pathMatcher = new AntPathMatcher();

    for (ResultItem item : result.getItems()) {
        if (isStopRequested(baseFolder)) {
            procLogger.info("Stop requested by file at {}/{}", baseFolder.getName().getPath(),
                    STOP_REQUEST_FILE_REL_PATH);
            break;
        }//from www . ja  v a  2  s  .  co m

        ContentMigrationRecord record = null;

        try {
            String handlePath = item.getPath();

            if (!isDocumentPathIncluded(pathMatcher, params, handlePath)) {
                continue;
            }

            if (!HippoNodeUtils.isDocumentPath(handlePath)) {
                continue;
            }

            if (!exportTask.getDocumentManager().getSession().nodeExists(handlePath)) {
                continue;
            }

            Node handle = exportTask.getDocumentManager().getSession().getNode(handlePath);
            Map<String, Node> variantsMap = HippoNodeUtils.getDocumentVariantsMap(handle);
            Node variant = variantsMap.get(HippoStdNodeType.PUBLISHED);
            if (variant == null) {
                variant = variantsMap.get(HippoStdNodeType.UNPUBLISHED);
            }

            if (variant == null) {
                continue;
            }

            String variantPath = variant.getPath();
            record = exportTask.beginRecord(variant.getIdentifier(), variantPath);

            Document document = new Document(variant.getIdentifier());
            ContentNode contentNode = exportTask.exportVariantToContentNode(document);
            record.setProcessed(true);

            ContentNodeUtils.replaceDocbasesByPaths(exportTask.getDocumentManager().getSession(), contentNode,
                    ContentNodeUtils.MIRROR_DOCBASES_XPATH, referredBinaryPaths);

            Set<String> docbasePropNames = params.getDocbasePropNames();
            if (CollectionUtils.isNotEmpty(docbasePropNames)) {
                for (String docbasePropName : docbasePropNames) {
                    ContentNodeUtils.replaceDocbasePropertiesByPaths(
                            exportTask.getDocumentManager().getSession(), contentNode,
                            "properties[@itemName='" + docbasePropName + "']");
                }
            }

            ContentNodeUtils.removeUrlPrefixInJcrDataValues(contentNode, baseFolderUrlPrefix);

            applyTagContentProperties(contentNode, params.getDocumentTags());

            String relPath = StringUtils
                    .removeStart(ContentPathUtils.removeIndexNotationInNodePath(variantPath), "/");
            FileObject file = baseFolder.resolveFile(relPath + ".json");
            record.setAttribute("file", file.getName().getPath());

            exportTask.writeContentNodeToJsonFile(contentNode, file);
            procLogger.debug("Exported document from {} to {}.", handlePath, file.getName().getPath());
            record.setSucceeded(true);
        } catch (Exception e) {
            procLogger.error("Failed to process record: {}", record, e);
            if (record != null) {
                record.setErrorMessage(e.toString());
            }
        } finally {
            if (record != null) {
                exportTask.endRecord();
                result.incrementTotalDocumentCount();
                if (record.isSucceeded()) {
                    result.incrementSucceededDocumentCount();
                } else {
                    result.incrementFailedDocumentCount();
                }
                if (processStatus != null) {
                    processStatus.setProgress(result.getProgress());
                }
            }
            ++batchCount;
            if (batchCount % params.getBatchSize() == 0) {
                exportTask.getDocumentManager().getSession().refresh(false);
                if (params.getThrottle() > 0) {
                    Thread.sleep(params.getThrottle());
                }
            }
        }
    }

    exportTask.getDocumentManager().getSession().refresh(false);

    return batchCount;
}

From source file:org.onehippo.forge.content.pojo.binder.jcr.DefaultJcrContentNodeBinderTest.java

@Test
public void testBindNewsDocument() throws Exception {
    MockNode newsFolderNode = getRootNode().getNode(StringUtils.removeStart(NEWS_DOC_FOLDER_PATH, "/"));
    Node handle = createHippoDocumentHandleNode(newsFolderNode, "news-harvest", "News Harvest", "en");
    binder.bind(handle, newsContentNode);

    assertEquals("news-harvest", handle.getName());
    assertEquals("hippo:handle", handle.getPrimaryNodeType().getName());
    assertTrue(handle.isNodeType("mix:referenceable"));
    assertTrue(handle.isNodeType("hippo:translated"));

    assertTrue(handle.hasNode("hippo:translation"));
    Node translationNode = handle.getNode("hippo:translation");
    assertEquals("hippo:translation", translationNode.getPrimaryNodeType().getName());
    assertEquals("en", translationNode.getProperty("hippo:language").getString());
    assertFalse(translationNode.getProperty("hippo:language").isMultiple());
    assertEquals("News Harvest", translationNode.getProperty("hippo:message").getString());
    assertFalse(translationNode.getProperty("hippo:message").isMultiple());

    assertTrue(handle.hasNode(handle.getName()));
    Node variant = handle.getNode(handle.getName());
    assertEquals("news-harvest", variant.getName());
    assertEquals("myhippoproject:newsdocument", variant.getPrimaryNodeType().getName());
    assertTrue(variant.isNodeType("mix:referenceable"));
    assertEquals("news", variant.getProperty("myhippoproject:documenttype").getString());
    assertFalse(variant.getProperty("myhippoproject:documenttype").isMultiple());
    assertEquals("Lorem ipsum dolor sit amet", variant.getProperty("myhippoproject:introduction").getString());
    assertFalse(variant.getProperty("myhippoproject:introduction").isMultiple());
    assertEquals("admin", variant.getProperty("hippostdpubwf:lastModifiedBy").getString());
    assertFalse(variant.getProperty("hippostdpubwf:lastModifiedBy").isMultiple());
    assertEquals("news", variant.getProperty("myhippoproject:documenttype").getString());
    assertFalse(variant.getProperty("myhippoproject:documenttype").isMultiple());
    assertEquals("en", variant.getProperty("hippotranslation:locale").getString());
    assertFalse(variant.getProperty("hippotranslation:locale").isMultiple());
    assertEquals("live", variant.getProperty("hippostd:stateSummary").getString());
    assertFalse(variant.getProperty("hippostd:stateSummary").isMultiple());
    assertEquals("admin", variant.getProperty("hippostd:holder").getString());
    assertFalse(variant.getProperty("hippostd:holder").isMultiple());
    assertEquals("published", variant.getProperty("hippostd:state").getString());
    assertFalse(variant.getProperty("hippostd:state").isMultiple());
    assertEquals("", variant.getProperty("myhippoproject:source").getString());
    assertFalse(variant.getProperty("myhippoproject:source").isMultiple());
    assertEquals("live,preview",
            StringUtils.join(JcrUtils.getMultipleStringProperty(variant, "hippo:availability", null), ","));
    assertTrue(variant.getProperty("hippo:availability").isMultiple());
    assertEquals("News Harvest", variant.getProperty("myhippoproject:title").getString());
    assertFalse(variant.getProperty("myhippoproject:title").isMultiple());
    assertEquals("Rome", variant.getProperty("myhippoproject:location").getString());
    assertFalse(variant.getProperty("myhippoproject:location").isMultiple());
    assertEquals(ISO8601.parse("2013-11-12T14:31:00.000+01:00"),
            variant.getProperty("hippostdpubwf:publicationDate").getDate());
    assertFalse(variant.getProperty("hippostdpubwf:publicationDate").isMultiple());
    assertEquals("046dc195-9720-4860-8512-6a9099e31b10",
            variant.getProperty("hippotranslation:id").getString());
    assertFalse(variant.getProperty("hippotranslation:id").isMultiple());
    assertEquals(ISO8601.parse("2013-11-12T14:31:00.000+01:00"),
            variant.getProperty("hippostdpubwf:lastModificationDate").getDate());
    assertFalse(variant.getProperty("hippostdpubwf:lastModificationDate").isMultiple());
    assertEquals("Alfred Anonymous", variant.getProperty("myhippoproject:author").getString());
    assertFalse(variant.getProperty("myhippoproject:author").isMultiple());
    assertEquals("admin", variant.getProperty("hippostdpubwf:createdBy").getString());
    assertFalse(variant.getProperty("hippostdpubwf:createdBy").isMultiple());
    assertEquals(ISO8601.parse("2015-11-12T05:31:00.000-05:00"),
            variant.getProperty("myhippoproject:date").getDate());
    assertFalse(variant.getProperty("myhippoproject:date").isMultiple());
    assertEquals(ISO8601.parse("2013-11-12T14:31:00.000+01:00"),
            variant.getProperty("hippostdpubwf:creationDate").getDate());
    assertFalse(variant.getProperty("hippostdpubwf:creationDate").isMultiple());

    assertTrue(variant.hasNode("myhippoproject:content"));
    Node contentNode = variant.getNode("myhippoproject:content");
    assertEquals("hippostd:html", contentNode.getPrimaryNodeType().getName());
    assertEquals("<html><body><p>Lorem ipsum dolor sit amet</p></body></html>",
            contentNode.getProperty("hippostd:content").getString());
    assertFalse(contentNode.getProperty("hippostd:content").isMultiple());

    assertTrue(variant.hasNode("myhippoproject:image"));
    Node imageLinkNode = variant.getNode("myhippoproject:image");
    assertEquals("hippogallerypicker:imagelink", imageLinkNode.getPrimaryNodeType().getName());
    assertTrue(!imageLinkNode.hasProperty("hippo:facets")
            || imageLinkNode.getProperty("hippo:facets").getValues().length == 0);
    assertTrue(!imageLinkNode.hasProperty("hippo:values")
            || imageLinkNode.getProperty("hippo:values").getValues().length == 0);
    assertEquals("/content/gallery/folderctxmenusdemo/samples/viognier-grapes-188185_640.jpg",
            imageLinkNode.getProperty("hippo:docbase").getString());
    assertTrue(!imageLinkNode.hasProperty("hippo:modes")
            || imageLinkNode.getProperty("hippo:modes").getValues().length == 0);
}

From source file:org.onehippo.forge.content.pojo.binder.jcr.DefaultJcrContentNodeBinderTest.java

@Test
public void testBindBinaryContent() throws Exception {
    MockNode newsGalleryFolderNode = getRootNode()
            .getNode(StringUtils.removeStart(NEWS_GALLERY_FOLDER_PATH, "/"));
    Node handle = createHippoGalleryHandleNode(newsGalleryFolderNode, "animal-2883_640.jpg");
    // TODO/*from  w w w .java  2s .c  o m*/
}

From source file:org.onehippo.forge.content.pojo.mapper.jcr.DefaultJcrContentNodeMapperTest.java

@Test
public void testMapDocumentVariant() throws Exception {
    Node liveVariantNode = getRootNode()
            .getNode(StringUtils.removeStart(NEWS1_DOC_HANDLE_PATH + "/news1", "/"));
    Node previewVariantNode = getRootNode()
            .getNode(StringUtils.removeStart(NEWS1_DOC_HANDLE_PATH + "/news1[2]", "/"));

    ContentNode liveContentNode = mapper.map(liveVariantNode);
    assertNotNull(liveContentNode);/*from  w w w .ja v a 2  s  .c om*/
    assertDocumentVariantContentNode(liveContentNode, HippoStdNodeType.PUBLISHED);

    ContentNode previewContentNode = mapper.map(previewVariantNode);
    assertNotNull(previewContentNode);
    assertDocumentVariantContentNode(previewContentNode, HippoStdNodeType.UNPUBLISHED);
}

From source file:org.onehippo.forge.content.pojo.mapper.jcr.DefaultJcrContentNodeMapperTest.java

@Test
public void testMapDocumentHandle() throws Exception {
    Node handleNode = getRootNode().getNode(StringUtils.removeStart(NEWS1_DOC_HANDLE_PATH, "/"));

    ContentNode handleContentNode = mapper.map(handleNode);
    assertEquals(HippoNodeType.NT_HANDLE, handleContentNode.getPrimaryType());

    ContentNode translationContentNode = handleContentNode.getNode(HippoNodeType.HIPPO_TRANSLATION);
    assertEquals(HippoNodeType.NT_TRANSLATION, translationContentNode.getPrimaryType());
    assertEquals("en", translationContentNode.getProperty(HippoNodeType.HIPPO_LANGUAGE).getValue());
    assertEquals("News 1", translationContentNode.getProperty(HippoNodeType.HIPPO_MESSAGE).getValue());

    assertEquals(translationContentNode,
            handleContentNode.queryObjectByXPath("nodes[@primaryType='" + HippoNodeType.NT_TRANSLATION + "']"));

    List<?> variantNodeObjects = handleContentNode
            .queryObjectsByXPath("nodes[properties[@itemName='hippostd:state']]");
    assertEquals(2, variantNodeObjects.size());

    ContentNode liveContentNode = (ContentNode) handleContentNode
            .queryObjectByXPath("nodes[properties[@itemName='hippostd:state']/value='published']");
    assertNotNull(liveContentNode);/*from www.j av a2 s  . com*/
    assertDocumentVariantContentNode(liveContentNode, HippoStdNodeType.PUBLISHED);

    ContentNode previewContentNode = (ContentNode) handleContentNode
            .queryObjectByXPath("nodes[properties[@itemName='hippostd:state']/value='unpublished']");
    assertNotNull(previewContentNode);
    assertDocumentVariantContentNode(previewContentNode, HippoStdNodeType.UNPUBLISHED);
}

From source file:org.onehippo.forge.content.pojo.mapper.jcr.DefaultJcrContentNodeMapperTest.java

@Test
public void testMapDocumentHandleWithPreviewOnly() throws Exception {
    Node handleNode = getRootNode().getNode(StringUtils.removeStart(NEWS1_DOC_HANDLE_PATH, "/"));

    ContentNode handleContentNode = mapper.map(handleNode, nonLiveVariantNodeFilter);
    assertEquals(HippoNodeType.NT_HANDLE, handleContentNode.getPrimaryType());

    List<?> variantNodeObjects = handleContentNode
            .queryObjectsByXPath("nodes[properties[@itemName='hippostd:state']]");
    assertEquals(1, variantNodeObjects.size());

    ContentNode previewContentNode = (ContentNode) handleContentNode
            .queryObjectByXPath("nodes[properties[@itemName='hippostd:state']/value='unpublished']");
    assertDocumentVariantContentNode(previewContentNode, HippoStdNodeType.UNPUBLISHED);
}

From source file:org.onehippo.forge.content.pojo.mapper.jcr.DefaultJcrContentNodeMapperTest.java

@Test
public void testMapDocumentFolder() throws Exception {
    Node handleNode = getRootNode().getNode(StringUtils.removeStart(NEWS1_DOC_HANDLE_PATH, "/"));
    Node folderNode = handleNode.getParent();

    ContentNode folderContentNode = mapper.map(folderNode);
    assertEquals(HippoStdNodeType.NT_FOLDER, folderContentNode.getPrimaryType());
    assertTrue(// ww  w  . ja va2  s.  c om
            folderContentNode.getProperty("hippostd:foldertype").getValues().contains("new-translated-folder"));
    assertTrue(folderContentNode.getProperty("hippostd:foldertype").getValues().contains("new-document"));

    ContentNode translationContentNode = folderContentNode.getNode(HippoNodeType.HIPPO_TRANSLATION);
    assertEquals(HippoNodeType.NT_TRANSLATION, translationContentNode.getPrimaryType());
    assertEquals("en", translationContentNode.getProperty(HippoNodeType.HIPPO_LANGUAGE).getValue());
    assertEquals("2015", translationContentNode.getProperty(HippoNodeType.HIPPO_MESSAGE).getValue());

    ContentNode handleContentNode = folderContentNode.getNode("news1");
    assertEquals(HippoNodeType.NT_HANDLE, handleContentNode.getPrimaryType());

    translationContentNode = handleContentNode.getNode(HippoNodeType.HIPPO_TRANSLATION);
    assertEquals(HippoNodeType.NT_TRANSLATION, translationContentNode.getPrimaryType());
    assertEquals("en", translationContentNode.getProperty(HippoNodeType.HIPPO_LANGUAGE).getValue());
    assertEquals("News 1", translationContentNode.getProperty(HippoNodeType.HIPPO_MESSAGE).getValue());

    List<?> variantNodeObjects = handleContentNode
            .queryObjectsByXPath("nodes[properties[@itemName='hippostd:state']]");
    assertEquals(2, variantNodeObjects.size());

    ContentNode liveContentNode = (ContentNode) handleContentNode
            .queryObjectByXPath("nodes[properties[@itemName='hippostd:state']/value='published']");
    assertNotNull(liveContentNode);
    assertDocumentVariantContentNode(liveContentNode, HippoStdNodeType.PUBLISHED);

    ContentNode previewContentNode = (ContentNode) handleContentNode
            .queryObjectByXPath("nodes[properties[@itemName='hippostd:state']/value='unpublished']");
    assertNotNull(previewContentNode);
    assertDocumentVariantContentNode(previewContentNode, HippoStdNodeType.UNPUBLISHED);
}

From source file:org.onehippo.forge.content.pojo.mapper.jcr.DefaultJcrContentNodeMapperTest.java

private void assertDocumentVariantContentNode(ContentNode varContentNode, String state)
        throws RepositoryException {
    log.debug("===== varContentNode: {}", ReflectionToStringBuilder.toString(varContentNode));

    for (ContentProperty contentProp : varContentNode.getProperties()) {
        log.debug("----- contentProp: {}", ReflectionToStringBuilder.toString(contentProp));
    }// w  w w.  j ava2  s  .  c o m

    if (HippoStdNodeType.PUBLISHED.equals(state)) {
        assertEquals(HippoStdNodeType.PUBLISHED,
                varContentNode.getProperty(HippoStdNodeType.HIPPOSTD_STATE).getValue());
        assertTrue(varContentNode.getProperty(HippoNodeType.HIPPO_AVAILABILITY).getValues().contains("live"));
        assertTrue(
                varContentNode.getProperty(HippoNodeType.HIPPO_AVAILABILITY).getValues().contains("preview"));
        assertEquals("live", varContentNode.getProperty(HippoStdNodeType.HIPPOSTD_STATESUMMARY).getValue());
    } else if (HippoStdNodeType.UNPUBLISHED.equals(state)) {
        assertEquals(HippoStdNodeType.UNPUBLISHED,
                varContentNode.getProperty(HippoStdNodeType.HIPPOSTD_STATE).getValue());
        assertFalse(varContentNode.getProperty(HippoNodeType.HIPPO_AVAILABILITY).getValues().contains("live"));
        assertTrue(
                varContentNode.getProperty(HippoNodeType.HIPPO_AVAILABILITY).getValues().contains("preview"));
        assertEquals("changed", varContentNode.getProperty(HippoStdNodeType.HIPPOSTD_STATESUMMARY).getValue());
    }

    assertEquals(NEWS_NODE_TYPE, varContentNode.getPrimaryType());
    assertEquals(DOC_VARIANT_NODE_MIXIN_TYPES, varContentNode.getMixinTypes());

    assertEquals(NEWS_TITLE_PROP_VALUE, varContentNode.getProperty(NEWS_TITLE_PROP_NAME).getValue());
    assertEquals(NEWS_DATE_PROP_STRING_VALUE, varContentNode.getProperty(NEWS_DATE_PROP_NAME).getValue());
    assertEquals(NEWS_SUMMARY_PROP_VALUE, varContentNode.getProperty(NEWS_SUMMARY_PROP_NAME).getValue());

    ContentNode bodyContentNode = varContentNode.getNode(NEWS_BODY_NODE_NAME);
    assertNotNull(bodyContentNode);
    log.debug("bodyContentNode: {}", ReflectionToStringBuilder.toString(bodyContentNode));

    assertEquals("hippostd:html", bodyContentNode.getPrimaryType());
    assertEquals(NEWS_BODY_CONTENT_VALUE,
            bodyContentNode.getProperty(HippoStdNodeType.HIPPOSTD_CONTENT).getValue());

    ContentNode imageLinkContentNode = varContentNode.getNode(NEWS_IMAGE_LINK_NODE_NAME);
    assertNotNull(imageLinkContentNode);
    log.debug("imageLinkContentNode: {}", ReflectionToStringBuilder.toString(imageLinkContentNode));

    assertEquals("hippogallerypicker:imagelink", imageLinkContentNode.getPrimaryType());
    Node newsImageSetHandleNode = getRootNode()
            .getNode(StringUtils.removeStart(NEWS1_IMAGE_SET_HANDLE_PATH, "/"));
    assertEquals(newsImageSetHandleNode.getIdentifier(),
            imageLinkContentNode.getProperty(HippoNodeType.HIPPO_DOCBASE).getValue());
}

From source file:org.onehippo.forge.folderctxmenus.common.FolderCopyTask.java

/**
 * Search all the link holder nodes having hippo:docbase property under destFolderNode
 * and reset the hippo:docbase properties to the copied nodes under destFolderNode
 * by comparing the relative paths with the corresponding nodes under the sourceFolderNode.
 *///  w  w  w.  j  a va2s .co  m
protected void resetHippoDocBaseLinks() {
    String destFolderNodePath = null;

    try {
        destFolderNodePath = getDestFolderNode().getPath();

        JcrTraverseUtils.traverseNodes(getDestFolderNode(), new NodeTraverser() {
            private String sourceFolderBase = getSourceFolderNode().getPath() + "/";

            @Override
            public boolean isAcceptable(Node node) throws RepositoryException {
                return node.isNodeType("hippo:mirror") && node.hasProperty("hippo:docbase");
            }

            @Override
            public boolean isTraversable(Node node) throws RepositoryException {
                return !node.isNodeType("hippo:mirror");
            }

            @Override
            public void accept(Node destLinkHolderNode) throws RepositoryException {
                String destLinkDocBase = JcrUtils.getStringProperty(destLinkHolderNode, "hippo:docbase", null);

                if (StringUtils.isNotBlank(destLinkDocBase)) {
                    try {
                        Node sourceLinkedNode = getSession().getNodeByIdentifier(destLinkDocBase);

                        if (StringUtils.startsWith(sourceLinkedNode.getPath(), sourceFolderBase)) {
                            String sourceLinkedNodeRelPath = StringUtils.removeStart(sourceLinkedNode.getPath(),
                                    sourceFolderBase);
                            Node destLinkedNode = JcrUtils.getNodeIfExists(getDestFolderNode(),
                                    sourceLinkedNodeRelPath);

                            if (destLinkedNode != null) {
                                getLogger().info("Updating the linked node at '{}'.",
                                        destLinkHolderNode.getPath());
                                destLinkHolderNode.setProperty("hippo:docbase", destLinkedNode.getIdentifier());
                            }
                        }
                    } catch (ItemNotFoundException ignore) {
                    }
                }
            }
        });
    } catch (RepositoryException e) {
        getLogger().error("Failed to reset link Nodes under destination folder: {}.", destFolderNodePath, e);
    }
}