use of org.alfresco.error.AlfrescoRuntimeException in project acs-community-packaging by Alfresco.
the class ManageTaskDialogCommand method execute.
/**
* @see org.alfresco.web.app.servlet.command.Command#execute(org.alfresco.service.ServiceRegistry, java.util.Map)
*/
public Object execute(ServiceRegistry serviceRegistry, Map<String, Object> properties) {
ServletContext sc = (ServletContext) properties.get(PROP_SERVLETCONTEXT);
ServletRequest req = (ServletRequest) properties.get(PROP_REQUEST);
ServletResponse res = (ServletResponse) properties.get(PROP_RESPONSE);
FacesContext fc = FacesHelper.getFacesContext(req, res, sc, "/jsp/close.jsp");
WorkflowBean wfBean = (WorkflowBean) FacesHelper.getManagedBean(fc, WorkflowBean.BEAN_NAME);
// setup dialog context from url args in properties map
String taskId = (String) properties.get(PROP_TASKID);
ParameterCheck.mandatoryString(PROP_TASKID, taskId);
String taskType = (String) properties.get(PROP_TASKTYPE);
ParameterCheck.mandatoryString(PROP_TASKTYPE, taskType);
wfBean.setupTaskDialog(taskId, taskType);
NavigationHandler navigationHandler = fc.getApplication().getNavigationHandler();
navigationHandler.handleNavigation(fc, null, "dialog:manageTask");
String viewId = fc.getViewRoot().getViewId();
try {
sc.getRequestDispatcher(BaseServlet.FACES_SERVLET + viewId).forward(req, res);
} catch (Exception e) {
throw new AlfrescoRuntimeException("Unable to forward to viewId: " + viewId, e);
}
return null;
}
use of org.alfresco.error.AlfrescoRuntimeException in project acs-community-packaging by Alfresco.
the class SearchContext method fromXML.
/**
* Restore a SearchContext from an XML definition
*
* @param xml XML format SearchContext @see #toXML()
*/
public SearchContext fromXML(String xml) {
try {
NamespaceService ns = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getNamespaceService();
// get the root element
SAXReader reader = new SAXReader();
Document document = reader.read(new StringReader(xml));
Element rootElement = document.getRootElement();
Element textElement = rootElement.element(ELEMENT_TEXT);
if (textElement != null) {
this.text = textElement.getText();
}
Element modeElement = rootElement.element(ELEMENT_MODE);
if (modeElement != null) {
this.mode = Integer.parseInt(modeElement.getText());
}
Element locationElement = rootElement.element(ELEMENT_LOCATION);
if (locationElement != null) {
this.location = locationElement.getText();
}
Element categoriesElement = rootElement.element(ELEMENT_CATEGORIES);
if (categoriesElement != null) {
List<String> categories = new ArrayList<String>(4);
for (Iterator i = categoriesElement.elementIterator(ELEMENT_CATEGORY); i.hasNext(); ) /**/
{
Element categoryElement = (Element) i.next();
categories.add(categoryElement.getText());
}
this.categories = categories.toArray(this.categories);
}
Element contentTypeElement = rootElement.element(ELEMENT_CONTENT_TYPE);
if (contentTypeElement != null) {
this.contentType = contentTypeElement.getText();
}
Element folderTypeElement = rootElement.element(ELEMENT_FOLDER_TYPE);
if (folderTypeElement != null) {
this.folderType = folderTypeElement.getText();
}
Element mimetypeElement = rootElement.element(ELEMENT_MIMETYPE);
if (mimetypeElement != null) {
this.mimeType = mimetypeElement.getText();
}
Element attributesElement = rootElement.element(ELEMENT_ATTRIBUTES);
if (attributesElement != null) {
for (Iterator i = attributesElement.elementIterator(ELEMENT_ATTRIBUTE); i.hasNext(); ) /**/
{
Element attrElement = (Element) i.next();
QName qname = QName.createQName(attrElement.attributeValue(ELEMENT_NAME), ns);
addAttributeQuery(qname, attrElement.getText());
}
}
Element rangesElement = rootElement.element(ELEMENT_RANGES);
if (rangesElement != null) {
for (Iterator i = rangesElement.elementIterator(ELEMENT_RANGE); i.hasNext(); ) /**/
{
Element rangeElement = (Element) i.next();
Element lowerElement = rangeElement.element(ELEMENT_LOWER);
Element upperElement = rangeElement.element(ELEMENT_UPPER);
Element incElement = rangeElement.element(ELEMENT_INCLUSIVE);
if (lowerElement != null && upperElement != null && incElement != null) {
QName qname = QName.createQName(rangeElement.attributeValue(ELEMENT_NAME), ns);
addRangeQuery(qname, lowerElement.getText(), upperElement.getText(), Boolean.parseBoolean(incElement.getText()));
}
}
}
Element valuesElement = rootElement.element(ELEMENT_FIXED_VALUES);
if (valuesElement != null) {
for (Iterator i = valuesElement.elementIterator(ELEMENT_VALUE); i.hasNext(); ) /**/
{
Element valueElement = (Element) i.next();
QName qname = QName.createQName(valueElement.attributeValue(ELEMENT_NAME), ns);
addFixedValueQuery(qname, valueElement.getText());
}
}
} catch (Throwable err) {
throw new AlfrescoRuntimeException("Failed to import SearchContext from XML.", err);
}
return this;
}
use of org.alfresco.error.AlfrescoRuntimeException in project acs-community-packaging by Alfresco.
the class Repository method extractMetadata.
/**
* Extracts the metadata of a "raw" piece of content into a map.
*
* @param context Faces Context
* @param reader Content reader for the source content to extract from
* @param destination Map of metadata to set metadata values into
* @return True if an extracter was found
*/
public static boolean extractMetadata(FacesContext context, ContentReader reader, Map<QName, Serializable> destination) {
// check that source mimetype is available
String mimetype = reader.getMimetype();
if (mimetype == null) {
throw new AlfrescoRuntimeException("The content reader mimetype must be set: " + reader);
}
// look for a transformer
MetadataExtracter extracter = getMetadataExtracterRegistry(context).getExtracter(mimetype);
if (extracter == null) {
// No metadata extracter is not a failure, but we flag it
return false;
}
try {
// we have a transformer, so do it
extracter.extract(reader, destination);
return true;
} catch (Throwable e) {
// it failed
logger.warn("Metadata extraction failed: \n" + " reader: " + reader + "\n" + " extracter: " + extracter);
return false;
}
}
use of org.alfresco.error.AlfrescoRuntimeException in project acs-community-packaging by Alfresco.
the class TransientNode method initNode.
/**
* Initialises the node.
*
* @param data The properties and associations to initialise the node with
*/
protected void initNode(Map<QName, Serializable> data) {
if (logger.isDebugEnabled())
logger.debug("Initialising transient node with data: " + data);
DictionaryService ddService = this.getServiceRegistry().getDictionaryService();
// marshall the given properties and associations into the internal maps
this.associations = new QNameNodeMap(this, this);
this.childAssociations = new QNameNodeMap(this, this);
if (data != null) {
// go through all data items and allocate to the correct internal list
for (QName item : data.keySet()) {
PropertyDefinition propDef = ddService.getProperty(item);
if (propDef != null) {
this.properties.put(item, data.get(item));
} else {
// see if the item is either type of association
AssociationDefinition assocDef = ddService.getAssociation(item);
if (assocDef != null) {
if (assocDef.isChild()) {
Object obj = data.get(item);
if (obj instanceof NodeRef) {
NodeRef child = (NodeRef) obj;
// create a child association reference, add it to a list and add the list
// to the list of child associations for this node
List<ChildAssociationRef> assocs = new ArrayList<ChildAssociationRef>(1);
ChildAssociationRef childRef = new ChildAssociationRef(assocDef.getName(), this.nodeRef, null, child);
assocs.add(childRef);
this.childAssociations.put(item, assocs);
} else if (obj instanceof List) {
List targets = (List) obj;
List<ChildAssociationRef> assocs = new ArrayList<ChildAssociationRef>(targets.size());
for (Object target : targets) {
if (target instanceof NodeRef) {
NodeRef currentChild = (NodeRef) target;
ChildAssociationRef childRef = new ChildAssociationRef(assocDef.getName(), this.nodeRef, null, currentChild);
assocs.add(childRef);
}
}
if (assocs.size() > 0) {
this.childAssociations.put(item, assocs);
}
}
} else {
Object obj = data.get(item);
if (obj instanceof NodeRef) {
NodeRef target = (NodeRef) obj;
// create a association reference, add it to a list and add the list
// to the list of associations for this node
List<AssociationRef> assocs = new ArrayList<AssociationRef>(1);
AssociationRef assocRef = new AssociationRef(null, this.nodeRef, assocDef.getName(), target);
assocs.add(assocRef);
this.associations.put(item, assocs);
} else if (obj instanceof List) {
List targets = (List) obj;
List<AssociationRef> assocs = new ArrayList<AssociationRef>(targets.size());
for (Object target : targets) {
if (target instanceof NodeRef) {
NodeRef currentTarget = (NodeRef) target;
AssociationRef assocRef = new AssociationRef(null, this.nodeRef, assocDef.getName(), currentTarget);
assocs.add(assocRef);
}
}
if (assocs.size() > 0) {
this.associations.put(item, assocs);
}
}
}
}
}
}
}
// show that the maps have been initialised
this.propsRetrieved = true;
this.assocsRetrieved = true;
this.childAssocsRetrieved = true;
// setup the list of aspects the node would have
TypeDefinition typeDef = ddService.getType(this.type);
if (typeDef == null) {
throw new AlfrescoRuntimeException("Failed to find type definition: " + this.type);
}
// get flat list of all aspects for the type
List<QName> defaultAspects = new ArrayList<QName>(16);
getMandatoryAspects(typeDef, defaultAspects);
this.aspects = new HashSet<QName>(defaultAspects);
// setup remaining variables
this.path = null;
this.locked = Boolean.FALSE;
this.workingCopyOwner = Boolean.FALSE;
}
use of org.alfresco.error.AlfrescoRuntimeException in project acs-community-packaging by Alfresco.
the class CreateRuleWizard method initialiseConditionHandlers.
/**
* Initialises the condition handlers from the current configuration.
*/
protected void initialiseConditionHandlers() {
if ((this.conditionHandlers == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
ConfigService svc = Application.getConfigService(FacesContext.getCurrentInstance());
Config wizardCfg = svc.getConfig("Action Wizards");
if (wizardCfg != null) {
ConfigElement conditionHandlerCfg = wizardCfg.getConfigElement("condition-handlers");
if (conditionHandlerCfg != null) {
this.conditionHandlers = new HashMap<String, IHandler>(20);
// instantiate each handler and store in the map
for (ConfigElement child : conditionHandlerCfg.getChildren()) {
String conditionName = child.getAttribute("name");
String handlerClass = child.getAttribute("class");
if (conditionName != null && conditionName.length() > 0 && handlerClass != null && handlerClass.length() > 0) {
try {
@SuppressWarnings("unchecked") Class klass = Class.forName(handlerClass);
IHandler handler = (IHandler) klass.newInstance();
this.conditionHandlers.put(conditionName, handler);
} catch (Exception e) {
throw new AlfrescoRuntimeException("Failed to setup condition handler for '" + conditionName + "'", e);
}
}
}
} else {
logger.warn("Could not find 'condition-handlers' configuration element");
}
} else {
logger.warn("Could not find 'Action Wizards' configuration section");
}
}
}
Aggregations