Class AbstractContentTypeUpgradeOperation

java.lang.Object
org.craftercms.commons.upgrade.impl.operations.AbstractUpgradeOperation<String>
All Implemented Interfaces:
org.craftercms.commons.upgrade.UpgradeOperation<String>, org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware, org.springframework.web.context.ServletContextAware
Direct Known Subclasses:
BoxRemoteAssetUpgradeOperation

public abstract class AbstractContentTypeUpgradeOperation extends AbstractContentUpgradeOperation
Base implementation of UpgradeOperation for all content-type related upgrades

Supported YAML properties:

  • includedContentTypes: (optional) list of content-types that can be handled by this operation, if left unset all content-types will be included
  • formDefinitionXpath: (optional) XPath selector to evaluate if a content-type should be handled by this operation, if left unset all content-types will be included
  • maxCacheItems: (optional) maximum number of items in the cache, can be used for performance tuning in case an upgrade needs to parse too many files in the repository. Defaults to 200
Author:
joseross
  • Field Details

    • CONFIG_KEY_CONTENT_TYPES

      public static final String CONFIG_KEY_CONTENT_TYPES
      See Also:
    • CONFIG_KEY_FORM_DEFINITION

      public static final String CONFIG_KEY_FORM_DEFINITION
      See Also:
    • CONFIG_KEY_MAX_ITEMS

      public static final String CONFIG_KEY_MAX_ITEMS
      See Also:
    • NAME_PLACEHOLDER

      public static final String NAME_PLACEHOLDER
      See Also:
    • DEFAULT_MAX_ITEMS

      public static final int DEFAULT_MAX_ITEMS
      See Also:
    • includedContentTypes

      protected List<String> includedContentTypes
      List of content-types that can be handled by this operation (optional)
    • formDefinitionXpath

      protected String formDefinitionXpath
      XPath to evaluate if a content-type can be handled by this operation (optional)
    • contentTypeXpath

      protected String contentTypeXpath
      XPath to query the content-type of item descriptors
    • formDefinitionTemplate

      protected String formDefinitionTemplate
      Path template to find the form-definition.xml file for a content-type
    • cache

      protected com.google.common.cache.Cache<Path,Document> cache
      Cache used to avoid parsing the same file multiple times during the execution of this operation
    • factory

      protected DocumentBuilderFactory factory
    • xPathFactory

      protected XPathFactory xPathFactory
    • transformerFactory

      protected TransformerFactory transformerFactory
  • Constructor Details

    • AbstractContentTypeUpgradeOperation

      public AbstractContentTypeUpgradeOperation(StudioConfiguration studioConfiguration, String contentTypeXpath, String formDefinitionTemplate)
  • Method Details

    • doInit

      protected void doInit(org.apache.commons.configuration2.HierarchicalConfiguration config)
      Overrides:
      doInit in class AbstractContentUpgradeOperation
    • shouldBeUpdated

      protected boolean shouldBeUpdated(StudioUpgradeContext context, Path file) throws org.craftercms.commons.upgrade.exception.UpgradeException
      Description copied from class: AbstractContentUpgradeOperation
      Indicates if the given file should be updated by this class
      Specified by:
      shouldBeUpdated in class AbstractContentUpgradeOperation
      Parameters:
      context - the current upgrade context
      file - the file to check
      Returns:
      true if the file should be updated
      Throws:
      org.craftercms.commons.upgrade.exception.UpgradeException - if there is any error checking the file
    • loadDocument

      protected Document loadDocument(Path file) throws ExecutionException
      Parses the given XML file
      Parameters:
      file - the file to parse
      Returns:
      the parsed file
      Throws:
      ExecutionException - if there is any error parsing the file
    • getFormDefinition

      protected Path getFormDefinition(StudioUpgradeContext context, String contentTypeName)
      Finds the form-definition.xml five for the given content-type
      Parameters:
      context - the current upgrade context
      contentTypeName - the content-type name
      Returns:
      the form definition file
    • select

      protected Object select(Object source, String xpath, QName type) throws XPathExpressionException
      Evaluates a XPath selector on the given object
      Parameters:
      source - the object to evaluate
      xpath - the selector to evaluate
      type - the type to return
      Returns:
      the evaluation result
      Throws:
      XPathExpressionException - if there is any error evaluating the selector
    • writeFile

      protected void writeFile(Path file, Document document) throws org.craftercms.commons.upgrade.exception.UpgradeException
      Writes an XML file to the file system without committing any changes in the repository
      Parameters:
      file - the file to write
      document - the XML document to write
      Throws:
      org.craftercms.commons.upgrade.exception.UpgradeException - if there is any error writing the file