Search in sources :

Example 6 with ImporterException

use of org.alfresco.service.cmr.view.ImporterException in project alfresco-repository by Alfresco.

the class ImporterBootstrap method getFile.

/**
 * Get a File representation of an XML view
 *
 * @param view  the view location
 * @return  the file
 */
public static File getFile(String view) {
    // Try as a file location
    File file = new File(view);
    if ((file != null) && (file.exists())) {
        return file;
    } else {
        // Try as a classpath location
        // Get input stream
        InputStream viewStream = ImporterBootstrap.class.getClassLoader().getResourceAsStream(view);
        if (viewStream == null) {
            throw new ImporterException("Could not find view file " + view);
        }
        // Create output stream
        File tempFile = TempFileProvider.createTempFile("acpImport", ".tmp");
        try {
            FileOutputStream os = new FileOutputStream(tempFile);
            FileCopyUtils.copy(viewStream, os);
        } catch (FileNotFoundException e) {
            throw new ImporterException("Could not import view " + view, e);
        } catch (IOException e) {
            throw new ImporterException("Could not import view " + view, e);
        }
        return tempFile;
    }
}
Also used : ImporterException(org.alfresco.service.cmr.view.ImporterException) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) File(java.io.File)

Example 7 with ImporterException

use of org.alfresco.service.cmr.view.ImporterException in project alfresco-repository by Alfresco.

the class ImapFoldersPatch method getFile.

private File getFile(String acpName) {
    // Try as a file location
    File file = new File(acpName);
    if ((file != null) && (file.exists())) {
        return file;
    } else {
        // Try as a classpath location
        // Get input stream
        InputStream viewStream = getClass().getClassLoader().getResourceAsStream(acpName);
        if (viewStream == null) {
            throw new ImporterException("Could not find view file " + acpName);
        }
        // Create output stream
        File tempFile = TempFileProvider.createTempFile("acpImport", ".tmp");
        try {
            FileOutputStream os = new FileOutputStream(tempFile);
            FileCopyUtils.copy(viewStream, os);
        } catch (FileNotFoundException e) {
            throw new ImporterException("Could not import view " + acpName, e);
        } catch (IOException e) {
            throw new ImporterException("Could not import view " + acpName, e);
        }
        return tempFile;
    }
}
Also used : ImporterException(org.alfresco.service.cmr.view.ImporterException) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) File(java.io.File)

Example 8 with ImporterException

use of org.alfresco.service.cmr.view.ImporterException in project alfresco-remote-api by Alfresco.

the class SiteImportPackageHandler method importStream.

@Override
public InputStream importStream(String contentPath) {
    String content = config.getImportContent(contentPath);
    if (content == null) {
        return null;
    }
    String siteContent = content.replace(SITEID_PLACEHOLDER, siteId);
    try {
        return new ByteArrayInputStream(siteContent.getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) {
        throw new ImporterException("Failed to read content " + contentPath, e);
    }
}
Also used : ImporterException(org.alfresco.service.cmr.view.ImporterException) ByteArrayInputStream(java.io.ByteArrayInputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 9 with ImporterException

use of org.alfresco.service.cmr.view.ImporterException in project alfresco-repository by Alfresco.

the class Import method execute.

/* (non-Javadoc)
     * @see org.alfresco.tools.Tool#execute()
     */
@Override
protected int execute() throws ToolException {
    ImporterService importer = getServiceRegistry().getImporterService();
    // determine type of import (from zip or file system)
    ImportPackageHandler importHandler;
    int status = 0;
    for (int i = 0; i < context.packageNames.length; i++) {
        importHandler = new ZipHandler(context.getSourceDir(), context.getPackageFile(i), context.encoding);
        try {
            if (context.zipFile[i]) {
                importHandler = new ZipHandler(context.getSourceDir(), context.getPackageFile(i), context.encoding);
            } else {
                importHandler = new FileHandler(context.getSourceDir(), context.getPackageFile(i), context.encoding);
            }
            try {
                ImportBinding binding = new ImportBinding(context.uuidBinding);
                importer.importView(importHandler, context.getLocation(), binding, new ImportProgress());
            } catch (ImporterException e) {
                throw new ToolException("Failed to import package due to " + e.getMessage(), e);
            }
        } catch (Throwable t) {
            status = handleError(t);
        }
    }
    return status;
}
Also used : ImporterException(org.alfresco.service.cmr.view.ImporterException) ImporterService(org.alfresco.service.cmr.view.ImporterService) ImportPackageHandler(org.alfresco.service.cmr.view.ImportPackageHandler) FileImportPackageHandler(org.alfresco.repo.importer.FileImportPackageHandler) ACPImportPackageHandler(org.alfresco.repo.importer.ACPImportPackageHandler)

Example 10 with ImporterException

use of org.alfresco.service.cmr.view.ImporterException in project alfresco-repository by Alfresco.

the class ViewParser method processStartElement.

/**
 * Process start of xml element
 *
 * @param xpp XmlPullParser
 * @param parserContext ParserContext
 * @throws XmlPullParserException
 * @throws IOException
 */
private void processStartElement(XmlPullParser xpp, ParserContext parserContext) throws XmlPullParserException, IOException {
    // Extract qualified name
    QName defName = getName(xpp);
    // Process the element
    Object element = parserContext.elementStack.peek();
    // Handle special view directives
    if (defName.equals(VIEW_METADATA)) {
        MetaDataContext metaDataContext = new MetaDataContext(defName, (ElementContext) element);
        parserContext.elementStack.push(metaDataContext);
        if (logger.isDebugEnabled())
            logger.debug(indentLog("Pushed " + metaDataContext, parserContext.elementStack.size() - 1));
    } else if (defName.equals(VIEW_ASPECTS) || defName.equals(VIEW_PROPERTIES) || defName.equals(VIEW_ASSOCIATIONS) || defName.equals(VIEW_ACL)) {
        if (element instanceof NodeItemContext) {
            throw new ImporterException("Cannot nest element " + defName + " within " + ((NodeItemContext) element).getElementName());
        }
        if (!(element instanceof NodeContext)) {
            throw new ImporterException("Element " + defName + " can only be declared within a node");
        }
        NodeContext node = (NodeContext) element;
        NodeItemContext nodeItemContext = new NodeItemContext(defName, node);
        parserContext.elementStack.push(nodeItemContext);
        if (logger.isDebugEnabled())
            logger.debug(indentLog("Pushed " + nodeItemContext, parserContext.elementStack.size() - 1));
        // process ACL specific attributes
        if (defName.equals(VIEW_ACL)) {
            processACL(xpp, parserContext);
        }
    } else {
        if (element instanceof MetaDataContext) {
            processMetaData(xpp, defName, parserContext);
        } else if (element instanceof ParentContext) {
            if (defName.equals(VIEW_REFERENCE)) {
                // Process reference
                processStartReference(xpp, defName, parserContext);
            } else {
                // Process type definition
                TypeDefinition typeDef = dictionaryService.getType(defName);
                if (typeDef == null) {
                    throw new ImporterException("Type " + defName + " has not been defined in the Repository dictionary");
                }
                processStartType(xpp, typeDef, parserContext);
            }
            return;
        } else if (element instanceof NodeContext) {
            // Process children of node
            // Note: Process in the following order: aspects, properties and associations
            Object def = ((NodeContext) element).determineDefinition(defName);
            if (def == null) {
                throw new ImporterException("Definition " + defName + " is not valid; cannot find in Repository dictionary");
            }
            if (def instanceof AspectDefinition) {
                processAspect(xpp, (AspectDefinition) def, parserContext);
                return;
            } else if (def instanceof PropertyDefinition) {
                processProperty(xpp, ((PropertyDefinition) def).getName(), parserContext);
                return;
            } else if (def instanceof AssociationDefinition) {
                processStartAssoc(xpp, (AssociationDefinition) def, parserContext);
                return;
            }
        } else if (element instanceof NodeItemContext) {
            NodeItemContext nodeItem = (NodeItemContext) element;
            NodeContext node = nodeItem.getNodeContext();
            QName itemName = nodeItem.getElementName();
            if (itemName.equals(VIEW_ASPECTS)) {
                AspectDefinition def = node.determineAspect(defName);
                if (def == null) {
                    throw new ImporterException("Aspect name " + defName + " is not valid; cannot find in Repository dictionary");
                }
                processAspect(xpp, def, parserContext);
            } else if (itemName.equals(VIEW_PROPERTIES)) {
                // Note: Allow properties which do not have a data dictionary definition
                processProperty(xpp, defName, parserContext);
            } else if (itemName.equals(VIEW_ASSOCIATIONS)) {
                AssociationDefinition def = (AssociationDefinition) node.determineAssociation(defName);
                if (def == null) {
                    throw new ImporterException("Association name " + defName + " is not valid; cannot find in Repository dictionary");
                }
                processStartAssoc(xpp, (AssociationDefinition) def, parserContext);
            } else if (itemName.equals(VIEW_ACL)) {
                processAccessControlEntry(xpp, parserContext);
            }
        }
    }
}
Also used : ImporterException(org.alfresco.service.cmr.view.ImporterException) AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) QName(org.alfresco.service.namespace.QName) AspectDefinition(org.alfresco.service.cmr.dictionary.AspectDefinition) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition)

Aggregations

ImporterException (org.alfresco.service.cmr.view.ImporterException)15 IOException (java.io.IOException)7 InputStream (java.io.InputStream)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 QName (org.alfresco.service.namespace.QName)4 BufferedReader (java.io.BufferedReader)3 InputStreamReader (java.io.InputStreamReader)3 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 FileOutputStream (java.io.FileOutputStream)2 Reader (java.io.Reader)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 ZipArchiveEntry (org.apache.commons.compress.archivers.zip.ZipArchiveEntry)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 Enumeration (java.util.Enumeration)1 Locale (java.util.Locale)1 UserTransaction (javax.transaction.UserTransaction)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 ACPImportPackageHandler (org.alfresco.repo.importer.ACPImportPackageHandler)1