Search in sources :

Example 16 with ContentReader

use of org.alfresco.service.cmr.repository.ContentReader in project acs-community-packaging by Alfresco.

the class ForumsBean method renderReplyContentHTML.

protected void renderReplyContentHTML(FacesContext context, Node replyToNode, StringWriter writer, String contextPath, String colour, String bgColour) throws IOException {
    // get the content of the article being replied to
    String replyContent = "";
    ContentReader reader = this.getContentService().getReader(replyToNode.getNodeRef(), ContentModel.PROP_CONTENT);
    if (reader != null) {
        replyContent = Utils.stripUnsafeHTMLTags(reader.getContentString());
    }
    // get the date of the article being replied to
    String postedDate = Utils.getDateTimeFormat(context).format(replyToNode.getProperties().get("created"));
    // generate the HTML
    writer.write("<td width='100%'>");
    TopicBubbleViewRenderer.renderBubbleTop(writer, contextPath, colour, bgColour);
    writer.write("<span class='mainSubTitle'>");
    writer.write(Application.getMessage(context, "posted"));
    writer.write(":&nbsp</span>");
    writer.write(postedDate);
    TopicBubbleViewRenderer.renderBubbleMiddle(writer, contextPath, colour);
    writer.write(replyContent);
    TopicBubbleViewRenderer.renderBubbleBottom(writer, contextPath, colour);
    writer.write("</td>");
}
Also used : ContentReader(org.alfresco.service.cmr.repository.ContentReader)

Example 17 with ContentReader

use of org.alfresco.service.cmr.repository.ContentReader in project acs-community-packaging by Alfresco.

the class EditOnlineDialog method handleHttpEditing.

/**
 * Action listener for handle http online(inline) editing action. E.g "edit_doc_online_http" action
 *
 * @param event ActionEvent
 */
public void handleHttpEditing(ActionEvent event) {
    handle(event);
    Node workingCopyNode = property.getDocument();
    if (workingCopyNode != null) {
        ContentReader reader = property.getContentService().getReader(workingCopyNode.getNodeRef(), ContentModel.PROP_CONTENT);
        if (reader != null) {
            String mimetype = reader.getMimetype();
            // calculate which editor screen to display
            if (MimetypeMap.MIMETYPE_TEXT_PLAIN.equals(mimetype) || MimetypeMap.MIMETYPE_XML.equals(mimetype) || MimetypeMap.MIMETYPE_TEXT_CSS.equals(mimetype) || MimetypeMap.MIMETYPE_JAVASCRIPT.equals(mimetype)) {
                // make content available to the text editing screen
                property.setEditorOutput(reader.getContentString());
                // navigate to appropriate screen
                FacesContext fc = FacesContext.getCurrentInstance();
                fc.getApplication().getNavigationHandler().handleNavigation(fc, null, "dialog:close:browse");
                this.navigator.setupDispatchContext(workingCopyNode);
                fc.getApplication().getNavigationHandler().handleNavigation(fc, null, "dialog:editTextInline");
            } else {
                // make content available to the html editing screen
                property.setDocumentContent(StringUtils.stripUnsafeHTMLTags(reader.getContentString(), false));
                property.setEditorOutput(null);
                // navigate to appropriate screen
                FacesContext fc = FacesContext.getCurrentInstance();
                fc.getApplication().getNavigationHandler().handleNavigation(fc, null, "dialog:close:browse");
                this.navigator.setupDispatchContext(workingCopyNode);
                fc.getApplication().getNavigationHandler().handleNavigation(fc, null, "dialog:editHtmlInline");
            }
        }
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) Node(org.alfresco.web.bean.repository.Node) ContentReader(org.alfresco.service.cmr.repository.ContentReader)

Example 18 with ContentReader

use of org.alfresco.service.cmr.repository.ContentReader in project acs-community-packaging by Alfresco.

the class EditPostDialog method init.

@Override
public void init(Map<String, String> parameters) {
    super.init(parameters);
    // we need to remove the <br> tags and replace with carriage returns
    // and then setup the content member variable
    Node currentDocument = this.browseBean.getDocument();
    ContentReader reader = this.getContentService().getReader(currentDocument.getNodeRef(), ContentModel.PROP_CONTENT);
    if (reader != null) {
        String htmlContent = reader.getContentString();
        if (htmlContent != null) {
            // ETHREEOH-1216: replace both forms of 'br' as older posts have the <br/> version
            // which doesn't work in all browsers supported by Alfresco Explorer
            htmlContent = StringUtils.replace(htmlContent, "<br/>", "\r\n");
            this.content = StringUtils.replace(htmlContent, "<br>", "\r\n");
        }
    }
}
Also used : Node(org.alfresco.web.bean.repository.Node) ContentReader(org.alfresco.service.cmr.repository.ContentReader)

Example 19 with ContentReader

use of org.alfresco.service.cmr.repository.ContentReader in project records-management by Alfresco.

the class BaseReportGenerator method generateReport.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.report.ReportGenerator#generateReport(org.alfresco.service.cmr.repository.NodeRef, java.lang.String, java.util.Map)
 */
@Override
public Report generateReport(NodeRef reportedUponNodeRef, String mimetype) {
    ParameterCheck.mandatory("reportedUponNodeRef", reportedUponNodeRef);
    ParameterCheck.mandatoryString("mimetype", mimetype);
    // check the applicability of the report generator for the given reported upon node
    checkReportApplicability(reportedUponNodeRef);
    // generate the report name
    String reportName = generateReportName(reportedUponNodeRef, mimetype);
    // generate the report meta-data
    Map<QName, Serializable> reportProperties = generateReportMetadata(reportedUponNodeRef);
    // generate the report content
    ContentReader contentReader = generateReportContent(reportedUponNodeRef, mimetype, generateReportTemplateContext(reportedUponNodeRef));
    // return the report information object
    return new ReportInfo(reportType, reportName, reportProperties, contentReader);
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) ContentReader(org.alfresco.service.cmr.repository.ContentReader)

Example 20 with ContentReader

use of org.alfresco.service.cmr.repository.ContentReader in project records-management by Alfresco.

the class RMCaveatConfigComponentImpl method validateAndReset.

/**
 * Validate the caveat config and optionally update the cache.
 *
 * @param nodeRef The nodeRef of the config
 * @param updateCache Set to <code>true</code> to update the cache
 */
@SuppressWarnings("unchecked")
protected void validateAndReset(NodeRef nodeRef) {
    ContentReader cr = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
    if (cr != null) {
        // TODO - check who can change caveat config !
        // TODO - locking (or checkout/checkin)
        String caveatConfigData = cr.getContentString();
        if (caveatConfigData != null) {
            NodeRef existing = getCaveatConfigNode();
            if ((existing != null && (!existing.equals(nodeRef)))) {
                throw new AlfrescoRuntimeException("Cannot create more than one caveat config (existing=" + existing + ", new=" + nodeRef + ")");
            }
            try {
                if (logger.isTraceEnabled()) {
                    logger.trace(caveatConfigData);
                }
                Set<QName> models = new HashSet<QName>(1);
                Set<QName> props = new HashSet<QName>(10);
                Set<String> expectedPrefixes = new HashSet<String>(10);
                if (caveatModelQNames.size() > 0) {
                    models.addAll(caveatModelQNames);
                } else {
                    models.addAll(dictionaryService.getAllModels());
                }
                if (logger.isTraceEnabled()) {
                    logger.trace("validateAndReset: models to check " + models);
                }
                for (QName model : models) {
                    props.addAll(dictionaryService.getProperties(model, DATATYPE_TEXT));
                    expectedPrefixes.addAll(namespaceService.getPrefixes(model.getNamespaceURI()));
                }
                if (props.size() == 0) {
                    logger.warn("validateAndReset: no caveat properties found");
                } else {
                    if (logger.isTraceEnabled()) {
                        logger.trace("validateAndReset: properties to check " + props);
                    }
                }
                Map<String, Object> caveatConfigMap = JSONtoFmModel.convertJSONObjectToMap(caveatConfigData);
                for (Map.Entry<String, Object> conEntry : caveatConfigMap.entrySet()) {
                    String conStr = conEntry.getKey();
                    QName conQName = QName.resolveToQName(namespaceService, conStr);
                    // check prefix
                    String conPrefix = QName.splitPrefixedQName(conStr)[0];
                    boolean prefixFound = false;
                    for (String expectedPrefix : expectedPrefixes) {
                        if (conPrefix.equals(expectedPrefix)) {
                            prefixFound = true;
                        }
                    }
                    if (!prefixFound) {
                        throw new AlfrescoRuntimeException("Unexpected prefix: " + conPrefix + " (" + conStr + ") expected one of " + expectedPrefixes + ")");
                    }
                    Map<String, List<String>> caveatMap = (Map<String, List<String>>) conEntry.getValue();
                    List<String> allowedValues = null;
                    @SuppressWarnings("unused") boolean found = false;
                    for (QName propertyName : props) {
                        PropertyDefinition propDef = dictionaryService.getProperty(propertyName);
                        List<ConstraintDefinition> conDefs = propDef.getConstraints();
                        for (ConstraintDefinition conDef : conDefs) {
                            final Constraint con = conDef.getConstraint();
                            if (con instanceof RMListOfValuesConstraint) {
                                String conName = ((RMListOfValuesConstraint) con).getShortName();
                                if (conName.equals(conStr)) {
                                    // note: assumes only one caveat/LOV against a given property
                                    allowedValues = AuthenticationUtil.runAs(new RunAsWork<List<String>>() {

                                        public List<String> doWork() {
                                            return ((RMListOfValuesConstraint) con).getAllowedValues();
                                        }
                                    }, AuthenticationUtil.getSystemUserName());
                                    found = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (allowedValues != null) {
                        if (logger.isInfoEnabled()) {
                            logger.info("Processing constraint: " + conQName);
                        }
                        for (Map.Entry<String, List<String>> caveatEntry : caveatMap.entrySet()) {
                            String authorityName = caveatEntry.getKey();
                            List<String> caveatList = caveatEntry.getValue();
                            // validate authority (user or group) - note: groups are configured with fullname (ie. GROUP_xxx)
                            if ((!authorityService.authorityExists(authorityName) && !personService.personExists(authorityName))) {
                                // TODO - review warnings (& I18N)
                                String msg = "User/group does not exist: " + authorityName + " (constraint=" + conStr + ")";
                                logger.warn(msg);
                            }
                            // validate caveat list
                            for (String value : caveatList) {
                                if (!allowedValues.contains(value)) {
                                    // TODO - review warnings (& add I18N)
                                    String msg = "Invalid value in list: " + value + " (authority=" + authorityName + ", constraint=" + conStr + ")";
                                    logger.warn(msg);
                                }
                            }
                        }
                    }
                }
                try {
                    writeLock.lock();
                    // we can't just clear the cache, as all puts to the cache afterwards in this transaction will be ignored
                    // first delete all keys that are now not in the config
                    caveatConfig.getKeys().retainAll(caveatConfigMap.keySet());
                    for (Map.Entry<String, Object> conEntry : caveatConfigMap.entrySet()) {
                        String conStr = conEntry.getKey();
                        Map<String, List<String>> caveatMap = (Map<String, List<String>>) conEntry.getValue();
                        Map<String, List<String>> cacheValue = caveatConfig.get(conStr);
                        if (cacheValue == null || !cacheValue.equals(caveatMap)) {
                            // update the cache
                            caveatConfig.put(conStr, caveatMap);
                        }
                    }
                } finally {
                    writeLock.unlock();
                }
            } catch (JSONException e) {
                throw new AlfrescoRuntimeException("Invalid caveat config syntax: " + e);
            }
        }
    }
}
Also used : Constraint(org.alfresco.service.cmr.dictionary.Constraint) RunAsWork(org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork) NodeRef(org.alfresco.service.cmr.repository.NodeRef) List(java.util.List) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) QName(org.alfresco.service.namespace.QName) ContentReader(org.alfresco.service.cmr.repository.ContentReader) JSONException(org.json.JSONException) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) ConstraintDefinition(org.alfresco.service.cmr.dictionary.ConstraintDefinition) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) JSONObject(org.json.JSONObject) Map(java.util.Map) MimetypeMap(org.alfresco.repo.content.MimetypeMap) HashMap(java.util.HashMap)

Aggregations

ContentReader (org.alfresco.service.cmr.repository.ContentReader)53 NodeRef (org.alfresco.service.cmr.repository.NodeRef)25 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)20 Test (org.junit.Test)17 HashMap (java.util.HashMap)16 AlfrescoDocument (org.alfresco.cmis.client.AlfrescoDocument)13 AlfrescoFolder (org.alfresco.cmis.client.AlfrescoFolder)13 FileContentWriter (org.alfresco.repo.content.filestore.FileContentWriter)13 VersionableAspectTest (org.alfresco.repo.version.VersionableAspectTest)13 TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)13 CmisSession (org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession)13 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)13 ContentStreamImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl)13 TestPerson (org.alfresco.rest.api.tests.RepoService.TestPerson)12 CmisUpdateConflictException (org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException)12 PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)11 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)11 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)11 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)11 CmisPermissionDeniedException (org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException)11