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;
}
}
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;
}
}
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);
}
}
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;
}
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);
}
}
}
}
Aggregations