Search in sources :

Example 31 with StoreRef

use of org.alfresco.service.cmr.repository.StoreRef in project SearchServices by Alfresco.

the class LoadCMISData method addTypeTestData.

protected static void addTypeTestData(NodeRef folder00NodeRef, NodeRef rootNodeRef, NodeRef baseFolderNodeRef, Object baseFolderQName, Object folder00QName, Date date1) throws IOException {
    HashMap<QName, PropertyValue> content00Properties = new HashMap<QName, PropertyValue>();
    MLTextPropertyValue desc00 = new MLTextPropertyValue();
    desc00.addValue(Locale.ENGLISH, "Test One");
    desc00.addValue(Locale.US, "Test 1");
    content00Properties.put(ContentModel.PROP_DESCRIPTION, desc00);
    content00Properties.put(ContentModel.PROP_TITLE, desc00);
    content00Properties.put(ContentModel.PROP_NAME, new StringPropertyValue("Test One"));
    content00Properties.put(ContentModel.PROP_CREATED, new StringPropertyValue(DefaultTypeConverter.INSTANCE.convert(String.class, date1)));
    StringPropertyValue single = new StringPropertyValue("Un tokenised");
    content00Properties.put(singleTextUntokenised, single);
    content00Properties.put(singleTextTokenised, single);
    content00Properties.put(singleTextBoth, single);
    MultiPropertyValue multi = new MultiPropertyValue();
    multi.addValue(single);
    multi.addValue(new StringPropertyValue("two parts"));
    content00Properties.put(multipleTextUntokenised, multi);
    content00Properties.put(multipleTextTokenised, multi);
    content00Properties.put(multipleTextBoth, multi);
    content00Properties.put(singleMLTextUntokenised, makeMLText());
    content00Properties.put(singleMLTextTokenised, makeMLText());
    content00Properties.put(singleMLTextBoth, makeMLText());
    content00Properties.put(multipleMLTextUntokenised, makeMLTextMVP());
    content00Properties.put(multipleMLTextTokenised, makeMLTextMVP());
    content00Properties.put(multipleMLTextBoth, makeMLTextMVP());
    StringPropertyValue one = new StringPropertyValue("1");
    StringPropertyValue two = new StringPropertyValue("2");
    MultiPropertyValue multiDec = new MultiPropertyValue();
    multiDec.addValue(one);
    multiDec.addValue(new StringPropertyValue("1.1"));
    content00Properties.put(singleFloat, one);
    content00Properties.put(multipleFloat, multiDec);
    content00Properties.put(singleDouble, one);
    content00Properties.put(multipleDouble, multiDec);
    MultiPropertyValue multiInt = new MultiPropertyValue();
    multiInt.addValue(one);
    multiInt.addValue(two);
    content00Properties.put(singleInteger, one);
    content00Properties.put(multipleInteger, multiInt);
    content00Properties.put(singleLong, one);
    content00Properties.put(multipleLong, multiInt);
    GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(date1);
    cal.add(Calendar.DAY_OF_MONTH, -1);
    cal.add(Calendar.DAY_OF_MONTH, 2);
    Date date2 = cal.getTime();
    StringPropertyValue d1 = new StringPropertyValue(DefaultTypeConverter.INSTANCE.convert(String.class, date1));
    StringPropertyValue d2 = new StringPropertyValue(DefaultTypeConverter.INSTANCE.convert(String.class, date2));
    MultiPropertyValue multiDate = new MultiPropertyValue();
    multiDate.addValue(d1);
    multiDate.addValue(d2);
    content00Properties.put(singleDate, d1);
    content00Properties.put(multipleDate, multiDate);
    content00Properties.put(singleDatetime, d1);
    content00Properties.put(multipleDatetime, multiDate);
    StringPropertyValue bTrue = new StringPropertyValue(DefaultTypeConverter.INSTANCE.convert(String.class, true));
    StringPropertyValue bFalse = new StringPropertyValue(DefaultTypeConverter.INSTANCE.convert(String.class, false));
    MultiPropertyValue multiBool = new MultiPropertyValue();
    multiBool.addValue(bTrue);
    multiBool.addValue(bFalse);
    content00Properties.put(singleBoolean, bTrue);
    content00Properties.put(multipleBoolean, multiBool);
    NodeRef content00NodeRef = new NodeRef(new StoreRef("workspace", "SpacesStore"), createGUID());
    QName content00QName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Test One");
    ChildAssociationRef content00CAR = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, folder00NodeRef, content00QName, content00NodeRef, true, 0);
    addNode(h.getCore(), dataModel, 1, 100, 1, extendedContent, new QName[] { ContentModel.ASPECT_OWNABLE, ContentModel.ASPECT_TITLED }, content00Properties, null, "andy", new ChildAssociationRef[] { content00CAR }, new NodeRef[] { baseFolderNodeRef, rootNodeRef, folder00NodeRef }, new String[] { "/" + baseFolderQName.toString() + "/" + folder00QName.toString() + "/" + content00QName.toString() }, content00NodeRef, true);
}
Also used : StringPropertyValue(org.alfresco.solr.client.StringPropertyValue) StoreRef(org.alfresco.service.cmr.repository.StoreRef) HashMap(java.util.HashMap) MultiPropertyValue(org.alfresco.solr.client.MultiPropertyValue) QName(org.alfresco.service.namespace.QName) GregorianCalendar(java.util.GregorianCalendar) MLTextPropertyValue(org.alfresco.solr.client.MLTextPropertyValue) MultiPropertyValue(org.alfresco.solr.client.MultiPropertyValue) PropertyValue(org.alfresco.solr.client.PropertyValue) StringPropertyValue(org.alfresco.solr.client.StringPropertyValue) ContentPropertyValue(org.alfresco.solr.client.ContentPropertyValue) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) Date(java.util.Date) NodeRef(org.alfresco.service.cmr.repository.NodeRef) MLTextPropertyValue(org.alfresco.solr.client.MLTextPropertyValue)

Example 32 with StoreRef

use of org.alfresco.service.cmr.repository.StoreRef in project SearchServices by Alfresco.

the class TrieFieldsCMISTest method addTrieTypeTestData.

private void addTrieTypeTestData(NodeRef folder00NodeRef, NodeRef rootNodeRef, NodeRef baseFolderNodeRef, QName baseFolderQName, QName folder00QName, Date date00) throws IOException {
    HashMap<QName, PropertyValue> content00Properties = new HashMap<QName, PropertyValue>();
    MLTextPropertyValue desc00 = new MLTextPropertyValue();
    desc00.addValue(Locale.ENGLISH, "Trie test1");
    content00Properties.put(ContentModel.PROP_DESCRIPTION, desc00);
    content00Properties.put(ContentModel.PROP_TITLE, desc00);
    content00Properties.put(ContentModel.PROP_NAME, new StringPropertyValue("Trie test1"));
    content00Properties.put(ContentModel.PROP_CREATED, new StringPropertyValue(DefaultTypeConverter.INSTANCE.convert(String.class, date00)));
    StringPropertyValue firstIntValue = new StringPropertyValue("98198");
    content00Properties.put(singleInteger, firstIntValue);
    StringPropertyValue firstLongValue = new StringPropertyValue("3956650");
    content00Properties.put(singleLong, firstLongValue);
    NodeRef content00NodeRef = new NodeRef(new StoreRef("workspace", "SpacesStore"), createGUID());
    QName content00QName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Trie test1");
    ChildAssociationRef content00CAR = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, folder00NodeRef, content00QName, content00NodeRef, true, 0);
    addNode(h.getCore(), dataModel, 1, 300, 1, extendedContent, new QName[] { ContentModel.ASPECT_OWNABLE, ContentModel.ASPECT_TITLED }, content00Properties, null, "andy", new ChildAssociationRef[] { content00CAR }, new NodeRef[] { baseFolderNodeRef, rootNodeRef, folder00NodeRef }, new String[] { "/" + baseFolderQName.toString() + "/" + folder00QName.toString() + "/" + content00QName.toString() }, content00NodeRef, true);
    HashMap<QName, PropertyValue> content01Properties = new HashMap<QName, PropertyValue>();
    MLTextPropertyValue desc01 = new MLTextPropertyValue();
    desc01.addValue(Locale.ENGLISH, "Trie test2");
    content01Properties.put(ContentModel.PROP_DESCRIPTION, desc01);
    content01Properties.put(ContentModel.PROP_TITLE, desc01);
    content01Properties.put(ContentModel.PROP_NAME, new StringPropertyValue("Trie test2"));
    content01Properties.put(ContentModel.PROP_CREATED, new StringPropertyValue(DefaultTypeConverter.INSTANCE.convert(String.class, date00)));
    StringPropertyValue secondIntValue = new StringPropertyValue("98200");
    content01Properties.put(singleInteger, secondIntValue);
    StringPropertyValue secondLongValue = new StringPropertyValue("3956651");
    content01Properties.put(singleLong, secondLongValue);
    NodeRef content01NodeRef = new NodeRef(new StoreRef("workspace", "SpacesStore"), createGUID());
    QName content01QName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Trie test1");
    ChildAssociationRef content01CAR = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, folder00NodeRef, content01QName, content01NodeRef, true, 0);
    addNode(h.getCore(), dataModel, 1, 301, 1, extendedContent, new QName[] { ContentModel.ASPECT_OWNABLE, ContentModel.ASPECT_TITLED }, content01Properties, null, "andy", new ChildAssociationRef[] { content01CAR }, new NodeRef[] { baseFolderNodeRef, rootNodeRef, folder00NodeRef }, new String[] { "/" + baseFolderQName.toString() + "/" + folder00QName.toString() + "/" + content01QName.toString() }, content01NodeRef, true);
}
Also used : StringPropertyValue(org.alfresco.solr.client.StringPropertyValue) NodeRef(org.alfresco.service.cmr.repository.NodeRef) StoreRef(org.alfresco.service.cmr.repository.StoreRef) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) MLTextPropertyValue(org.alfresco.solr.client.MLTextPropertyValue) MLTextPropertyValue(org.alfresco.solr.client.MLTextPropertyValue) PropertyValue(org.alfresco.solr.client.PropertyValue) StringPropertyValue(org.alfresco.solr.client.StringPropertyValue) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 33 with StoreRef

use of org.alfresco.service.cmr.repository.StoreRef in project SearchServices by Alfresco.

the class AFTSDisjunctionTest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    initAlfrescoCore("schema.xml");
    Thread.sleep(1000);
    // Root
    SolrCore core = h.getCore();
    AlfrescoSolrDataModel dataModel = AlfrescoSolrDataModel.getInstance();
    dataModel.getNamespaceDAO().removePrefix("");
    dataModel.setCMDefaultUri();
    NodeRef rootNodeRef = new NodeRef(new StoreRef("workspace", "SpacesStore"), createGUID());
    addStoreRoot(core, dataModel, rootNodeRef, 1, 1, 1, 1);
    NodeRef baseFolderNodeRef = new NodeRef(new StoreRef("workspace", "SpacesStore"), createGUID());
    QName baseFolderQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "baseFolder");
    HashMap<QName, PropertyValue> folder00Properties = new HashMap<QName, PropertyValue>();
    folder00Properties.put(ContentModel.PROP_NAME, new StringPropertyValue("Folder 0"));
    NodeRef folder00NodeRef = new NodeRef(new StoreRef("workspace", "SpacesStore"), createGUID());
    QName folder00QName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Folder 0");
    ChildAssociationRef folder00CAR = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, baseFolderNodeRef, folder00QName, folder00NodeRef, true, 0);
    addNode(h.getCore(), dataModel, 1, 3, 1, ContentModel.TYPE_FOLDER, null, folder00Properties, null, "andy", new ChildAssociationRef[] { folder00CAR }, new NodeRef[] { baseFolderNodeRef, rootNodeRef }, new String[] { "/" + baseFolderQName.toString() + "/" + folder00QName.toString() }, folder00NodeRef, true);
    // 1
    String guid = createGUID();
    NodeRef nodeRef1 = new NodeRef(new StoreRef("workspace", "SpacesStore"), guid);
    QName name1 = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "test1");
    HashMap<QName, PropertyValue> properties1 = new HashMap<QName, PropertyValue>();
    properties1.put(ContentModel.PROP_NAME, new StringPropertyValue("test1"));
    addNode(core, dataModel, 1, 2, 1, ContentModel.TYPE_CONTENT, null, properties1, null, "michael", null, new NodeRef[] { rootNodeRef }, new String[] { "/" + name1.toString() }, nodeRef1, true);
    System.out.println("create node test1 " + guid);
    guid = createGUID();
    NodeRef nodeRef2 = new NodeRef(new StoreRef("workspace", "SpacesStore"), guid);
    QName name2 = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "test2");
    HashMap<QName, PropertyValue> properties2 = new HashMap<QName, PropertyValue>();
    properties2.put(ContentModel.PROP_NAME, new StringPropertyValue("test2"));
    addNode(core, dataModel, 1, 3, 1, ContentModel.TYPE_CONTENT, null, properties2, null, "michael", null, new NodeRef[] { rootNodeRef }, new String[] { "/" + name2.toString() }, nodeRef2, true);
    System.out.println("create node test2 " + guid);
    guid = createGUID();
    NodeRef nodeRef3 = new NodeRef(new StoreRef("workspace", "SpacesStore"), guid);
    QName name3 = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "test3");
    HashMap<QName, PropertyValue> properties3 = new HashMap<QName, PropertyValue>();
    properties3.put(ContentModel.PROP_NAME, new StringPropertyValue("test3"));
    addNode(core, dataModel, 1, 4, 1, ContentModel.TYPE_CONTENT, null, properties3, null, "michael", null, new NodeRef[] { rootNodeRef }, new String[] { "/" + name3.toString() }, nodeRef3, true);
    System.out.println("create node test3 " + guid);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) StoreRef(org.alfresco.service.cmr.repository.StoreRef) StringPropertyValue(org.alfresco.solr.client.StringPropertyValue) HashMap(java.util.HashMap) SolrCore(org.apache.solr.core.SolrCore) QName(org.alfresco.service.namespace.QName) PropertyValue(org.alfresco.solr.client.PropertyValue) StringPropertyValue(org.alfresco.solr.client.StringPropertyValue) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) AlfrescoSolrDataModel(org.alfresco.solr.AlfrescoSolrDataModel) BeforeClass(org.junit.BeforeClass)

Example 34 with StoreRef

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

the class AdminNodeBrowseBean method selectStore.

/**
 * Action to select a store
 *
 * @return next action
 */
public String selectStore() {
    StoreRef storeRef = (StoreRef) getStores().getRowData();
    NodeRef rootNode = getNodeService().getRootNode(storeRef);
    setNodeRef(rootNode);
    return "success";
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef)

Example 35 with StoreRef

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

the class BaseDownloadContentServlet method processDownloadRequest.

/**
 * Processes the download request using the current context i.e. no authentication checks are made, it is presumed
 * they have already been done.
 *
 * @param req
 *           The HTTP request
 * @param res
 *           The HTTP response
 * @param allowLogIn
 *           Indicates whether guest users without access to the content should be redirected to the log in page. If
 *           <code>false</code>, a status 403 forbidden page is displayed instead.
 */
protected void processDownloadRequest(HttpServletRequest req, HttpServletResponse res, boolean allowLogIn, boolean transmitContent) throws ServletException, IOException {
    Log logger = getLogger();
    String uri = req.getRequestURI();
    if (logger.isDebugEnabled()) {
        String queryString = req.getQueryString();
        logger.debug("Processing URL: " + uri + ((queryString != null && queryString.length() > 0) ? ("?" + queryString) : ""));
    }
    uri = uri.substring(req.getContextPath().length());
    StringTokenizer t = new StringTokenizer(uri, "/");
    int tokenCount = t.countTokens();
    // skip servlet name
    t.nextToken();
    // attachment mode (either 'attach' or 'direct')
    String attachToken = t.nextToken();
    boolean attachment = URL_ATTACH.equals(attachToken) || URL_ATTACH_LONG.equals(attachToken);
    ServiceRegistry serviceRegistry = getServiceRegistry(getServletContext());
    // get or calculate the noderef and filename to download as
    NodeRef nodeRef;
    String filename;
    // do we have a path parameter instead of a NodeRef?
    String path = req.getParameter(ARG_PATH);
    if (path != null && path.length() != 0) {
        // process the name based path to resolve the NodeRef and the Filename element
        try {
            PathRefInfo pathInfo = resolveNamePath(getServletContext(), path);
            nodeRef = pathInfo.NodeRef;
            filename = pathInfo.Filename;
        } catch (IllegalArgumentException e) {
            Application.handleSystemError(getServletContext(), req, res, MSG_ERROR_NOT_FOUND, HttpServletResponse.SC_NOT_FOUND, logger);
            return;
        }
    } else {
        // a NodeRef must have been specified if no path has been found
        if (tokenCount < 6) {
            throw new IllegalArgumentException("Download URL did not contain all required args: " + uri);
        }
        // assume 'workspace' or other NodeRef based protocol for remaining URL elements
        StoreRef storeRef = new StoreRef(URLDecoder.decode(t.nextToken()), URLDecoder.decode(t.nextToken()));
        String id = URLDecoder.decode(t.nextToken());
        // build noderef from the appropriate URL elements
        nodeRef = new NodeRef(storeRef, id);
        if (tokenCount > 6) {
            // found additional relative path elements i.e. noderefid/images/file.txt
            // this allows a url to reference siblings nodes via a cm:name based relative path
            // solves the issue with opening HTML content containing relative URLs in HREF or IMG tags etc.
            List<String> paths = new ArrayList<String>(tokenCount - 5);
            while (t.hasMoreTokens()) {
                paths.add(URLDecoder.decode(t.nextToken()));
            }
            filename = paths.get(paths.size() - 1);
            try {
                NodeRef parentRef = serviceRegistry.getNodeService().getPrimaryParent(nodeRef).getParentRef();
                FileInfo fileInfo = serviceRegistry.getFileFolderService().resolveNamePath(parentRef, paths);
                nodeRef = fileInfo.getNodeRef();
            } catch (FileNotFoundException e) {
                Application.handleSystemError(getServletContext(), req, res, MSG_ERROR_NOT_FOUND, HttpServletResponse.SC_NOT_FOUND, logger);
                return;
            }
        } else {
            // filename is last remaining token
            filename = t.nextToken();
        }
    }
    // get qualified of the property to get content from - default to ContentModel.PROP_CONTENT
    QName propertyQName = ContentModel.PROP_CONTENT;
    String property = req.getParameter(ARG_PROPERTY);
    if (property != null && property.length() != 0) {
        propertyQName = QName.createQName(property);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Found NodeRef: " + nodeRef);
        logger.debug("Will use filename: " + filename);
        logger.debug("For property: " + propertyQName);
        logger.debug("With attachment mode: " + attachment);
    }
    // get the services we need to retrieve the content
    NodeService nodeService = serviceRegistry.getNodeService();
    ContentService contentService = serviceRegistry.getContentService();
    // Check that the node still exists
    if (!nodeService.exists(nodeRef)) {
        Application.handleSystemError(getServletContext(), req, res, MSG_ERROR_NOT_FOUND, HttpServletResponse.SC_NOT_FOUND, logger);
        return;
    }
    try {
        // check that the user has at least READ_CONTENT access - else redirect to an error or login page
        if (!checkAccess(req, res, nodeRef, PermissionService.READ_CONTENT, allowLogIn)) {
            return;
        }
        // check If-Modified-Since header and set Last-Modified header as appropriate
        Date modified = (Date) nodeService.getProperty(nodeRef, ContentModel.PROP_MODIFIED);
        if (modified != null) {
            long modifiedSince = req.getDateHeader(HEADER_IF_MODIFIED_SINCE);
            if (modifiedSince > 0L) {
                // round the date to the ignore millisecond value which is not supplied by header
                long modDate = (modified.getTime() / 1000L) * 1000L;
                if (modDate <= modifiedSince) {
                    if (logger.isDebugEnabled())
                        logger.debug("Returning 304 Not Modified.");
                    res.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
                    return;
                }
            }
            res.setDateHeader(HEADER_LAST_MODIFIED, modified.getTime());
            res.setHeader(HEADER_CACHE_CONTROL, "must-revalidate, max-age=0");
            res.setHeader(HEADER_ETAG, "\"" + Long.toString(modified.getTime()) + "\"");
        }
        if (attachment == true) {
            setHeaderContentDisposition(req, res, filename);
        }
        // get the content reader
        ContentReader reader = contentService.getReader(nodeRef, propertyQName);
        // ensure that it is safe to use
        reader = FileContentReader.getSafeContentReader(reader, Application.getMessage(req.getSession(), MSG_ERROR_CONTENT_MISSING), nodeRef, reader);
        String mimetype = reader.getMimetype();
        // fall back if unable to resolve mimetype property
        if (mimetype == null || mimetype.length() == 0) {
            MimetypeService mimetypeMap = serviceRegistry.getMimetypeService();
            mimetype = MIMETYPE_OCTET_STREAM;
            int extIndex = filename.lastIndexOf('.');
            if (extIndex != -1) {
                String ext = filename.substring(extIndex + 1);
                mimetype = mimetypeMap.getMimetype(ext);
            }
        }
        // explicitly set the content disposition header if the content is powerpoint
        if (!attachment && (mimetype.equals(POWER_POINT_2007_DOCUMENT_MIMETYPE) || mimetype.equals(POWER_POINT_DOCUMENT_MIMETYPE))) {
            setHeaderContentDisposition(req, res, filename);
        }
        // get the content and stream directly to the response output stream
        // assuming the repo is capable of streaming in chunks, this should allow large files
        // to be streamed directly to the browser response stream.
        res.setHeader(HEADER_ACCEPT_RANGES, "bytes");
        // for a GET request, transmit the content else just the headers are sent
        if (transmitContent) {
            try {
                boolean processedRange = false;
                String range = req.getHeader(HEADER_CONTENT_RANGE);
                if (range == null) {
                    range = req.getHeader(HEADER_RANGE);
                }
                if (range != null) {
                    if (logger.isDebugEnabled())
                        logger.debug("Found content range header: " + range);
                    // ensure the range header is starts with "bytes=" and process the range(s)
                    if (range.length() > 6) {
                        HttpRangeProcessor rangeProcessor = new HttpRangeProcessor(contentService);
                        processedRange = rangeProcessor.processRange(res, reader, range.substring(6), nodeRef, propertyQName, mimetype, req.getHeader(HEADER_USER_AGENT));
                    }
                }
                if (processedRange == false) {
                    if (logger.isDebugEnabled())
                        logger.debug("Sending complete file content...");
                    // set mimetype for the content and the character encoding for the stream
                    res.setContentType(mimetype);
                    res.setCharacterEncoding(reader.getEncoding());
                    // MNT-10642 Alfresco Explorer has javascript vulnerability opening HTML files
                    if (req.getRequestURI().contains("/d/d/") && (mimetype.equals("text/html") || mimetype.equals("application/xhtml+xml") || mimetype.equals("text/xml"))) {
                        String content = reader.getContentString();
                        if (mimetype.equals("text/html") || mimetype.equals("application/xhtml+xml")) {
                            // process with HTML stripper
                            content = StringUtils.stripUnsafeHTMLTags(content, false);
                        } else if (mimetype.equals("text/xml") && mimetype.equals("text/x-component")) {
                            // IE supports "behaviour" which means that css can load a .htc file that could
                            // contain XSS code in the form of jscript, vbscript etc, to stop it form being
                            // evaluated we set the contient type to text/plain
                            res.setContentType("text/plain");
                        }
                        String encoding = reader.getEncoding();
                        byte[] bytes = encoding != null ? content.getBytes(encoding) : content.getBytes();
                        res.setContentLength(bytes.length);
                        res.getOutputStream().write(bytes);
                        return;
                    }
                    // return the complete entity range
                    long size = reader.getSize();
                    res.setHeader(HEADER_CONTENT_RANGE, "bytes 0-" + Long.toString(size - 1L) + "/" + Long.toString(size));
                    res.setHeader(HEADER_CONTENT_LENGTH, Long.toString(size));
                    reader.getContent(res.getOutputStream());
                }
            } catch (SocketException e1) {
                // the client cut the connection - our mission was accomplished apart from a little error message
                if (logger.isDebugEnabled())
                    logger.debug("Client aborted stream read:\n\tnode: " + nodeRef + "\n\tcontent: " + reader);
            } catch (ContentIOException e2) {
                if (logger.isInfoEnabled())
                    logger.info("Failed stream read:\n\tnode: " + nodeRef + " due to: " + e2.getMessage());
            } catch (Throwable err) {
                if (err.getCause() instanceof SocketException) {
                    // the client cut the connection - our mission was accomplished apart from a little error message
                    if (logger.isDebugEnabled())
                        logger.debug("Client aborted stream read:\n\tnode: " + nodeRef + "\n\tcontent: " + reader);
                } else
                    throw err;
            }
        } else {
            if (logger.isDebugEnabled())
                logger.debug("HEAD request processed - no content sent.");
            res.getOutputStream().close();
        }
    } catch (Throwable err) {
        throw new AlfrescoRuntimeException("Error during download content servlet processing: " + err.getMessage(), err);
    }
}
Also used : SocketException(java.net.SocketException) ArrayList(java.util.ArrayList) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) HttpRangeProcessor(org.alfresco.repo.web.util.HttpRangeProcessor) StoreRef(org.alfresco.service.cmr.repository.StoreRef) Log(org.apache.commons.logging.Log) QName(org.alfresco.service.namespace.QName) NodeService(org.alfresco.service.cmr.repository.NodeService) FileContentReader(org.alfresco.repo.content.filestore.FileContentReader) ContentReader(org.alfresco.service.cmr.repository.ContentReader) ContentService(org.alfresco.service.cmr.repository.ContentService) Date(java.util.Date) StringTokenizer(java.util.StringTokenizer) MimetypeService(org.alfresco.service.cmr.repository.MimetypeService) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ServiceRegistry(org.alfresco.service.ServiceRegistry)

Aggregations

StoreRef (org.alfresco.service.cmr.repository.StoreRef)67 NodeRef (org.alfresco.service.cmr.repository.NodeRef)50 HashMap (java.util.HashMap)18 QName (org.alfresco.service.namespace.QName)17 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)13 StringPropertyValue (org.alfresco.solr.client.StringPropertyValue)13 PropertyValue (org.alfresco.solr.client.PropertyValue)11 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)10 ArrayList (java.util.ArrayList)9 ContentPropertyValue (org.alfresco.solr.client.ContentPropertyValue)9 MLTextPropertyValue (org.alfresco.solr.client.MLTextPropertyValue)9 IOException (java.io.IOException)7 Date (java.util.Date)6 MultiPropertyValue (org.alfresco.solr.client.MultiPropertyValue)6 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)5 PermissionService (org.alfresco.service.cmr.security.PermissionService)5 SolrCore (org.apache.solr.core.SolrCore)5 StringTokenizer (java.util.StringTokenizer)4 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)4 ServiceRegistry (org.alfresco.service.ServiceRegistry)4