Class Archivers
- java.lang.Object
-
- org.ametys.plugins.contentio.archive.Archivers
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classArchivers.AmetysObjectNotImportedExceptionException indicating an Ametys Object cannot be imported
-
Field Summary
Fields Modifier and Type Field Description (package private) static String__BINARY_ATTRIBUTES_FOLDER_NAME(package private) static String__FILE_ATTRIBUTES_FOLDER_NAMEprivate static Properties__OUTPUT_FORMAT_PROPERTIES(package private) static String__RICH_TEXT_ATTACHMENTS_FOLDER_NAMEprivate static SAXTransformerFactory__transformerFactorystatic StringWARN_MESSAGE_ROOT_HAS_PENDING_CHANGESThe warning message for a root ofArchiverwhich stil has pending change while we do a unitary save on every imported object.
-
Constructor Summary
Constructors Modifier Constructor Description privateArchivers()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static void_exportResource(String dataPath, NamedResource resource, ZipOutputStream zos, String prefix)private static void_exportRichText(String richTextDataPath, RichText richText, ZipOutputStream zos, String prefix)static voidexportAcl(Node node, ZipOutputStream zos, String path)Export ACL sub-nodestatic voidexportBinaries(ModelAwareDataHolder dataHolder, ZipOutputStream zos, String path)Export the given data holder's binariesstatic voidexportFiles(ModelAwareDataHolder dataHolder, ZipOutputStream zos, String path)Export the given data holder's filesstatic voidexportRichTexts(ModelAwareDataHolder dataHolder, ZipOutputStream zos, String path)Export the attachments of the given data holder's rich textsstatic StringgetFolderPathFromDataPath(String dataPath)Retrieves a folder path from a data path.static StringgetHashedPath(String name)Computes a hashed path from an object name.static SAXTransformerFactorygetSaxTransformerFactory()Gets aSAXTransformerFactorystatic voidimportAcl(Node node, Path zipPath, Merger merger, String zipEntryPath, org.slf4j.Logger logger)Import ACL sub-nodestatic TransformerHandlernewTransformerHandler()Get a TransformerHandler object that can process SAXContentHandler events into a Resultstatic NodereplaceNodeWithDesiredUuid(Node srcNode, String uuid)Replace the given JCR Node by a copy of it with the given UUID.static voidsetStandardOutputProperties(TransformerHandler transformerHandler)Sets standard output properties to the transformer of the given handler, such as encoding and indentation.static voidunitarySave(Node ametysObjectNode, org.slf4j.Logger logger)Save the pending changes brought to this node associated to anAmetysObject
If the save failed, it is logged in ERROR level and the changes are discarded.static StringxpathEvalNonEmpty(String xPath, Node domNode)Evaluates a non-empty XPath query.
-
-
-
Field Detail
-
WARN_MESSAGE_ROOT_HAS_PENDING_CHANGES
public static final String WARN_MESSAGE_ROOT_HAS_PENDING_CHANGES
The warning message for a root ofArchiverwhich stil has pending change while we do a unitary save on every imported object.- See Also:
- Constant Field Values
-
__BINARY_ATTRIBUTES_FOLDER_NAME
static final String __BINARY_ATTRIBUTES_FOLDER_NAME
- See Also:
- Constant Field Values
-
__FILE_ATTRIBUTES_FOLDER_NAME
static final String __FILE_ATTRIBUTES_FOLDER_NAME
- See Also:
- Constant Field Values
-
__RICH_TEXT_ATTACHMENTS_FOLDER_NAME
static final String __RICH_TEXT_ATTACHMENTS_FOLDER_NAME
- See Also:
- Constant Field Values
-
__OUTPUT_FORMAT_PROPERTIES
private static final Properties __OUTPUT_FORMAT_PROPERTIES
-
__transformerFactory
private static SAXTransformerFactory __transformerFactory
-
-
Constructor Detail
-
Archivers
private Archivers()
-
-
Method Detail
-
getSaxTransformerFactory
public static SAXTransformerFactory getSaxTransformerFactory()
Gets aSAXTransformerFactory- Returns:
- a
SAXTransformerFactory
-
newTransformerHandler
public static TransformerHandler newTransformerHandler() throws TransformerConfigurationException
Get a TransformerHandler object that can process SAXContentHandler events into a Result- Returns:
- A non-null reference to a TransformerHandler, that maybe used as a ContentHandler for SAX parse events.
- Throws:
TransformerConfigurationException- If for some reason theTransformerHandler cannot be created.
-
setStandardOutputProperties
public static void setStandardOutputProperties(TransformerHandler transformerHandler)
Sets standard output properties to the transformer of the given handler, such as encoding and indentation.- Parameters:
transformerHandler- The transformer handler
-
getHashedPath
public static String getHashedPath(String name)
Computes a hashed path from an object name.- Parameters:
name- the object name.- Returns:
- a hashed path.
-
exportAcl
public static void exportAcl(Node node, ZipOutputStream zos, String path) throws RepositoryException, IOException
Export ACL sub-node- Parameters:
node- The JCR nodezos- the ZIP OutputStream.path- the zip entry path- Throws:
RepositoryException- if an error occursIOException- if an I/O error occurs
-
importAcl
public static void importAcl(Node node, Path zipPath, Merger merger, String zipEntryPath, org.slf4j.Logger logger) throws RepositoryException, IOException
Import ACL sub-node- Parameters:
node- The JCR nodezipPath- the input zip pathmerger- TheMergerzipEntryPath- the zip entry pathlogger- The logger- Throws:
RepositoryException- if an error occursIOException- if an I/O error occurs
-
xpathEvalNonEmpty
public static String xpathEvalNonEmpty(String xPath, Node domNode) throws Archivers.AmetysObjectNotImportedException, TransformerException
Evaluates a non-empty XPath query. If the result is empty, anArchivers.AmetysObjectNotImportedExceptionis thrown.- Parameters:
xPath- The XPath querydomNode- The DOM node- Returns:
- The evaluation as String
- Throws:
Archivers.AmetysObjectNotImportedException- If the result is emptyTransformerException- if an evaluation error occured
-
replaceNodeWithDesiredUuid
public static Node replaceNodeWithDesiredUuid(Node srcNode, String uuid) throws RepositoryException
Replace the given JCR Node by a copy of it with the given UUID. The source JCR Node is removed.- Parameters:
srcNode- The source JCR Nodeuuid- The desired UUID- Returns:
- The JCR Node with the desired UUID
- Throws:
RepositoryException- if an error occurs
-
unitarySave
public static void unitarySave(Node ametysObjectNode, org.slf4j.Logger logger) throws Archivers.AmetysObjectNotImportedException, ImportGlobalFailException
Save the pending changes brought to this node associated to anAmetysObject
If the save failed, it is logged in ERROR level and the changes are discarded.- Parameters:
ametysObjectNode- The nodelogger- The logger- Throws:
Archivers.AmetysObjectNotImportedException- If the save failedImportGlobalFailException- If a severe error occured and the global import process must be stopped
-
exportRichTexts
public static void exportRichTexts(ModelAwareDataHolder dataHolder, ZipOutputStream zos, String path) throws IOException
Export the attachments of the given data holder's rich texts- Parameters:
dataHolder- The data holderzos- TheZipOutputStreamwhere to export the attachmentspath- The path of the folder used to export the attachments- Throws:
IOException- if an error occurs while exporting the attachments
-
_exportRichText
private static void _exportRichText(String richTextDataPath, RichText richText, ZipOutputStream zos, String prefix) throws IOException
- Throws:
IOException
-
exportBinaries
public static void exportBinaries(ModelAwareDataHolder dataHolder, ZipOutputStream zos, String path) throws IOException
Export the given data holder's binaries- Parameters:
dataHolder- The data holderzos- TheZipOutputStreamwhere to export the binariespath- The path of the folder used to export the binaries- Throws:
IOException- if an error occurs while exporting the binaries
-
exportFiles
public static void exportFiles(ModelAwareDataHolder dataHolder, ZipOutputStream zos, String path) throws IOException
Export the given data holder's files- Parameters:
dataHolder- The data holderzos- TheZipOutputStreamwhere to export the filespath- The path of the folder used to export the files- Throws:
IOException- if an error occurs while exporting the files
-
_exportResource
private static void _exportResource(String dataPath, NamedResource resource, ZipOutputStream zos, String prefix) throws IOException
- Throws:
IOException
-
getFolderPathFromDataPath
public static String getFolderPathFromDataPath(String dataPath)
Retrieves a folder path from a data path. Replaces all repeater entries like '[x]', to a folder with the position ('/x')- Parameters:
dataPath- the data path- Returns:
- the folder path
-
-