Class ImporterUtil
- java.lang.Object
-
- com.day.cq.wcm.designimporter.util.ImporterUtil
-
public class ImporterUtil extends java.lang.Object
Utility class for Importer component related stuff
-
-
Constructor Summary
Constructors Constructor Description ImporterUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
checkCanvasPrimary(Resource resource)
Checks if the passed canvas is primary.static boolean
checkCanvasSecondary(Resource resource)
Checks if the passed canvas is secondary.static void
cleanupDanglingAscendants(Resource resource)
This method traverses up the hierarchy (uptil canvas dir) of the passed resource and deletes all nodes without children.static void
deleteCanvasArtifact(Resource resource)
Deletes the canvas artifact along with any dangling ascendants.static void
deleteCanvasArtifact(Resource resource, boolean cleanupDanglingAscendants)
Deletes the canvas artifactstatic Resource
findImporter(Resource resource)
Looks up importer in the passed page resourcestatic java.util.List<Resource>
findImporters(Resource resource)
Finds importer resources within the page resource passed.static java.util.List<Resource>
findImporters(Resource resource, boolean recursive)
Finds importer resources within the passed page resource.static Resource
getCanvas(Resource resource)
Convenience method to get canvas from the importer.static Resource
getCanvasDesign(Resource resource)
Returns the resource corresponding to the canvas designstatic Resource
getDanglingAscendantRoot(Resource resource)
For internal usestatic boolean
isCanvas(Resource resource)
Checks if the passed resource corresponds to a generated canvas node based on the following heuristics: Its parent has the resource typeImporterConstants.RESOURCE_TYPE_IMPORTER
static boolean
isImporter(Resource resource)
Checks if the passed resource corresponds to importerstatic boolean
isImporterPage(Page page)
Checks if the passed page is created using theImporterConstants.PAGE_TEMPLATE_IMPORTER_PAGE
templatestatic boolean
isImporterPage(Resource resource)
Checks if the passed resource is a, or belongs to a page created using theImporterConstants.PAGE_TEMPLATE_IMPORTER_PAGE
template
-
-
-
Method Detail
-
findImporter
public static Resource findImporter(Resource resource)
Looks up importer in the passed page resource- Parameters:
resource
- The page resource which needs to be searched for importer resource- Returns:
- The found importer resource. In case of multiple, the first found importer resource is returned
-
findImporters
public static java.util.List<Resource> findImporters(Resource resource)
Finds importer resources within the page resource passed. Doesn't look into sub pages.- Parameters:
resource
- The page resource which needs to be searched for importer resource- Returns:
- The list of importer resources found
-
findImporters
public static java.util.List<Resource> findImporters(Resource resource, boolean recursive)
Finds importer resources within the passed page resource. Looks into sub pages if the recursive param is passed true- Parameters:
resource
- The page resource which needs to be searched for importer resourcerecursive
- if true, all sub pages are looked up as well- Returns:
- The list of importer resources found
-
checkCanvasPrimary
public static boolean checkCanvasPrimary(Resource resource) throws java.lang.IllegalArgumentException
Checks if the passed canvas is primary.- Parameters:
resource
- The resource corresponding to a canvas- Returns:
- true if the passed canvas resource is primary in nature
- Throws:
java.lang.IllegalArgumentException
- When the passed resource is not a valid canvas resource
-
checkCanvasSecondary
public static boolean checkCanvasSecondary(Resource resource) throws java.lang.IllegalArgumentException
Checks if the passed canvas is secondary.Note: A design import typically results in one primary canvas accompanied by zero or more secondary canvases.
- Parameters:
resource
- The resource corresponding to a canvas- Returns:
- true if the passed canvas resource is secondary in nature
- Throws:
java.lang.IllegalArgumentException
- When the passed resource is not a valid canvas resource
-
getCanvasDesign
public static Resource getCanvasDesign(Resource resource)
Returns the resource corresponding to the canvas design- Parameters:
resource
- The resource corresponding to a canvas or its container importer component node- Returns:
- Resource corresponding to the canvas design
-
getCanvas
public static Resource getCanvas(Resource resource)
Convenience method to get canvas from the importer. If a canvas resource is passed, it's returned back- Parameters:
resource
-- Returns:
-
isCanvas
public static boolean isCanvas(Resource resource)
Checks if the passed resource corresponds to a generated canvas node based on the following heuristics:- Its parent has the resource type
ImporterConstants.RESOURCE_TYPE_IMPORTER
- Parameters:
resource
-- Returns:
- Its parent has the resource type
-
isImporter
public static boolean isImporter(Resource resource)
Checks if the passed resource corresponds to importer- Parameters:
resource
-- Returns:
-
isImporterPage
public static boolean isImporterPage(Page page)
Checks if the passed page is created using theImporterConstants.PAGE_TEMPLATE_IMPORTER_PAGE
template- Parameters:
page
-- Returns:
-
isImporterPage
public static boolean isImporterPage(Resource resource)
Checks if the passed resource is a, or belongs to a page created using theImporterConstants.PAGE_TEMPLATE_IMPORTER_PAGE
template- Parameters:
resource
- The page resource or a resource contained within the page- Returns:
-
deleteCanvasArtifact
public static void deleteCanvasArtifact(Resource resource) throws RepositoryException
Deletes the canvas artifact along with any dangling ascendants.- Parameters:
resource
- Resource corresponding to a canvas artifact like canvas design or canvas component- Throws:
RepositoryException
-
deleteCanvasArtifact
public static void deleteCanvasArtifact(Resource resource, boolean cleanupDanglingAscendants) throws RepositoryException
Deletes the canvas artifact- Parameters:
resource
- Resource corresponding to a canvas artifact like canvas design or canvas componentcleanupDanglingAscendants
- flag to indicate if ascendants left dangling, because of the deleted canvas, also need to be cleaned up.- Throws:
RepositoryException
-
cleanupDanglingAscendants
public static void cleanupDanglingAscendants(Resource resource) throws RepositoryException
This method traverses up the hierarchy (uptil canvas dir) of the passed resource and deletes all nodes without children. Since the canvas artifacts are created in convention based structured folders, deletion of artifacts requires cleanup of the folders that were created to contain the artifact.- Throws:
RepositoryException
-
getDanglingAscendantRoot
public static Resource getDanglingAscendantRoot(Resource resource) throws RepositoryException
For internal use- Throws:
RepositoryException
-
-