diff --git a/src/main/java/org/alfresco/extensions/bulkexport/controler/Engine.java b/src/main/java/org/alfresco/extensions/bulkexport/controler/Engine.java index 7ab631c..333ffbe 100644 --- a/src/main/java/org/alfresco/extensions/bulkexport/controler/Engine.java +++ b/src/main/java/org/alfresco/extensions/bulkexport/controler/Engine.java @@ -1,230 +1,229 @@ -/** - * This file is part of Alfresco Bulk Export Tool. - *

- * Alfresco Bulk Export Tool is free software: you can redistribute it - * and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - *

- * Alfresco Bulk Export Tool is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. - *

- * You should have received a copy of the GNU General Public License along - * with Alfresco Bulk Export Tool. If not, see . - */ -package org.alfresco.extensions.bulkexport.controler; - -import org.alfresco.extensions.bulkexport.dao.AlfrescoExportDao; -import org.alfresco.extensions.bulkexport.model.FileFolder; -import org.alfresco.service.cmr.repository.NodeRef; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import java.io.*; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; - - -/** - * This class is a engine of systems - * - * @author Denys G. Santos (gsdenys@gmail.com) - * @version 1.0.1 - */ -public class Engine { - Log log = LogFactory.getLog(Engine.class); - - /** Data Access Object */ - private AlfrescoExportDao dao; - - /** if true the look for a cache containing a list of all nodes to export - * */ - private boolean useNodeCache; - - - /** File and folder manager */ - private FileFolder fileFolder; - - private boolean exportVersions; - - /** If true the the head revision will be named, eg. if head revision is 1.4 then filename will contain the revision. - * This behaviour is not how the bulk importer expects revisions */ - private boolean revisionHead; - - /* Nb of Parralel Threads**/ - private int nbOfThreads; - - /** How many Nodes are exported per process*/ - private int exportChunkSize; - - /** - * Engine Default Builder - * - * @param dao Data Access Object - * @param fileFolder File and Folder magager - */ - public Engine(AlfrescoExportDao dao, FileFolder fileFolder, boolean exportVersions, boolean revisionHead, boolean useNodeCache, int nbOfThreads, int exportChunkSize) { - this.dao = dao; - this.fileFolder = fileFolder; - this.exportVersions = exportVersions; - this.revisionHead = revisionHead; - this.useNodeCache = useNodeCache; - this.nbOfThreads = nbOfThreads; - this.exportChunkSize = exportChunkSize; - } - - /** - * Recursive method to export alfresco nodes to file system - * - * @param nodeRef - */ - public void execute(NodeRef nodeRef) throws Exception { - // case node is folder create a folder and execute recursively - // other else create file - log.debug("execute (noderef)"); - - if (!this.dao.isNodeIgnored(nodeRef.toString())) { - log.info("Find all nodes to export (no history)"); - List allNodes = getNodesToExport(nodeRef); - log.info("Nodes to export = " + allNodes.size()); - exportNodes(allNodes); - } - log.debug("execute (noderef) finished"); - } - - private List getNodesToExport(NodeRef rootNode) throws Exception { - List nodes = null; - if (useNodeCache) { - nodes = retrieveNodeListFromCache(rootNode); - } - - if (nodes == null) { - nodes = findAllNodes(rootNode); - storeNodeListToCache(rootNode, nodes); - if (useNodeCache) { - log.info("Generated Cached Node list"); - throw new CacheGeneratedException("Generated Cached Node List Only"); - } - } else { - log.info("Using Cached Node list"); - } - - return nodes; - } - - private String nodeFileName(NodeRef rootNode) { - File fname = new File(fileFolder.basePath(), rootNode.getId() + ".cache"); - return fname.getPath(); - } - - private void storeNodeListToCache(NodeRef rootNode, List list) throws Exception { - // get a better name - FileOutputStream fos = new FileOutputStream(nodeFileName(rootNode)); - ObjectOutputStream oos = new ObjectOutputStream(fos); - oos.writeObject(list); - oos.close(); - fos.close(); - } - - private List retrieveNodeListFromCache(NodeRef rootNode) throws Exception { - List list = null; - - try { - FileInputStream fis = new FileInputStream(nodeFileName(rootNode)); - ObjectInputStream ois = new ObjectInputStream(fis); - list = (List) ois.readObject(); - ois.close(); - } catch (FileNotFoundException e) { - // this exception means we have no noelist cache - we just ignore and continue - log.debug("could not open nodelist cache file"); - } - return list; - } - - /** - * Recursive find of all item head nodes from a given node ref - * - * @param nodeRef - */ - private List findAllNodes(NodeRef nodeRef) throws Exception { - List nodes = new ArrayList(); - - log.debug("findAllNodes (noderef)"); - try { - if (!this.dao.isNodeIgnored(nodeRef.toString())) { - if (this.dao.isFolder(nodeRef)) { - nodes.add(nodeRef); // add folder as well - List children = this.dao.getChildren(nodeRef); - for (NodeRef child : children) { - nodes.addAll(this.findAllNodes(child)); - } - } else { - nodes.add(nodeRef); - } - } - } catch (Throwable e) { - e.printStackTrace(); - log.info("Error Multithreading", e); - throw e; - } - log.debug("execute (noderef) finished"); - return nodes; - } - - - /** - * Creates Thread Pool and Tasks with dispatch nodes - * - * @param nodesToExport - */ - private void exportNodes(final List nodesToExport) throws InterruptedException, ExecutionException { - ExecutorService threadPool = Executors.newFixedThreadPool(nbOfThreads); - List> futures = new ArrayList<>(); - - int previousLowerLimitNodeNumber = 0; - int noOfTasks = new Double(Math.ceil((double) nodesToExport.size() / (double) this.exportChunkSize)).intValue(); - - log.info("Number of tasks: " + noOfTasks); - - for (int taskNumber = 1; taskNumber <= noOfTasks; taskNumber++) { - int upperLimitNodeNumber = calculateNextUpperLimitNodeNumber(previousLowerLimitNodeNumber, nodesToExport.size()); - int lowerLimitNodeNumber = calculateNextLowerLimitNodeNumber(previousLowerLimitNodeNumber, upperLimitNodeNumber); - log.info("Task number" + taskNumber + " LowerLimitNodeNumber " + lowerLimitNodeNumber); - log.info("Task number" + taskNumber + " UpperLimitNodeNumber " + upperLimitNodeNumber); - - previousLowerLimitNodeNumber = upperLimitNodeNumber; - - List nodesForCurrentThread = nodesToExport.subList(lowerLimitNodeNumber, upperLimitNodeNumber); - futures.add(threadPool.submit(new NodeExportTask(nodesForCurrentThread, exportVersions, revisionHead, dao, fileFolder, taskNumber))); - } - - boolean exportTerminated = false; - - for (Future future : futures) { - exportTerminated &= future.isDone(); - } - - } - - private int calculateNextLowerLimitNodeNumber(int previousLowerLimitNodeNumber, int upperLimitNodeNumber) { - int nextLowerLimitNodeNumber = previousLowerLimitNodeNumber; - if (nextLowerLimitNodeNumber > upperLimitNodeNumber) { - nextLowerLimitNodeNumber = upperLimitNodeNumber; - } - return nextLowerLimitNodeNumber; - } - - private int calculateNextUpperLimitNodeNumber(int previousLowerLimitNodeNumber, int nodesToExportSize) { - int nextUpperLimitNodeNumber = previousLowerLimitNodeNumber + this.exportChunkSize; - if (nextUpperLimitNodeNumber > nodesToExportSize) { - nextUpperLimitNodeNumber = nodesToExportSize; - } - return nextUpperLimitNodeNumber; - } -} +/** + * This file is part of Alfresco Bulk Export Tool. + *

+ * Alfresco Bulk Export Tool is free software: you can redistribute it + * and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + *

+ * Alfresco Bulk Export Tool is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + *

+ * You should have received a copy of the GNU General Public License along + * with Alfresco Bulk Export Tool. If not, see . + */ +package org.alfresco.extensions.bulkexport.controler; + +import org.alfresco.extensions.bulkexport.dao.AlfrescoExportDao; +import org.alfresco.extensions.bulkexport.model.FileFolder; +import org.alfresco.service.cmr.repository.NodeRef; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + + +/** + * This class is a engine of systems + * + * @author Denys G. Santos (gsdenys@gmail.com) + * @version 1.0.1 + */ +public class Engine { + Log log = LogFactory.getLog(Engine.class); + + /** Data Access Object */ + private AlfrescoExportDao dao; + + /** if true the look for a cache containing a list of all nodes to export + * */ + private boolean useNodeCache; + + + /** File and folder manager */ + private FileFolder fileFolder; + + private boolean exportVersions; + + /** If true the the head revision will be named, eg. if head revision is 1.4 then filename will contain the revision. + * This behaviour is not how the bulk importer expects revisions */ + private boolean revisionHead; + + /* Nb of Parralel Threads**/ + private int nbOfThreads; + + /** How many Nodes are exported per process*/ + private int exportChunkSize; + + /** + * Engine Default Builder + * + * @param dao Data Access Object + * @param fileFolder File and Folder magager + */ + public Engine(AlfrescoExportDao dao, FileFolder fileFolder, boolean exportVersions, boolean revisionHead, boolean useNodeCache, int nbOfThreads, int exportChunkSize) { + this.dao = dao; + this.fileFolder = fileFolder; + this.exportVersions = exportVersions; + this.revisionHead = revisionHead; + this.useNodeCache = useNodeCache; + this.nbOfThreads = nbOfThreads; + this.exportChunkSize = exportChunkSize; + } + + /** + * Recursive method to export alfresco nodes to file system + * + * @param nodeRef + */ + public void execute(NodeRef nodeRef) throws Exception { + // case node is folder create a folder and execute recursively + // other else create file + log.debug("execute (noderef)"); + + if (!this.dao.isNodeIgnored(nodeRef.toString())) { + log.info("Find all nodes to export (no history)"); + List allNodes = getNodesToExport(nodeRef); + log.info("Nodes to export = " + allNodes.size()); + exportNodes(allNodes); + } + log.debug("execute (noderef) finished"); + } + + private List getNodesToExport(NodeRef rootNode) throws Exception { + List nodes = null; + if (useNodeCache) { + nodes = retrieveNodeListFromCache(rootNode); + } + + if (nodes == null) { + nodes = findAllNodes(rootNode); + storeNodeListToCache(rootNode, nodes); + if (useNodeCache) { + log.info("Generated Cached Node list"); + throw new CacheGeneratedException("Generated Cached Node List Only"); + } + } else { + log.info("Using Cached Node list"); + } + + return nodes; + } + + private String nodeFileName(NodeRef rootNode) { + File fname = new File(fileFolder.basePath(), rootNode.getId() + ".cache"); + return fname.getPath(); + } + + private void storeNodeListToCache(NodeRef rootNode, List list) throws Exception { + // get a better name + FileOutputStream fos = new FileOutputStream(nodeFileName(rootNode)); + ObjectOutputStream oos = new ObjectOutputStream(fos); + oos.writeObject(list); + oos.close(); + fos.close(); + } + + private List retrieveNodeListFromCache(NodeRef rootNode) throws Exception { + List list = null; + + try { + FileInputStream fis = new FileInputStream(nodeFileName(rootNode)); + ObjectInputStream ois = new ObjectInputStream(fis); + list = (List) ois.readObject(); + ois.close(); + } catch (FileNotFoundException e) { + // this exception means we have no noelist cache - we just ignore and continue + log.debug("could not open nodelist cache file"); + } + return list; + } + + /** + * Recursive find of all item head nodes from a given node ref + * + * @param nodeRef + */ + private List findAllNodes(NodeRef nodeRef) throws Exception { + List nodes = new ArrayList(); + + log.debug("findAllNodes (noderef)"); + try { + if (!this.dao.isNodeIgnored(nodeRef.toString())) { + if (this.dao.isFolder(nodeRef)) { + nodes.add(nodeRef); // add folder as well + List children = this.dao.getChildren(nodeRef); + for (NodeRef child : children) { + nodes.addAll(this.findAllNodes(child)); + } + } else { + nodes.add(nodeRef); + } + } + } catch (Throwable e) { + e.printStackTrace(); + log.info("Error Multithreading", e); + throw e; + } + log.debug("execute (noderef) finished"); + return nodes; + } + + + /** + * Creates Thread Pool and Tasks with dispatch nodes + * + * @param nodesToExport + */ + private void exportNodes(final List nodesToExport) throws InterruptedException, ExecutionException { + ExecutorService threadPool = Executors.newFixedThreadPool(nbOfThreads); + List> futures = new ArrayList<>(); + + int previousLowerLimitNodeNumber = 0; + int noOfTasks = new Double(Math.ceil((double) nodesToExport.size() / (double) this.exportChunkSize)).intValue(); + + log.info("Number of tasks: " + noOfTasks); + + for (int taskNumber = 1; taskNumber <= noOfTasks; taskNumber++) { + int upperLimitNodeNumber = calculateNextUpperLimitNodeNumber(previousLowerLimitNodeNumber, nodesToExport.size()); + int lowerLimitNodeNumber = calculateNextLowerLimitNodeNumber(previousLowerLimitNodeNumber, upperLimitNodeNumber); + log.info("Task number" + taskNumber + " LowerLimitNodeNumber " + lowerLimitNodeNumber); + log.info("Task number" + taskNumber + " UpperLimitNodeNumber " + upperLimitNodeNumber); + + previousLowerLimitNodeNumber = upperLimitNodeNumber; + + List nodesForCurrentThread = nodesToExport.subList(lowerLimitNodeNumber, upperLimitNodeNumber); + futures.add(threadPool.submit(new NodeExportTask(nodesForCurrentThread, exportVersions, revisionHead, dao, fileFolder, taskNumber))); + } + + boolean exportTerminated = false; + + for (Future future : futures) { + exportTerminated &= future.isDone(); + } + + } + + private int calculateNextLowerLimitNodeNumber(int previousLowerLimitNodeNumber, int upperLimitNodeNumber) { + int nextLowerLimitNodeNumber = previousLowerLimitNodeNumber; + if (nextLowerLimitNodeNumber > upperLimitNodeNumber) { + nextLowerLimitNodeNumber = upperLimitNodeNumber; + } + return nextLowerLimitNodeNumber; + } + + private int calculateNextUpperLimitNodeNumber(int previousLowerLimitNodeNumber, int nodesToExportSize) { + int nextUpperLimitNodeNumber = previousLowerLimitNodeNumber + this.exportChunkSize; + if (nextUpperLimitNodeNumber > nodesToExportSize) { + nextUpperLimitNodeNumber = nodesToExportSize; + } + return nextUpperLimitNodeNumber; + } +} diff --git a/src/main/java/org/alfresco/extensions/bulkexport/controler/NodeExportTask.java b/src/main/java/org/alfresco/extensions/bulkexport/controler/NodeExportTask.java index 7baa7c4..78a517f 100644 --- a/src/main/java/org/alfresco/extensions/bulkexport/controler/NodeExportTask.java +++ b/src/main/java/org/alfresco/extensions/bulkexport/controler/NodeExportTask.java @@ -94,7 +94,7 @@ private void createFile(NodeRef file) throws Exception { private void doCreateFile(NodeRef file, String path) throws Exception { //get Informations - log.debug("doCreateFile (noderef)"); + LOG.debug("doCreateFile (" + file.getId() + ")"); // need these variables out of the try scope for debugging purposes when the exception is thrown String type = null; @@ -105,7 +105,7 @@ private void doCreateFile(NodeRef file, String path) throws Exception { String fname = this.fileFolder.createFullPath(path); log.debug("doCreateFile file =" + fname); if (this.dao.getContentAndStoreInFile(file, fname) == false) { - log.debug("doCreateFile ignore this file"); + LOG.debug("doCreateFile ignore this file: " + fname); return; } type = this.dao.getType(file); @@ -133,7 +133,6 @@ private void doCreateFile(NodeRef file, String path) throws Exception { */ private void createFolder(NodeRef folder) throws Exception { //Get Data - log.debug("createFolder"); String path = this.dao.getPath(folder); log.debug("createFolder path=" + path); String type = this.dao.getType(folder); @@ -181,16 +180,15 @@ public String call() throws Exception { int logCount = nodesToExport.size(); log.info("Running task " + taskNumber + " will export " + logCount + " nodes"); final int NODES_TO_PROCESS = 100; - try { - for (NodeRef nodeRef : nodesToExport) { - if (Thread.currentThread().isInterrupted()) { - log.error(Thread.currentThread().getName() + " interrupted"); - throw new InterruptedException(); - } + for (NodeRef nodeRef : nodesToExport) { + try { + LOG.debug("Handling in task NodeRef: " + nodeRef.getId()); logCount--; if (this.dao.isFolder(nodeRef)) { + log.debug("NodeRef is folder: " + nodeRef.getId()); this.createFolder(nodeRef); } else { + LOG.debug("NodeRef is document: " + nodeRef.getId()); if (exportVersions) { exportFullRevisionHistory(nodeRef); } else { @@ -200,11 +198,14 @@ public String call() throws Exception { if (logCount % NODES_TO_PROCESS == 0) { log.info("Task " + taskNumber + " has remaining nodes to process " + logCount); } + } catch (InterruptedException e) { + LOG.info(Thread.currentThread().getName() + " interrupted"); + } catch (Exception e) { + LOG.error("Error in task:" + taskNumber + " on Node: " + nodeRef.getId(), e); } - } catch (Exception e) { - log.error(e); } + AuthenticationUtil.clearCurrentSecurityContext(); return "Task " + taskNumber + " is finished"; } -} +} \ No newline at end of file diff --git a/src/main/java/org/alfresco/extensions/bulkexport/dao/AlfrescoExportDaoImpl.java b/src/main/java/org/alfresco/extensions/bulkexport/dao/AlfrescoExportDaoImpl.java index 7905dc0..56ed77f 100644 --- a/src/main/java/org/alfresco/extensions/bulkexport/dao/AlfrescoExportDaoImpl.java +++ b/src/main/java/org/alfresco/extensions/bulkexport/dao/AlfrescoExportDaoImpl.java @@ -1,72 +1,56 @@ /** - * This file is part of Alfresco Bulk Export Tool. - * - * Alfresco Bulk Export Tool is free software: you can redistribute it - * and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Alfresco Bulk Export Tool is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with Alfresco Bulk Export Tool. If not, see . + * This file is part of Alfresco Bulk Export Tool. + *

+ * Alfresco Bulk Export Tool is free software: you can redistribute it + * and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + *

+ * Alfresco Bulk Export Tool is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + *

+ * You should have received a copy of the GNU General Public License along + * with Alfresco Bulk Export Tool. If not, see . */ package org.alfresco.extensions.bulkexport.dao; -import java.io.ByteArrayOutputStream; -import java.io.InputStream; -import java.io.Serializable; -import java.io.File; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.Collection; -import java.util.Iterator; - +import com.ibm.icu.text.SimpleDateFormat; import org.alfresco.model.ContentModel; import org.alfresco.repo.action.ActionModel; import org.alfresco.repo.publishing.PublishingModel; import org.alfresco.service.ServiceRegistry; import org.alfresco.service.cmr.model.FileFolderService; import org.alfresco.service.cmr.model.FileInfo; -import org.alfresco.service.cmr.repository.ChildAssociationRef; -import org.alfresco.service.cmr.repository.ContentReader; -import org.alfresco.service.cmr.repository.ContentService; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.repository.Path; +import org.alfresco.service.cmr.repository.*; import org.alfresco.service.cmr.security.PermissionService; -import org.alfresco.service.cmr.version.VersionService; -import org.alfresco.service.cmr.version.VersionType; -import org.alfresco.service.cmr.version.VersionHistory; import org.alfresco.service.cmr.version.Version; +import org.alfresco.service.cmr.version.VersionHistory; +import org.alfresco.service.cmr.version.VersionService; import org.alfresco.service.namespace.NamespacePrefixResolver; import org.alfresco.service.namespace.QName; - -import com.ibm.icu.text.SimpleDateFormat; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.InputStream; +import java.io.Serializable; +import java.util.*; + /** * Implementation of {@link AlfrescoExportDao} interface - * + * * @author Denys Santos (gsdenys@gmail.com) * @version 1.0.1 */ -public class AlfrescoExportDaoImpl implements AlfrescoExportDao -{ +public class AlfrescoExportDaoImpl implements AlfrescoExportDao { Log log = LogFactory.getLog(AlfrescoExportDaoImpl.class); - /** Alfresco {@link ServiceRegistry} to Data Access Object */ + /** Alfresco {@link ServiceRegistry} to Data Access Object */ private ServiceRegistry registry; private final NodeService nodeService; @@ -75,318 +59,292 @@ public class AlfrescoExportDaoImpl implements AlfrescoExportDao private final ContentService contentService; private final PermissionService permissionService; private final VersionService versionService; - - private QName ignoreAspectQname[] = - { - ContentModel.ASPECT_TAGGABLE - }; - - private String ignoreAspectPrefix[] = - { - "app" - }; - - private QName ignorePropertyQname[] = - { - ContentModel.PROP_NODE_DBID, - ContentModel.PROP_NODE_UUID, - ContentModel.PROP_CATEGORIES, - ContentModel.PROP_CONTENT, - ContentModel.ASPECT_TAGGABLE - }; - - private String[] ignorePropertyPrefix = - { - "app", - "exif" - }; - - private QName[] ignoredType = - { - ContentModel.TYPE_SYSTEM_FOLDER, - ContentModel.TYPE_LINK, - ContentModel.TYPE_RATING, - ActionModel.TYPE_ACTION, - ActionModel.TYPE_COMPOSITE_ACTION, - PublishingModel.TYPE_PUBLISHING_QUEUE - }; - - + + private QName ignoreAspectQname[] = + { + ContentModel.ASPECT_TAGGABLE + }; + + private String ignoreAspectPrefix[] = + { + "app" + }; + + private QName ignorePropertyQname[] = + { + ContentModel.PROP_NODE_DBID, + ContentModel.PROP_NODE_UUID, + ContentModel.PROP_CATEGORIES, + ContentModel.PROP_CONTENT, + ContentModel.ASPECT_TAGGABLE + }; + + private String[] ignorePropertyPrefix = + { + "app", + "exif" + }; + + private QName[] ignoredType = + { + ContentModel.TYPE_SYSTEM_FOLDER, + ContentModel.TYPE_LINK, + ContentModel.TYPE_RATING, + ActionModel.TYPE_ACTION, + ActionModel.TYPE_COMPOSITE_ACTION, + PublishingModel.TYPE_PUBLISHING_QUEUE + }; + + /** * Data Access Object Builder - * + * * @param registry Alfresco {@link ServiceRegistry} */ - public AlfrescoExportDaoImpl(ServiceRegistry registry) - { + public AlfrescoExportDaoImpl(ServiceRegistry registry) { log.debug("Test debug logging. Congratulation your AMP is working"); - this.registry = registry; + this.registry = registry; - nodeService = this.registry.getNodeService(); - service = this.registry.getFileFolderService(); - nsR = this.registry.getNamespaceService(); + nodeService = this.registry.getNodeService(); + service = this.registry.getFileFolderService(); + nsR = this.registry.getNamespaceService(); contentService = this.registry.getContentService(); permissionService = this.registry.getPermissionService(); versionService = this.registry.getVersionService(); } - - + + /** * @see com.alfresco.bulkexport.dao.AlfrescoExportDao#getProperties(java.lang.String) */ - public Map getProperties(NodeRef nodeRef) throws Exception - { + public Map getProperties(NodeRef nodeRef) throws Exception { Map properties = nodeService.getProperties(nodeRef); return properties; } - - + + /** * @see com.alfresco.bulkexport.dao.AlfrescoExportDao#getMetadataAsString(java.lang.String) */ - public Map getPropertiesAsString(NodeRef nodeRef) throws Exception - { - + public Map getPropertiesAsString(NodeRef nodeRef) throws Exception { + Map properties = this.getProperties(nodeRef); - + Map props = new HashMap(); Set qNameSet = properties.keySet(); - - for (QName qName : qNameSet) - { + + for (QName qName : qNameSet) { //case the qname is in ignored type do nothing will do. - if(this.isPropertyIgnored(qName)) - { + if (this.isPropertyIgnored(qName)) { continue; } - + Serializable obj = properties.get(qName); String name = this.getQnameStringFormat(qName); String value = this.formatMetadata(obj); - + //put key value in the property list as props.put(name, value); } - + return props; } - + /** * @see com.alfresco.bulkexport.dao.AlfrescoExportDao#getChildren(java.lang.String) */ - public List getChildren(NodeRef nodeRef) throws Exception - { + public List getChildren(NodeRef nodeRef) throws Exception { List listChildren = new ArrayList(); - + List children = nodeService.getChildAssocs(nodeRef); - - for (ChildAssociationRef childAssociationRef : children) - { + + for (ChildAssociationRef childAssociationRef : children) { NodeRef child = childAssociationRef.getChildRef(); - - if(this.isTypeIgnored(nodeService.getType(child))) - { + + if (this.isTypeIgnored(nodeService.getType(child))) { continue; } - + listChildren.add(new NodeRef(child.toString())); // deep copy } - + return listChildren; } - + /** * @see com.alfresco.bulkexport.dao.AlfrescoExportDao#getFolderChildren(java.lang.String) */ - public List getFolderChildren(NodeRef nodeRef) throws Exception - { - + public List getFolderChildren(NodeRef nodeRef) throws Exception { + List folders = service.listFolders(nodeRef); - + List listChildren = new ArrayList(); - - for (FileInfo fileInfo : folders) - { + + for (FileInfo fileInfo : folders) { listChildren.add(fileInfo.getNodeRef()); } - + return listChildren; } - + /** * @see com.alfresco.bulkexport.dao.AlfrescoExportDao#getFileChildren(java.lang.String) */ - public List getFileChildren(NodeRef nodeRef) throws Exception - { + public List getFileChildren(NodeRef nodeRef) throws Exception { List files = service.listFiles(nodeRef); - + List listChildren = new ArrayList(); - - for (FileInfo fileInfo : files) - { + + for (FileInfo fileInfo : files) { listChildren.add(fileInfo.getNodeRef()); } - + return listChildren; } - + /** * @see com.alfresco.bulkexport.dao.AlfrescoExportDao#getPath(java.lang.String) */ - public String getPath(NodeRef nodeRef) throws Exception - { + public String getPath(NodeRef nodeRef) throws Exception { //get element Path Path path = nodeService.getPath(nodeRef); - + //get element name Serializable name = nodeService.getProperty(nodeRef, ContentModel.PROP_NAME); - + //get element Path as String String basePath = path.toDisplayPath(nodeService, permissionService); - + return (basePath + "/" + name); } - + /** * @see com.alfresco.bulkexport.dao.AlfrescoExportDao#getContent(java.lang.String) */ - public ByteArrayOutputStream getContent(NodeRef nodeRef) throws Exception - { + public ByteArrayOutputStream getContent(NodeRef nodeRef) throws Exception { ContentReader reader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT); - if (reader == null) - { + if (reader == null) { // no data for this node return null; } - + InputStream in = reader.getContentInputStream(); int size = in.available(); - + ByteArrayOutputStream out = new ByteArrayOutputStream(); - byte[] buf = new byte[ (size + 100) ]; + byte[] buf = new byte[(size + 100)]; int sizeOut; - - while ((sizeOut=in.read(buf)) != -1 ) - { + + while ((sizeOut = in.read(buf)) != -1) { out.write(buf, 0, sizeOut); } - + out.flush(); out.close(); - + in.close(); - - + + return out; } - public boolean getContentAndStoreInFile(NodeRef nodeRef, String outputFileName) throws Exception - { + public boolean getContentAndStoreInFile(NodeRef nodeRef, String outputFileName) throws Exception { ContentReader reader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT); - if (reader == null) - { + if (reader == null) { // no data for this node return false; } - + File output = new File(outputFileName); reader.getContent(output); return true; } - + /** * @see com.alfresco.bulkexport.dao.AlfrescoExportDao#getProperty(java.lang.String, java.lang.String) */ - public String getProperty(NodeRef nodeRef, QName propertyQName) throws Exception - { + public String getProperty(NodeRef nodeRef, QName propertyQName) throws Exception { Serializable value = nodeService.getProperty(nodeRef, propertyQName); - + return this.formatMetadata(value); } - + /** * @see com.alfresco.bulkexport.dao.AlfrescoExportDao#getType(java.lang.String) */ - public String getType(NodeRef nodeRef) throws Exception - { + public String getType(NodeRef nodeRef) throws Exception { QName value = nodeService.getType(nodeRef); - + String name = this.getQnameStringFormat(value); - + return name; } - - + + /** * @see com.alfresco.bulkexport.dao.AlfrescoExportDao#getAspects(java.lang.String) */ - public List getAspects(NodeRef nodeRef) throws Exception - { + public List getAspects(NodeRef nodeRef) throws Exception { Set aspectSet = nodeService.getAspects(nodeRef); List qn = new ArrayList(aspectSet); - + return qn; } - - + + /** * @see com.alfresco.bulkexport.dao.AlfrescoExportDao#getAspectsAsString(java.lang.String) */ - public List getAspectsAsString(NodeRef nodeRef) throws Exception - { + public List getAspectsAsString(NodeRef nodeRef) throws Exception { List qn = this.getAspects(nodeRef); List str = new ArrayList(); - - for (QName qName : qn) - { - if(this.isAspectIgnored(qName)) - { + + for (QName qName : qn) { + if (this.isAspectIgnored(qName)) { continue; } - + String name = this.getQnameStringFormat(qName); - str.add(name); + str.add(name); } - + return str; } - - + + /** * @see com.alfresco.bulkexport.dao.AlfrescoExportDao#isFolder(java.lang.String) */ - public boolean isFolder(NodeRef nodeRef) throws Exception - { + public boolean isFolder(NodeRef nodeRef) throws Exception { log.debug("isFolder"); - FileInfo info = service.getFileInfo(nodeRef); - log.debug("isFolder got file info getName = " + info.getName()); - log.debug("isFolder got file info isFolder = " + info.isFolder()); - log.debug("isFolder return isFolder"); - + if (info != null) { + LOG.debug("isFolder got file info getName = " + info.getName()); + LOG.debug("isFolder got file info isFolder = " + info.isFolder()); + LOG.debug("isFolder return isFolder"); + } else { + LOG.debug("Fileinfo for Noderef is null: " + nodeRef.getId()); + } + return info.isFolder(); } - + /** * @see com.alfresco.bulkexport.dao.AlfrescoExportDao#getNodeRef(java.lang.String) */ - public NodeRef getNodeRef(String nodeRef) - { - try - { + public NodeRef getNodeRef(String nodeRef) { + try { NodeRef nr = new NodeRef(nodeRef); return nr; - } - catch (Exception e) - { + } catch (Exception e) { return null; } } @@ -394,204 +352,180 @@ public NodeRef getNodeRef(String nodeRef) /** * @see com.alfresco.bulkexport.dao.AlfrescoExportDao#getNodeRefHistory(java.lang.String) */ - public Map getNodeRefHistory(String nodeRef) throws Exception - { + public Map getNodeRefHistory(String nodeRef) throws Exception { log.debug("getNodeRefHistory(nodeRef) nodeRef = " + nodeRef); - Map nodes = null; + Map nodes = null; NodeRef nr = getNodeRef(nodeRef); - if (nr != null) - { - VersionHistory history = versionService.getVersionHistory(nr); - if (history == null) - { + if (nr != null) { + VersionHistory history = versionService.getVersionHistory(nr); + if (history == null) { log.debug("getNodeRefHistory(nodeRef) no history available"); return nodes; } Collection availableVersions = history.getAllVersions(); - if (availableVersions == null) - { + if (availableVersions == null) { log.debug("getNodeRefHistory(nodeRef) no versions found in history"); return nodes; } - nodes = new HashMap(); + nodes = new HashMap(); Iterator iterator = availableVersions.iterator(); - while(iterator.hasNext()) - { - Object ov = iterator.next(); - Version v = (Version)ov; // contains storeRef - String checkInComment = v.getDescription(); // check in comment - String vlabel = v.getVersionLabel(); // version label eg. 1.1 - NodeRef frozenNodeRef = v.getFrozenStateNodeRef(); // this contains the revisioned versions - NodeRef versionedNodeRef = v.getVersionedNodeRef(); // this is allways the latest revision - String frozenNodRef = frozenNodeRef.toString(); - String headNodeRef = versionedNodeRef.toString(); - - // this contains a list of all attributes for the Item. We may not need it since we dig them out at a store item id level. - Map versionProps = v.getVersionProperties(); - NodeRefRevision revision = new NodeRefRevision(); - revision.comment = checkInComment; - revision.node = frozenNodeRef; - - nodes.put(vlabel, revision); - // - // we need to get the comment history as well because this is not available when we get content data and properties.... - log.debug("getNodeRefHistory(nodeRef) v = " + v.toString()); + while (iterator.hasNext()) { + Object ov = iterator.next(); + Version v = (Version) ov; // contains storeRef + String checkInComment = v.getDescription(); // check in comment + String vlabel = v.getVersionLabel(); // version label eg. 1.1 + NodeRef frozenNodeRef = v.getFrozenStateNodeRef(); // this contains the revisioned versions + NodeRef versionedNodeRef = v.getVersionedNodeRef(); // this is allways the latest revision + String frozenNodRef = frozenNodeRef.toString(); + String headNodeRef = versionedNodeRef.toString(); + + // this contains a list of all attributes for the Item. We may not need it since we dig them out at a store item id level. + Map versionProps = v.getVersionProperties(); + NodeRefRevision revision = new NodeRefRevision(); + revision.comment = checkInComment; + revision.node = frozenNodeRef; + + nodes.put(vlabel, revision); + // + // we need to get the comment history as well because this is not available when we get content data and properties.... + log.debug("getNodeRefHistory(nodeRef) v = " + v.toString()); } } return nodes; } - - - public boolean isNodeIgnored(String nodeRef) - { + + + public boolean isNodeIgnored(String nodeRef) { log.debug("isNodeIgnored"); NodeRef nr = getNodeRef(nodeRef); - + QName value = nodeService.getType(nr); - + log.debug("isNodeIgnored got service type"); return isTypeIgnored(value); } - + // ####################################################################################### // #### PRIVATE METHODS ### // ####################################################################################### /** * Verify if the type qname is ignored - * + * * @param qName * @return {@link Boolean} */ - private boolean isPropertyIgnored(QName qName) - { + private boolean isPropertyIgnored(QName qName) { //verify if qname is in ignored - for (QName qn : this.ignorePropertyQname) - { - if(qn.equals(qName)) - { + for (QName qn : this.ignorePropertyQname) { + if (qn.equals(qName)) { return true; } } - + //verify if qname prefix is in ignored //String prefix = qName.getPrefixString(); String prefix = qName.getPrefixedQName(nsR).getPrefixString(); - for (String str : this.ignorePropertyPrefix) - { - + for (String str : this.ignorePropertyPrefix) { + //str.equalsIgnoreCase(prefix) - - if(prefix.startsWith(str)) - { + + if (prefix.startsWith(str)) { return true; } } - + return false; } - + /** * Verify if the aspect qname is ignored - * + * * @param qName * @return {@link Boolean} */ - private boolean isAspectIgnored(QName qName) - { + private boolean isAspectIgnored(QName qName) { //verify if qname is in ignored - for (QName qn : this.ignoreAspectQname) - { - if(qn.equals(qName)) - { + for (QName qn : this.ignoreAspectQname) { + if (qn.equals(qName)) { return true; } } - + //verify if qname prefix is in ignored //String prefix = qName.getPrefixString(); String prefix = qName.getPrefixedQName(nsR).getPrefixString(); - for (String str : this.ignoreAspectPrefix) - { - if(prefix.startsWith(str)) - { + for (String str : this.ignoreAspectPrefix) { + if (prefix.startsWith(str)) { return true; } } - + return false; } - - + + /** * Verify if the tipe qname is ignored - * + * * @param qName * @return {@link Boolean} */ - private boolean isTypeIgnored(QName qName) - { + private boolean isTypeIgnored(QName qName) { //verify if qname is in ignored - for (QName qn : this.ignoredType) - { - if(qn.equals(qName)) - { + for (QName qn : this.ignoredType) { + if (qn.equals(qName)) { + LOG.debug("nodeIsIgnored" + nodeRef); return true; } } - + return false; } - + /** * Return Qname in String Format - * + * * @param qName * @return {@link String} */ - private String getQnameStringFormat(QName qName) throws Exception - { + private String getQnameStringFormat(QName qName) throws Exception { return qName.getPrefixedQName(nsR).getPrefixString(); } /** * Format metadata guided by Bulk-Import format - * + * * @param obj * @return {@link String} */ - private String formatMetadata (Serializable obj) - { + private String formatMetadata(Serializable obj) { String returnValue = ""; - - if(obj != null) - { - if(obj instanceof Date) - { + + if (obj != null) { + if (obj instanceof Date) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSSZ"); - + Date date = (Date) obj; returnValue = format.format(date); returnValue = returnValue.substring(0, 26) + ":" + returnValue.substring(26); - } - else - { - + } else { + // // TODO: Format data to all bulk-import data format (list as example) // - + returnValue = obj.toString(); } } - + return returnValue; } } diff --git a/src/main/java/org/alfresco/extensions/bulkexport/model/FileFolder.java b/src/main/java/org/alfresco/extensions/bulkexport/model/FileFolder.java index f4ad064..801626e 100644 --- a/src/main/java/org/alfresco/extensions/bulkexport/model/FileFolder.java +++ b/src/main/java/org/alfresco/extensions/bulkexport/model/FileFolder.java @@ -1,390 +1,334 @@ /** - * This file is part of Alfresco Bulk Export Tool. - * - * Alfresco Bulk Export Tool is free software: you can redistribute it - * and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Alfresco Bulk Export Tool is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with Alfresco Bulk Export Tool. If not, see . + * This file is part of Alfresco Bulk Export Tool. + *

+ * Alfresco Bulk Export Tool is free software: you can redistribute it + * and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + *

+ * Alfresco Bulk Export Tool is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + *

+ * You should have received a copy of the GNU General Public License along + * with Alfresco Bulk Export Tool. If not, see . */ package org.alfresco.extensions.bulkexport.model; -import java.io.BufferedWriter; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.util.List; -import java.util.Map; -import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.extensions.webscripts.WebScriptResponse; +import java.io.*; +import java.util.List; +import java.util.Map; +import java.util.Set; /** * This class manage the files and folders creation - * + * * @author Denys G. Santos (gsdenys@gmail.com) * @version 1.0.1 */ -public class FileFolder -{ +public class FileFolder { Log log = LogFactory.getLog(FileFolder.class); /** {@link String} interface to web page for displaying messages * server */ private WebScriptResponse ui; - + /** {@link String} path to export data location in Alfresco * server */ private String basePath; - + /** {@link Boolean} value to avaliate if ovewrite content * exported or no */ private boolean scapeExported; - + /** * File Folder default builder - * + * * @param basePath */ - public FileFolder(WebScriptResponse ui, String basePath, boolean scapeExported) - { + public FileFolder(WebScriptResponse ui, String basePath, boolean scapeExported) { log.debug("debug enabled for FileFolder"); this.basePath = basePath; this.scapeExported = scapeExported; this.ui = ui; - } - - public String basePath() - { + } + + public FileFolder(String basePath, boolean scapeExported) { + this.scapeExported = scapeExported; + this.basePath = basePath; + } + + public String basePath() { return this.basePath; } - + /** * Create a new Folder in a {@link String} path - * + * * @param path Path of Alfresco folder */ - public void createFolder(String path) throws Exception - { + public void createFolder(String path) throws Exception { path = this.basePath + path; log.debug("createFolder path to create : " + path); - - try - { + + try { File dir = new File(path); - if (!dir.exists()) - { - if (!dir.mkdirs()) - { + if (!dir.exists()) { + if (!dir.mkdirs()) { log.error("createFolder failed to create path : " + path); - } - else - { + } else { log.debug("createFolder path : " + path); } + } else { + log.debug("Folder already existing: " + dir.getAbsolutePath()); } - } - catch (Exception e) - { + } catch (Exception e) { e.printStackTrace(); - ui.getWriter().write(e.toString()); + ui.getWriter().write(e.toString()); } } - - + + /** - * Create a new file in the {@link String} path - * + * Create a new file in the {@link String} path + * * @param filePath Path of file * @throws IOException */ - private void createFile (String filePath) throws Exception - { + private void createFile(String filePath) throws Exception { log.debug("createFile = " + filePath); - File f=new File(filePath); - - try - { - if(!f.exists()) - { - if (!f.getParentFile().exists()) - { - if (!f.getParentFile().mkdirs()) - { - log.error("failed to create folder : " + f.getParentFile().getPath()); - } - else - { - log.debug("created folder : " + f.getParentFile().getPath()); - } - } - f.createNewFile(); + File f = new File(filePath); + + try { + if (!f.exists()) { + if (!f.getParentFile().exists()) { + if (!f.getParentFile().mkdirs()) { + log.error("failed to create folder : " + f.getParentFile().getPath()); + } else { + log.debug("created folder : " + f.getParentFile().getPath()); + } + } + f.createNewFile(); } - } - catch (Exception e) + } else{ + log.info("Folder already existing: " + f.getName()); + } + catch(Exception e) { e.printStackTrace(); - ui.getWriter().write(e.toString()); + ui.getWriter().write(e.toString()); } - log.debug("createFile filepath done"); + log.debug("createFile filepath done" + f.getName()); } - - + + /** * Create XML File - * + * * @param filePath Path of file * @return {@link String} Name of file * @throws Exception */ - private String createXmlFile(String filePath) throws Exception - { + private String createXmlFile(String filePath) throws Exception { String fp = filePath + ".metadata.properties.xml"; - + this.createFile(fp); - + return fp; } - - + + /** * create content file - * + * * @param content * @param filePath * @throws IOException */ - public void insertFileContent (ByteArrayOutputStream out, String filePath) throws Exception - { + public void insertFileContent(ByteArrayOutputStream out, String filePath) throws Exception { log.debug("insertFileContent"); filePath = this.basePath + filePath; - + log.debug("insertFileContent filepath = " + filePath); - if(this.isFileExist(filePath) && this.scapeExported) - { - log.debug("insertFileContent ignore file"); + if (this.isFileExist(filePath) && this.scapeExported) { + log.debug("insertFileContent ignore file" + filePath); return; } - + this.createFile(filePath); - - try - { + + try { FileOutputStream output = new FileOutputStream(filePath); output.write(out.toByteArray()); output.flush(); output.close(); - } - catch (Exception e) - { + } catch (Exception e) { e.printStackTrace(); } } /** * construct full file path and make directory if it does not exist - * + * * @param filePath * @throws IOException */ - public String createFullPath(String filePath) throws Exception - { + public String createFullPath(String filePath) throws Exception { log.debug("createFullPath"); filePath = this.basePath + filePath; - + log.debug("createFullPath filepath = " + filePath); - if(this.isFileExist(filePath) && this.scapeExported) - { - log.debug("createFullPath ignore file"); + if (this.isFileExist(filePath) && this.scapeExported) { + log.debug("createFullPath ignore file: " + filePath); return filePath; } - - File f=new File(filePath); - - try - { - if(!f.exists()) - { - if (!f.getParentFile().exists()) - { - if (!f.getParentFile().mkdirs()) - { - log.error("failed to create folder : " + f.getParentFile().getPath()); - } - else - { - log.debug("created folder : " + f.getParentFile().getPath()); - } - } + + File f = new File(filePath); + + try { + if (!f.exists()) { + if (!f.getParentFile().exists()) { + if (!f.getParentFile().mkdirs()) { + log.error("failed to create folder : " + f.getParentFile().getPath()); + } else { + log.debug("created folder : " + f.getParentFile().getPath()); + } + } } - } - catch (Exception e) - { + } catch (Exception e) { e.printStackTrace(); - ui.getWriter().write(e.toString()); + ui.getWriter().write(e.toString()); } return filePath; } - - + + /** * Insert Content Properties in the XML File - * + * * @param type The type of node * @param aspects The aspect {@link List} of node in {@link String} format * @param properties The properties {@link Map} of node in {@link String} format * @param filePath The path of file * @throws Exception */ - public void insertFileProperties(String type, List aspects,Map properties, String filePath) throws Exception - { + public void insertFileProperties(String type, List aspects, Map properties, String filePath) throws Exception { filePath = this.basePath + filePath; - - if(this.isFileExist(filePath) && this.isFileExist(filePath + ".metadata.properties.xml") && this.scapeExported) - { + + if (this.isFileExist(filePath) && this.isFileExist(filePath + ".metadata.properties.xml") && this.scapeExported) { + log.debug("Following metadata file is not created :" + filePath); return; } - - + + String header = "\n\n"; String footer = "\n"; - + String tType = "" + type + ""; String tAspect = "" + this.formatAspects(aspects) + ""; - + String text = "\n\t" + tType + "\n\t" + tAspect; - + Set set = properties.keySet(); - - for (String string : set) - { + + for (String string : set) { String key = string; String value = properties.get(key); - - + + value = this.formatProperty(value); - - - text += "\n\t" + value + ""; + + + text += "\n\t" + value + ""; } - - try - { + + try { String fp = this.createXmlFile(filePath); File file = new File(fp); - -// FileWriter fw = new FileWriter(file.getAbsoluteFile()); - + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF8")); - + StringBuilder builder = new StringBuilder(); builder.append(header); builder.append(text); builder.append(footer); - + bw.write(builder.toString()); bw.close(); - - -// BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF8")); -// out.append(header); -// out.append(text); -// out.append(footer); -// -// out.flush(); -// out.close(); - - - - } - catch (Exception e) - { + } catch (Exception e) { e.printStackTrace(); } - + } - - + + /** * Format aspects - * + * * @param aspects * @return */ - private String formatAspects(List aspects) - { - + private String formatAspects(List aspects) { + String dado = ""; - + boolean flag = false; - for (String string : aspects) - { - if(flag) - { + for (String string : aspects) { + if (flag) { dado += ","; } - + dado += string; flag = true; } - + return dado; } - - + + /** * Method to replace special character to html code - * + * * @param value {@link String} value of field * @return {@link String} */ - private String formatProperty(String value) - { - + private String formatProperty(String value) { + //format & value = value.replaceAll("&", "&"); //format < and > value = value.replaceAll("<", "<").replaceAll(">", ">"); - + return value; } - - + + /** * Method to see if file already exists - * - * @param path The {@link String} path of file + * + * @param path The {@link String} path of file * @return {@link Boolean} */ - private boolean isFileExist(String path) - { - File f=new File(path); - - if(f.exists()) - { - return true; + private boolean isFileExist(String path) { + File f = new File(path); + + if (f.exists()) { + return true; } return false; } - - -} + + +} \ No newline at end of file