Package org.apache.roller.weblogger.business

Examples of org.apache.roller.weblogger.business.MediaFileManager


     * @return String The result of the action.
     */
    @SkipValidation
    public String execute() {
        try {
            MediaFileManager mgr = WebloggerFactory.getWeblogger().getMediaFileManager();
            MediaFile mediaFile = mgr.getMediaFile(getMediaFileId());
            bean.copyFrom(mediaFile);
        } catch (WebloggerException ex) {
            log.error("Error looking up media file directory", ex);
        }
        return SUCCESS;
View Full Code Here


            byte[] bits = (byte[]) struct.get("bits");
           
            RollerMessages msgs = new RollerMessages();

            Weblogger roller = WebloggerFactory.getWeblogger();
            MediaFileManager fmgr = roller.getMediaFileManager();
            MediaFileDirectory root = fmgr.getMediaFileRootDirectory(website);
            // Try to save file
            MediaFile mf = new MediaFile();
            mf.setDirectory(root);
            mf.setWeblog(website);
            mf.setName(name);
            mf.setContentType(type);
            mf.setInputStream(new ByteArrayInputStream(bits));
            mf.setLength(bits.length);
            String fileLink = mf.getPermalink();
           
            RollerMessages errors = new RollerMessages();
            fmgr.createMediaFile(website, mf, errors);
           
            if (errors.getErrorCount() > 0) {
                throw new Exception(errors.toString());
            }
View Full Code Here

     *
     * @return String The result of the action.
     */
    @SkipValidation
    public String execute() {
        MediaFileManager manager = WebloggerFactory.getWeblogger().getMediaFileManager();
        try {
            MediaFileDirectory directory;
            if (this.directoryId != null) {
                directory = manager.getMediaFileDirectory(this.directoryId);
            } else if (this.directoryPath != null) {
                directory = manager.getMediaFileDirectoryByPath(getActionWeblog(), this.directoryPath);
                this.directoryId = directory.getId();
            } else {
                directory = manager.getMediaFileRootDirectory(getActionWeblog());
                this.directoryId = directory.getId();
            }

            this.childDirectories = new ArrayList<MediaFileDirectory>();
            this.childDirectories.addAll(directory.getChildDirectories());
View Full Code Here

            throws WebloggerException {

        log.debug("Importing theme [" + theme.getName() + "] to weblog [" + website.getName() + "]");

        WeblogManager wmgr = roller.getWeblogManager();
        MediaFileManager fileMgr = roller.getMediaFileManager();
       
        MediaFileDirectory root = fileMgr.getMediaFileRootDirectory(website);
        log.warn("Weblog " + website.getHandle() + " does not have a root MediaFile directory");

        Set importedActionTemplates = new HashSet();
        ThemeTemplate themeTemplate = null;
        ThemeTemplate stylesheetTemplate = theme.getStylesheet();
        Iterator iter = theme.getTemplates().iterator();
        while (iter.hasNext()) {
            themeTemplate = (ThemeTemplate) iter.next();

            WeblogTemplate template = null;

            // if template is an action, lookup by action
            if (themeTemplate.getAction() != null
                    && !themeTemplate.getAction().equals(WeblogTemplate.ACTION_CUSTOM)) {
                importedActionTemplates.add(themeTemplate.getAction());
                template = wmgr.getPageByAction(website, themeTemplate.getAction());

                // otherwise, lookup by name
            } else {
                template = wmgr.getPageByName(website, themeTemplate.getName());
            }

            // Weblog does not have this template, so create it.
            boolean newTmpl = false;
            if (template == null) {
                template = new WeblogTemplate();
                template.setWebsite(website);
                newTmpl = true;
            }

            // TODO: fix conflict situation
            // it's possible that someone has defined a theme template which
            // matches 2 existing templates, 1 by action, the other by name

            // update template attributes
            // NOTE: we don't want to copy the template data for an existing stylesheet
            if (newTmpl || !themeTemplate.equals(stylesheetTemplate)) {
                template.setAction(themeTemplate.getAction());
                template.setName(themeTemplate.getName());
                template.setDescription(themeTemplate.getDescription());
                template.setLink(themeTemplate.getLink());
                template.setContents(themeTemplate.getContents());
                template.setHidden(themeTemplate.isHidden());
                template.setNavbar(themeTemplate.isNavbar());
                template.setTemplateLanguage(themeTemplate.getTemplateLanguage());
                // NOTE: decorators are deprecated starting in 4.0
                template.setDecoratorName(null);
                template.setLastModified(new Date());

                // save it
                wmgr.savePage(template);
            }
        }

        // now, see if the weblog has left over action templates that
        // need to be deleted because they aren't in their new theme
        for (int i = 0; i < WeblogTemplate.ACTIONS.length; i++) {
            String action = WeblogTemplate.ACTIONS[i];

            // if we didn't import this action then see if it should be deleted
            if (!importedActionTemplates.contains(action)) {
                WeblogTemplate toDelete = wmgr.getPageByAction(website, action);
                if (toDelete != null) {
                    log.debug("Removing stale action template " + toDelete.getId());
                    wmgr.removePage(toDelete);
                }
            }
        }


        // always update this weblog's theme and customStylesheet, then save
        website.setEditorTheme(WeblogTheme.CUSTOM);
        if (theme.getStylesheet() != null) {
            website.setCustomStylesheetPath(theme.getStylesheet().getLink());
        }
        wmgr.saveWeblog(website);

        // now lets import all the theme resources
        List resources = theme.getResources();
        Iterator iterat = resources.iterator();
        ThemeResource resource = null;
        while (iterat.hasNext()) {
            resource = (ThemeResource) iterat.next();

            log.debug("Importing resource " + resource.getPath());

            if (resource.isDirectory()) {
                MediaFileDirectory mdir =
                    fileMgr.getMediaFileDirectoryByPath(website, resource.getPath());
                if (mdir == null) {
                    log.debug("    Creating directory: " + resource.getPath());
                    mdir = fileMgr.createMediaFileDirectory(
                      fileMgr.getMediaFileRootDirectory(website), resource.getPath());
                    roller.flush();
                } else {
                    log.debug("    No action: directory already exists");
                }

            } else {
                String resourcePath = resource.getPath();

                MediaFileDirectory mdir = null;
                String justName = null;
                String justPath = null;

                if (resourcePath.indexOf("/") == -1) {
                    mdir = fileMgr.getMediaFileRootDirectory(website);
                    justPath = "";
                    justName = resourcePath;
                   
                } else {
                    justPath = resourcePath.substring(0, resourcePath.lastIndexOf("/"));
                    if (!justPath.startsWith("/")) justPath = "/" + justPath;
                    justName = resourcePath.substring(resourcePath.lastIndexOf("/") + 1);
                    mdir = fileMgr.getMediaFileDirectoryByPath(website, justPath);
                    if (mdir == null) {
                        log.debug("    Creating directory: " + justPath);
                        mdir = fileMgr.createMediaFileDirectoryByPath(website, justPath);
                        roller.flush();
                    }
                }

                MediaFile oldmf = fileMgr.getMediaFileByOriginalPath(website, justPath + "/" + justName);
                if (oldmf != null) {
                    fileMgr.removeMediaFile(website, oldmf);
                }

                // save file without file-type, quota checks, etc.
                InputStream is = resource.getInputStream();
                MediaFile mf = new MediaFile();
                mf.setDirectory(mdir);
                mf.setWeblog(website);
                mf.setName(justName);
                mf.setOriginalPath(justPath + "/" + justName);
                mf.setContentType(map.getContentType(justName));
                mf.setInputStream(is);
                mf.setLength(resource.getLength());

                log.debug("    Saving file: " + justName);
                log.debug("    Saviving in directory = " + mf.getDirectory());
                RollerMessages errors = new RollerMessages();
                fileMgr.createMediaFile(website, mf, errors);
                try {
                    resource.getInputStream().close();
                } catch (IOException ex) {
                    errors.addError("error.closingStream");
                    log.debug("ERROR closing inputstream");
View Full Code Here

                    throw new AtomException("Creating weblog entry collection for service doc", e);
                }

                // And add one media collection for each of weblog's upload directories
                try {
                    MediaFileManager mgr = roller.getMediaFileManager();
                    List<MediaFileDirectory> dirs = mgr.getMediaFileDirectories(weblog);
                    for (MediaFileDirectory dir : dirs) {
                        Collection uploadSubCol = new Collection(
                            "Media Files: " + dir.getPath(), "text",
                            atomURL + "/" + weblog.getHandle() + "/resources/" + dir.getPath());
                        uploadSubCol.setAccepts(uploadAccepts);
View Full Code Here

            String title = entry.getTitle() != null ? entry.getTitle() : slug;
           
            // authenticated client posted a weblog entry
            File tempFile = null;
            String handle = pathInfo[0];
            MediaFileManager fileMgr = roller.getMediaFileManager();
            Weblog website = WebloggerFactory.getWeblogger().getWeblogManager().getWeblogByHandle(handle);
            if (!RollerAtomHandler.canEdit(user, website)) {
                throw new AtomNotAuthorizedException("Not authorized to edit weblog: " + handle);
            }
            if (pathInfo.length > 1) {
                // Save to temp file
                String fileName = createFileName(website,
                    (slug != null) ? slug : Utilities.replaceNonAlphanumeric(title,' '), contentType);
                try {
                    tempFile = File.createTempFile(fileName, "tmp");
                    FileOutputStream fos = new FileOutputStream(tempFile);
                    Utilities.copyInputToOutput(is, fos);
                    fos.close();
                                       
                    // Parse pathinfo to determine file path
                    String path = filePathFromPathInfo(pathInfo);
                    String justPath = path;
                    int lastSlash = path.lastIndexOf("/");
                    if (lastSlash > -1) {
                        justPath = path.substring(lastSlash);
                    }

                    MediaFileDirectory mdir =
                        fileMgr.getMediaFileDirectoryByPath(website, justPath);

                    if (mdir.hasMediaFile(fileName)) {
                        throw new AtomException("Duplicate file name");
                    }

                    if (path.length() > 0) path = path + File.separator;
                    FileInputStream fis = new FileInputStream(tempFile);

                    MediaFile mf = new MediaFile();
                    mf.setDirectory(mdir);
                    mf.setWeblog(website);
                    mf.setName(fileName);
                    mf.setOriginalPath(justPath);
                    mf.setContentType(contentType);
                    mf.setInputStream(fis);
                    mf.setLength(tempFile.length());

                    RollerMessages errors = new RollerMessages();
                    fileMgr.createMediaFile(website, mf, errors);
                    if (errors.getErrorCount() > 0) {
                        throw new AtomException(errors.toString());
                    }

                    roller.flush();
                   
                    fis.close();
                                     
                    MediaFile stored = fileMgr.getMediaFile(mf.getId());
                    Entry mediaEntry = createAtomResourceEntry(website, stored);
                    for (Iterator it = mediaEntry.getOtherLinks().iterator(); it.hasNext();) {
                        Link link = (Link)it.next();
                        if ("edit".equals(link.getRel())) {
                            log.debug("Exiting");
View Full Code Here

            String filePath = filePathFromPathInfo(pathInfo);
            filePath = filePath.substring(0, filePath.length() - ".media-link".length());
            String handle = pathInfo[0];
            Weblog website = roller.getWeblogManager().getWeblogByHandle(handle);

            MediaFileManager fileMgr = roller.getMediaFileManager();
            MediaFile mf = fileMgr.getMediaFileByPath(website, filePath);

            log.debug("Exiting");
            if (mf != null) {
                return createAtomResourceEntry(website, mf);
            }
View Full Code Here

        String[] pathInfo = StringUtils.split(areq.getPathInfo(),"/");
        try {
            // authenticated client posted a weblog entry
            File tempFile = null;
            String handle = pathInfo[0];
            MediaFileManager fmgr = roller.getMediaFileManager();
            Weblog website = WebloggerFactory.getWeblogger().getWeblogManager().getWeblogByHandle(handle);
            if (!RollerAtomHandler.canEdit(user, website)) {
                throw new AtomNotAuthorizedException("Not authorized to edit weblog: " + handle);
            }
            if (pathInfo.length > 1) {
                try {                                       
                    // Parse pathinfo to determine file path
                    String filePath = filePathFromPathInfo(pathInfo);
                    MediaFile mf = fmgr.getMediaFileByOriginalPath(website, filePath);
                    return new AtomMediaResource(
                            mf.getName(),
                            mf.getLength(),
                            new Date(mf.getLastModified()),
                            mf.getInputStream());
View Full Code Here

            link.setHref(absUrl + "/" + website.getHandle());
            link.setRel("alternate");
            link.setType("text/html");
            feed.setAlternateLinks(Collections.singletonList(link));

            MediaFileManager fmgr = roller.getMediaFileManager();
            MediaFileDirectory dir = null;
            if (StringUtils.isNotEmpty(path)) {
                log.debug("Fetching resource collection from weblog " + handle + " at path: " + path);
                dir = fmgr.getMediaFileDirectoryByPath(website, path);
            } else {
                log.debug("Fetching root resource collection from weblog " + handle);
                dir = fmgr.getMediaFileRootDirectory(website);
            }
            Set<MediaFile> files = dir.getMediaFiles();

            SortedSet sortedSet = new TreeSet(new Comparator() {
                public int compare(Object o1, Object o2) {
View Full Code Here

            InputStream is = areq.getInputStream();
    
            // authenticated client posted a weblog entry
            File tempFile = null;
            String handle = pathInfo[0];
            MediaFileManager fmgr = roller.getMediaFileManager();
            WeblogManager wmgr = roller.getWeblogManager();
            Weblog website = wmgr.getWeblogByHandle(handle);
            if (!RollerAtomHandler.canEdit(user, website)) {
                throw new AtomNotAuthorizedException("Not authorized to edit weblog: " + handle);
            }
            if (pathInfo.length > 1) {
                // Save to temp file
                try {
                    tempFile = File.createTempFile(UUID.randomUUID().toString(), "tmp");
                    FileOutputStream fos = new FileOutputStream(tempFile);
                    Utilities.copyInputToOutput(is, fos);
                    fos.close();
                                       
                    FileInputStream fis = new FileInputStream(tempFile);

                    // Parse pathinfo to determine file path
                    String path = filePathFromPathInfo(pathInfo);
                   
                    // Attempt to load file, to ensure it exists
                    MediaFile mf = fmgr.getMediaFileByPath(website, path);
                    mf.setContentType(contentType);
                    mf.setInputStream(fis);
                    mf.setLength(tempFile.length());

                    fmgr.updateMediaFile(website, mf, fis);

                    roller.flush();

                    fis.close();
                   
View Full Code Here

TOP

Related Classes of org.apache.roller.weblogger.business.MediaFileManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.