append data to source file

@throws PageException
436708
private void actionAppend() throws PageException {
	if (output == null) throw new ApplicationException("attribute output is not defined for tag file");
	checkFile(pageContext, securityManager, file, serverPassword, createPath, true, false, true);

	setACL(pageContext, file, acl);
	try {
	    if (!file.exists()) file.createNewFile();
	    String content = Caster.toString(output);
	    if (fixnewline) content = doFixNewLine(content);
	    if (addnewline) content += SystemUtil.getOSSpecificLineSeparator();
	    IOUtil.write(file, content, CharsetUtil.toCharset(charset), true);

	}
	catch (UnsupportedEncodingException e) {
	    throw new ApplicationException("Unsupported Charset Definition [" + charset + "]", e.getMessage());
	}
	catch (IOException e) {
	    throw new ApplicationException("can't write file", e.getMessage());
	}
	setMode(file, mode);
	setAttributes(file, attributes);
    }
460882
public void actionNew() throws JspException {

        String newFileName = "";
        try {
            newFileName = A_CmsResourceCollector.createResourceForCollector(
                getCms(),
                m_paramNewLink,
                getElementLocale(),
                getParamResource(),
                getParamModelFile(),
                getParamMode(),
                getParamPostCreateHandler());
            // wipe out parameters for the editor to ensure proper operation
            setParamNewLink(null);
            setParamAction(null);
            setParamResource(newFileName);
            setAction(ACTION_DEFAULT);

            // create the temporary file to work with
            setParamTempfile(createTempFile());

            // set the member variables for the content
            m_file = getCms().readFile(getParamTempfile(), CmsResourceFilter.ALL);
            if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getParamModelFile())) {
                m_content = CmsXmlContentFactory.unmarshal(
                    getCms(),
                    getCms().readFile(newFileName, CmsResourceFilter.ALL));
            } else {
                m_content = CmsXmlContentFactory.unmarshal(getCms(), m_file);
            }

        } catch (CmsException e) {
            if (LOG.isErrorEnabled()) {
                LOG.error(Messages.get().getBundle().key(Messages.LOG_CREATE_XML_CONTENT_ITEM_1, m_paramNewLink), e);
            }
            throw new JspException(e);
        } finally {
            try {
                // delete the new file
                getCms().deleteResource(newFileName, CmsResource.DELETE_REMOVE_SIBLINGS);
            } catch (CmsException e) {
                // ignore
            }
        }
    }
102284
@Override
    public void actionSave() throws JspException {

        CmsFile editFile = null;
        try {
            editFile = getCms().readFile(getParamResource(), CmsResourceFilter.ALL);
            String decodedContent = decodeContentParameter(getParamContent(), getFileEncoding(), editFile);
            try {
                editFile.setContents(decodedContent.getBytes(getFileEncoding()));
            } catch (UnsupportedEncodingException e) {
                throw new CmsException(
                    Messages.get().container(Messages.ERR_INVALID_CONTENT_ENC_1, getParamResource()),
                    e);
            }
            if (OpenCms.getWorkplaceManager().isXmlContentAutoCorrect()
                && (CmsResourceTypeXmlContent.isXmlContent(editFile))) {
                // enable auto correction in case of XML content (if configured)
                getCms().getRequestContext().setAttribute(CmsXmlContent.AUTO_CORRECTION_ATTRIBUTE, Boolean.TRUE);
            }
            // the file content might have been modified during the write operation
            CmsFile writtenFile = getCms().writeFile(editFile);
            decodedContent = CmsEncoder.createString(writtenFile.getContents(), getFileEncoding());
            setParamContent(encodeContent(decodedContent));
            // set the modified parameter
            setParamModified(Boolean.TRUE.toString());
        } catch (CmsException e) {
            showErrorPage(e);
        }

        if (getAction() != ACTION_CANCEL) {
            // save successful, set save action
            setAction(ACTION_SAVE);
        }
    }
329194
private function saveFile(): void
    {
        $sourceCode = Helpers::tabsToSpaces((string) $this->entityFile);
        $entityPath = dirname(__DIR__, 7) . '/src/' . $this->entityData['namespace'] . '/';

        $handle = fopen($entityPath . $this->entityData['class'] . '.php', 'w');
        fwrite($handle, $sourceCode);
        fclose($handle);
    }
935579
private void doUpdateDebug() throws PageException {

	admin.updateDebug(Caster.toBoolean(getString("debug", ""), null), Caster.toBoolean(getString("database", ""), null), Caster.toBoolean(getString("exception", ""), null),
		Caster.toBoolean(getString("tracing", ""), null), Caster.toBoolean(getString("dump", ""), null), Caster.toBoolean(getString("timer", ""), null),
		Caster.toBoolean(getString("implicitAccess", ""), null), Caster.toBoolean(getString("queryUsage", ""), null));

	admin.updateDebugTemplate(getString("admin", action, "debugTemplate"));
	store();
	adminSync.broadcast(attributes, config);
    }
1229224
private void doUpdateScope() throws PageException {

	admin.updateScopeCascadingType(getString("admin", action, "scopeCascadingType"));
	admin.updateAllowImplicidQueryCall(getBoolObject("admin", action, "allowImplicidQueryCall"));
	admin.updateMergeFormAndUrl(getBoolObject("admin", action, "mergeFormAndUrl"));
	admin.updateSessionManagement(getBoolObject("admin", action, "sessionManagement"));
	admin.updateClientManagement(getBoolObject("admin", action, "clientManagement"));
	admin.updateDomaincookies(getBoolObject("admin", action, "domainCookies"));
	admin.updateClientCookies(getBoolObject("admin", action, "clientCookies"));
	// admin.updateRequestTimeout(getTimespan("admin",action,"requestTimeout"));
	admin.updateClientTimeout(getTimespan("admin", action, "clientTimeout"));
	admin.updateSessionTimeout(getTimespan("admin", action, "sessionTimeout"));
	admin.updateClientStorage(getString("admin", action, "clientStorage"));
	admin.updateSessionStorage(getString("admin", action, "sessionStorage"));
	admin.updateApplicationTimeout(getTimespan("admin", action, "applicationTimeout"));
	admin.updateSessionType(getString("admin", action, "sessionType"));
	admin.updateLocalMode(getString("admin", action, "localMode"));
	admin.updateCGIReadonly(getBoolObject("admin", action, "cgiReadonly"));
	store();
	adminSync.broadcast(attributes, config);
    }
836200
function insertContent(pageNum) {
        var $page = $pages.eq(pageNum - 1).find('.crocodoc-page-inner');
        var $content = $(util.template(config.template, {
            pageInfo: config.pageInfos[pageNum - 1] || config.defaultInfo
        }));

        $page.append($content);
        // listen for click events on the buttons
        $page.find('.front').on('click', function (event) {
            showPageInfo(pageNum);
            event.stopPropagation();
        });
    }
399598
public void add(PageFactory<? extends IRequestablePage> pageSource)
        throws IllegalArgumentException {
        validateNotNull(pageSource, "pageSource");
        Class<? extends IRequestablePage> pageClass = pageSource.getPageClass();
        validateNotNull(pageSource, "pageClass");
        synchronized (this) {
            contents.put(pageClass, pageSource);
        }
    }
228563
public function savePage()
    {
        // Get dependencies
        $pageMapper = ($this->container->dataMapper)('PageMapper');
        $pageElementMapper = ($this->container->dataMapper)('PageElementMapper');
        $pageSettingMapper = ($this->container->dataMapper)('PageSettingMapper');
        $markdown = $this->container->markdownParser;
        $toolbox = $this->container->toolbox;
        $json = $this->container->json;

        // Get page object
        $pageId = empty($this->request->getParsedBodyParam('id')) ? null : $this->request->getParsedBodyParam('id');
        $newSlug = $toolbox->cleanUrl($this->request->getParsedBodyParam('slug'));

        if (null !== $pageId) {
            $page = $pageMapper->findById($pageId);

            // Ensure we are not futzing with the home page slug
            if ($page->slug === 'home' && $newSlug !== 'home') {
                throw new Exception('PitonCMS: Cannot change home page slug');
            }
        } else {
            $page = $pageMapper->make();
        }

        $page->collection_id = $this->request->getParsedBodyParam('collection_id');
        $page->definition = $this->request->getParsedBodyParam('definition');
        $page->template = $this->request->getParsedBodyParam('template');
        $page->title = $this->request->getParsedBodyParam('title');
        $page->sub_title = $this->request->getParsedBodyParam('sub_title');
        $page->slug = $newSlug;
        $page->meta_description = $this->request->getParsedBodyParam('meta_description');
        $page->image_path = $this->request->getParsedBodyParam('image_path');

        // Process published date
        $publishedDate = $this->request->getParsedBodyParam('published_date');
        if (!empty($publishedDate)) {
            // The leading ! sets the time to 00:00:00
            $phpDateFormat = [
                'mm/dd/yyyy' => '!m/d/Y',
                'dd-mm-yyyy' => '!d-m-Y',
                'dd.mm.yyyy' => '!d.m.Y'
            ];

            $date = \DateTime::createFromFormat($phpDateFormat[$this->siteSettings['dateFormat']], $publishedDate);
            $page->published_date = $date->format('Y-m-d');
        }

        // Save Page and get ID
        $page = $pageMapper->save($page);

        // Save any custom page settings
        if ($this->request->getParsedBodyParam('setting_id')) {
            foreach ($this->request->getParsedBodyParam('setting_id') as $settingKey => $settingValue) {
                $setting = $pageSettingMapper->make();
                $setting->id = $this->request->getParsedBodyParam('setting_id')[$settingKey];

                // Check for a page setting delete
                if (isset($this->request->getParsedBodyParam('setting_delete')[$settingKey])) {
                    $pageSettingMapper->delete($setting);
                    continue;
                }

                $setting->page_id = $page->id;
                $setting->setting_key = $this->request->getParsedBodyParam('setting_key')[$settingKey];
                $setting->setting_value = $this->request->getParsedBodyParam('setting_value')[$settingKey];

                $pageSettingMapper->save($setting);
            }
        }

        // Save page elements by block
        foreach ($this->request->getParsedBodyParam('block_key') as $key => $value) {
            // Save element
            $pageElement = $pageElementMapper->make();
            $pageElement->id = $this->request->getParsedBodyParam('element_id')[$key];
            $pageElement->page_id = $page->id;
            $pageElement->block_key = $this->request->getParsedBodyParam('block_key')[$key];
            $pageElement->definition = $this->request->getParsedBodyParam('element_type')[$key];
            $pageElement->element_sort = $this->request->getParsedBodyParam('element_sort')[$key];
            $pageElement->title = $this->request->getParsedBodyParam('element_title')[$key];
            $pageElement->content_raw = $this->request->getParsedBodyParam('content_raw')[$key];
            $pageElement->content = $markdown->text($this->request->getParsedBodyParam('content_raw')[$key]);
            $pageElement->excerpt = $toolbox->truncateHtmlText($pageElement->content, 60);
            $pageElement->collection_id = $this->request->getParsedBodyParam('element_collection_id')[$key];
            $pageElement->gallery_id = $this->request->getParsedBodyParam('element_gallery_id')[$key];
            $pageElement->embedded = $this->request->getParsedBodyParam('embedded')[$key];

            // If the image path does not start with http then get base name
            $imagePath = $this->request->getParsedBodyParam('element_image_path')[$key];
            if (stripos($imagePath, 'http') === 0) {
                $pageElement->image_path = $imagePath;
            } else {
                $pageElement->image_path = pathinfo($imagePath, PATHINFO_BASENAME);
            }

            // Get the elementTemplateFile from element JSON file
            $jsonPath = ROOT_DIR . "structure/definitions/elements/{$pageElement->definition}";

            if (null === $elementDefinition = $json->getJson($jsonPath, 'element')) {
                throw new Exception('Element JSON Definition Error: ' . print_r($json->getErrorMessages(), true));
            }

            $pageElement->template = $elementDefinition->elementTemplateFile;

            $pageElement = $pageElementMapper->save($pageElement);
        }

        // Determine redirect path based on whether this is a collection
        if (!empty($this->request->getParsedBodyParam('collection_id'))) {
            $redirectPath = 'adminCollections';
        } else {
            $redirectPath = 'adminPages';
        }

        // Redirect back to show page
        return $this->redirect($redirectPath);
    }
1219184
def insertFromMimeData(self, source):
        
        lines = projex.text.nativestring(source.text()).splitlines()
        for i in range(1, len(lines)):
            if not lines[i].startswith('... '):
                lines[i] = '... ' + lines[i]
        
        if len(lines) > 1:
            lines.append('... ')
        
        self.insertPlainText('\n'.join(lines))
914098
public static void append(File file, Writer writer) throws IOException {
        append(file, writer, false);
    }
654913
public void setMimeattach(String strMimeattach, String fileName, String type, String disposition, String contentID, boolean removeAfterSend) throws PageException {
	Resource file = ResourceUtil.toResourceNotExisting(pageContext, strMimeattach);
	pageContext.getConfig().getSecurityManager().checkFileLocation(file);
	if (!file.exists()) throw new ApplicationException("can't attach file " + strMimeattach + ", this file doesn't exist");

	smtp.addAttachment(file, fileName, type, disposition, contentID, removeAfterSend);

    }
332693
private void doUpdateSerial() throws PageException {
	admin.updateSerial(getString("admin", action, "serial"));
	store();
	pageContext.serverScope().reload();
    }
834696
private void initPageData() {

        m_elementInstances = new HashMap<String, CmsContainerElementBean>();
        m_parentContainers = new HashMap<String, CmsContainerBean>();
        if (m_page != null) {
            for (CmsContainerBean container : m_page.getContainers().values()) {
                for (CmsContainerElementBean element : container.getElements()) {
                    m_elementInstances.put(element.getInstanceId(), element);
                    m_parentContainers.put(element.getInstanceId(), container);
                    try {
                        if (element.isGroupContainer(m_cms) || element.isInheritedContainer(m_cms)) {
                            List<CmsContainerElementBean> children;
                            if (element.isGroupContainer(m_cms)) {
                                children = CmsJspTagContainer.getGroupContainerElements(
                                    m_cms,
                                    element,
                                    m_request,
                                    container.getType());
                            } else {
                                children = CmsJspTagContainer.getInheritedContainerElements(m_cms, element);
                            }
                            for (CmsContainerElementBean childElement : children) {
                                m_elementInstances.put(childElement.getInstanceId(), childElement);
                                m_parentContainers.put(childElement.getInstanceId(), container);
                            }
                        }
                    } catch (CmsException e) {
                        LOG.error(e.getLocalizedMessage(), e);
                    }
                }
            }
            // also add detail only data
            if (m_detailOnlyPage != null) {
                for (CmsContainerBean container : m_detailOnlyPage.getContainers().values()) {
                    for (CmsContainerElementBean element : container.getElements()) {
                        m_elementInstances.put(element.getInstanceId(), element);
                        m_parentContainers.put(element.getInstanceId(), container);
                    }
                }
            }
        }
    }
1058705
public void copyFromPagesToView(
			AbstractPagedInputView source, DataOutputView target) throws IOException {
		checkSkipReadForFixLengthPart(source);
		int length = source.readInt();
		target.writeInt(length);
		target.write(source, length);
	}
1225350
private void doGetApplicationSetting() throws PageException {
	Struct sct = new StructImpl();
	pageContext.setVariable(getString("admin", action, "returnVariable"), sct);
	sct.set("scriptProtect", AppListenerUtil.translateScriptProtect(config.getScriptProtect()));

	// request timeout
	sct.set("requestTimeout", config.getRequestTimeout());
	sct.set("requestTimeout_day", Caster.toInteger(config.getRequestTimeout().getDay()));
	sct.set("requestTimeout_hour", Caster.toInteger(config.getRequestTimeout().getHour()));
	sct.set("requestTimeout_minute", Caster.toInteger(config.getRequestTimeout().getMinute()));
	sct.set("requestTimeout_second", Caster.toInteger(config.getRequestTimeout().getSecond()));

	// AllowURLRequestTimeout
	sct.set("AllowURLRequestTimeout", Caster.toBoolean(config.isAllowURLRequestTimeout()));

    }
834329
private void actionInfo() throws PageException {
	if (variable == null) throw new ApplicationException("attribute variable is not defined for tag file");
	pageContext.setVariable(variable, getInfo(pageContext, file, serverPassword));

    }