use of org.alfresco.service.cmr.view.ImporterException in project alfresco-repository by Alfresco.
the class ViewParser method processStartReference.
/**
* Process start reference
*
* @param xpp XmlPullParser
* @param refName QName
* @param parserContext ParserContext
* @throws XmlPullParserException
* @throws IOException
*/
private void processStartReference(XmlPullParser xpp, QName refName, ParserContext parserContext) throws XmlPullParserException, IOException {
ParentContext parent = (ParentContext) parserContext.elementStack.peek();
NodeContext node = new NodeContext(refName, parent, null);
node.setReference(true);
// Extract Import scoped reference Id if explicitly defined
String idRefAttr = xpp.getAttributeValue(NamespaceService.REPOSITORY_VIEW_1_0_URI, VIEW_IDREF_ATTR);
String pathRefAttr = xpp.getAttributeValue(NamespaceService.REPOSITORY_VIEW_1_0_URI, VIEW_PATHREF_ATTR);
String nodeRefAttr = xpp.getAttributeValue(NamespaceService.REPOSITORY_VIEW_1_0_URI, VIEW_NODEREF_ATTR);
if ((idRefAttr != null && idRefAttr.length() > 0) && (pathRefAttr != null && pathRefAttr.length() > 0) && (nodeRefAttr != null && nodeRefAttr.length() > 0)) {
// Do not support both IDREF and PATHREF
throw new ImporterException("Only one of " + VIEW_IDREF_ATTR + " or " + VIEW_PATHREF_ATTR + " or " + VIEW_NODEREF_ATTR + " can be specified.");
}
// Convert to Node Reference
NodeRef nodeRef = null;
if (nodeRefAttr != null) {
nodeRef = new NodeRef(nodeRefAttr);
} else if (idRefAttr != null && idRefAttr.length() > 0) {
// retrieve uuid from previously imported node
nodeRef = getImportReference(parserContext, idRefAttr);
if (nodeRef == null) {
throw new ImporterException("Cannot find node referenced by id " + idRefAttr);
}
} else if (pathRefAttr != null && pathRefAttr.length() > 0) {
nodeRef = parserContext.importer.resolvePath(pathRefAttr);
if (nodeRef == null) {
throw new ImporterException("Cannot find node referenced by path " + pathRefAttr);
}
}
// Establish node definition
node.setUUID(nodeRef.getId());
node.setTypeDefinition(dictionaryService.getType(nodeService.getType(nodeRef)));
Set<QName> aspects = nodeService.getAspects(nodeRef);
for (QName aspect : aspects) {
node.addAspect(dictionaryService.getAspect(aspect));
}
// Extract child name if explicitly defined
String childName = xpp.getAttributeValue(NamespaceService.REPOSITORY_VIEW_1_0_URI, VIEW_CHILD_NAME_ATTR);
if (childName != null && childName.length() > 0) {
node.setChildName(childName);
}
// Extract import id if explicitly defined
String importId = xpp.getAttributeValue(NamespaceService.REPOSITORY_VIEW_1_0_URI, VIEW_ID_ATTR);
if (importId != null && importId.length() > 0) {
node.setImportId(importId);
}
parserContext.elementStack.push(node);
if (logger.isDebugEnabled())
logger.debug(indentLog("Pushed Reference " + node, parserContext.elementStack.size() - 1));
}
use of org.alfresco.service.cmr.view.ImporterException in project alfresco-repository by Alfresco.
the class ImporterBootstrap method getReader.
/**
* Get a Reader onto an XML view
*
* @param view the view location
* @param encoding the encoding of the view
* @return the reader
*/
private Reader getReader(String view, String encoding) {
// Get Input Stream
ResourceLoader resourceLoader = new DefaultResourceLoader(getClass().getClassLoader());
Resource viewResource = resourceLoader.getResource(view);
if (viewResource == null) {
throw new ImporterException("Could not find view file " + view);
}
// Wrap in buffered reader
try {
InputStream viewStream = viewResource.getInputStream();
InputStreamReader inputReader = (encoding == null) ? new InputStreamReader(viewStream) : new InputStreamReader(viewStream, encoding);
BufferedReader reader = new BufferedReader(inputReader);
return reader;
} catch (UnsupportedEncodingException e) {
throw new ImporterException("Could not create reader for view " + view + " as encoding " + encoding + " is not supported");
} catch (IOException e) {
throw new ImporterException("Could not open resource for view " + view);
}
}
use of org.alfresco.service.cmr.view.ImporterException in project alfresco-repository by Alfresco.
the class ACPImportPackageHandler method importStream.
/* (non-Javadoc)
* @see org.alfresco.service.cmr.view.ImportStreamHandler#importStream(java.lang.String)
*/
public InputStream importStream(String content) {
ZipArchiveEntry zipEntry = zipFile.getEntry(content);
if (zipEntry == null) {
// Note: for some reason, when modifying a zip archive the path seperator changes
// TODO: Need to investigate further as to why and whether this workaround is enough
content = content.replace('\\', '/');
zipEntry = zipFile.getEntry(content);
if (zipEntry == null) {
throw new ImporterException("Failed to find content " + content + " within zip package");
}
}
try {
return zipFile.getInputStream(zipEntry);
} catch (IOException e) {
throw new ImporterException("Failed to open content " + content + " within zip package due to " + e.getMessage(), e);
}
}
use of org.alfresco.service.cmr.view.ImporterException in project alfresco-repository by Alfresco.
the class ImporterComponent method getNodeRef.
/**
* Get Node Reference from Location
*
* @param location the location to extract node reference from
* @param binding import configuration
* @return node reference
*/
private NodeRef getNodeRef(Location location, ImporterBinding binding) {
ParameterCheck.mandatory("Location", location);
// Establish node to import within
NodeRef nodeRef = location.getNodeRef();
if (nodeRef == null) {
// If a specific node has not been provided, default to the root
nodeRef = nodeService.getRootNode(location.getStoreRef());
}
// Resolve to path within node, if one specified
String path = location.getPath();
if (path != null && path.length() > 0) {
// Create a valid path and search
path = bindPlaceHolder(path, binding);
path = createValidPath(path);
List<NodeRef> nodeRefs = searchService.selectNodes(nodeRef, path, null, namespaceService, false);
if (nodeRefs.size() == 0) {
throw new ImporterException("Path " + path + " within node " + nodeRef + " does not exist - the path must resolve to a valid location");
}
if (nodeRefs.size() > 1) {
throw new ImporterException("Path " + path + " within node " + nodeRef + " found too many locations - the path must resolve to one location");
}
nodeRef = nodeRefs.get(0);
}
return nodeRef;
}
use of org.alfresco.service.cmr.view.ImporterException in project alfresco-repository by Alfresco.
the class SystemInfoBootstrap method bootstrap.
/**
* Bootstrap
*/
public void bootstrap() {
UserTransaction userTransaction = transactionService.getUserTransaction();
authenticationContext.setSystemUserAsCurrentUser();
try {
userTransaction.begin();
// check the repository exists, create if it doesn't
if (performBootstrap()) {
InputStream viewStream = getClass().getClassLoader().getResourceAsStream(bootstrapView);
if (viewStream == null) {
throw new ImporterException("Could not find system info file " + bootstrapView);
}
try {
systemImporter.importSystem(viewStream);
} finally {
viewStream.close();
}
}
userTransaction.commit();
} catch (Throwable e) {
// rollback the transaction
try {
if (userTransaction != null) {
userTransaction.rollback();
}
} catch (Exception ex) {
}
try {
authenticationContext.clearCurrentSecurityContext();
} catch (Exception ex) {
}
throw new AlfrescoRuntimeException("System Info Bootstrap failed", e);
} finally {
authenticationContext.clearCurrentSecurityContext();
}
}
Aggregations