/* (non-Javadoc)
@see org.opoo.press.Processor#postWrite(org.opoo.press.Site)
778393
@Override
	public void postWrite(Site site) {
		if(processors != null){
			for(Processor p: processors){
				p.postWrite(site);
			}
		}
	}
180119
private static void publishEvent(String event, SiteNode node) {
		ZAP.getEventBus().publishSyncEvent(SiteMapEventPublisher.getPublisher(), new Event(SiteMapEventPublisher.getPublisher(), event, new Target(node)));
	}
1208212
public void postProcessWriteBuffers(long dataWritten) {

        if (getByteBufferArrayDirect() == null) {
            try {
                // see if we should post process just the one buffer case
                if (((WsByteBufferImpl) getBuffer()).oWsBBDirect != null) {
                    ((WsByteBufferImpl) getBuffer()).setParmsFromDirectBuffer();
                }
            } catch (ClassCastException cce) {
                // Nothing to do here, already flagged this condition on the
                // pre-processing
            }
            return;
        }

        WsByteBuffer wsBuffArray[] = getBuffers();
        for (int i = 0; i < wsBuffArray.length; i++) {
            if (wsBuffArray[i] == null) {
                break;
            }
            try {
                ((WsByteBufferImpl) wsBuffArray[i]).setParmsFromDirectBuffer();
            } catch (ClassCastException cce) {
                // Nothing to do here, already flagged this condition on the
                // pre-processing
                return;
            }

        }
    }
604936
protected void onSiteChange(String site) {

        try {
            m_treeData.removeAllItems();
            CmsObject rootCms = OpenCms.initCmsObject(A_CmsUI.getCmsObject());
            rootCms.getRequestContext().setSiteRoot("");
            CmsResource siteRootResource = rootCms.readResource(site);

            m_treeData.initRoot(rootCms, siteRootResource);
            m_fileTree.expandItem(siteRootResource.getStructureId());
            m_siteRoot = site;
            updateRoot(rootCms, siteRootResource);
        } catch (CmsException e) {
            LOG.error(e.getLocalizedMessage(), e);
        }
    }
1075396
void submit(boolean overwrite, Map<String, String> makroMap) {

        try {
            CmsResource targetFolder = null;
            String targetName = null;
            String target = m_targetPath.getValue();
            boolean isSingleResource = m_context.getResources().size() == 1;
            // resolve relative paths
            target = CmsLinkManager.getAbsoluteUri(
                target,
                CmsResource.getParentFolder(getCms().getSitePath(m_context.getResources().get(0))));

            // check if the given path is a root path
            CmsObject cms = OpenCms.getSiteManager().getSiteForRootPath(target) != null ? getRootCms() : getCms();

            if (cms.existsResource(target, CmsResourceFilter.ALL.addRequireFolder())) {
                // The target is an existing folder
                // always copy files into that folder
                targetFolder = cms.readResource(target);
            } else if (cms.existsResource(target, CmsResourceFilter.ALL.addRequireFile())) {
                // The target is an existing file
                if (isSingleResource) {
                    // Replace the file with the resource copied, if it is just a single resource
                    if (target.equals(m_context.getResources().get(0).getRootPath())) {
                        throw new CmsVfsException(
                            org.opencms.workplace.commons.Messages.get().container(
                                org.opencms.workplace.commons.Messages.ERR_COPY_ONTO_ITSELF_1,
                                target));
                    }
                    targetName = CmsResource.getName(target);
                    targetFolder = cms.readResource(CmsResource.getParentFolder(target));
                } else {
                    // Throw an error if a single file should be replaced with multiple resources
                    // since we cannot copy multiple resources to a single file
                    throw new CmsVfsException(
                        org.opencms.workplace.commons.Messages.get().container(
                            org.opencms.workplace.commons.Messages.ERR_COPY_MULTI_TARGET_NOFOLDER_1,
                            target));
                }
            } else {
                // The target does not exist
                if (isSingleResource) {
                    // If we have a single resource, we could possible create the target as copy of that resource
                    if (cms.existsResource(
                        CmsResource.getParentFolder(target),
                        CmsResourceFilter.ALL.addRequireFolder())) {
                        targetName = CmsResource.getName(target);
                        targetFolder = cms.readResource(CmsResource.getParentFolder(target));
                    } else {
                        // If the parent folder of the resource does not exist, we will not create it automatically.
                        // Thus we need to throw an exception.
                        throw new CmsVfsException(
                            org.opencms.workplace.commons.Messages.get().container(
                                org.opencms.workplace.commons.Messages.ERR_COPY_TARGET_PARENT_FOLDER_MISSING_1,
                                target));
                    }
                } else {
                    // We cannot copy multiple resources to a single resource
                    throw new CmsVfsException(
                        org.opencms.workplace.commons.Messages.get().container(
                            org.opencms.workplace.commons.Messages.ERR_COPY_MULTI_TARGET_NOFOLDER_1,
                            target));
                }
            }

            Action action = m_actionCombo != null ? (Action)m_actionCombo.getValue() : Action.move;

            overwrite = overwrite || isOverwriteExisting();
            if (!overwrite || action.equals(Action.move)) {
                List<CmsResource> collidingResources = getExistingFileCollisions(targetFolder, targetName);
                if (collidingResources != null) {
                    if (action.equals(Action.move)) {
                        throw new CmsVfsException(
                            org.opencms.workplace.commons.Messages.get().container(
                                org.opencms.workplace.commons.Messages.ERR_MOVE_FORCES_OVERWRITE_EXISTING_RESOURCE_0));
                    } else {
                        showConfirmOverwrite(collidingResources);
                        return;
                    }
                }
            }
            Map<CmsResource, CmsException> errors = new HashMap<CmsResource, CmsException>();

            //Check if dialog for macro resolver has to be shown: action correct?, makroMap==null (default, not set by dialog yet)
            if ((action == Action.sub_sitemap) & (makroMap == null)) {
                if (CmsSiteManager.isFolderWithMacros(getRootCms(), m_context.getResources().get(0).getRootPath())) {
                    showMacroResolverDialog(m_context.getResources().get(0));
                    return;
                }
            }
            if (targetName == null) {
                for (CmsResource source : m_context.getResources()) {
                    try {
                        performSingleOperation(source, targetFolder, action, overwrite, makroMap);
                    } catch (CmsException e) {
                        errors.put(source, e);
                        LOG.error(
                            "Error while executing "
                                + m_actionCombo.getValue().toString()
                                + " on resource "
                                + source.getRootPath(),
                            e);
                    }
                }
            } else {
                // this will only be the case in a single resource scenario
                CmsResource source = m_context.getResources().get(0);
                try {
                    performSingleOperation(source, targetFolder, targetName, action, overwrite, makroMap);
                } catch (CmsException e) {
                    errors.put(source, e);
                    LOG.error(
                        "Error while executing "
                            + m_actionCombo.getValue().toString()
                            + " on resource "
                            + source.getRootPath(),
                        e);
                }
            }

            if (!errors.isEmpty()) {
                m_context.finish(m_updateResources);
                m_context.error(errors.values().iterator().next());
            } else {
                m_context.finish(m_updateResources);
            }

        } catch (CmsException e) {
            m_context.error(e);
        }
    }
566741
void submit() {

        // switch to root site
        m_clonedCms.getRequestContext().setSiteRoot("");

        CmsSite site = getSiteFromForm();

        if (m_site == null) {

            //Show report field and hide form fields
            m_report.setVisible(true);
            m_tab.setVisible(false);
            m_ok.setEnabled(false);
            m_ok.setVisible(true);
            //Change cancel caption to close (will not interrupt site creation anymore)
            m_cancel.setVisible(false);
            setOkButtonEnabled();
            m_cancel.setCaption(
                CmsVaadinUtils.getMessageText(org.opencms.workplace.Messages.GUI_DIALOG_BUTTON_CLOSE_0));

            Map<String, String> bundle = getBundleMap();

            boolean createOU = m_fieldCreateOU.isEnabled() & m_fieldCreateOU.getValue().booleanValue();
            CmsCreateSiteThread createThread = new CmsCreateSiteThread(
                m_clonedCms,
                m_manager,
                site,
                m_site,
                m_fieldLoadSiteTemplate.getValue(),
                getFieldTemplate(),
                createOU,
                (String)m_fieldSelectParentOU.getValue(),
                (String)m_fieldSelectOU.getValue(),
                m_os,
                bundle,
                new Runnable() {

                    public void run() {

                }

                });

            CmsReportWidget report = new CmsReportWidget(createThread);

            report.setWidth("100%");
            report.setHeight("350px");

            m_threadReport.addComponent(report);
            createThread.start();
        } else {
            if (!site.getSiteRoot().equals(m_site.getSiteRoot())) {
                m_manager.deleteElements(Collections.singletonList(m_site.getSiteRoot()));
            }
            m_manager.writeElement(site);
            m_manager.closeDialogWindow(true);
        }

    }
1155397
public void write(final Point point) {
        this.influxDb.write(influxDbProperties.getDatabase(), influxDbProperties.getRetentionPolicy(), point);
    }
1224594
public void changeSite(String siteRoot, String path, boolean force) {

        CmsObject cms = A_CmsUI.getCmsObject();
        String currentSiteRoot = cms.getRequestContext().getSiteRoot();
        if (force || !currentSiteRoot.equals(siteRoot)) {
            CmsAppWorkplaceUi.get().changeSite(siteRoot);
            if (path == null) {
                path = m_locationCache.getFileExplorerLocation(siteRoot);
                if (CmsStringUtil.isEmptyOrWhitespaceOnly(siteRoot)
                    && ((path == null) || !path.startsWith("/system"))) {
                    // switching to the root site and previous root site folder is not below /system
                    // -> stay in the current folder
                    path = m_locationCache.getFileExplorerLocation(currentSiteRoot);
                    if (path != null) {
                        path = CmsStringUtil.joinPaths(currentSiteRoot, path);
                    }
                }
            }
            openPath(path, true);
            Container container = m_siteSelector.getContainerDataSource();
            for (Object id : container.getItemIds()) {
                String key = (String)id;
                if (CmsStringUtil.comparePaths(key, siteRoot)) {
                    siteRoot = key;
                    break;
                }
            }
            m_siteSelector.select(siteRoot);
        }
    }
40558
void submit() {

        try {
            OpenCms.getSiteManager().updateGeneralSettings(
                m_cms,
                ((CmsSite)m_fieldDefaultURI.getValue()).getSiteRoot(),
                getWebserverList(),
                "/" + (String)m_fieldSharedFolder.getValue() + "/");
            if (!CmsEditSiteForm.FORBIDDEN_FOLDER_NAMES.isEmpty()) {
                CmsEditSiteForm.FORBIDDEN_FOLDER_NAMES.set(1, (String)m_fieldSharedFolder.getValue());
            }
            // write the system configuration
            OpenCms.writeConfiguration(CmsSitesConfiguration.class);
        } catch (CmsException e) {
            //
        }

    }
437645
@Override
    public void write(int idx) throws IOException {
        try {
            beforeWrite(1);
            out.write(idx);
            afterWrite(1);
        } catch (IOException e) {
            handleIOException(e);
        }
    }
155525
protected void push(String location, FragmentBuilder builder, Node node) {

        // Check if any in content should be processed for the current node
        processInContent(location, builder, -1);

        builder.pushNode(node);
    }
460666
@Override
    public void generate(Site site) {
        if (generators != null) {
            for (Generator g : generators) {
                g.generate(site);
            }
        }
    }
853133
@Override
    public void generate(Site site) {
        log.debug("Generating paginate pages...");

        List<Page> pages = site.getAllPages();
        SiteConfig config = site.getConfig();

        List<Page> allNewPages = new ArrayList<Page>();
        for (Page page : pages) {
            if (isPaginationEnabled(config, page)) {

                log.debug("[{}]: Paginating...", page.getUrl());
                List<Page> newPages = paginate(site, page);
                if (newPages != null) {
                    allNewPages.addAll(newPages);
                }
            }
        }

        if (!allNewPages.isEmpty()) {
            log.debug("Add {} paginated pages.", allNewPages.size());
            for(Page page: allNewPages){
                site.addPage(page);
                log.debug(page.getUrl());
            }
        }
    }
734590
public void setSiteUrl(String siteUrl) {
        this.siteUrl = StringUtils.isBlank(siteUrl) ? new ServerSiteUrlConfig() : new ServerSiteUrlConfig(siteUrl);
    }
941678
void submit() {

        //        if (!m_dateField.isValid()) {
        //            return;
        //        }
        long current = System.currentTimeMillis();
        Date dateValue = m_dateField.getDate();
        long publishTime = dateValue.getTime();
        if (current > publishTime) {
            m_context.error(
                new CmsException(Messages.get().container(Messages.ERR_PUBLISH_SCHEDULED_DATE_IN_PAST_1, dateValue)));
        } else {
            try {
                // make copies from the admin cmsobject and the user cmsobject
                // get the admin cms object
                CmsWorkplaceAction action = CmsWorkplaceAction.getInstance();
                CmsObject cmsAdmin = action.getCmsAdminObject();
                // get the user cms object
                CmsObject cms = OpenCms.initCmsObject(m_context.getCms());

                // set the current user site to the admin cms object
                cmsAdmin.getRequestContext().setSiteRoot(cms.getRequestContext().getSiteRoot());
                CmsProject tmpProject = createTempProject(cmsAdmin, m_context.getResources(), dateValue);
                // set project as current project
                cmsAdmin.getRequestContext().setCurrentProject(tmpProject);
                cms.getRequestContext().setCurrentProject(tmpProject);

                Set<CmsUUID> changeIds = new HashSet<CmsUUID>();
                for (CmsResource resource : m_context.getResources()) {
                    addToTempProject(cmsAdmin, cms, resource, tmpProject);
                    if (resource.isFolder() && m_includeSubResources.getValue().booleanValue()) {
                        List<CmsResource> subResources = cms.readResources(
                            resource,
                            CmsResourceFilter.ONLY_VISIBLE.addExcludeState(CmsResourceState.STATE_UNCHANGED),
                            true);
                        for (CmsResource sub : subResources) {
                            // check publish permissions on sub resource
                            if (cms.hasPermissions(
                                sub,
                                CmsPermissionSet.ACCESS_DIRECT_PUBLISH,
                                false,
                                CmsResourceFilter.ALL)) {
                                addToTempProject(cmsAdmin, cms, sub, tmpProject);
                            }
                        }
                    }

                    changeIds.add(resource.getStructureId());
                }
                // create a new scheduled job
                CmsScheduledJobInfo job = new CmsScheduledJobInfo();
                // the job name
                String jobName = tmpProject.getName();
                jobName = jobName.replace("&#47;", "/");
                // set the job parameters
                job.setJobName(jobName);
                job.setClassName("org.opencms.scheduler.jobs.CmsPublishScheduledJob");
                // create the cron expression
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(dateValue);
                String cronExpr = ""
                    + calendar.get(Calendar.SECOND)
                    + " "
                    + calendar.get(Calendar.MINUTE)
                    + " "
                    + calendar.get(Calendar.HOUR_OF_DAY)
                    + " "
                    + calendar.get(Calendar.DAY_OF_MONTH)
                    + " "
                    + (calendar.get(Calendar.MONTH) + 1)
                    + " "
                    + "?"
                    + " "
                    + calendar.get(Calendar.YEAR);
                // set the cron expression
                job.setCronExpression(cronExpr);
                // set the job active
                job.setActive(true);
                // create the context info
                CmsContextInfo contextInfo = new CmsContextInfo();
                contextInfo.setProjectName(tmpProject.getName());
                contextInfo.setUserName(cmsAdmin.getRequestContext().getCurrentUser().getName());
                // create the job schedule parameter
                SortedMap<String, String> params = new TreeMap<String, String>();
                // the user to send mail to
                String userName = m_context.getCms().getRequestContext().getCurrentUser().getName();
                params.put(CmsPublishScheduledJob.PARAM_USER, userName);
                // the job name
                params.put(CmsPublishScheduledJob.PARAM_JOBNAME, jobName);
                // the link check
                params.put(CmsPublishScheduledJob.PARAM_LINKCHECK, "true");
                // add the job schedule parameter
                job.setParameters(params);
                // add the context info to the scheduled job
                job.setContextInfo(contextInfo);
                // add the job to the scheduled job list
                OpenCms.getScheduleManager().scheduleJob(cmsAdmin, job);
                // update the XML configuration
                OpenCms.writeConfiguration(CmsSchedulerConfiguration.class);
                m_context.finish(changeIds);
            } catch (CmsException ex) {
                LOG.error("Error performing publish scheduled dialog operation.", ex);
                m_context.error(ex);
            }
        }

    }
699923
@SuppressWarnings({"UnusedDeclaration"})
    public void doSubmit(StaplerRequest req, StaplerResponse resp) throws IOException, ServletException {
        getACL().checkPermission(getPermission());

        bindParameters(req);
        // current user is bound to the thread and will be lost in the perform method
        User user = User.current();
        String ciUser = (user == null) ? "anonymous" : user.getId();

        JSONObject formData = req.getSubmittedForm();
        if (formData.has("promotionPlugin")) {
            JSONObject pluginSettings = formData.getJSONObject("promotionPlugin");
            if (pluginSettings.has("pluginName")) {
                String pluginName = pluginSettings.getString("pluginName");
                if (!UserPluginInfo.NO_PLUGIN_KEY.equals(pluginName)) {
                    PluginSettings settings = new PluginSettings();
                    Map<String, String> paramMap = Maps.newHashMap();
                    settings.setPluginName(pluginName);
                    Map<String, Object> filteredPluginSettings = Maps.filterKeys(pluginSettings,
                            new Predicate<String>() {
                                public boolean apply(String input) {
                                    return StringUtils.isNotBlank(input) && !"pluginName".equals(input);
                                }
                            });
                    for (Map.Entry<String, Object> settingsEntry : filteredPluginSettings.entrySet()) {
                        String key = settingsEntry.getKey();
                        paramMap.put(key, pluginSettings.getString(key));
                    }
                    paramMap.put("ciUser", ciUser);
                    if (!paramMap.isEmpty()) {
                        settings.setParamMap(paramMap);
                    }
                    setPromotionPlugin(settings);
                }
            }
        }

        final BuildInfoAwareConfigurator configurator = getCurrentConfigurator();
        ArtifactoryServer server = configurator.getArtifactoryServer();

        new PromoteWorkerThread(server, CredentialManager.getPreferredDeployer((DeployerOverrider) configurator, server), ciUser).start();

        resp.sendRedirect(".");
    }
568401
void submit() {

        List<String> siteRootsToDelete = new ArrayList<String>();
        for (CmsSite site : m_sitesToDelete) {

            String currentSite = A_CmsUI.getCmsObject().getRequestContext().getSiteRoot();
            if (currentSite.equals(site.getSiteRoot())) {
                A_CmsUI.getCmsObject().getRequestContext().setSiteRoot("");
            }
            siteRootsToDelete.add(site.getSiteRoot());
        }
        m_manager.deleteElements(siteRootsToDelete);
        if (m_deleteResources.getValue().booleanValue()) {
            for (CmsSite site : m_sitesToDelete) {
                try {
                    m_manager.getRootCmsObject().lockResource(site.getSiteRoot());
                } catch (CmsException e) {
                    LOG.error("unable to lock resource");
                }
                try {
                    m_manager.getRootCmsObject().deleteResource(
                        site.getSiteRoot(),
                        CmsResource.DELETE_PRESERVE_SIBLINGS);
                    try {
                        m_manager.getRootCmsObject().unlockResource(site.getSiteRoot());
                    } catch (CmsLockException e) {
                        LOG.info("Unlock failed.", e);
                    }
                } catch (CmsException e) {
                    //ok, resource was not published and can not be unlocked anymore..
                }
            }
        }
    }