Returns the serialized element data.<p>

@param cms the current cms context
@param elementBean the element to serialize
@param page the container page

@return the serialized element data

@throws Exception if something goes wrong
197310
private String getElementInfo(CmsObject cms, CmsContainerElementBean elementBean, CmsContainerPageBean page)
    throws Exception {

        return CmsContainerpageService.getSerializedElementInfo(
            cms,
            (HttpServletRequest)pageContext.getRequest(),
            (HttpServletResponse)pageContext.getResponse(),
            elementBean,
            page);
    }
1118751
public Map<String, CmsClientTemplateBean> getTemplates() throws CmsException {

        Map<String, CmsClientTemplateBean> result = new HashMap<String, CmsClientTemplateBean>();
        CmsObject cms = getCmsObject();

        // find current site templates
        int templateId = OpenCms.getResourceManager().getResourceType(
            CmsResourceTypeJsp.getContainerPageTemplateTypeName()).getTypeId();
        List<CmsResource> templates = cms.readResources(
            "/",
            CmsResourceFilter.ONLY_VISIBLE_NO_DELETED.addRequireType(templateId),
            true);
        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(cms.getRequestContext().getSiteRoot())) {
            // if not in the root site, also add template under /system/
            templates.addAll(
                cms.readResources(
                    CmsWorkplace.VFS_PATH_SYSTEM,
                    CmsResourceFilter.ONLY_VISIBLE_NO_DELETED.addRequireType(templateId),
                    true));
        }
        // convert resources to template beans
        for (CmsResource template : templates) {
            CmsClientTemplateBean templateBean = getTemplateBean(cms, template);
            result.put(templateBean.getSitePath(), templateBean);
        }
        return result;
    }
129143
protected void setGroupContainerData(Map<String, CmsContainerElementData> elementsData) {

        m_elementData = elementsData.get(getGroupContainerWidget().getId());
        if (m_elementData != null) {
            setSaveEnabled(true, null);
            m_groupContainerBean = new CmsGroupContainer();
            m_groupContainerBean.setClientId(m_elementData.getClientId());
            m_groupContainerBean.setResourceType(getGroupContainerWidget().getNewType());
            m_groupContainerBean.setNew(getGroupContainerWidget().isNew());
            m_groupContainerBean.setSitePath(m_elementData.getSitePath());
            if (m_elementData.getTypes().isEmpty()) {
                Set<String> types = new HashSet<String>();
                types.add(((CmsContainerPageContainer)getGroupContainerWidget().getParentTarget()).getContainerType());
                m_elementData.setTypes(types);
                m_groupContainerBean.setTypes(types);
            } else {
                m_groupContainerBean.setTypes(m_elementData.getTypes());
            }
            m_inputDescription.setFormValueAsString(m_elementData.getDescription());
            m_inputTitle.setFormValueAsString(m_elementData.getTitle());
            m_groupContainerBean.setTitle(m_elementData.getTitle());
            m_groupContainerBean.setDescription(m_elementData.getDescription());
        } else {
            CmsDebugLog.getInstance().printLine("Loading groupcontainer error.");
        }
    }
1292599
protected void saveContainerPage(CmsObject cms, Element parent, CmsContainerPageBean cntPage) throws CmsException {

        parent.clearContent();

        // save containers in a defined order
        List<String> containerNames = new ArrayList<String>(cntPage.getNames());
        Collections.sort(containerNames);

        for (String containerName : containerNames) {
            CmsContainerBean container = cntPage.getContainers().get(containerName);

            // the container
            Element cntElement = parent.addElement(XmlNode.Containers.name());
            cntElement.addElement(XmlNode.Name.name()).addCDATA(container.getName());
            cntElement.addElement(XmlNode.Type.name()).addCDATA(container.getType());
            if (container.isNestedContainer()) {
                cntElement.addElement(XmlNode.ParentInstanceId.name()).addCDATA(container.getParentInstanceId());
            }
            if (container.isRootContainer()) {
                cntElement.addElement(XmlNode.IsRootContainer.name()).addText(Boolean.TRUE.toString());
            }

            // the elements
            for (CmsContainerElementBean element : container.getElements()) {
                Element elemElement = cntElement.addElement(XmlNode.Elements.name());

                // the element
                Element uriElem = elemElement.addElement(XmlNode.Uri.name());
                CmsResource uriRes = fillResource(cms, uriElem, element.getId());
                Element formatterElem = elemElement.addElement(XmlNode.Formatter.name());
                fillResource(cms, formatterElem, element.getFormatterId());
                if (element.isCreateNew()) {
                    Element createNewElem = elemElement.addElement(XmlNode.CreateNew.name());
                    createNewElem.addText(Boolean.TRUE.toString());
                }
                // the properties
                Map<String, String> properties = element.getIndividualSettings();
                Map<String, CmsXmlContentProperty> propertiesConf = OpenCms.getADEManager().getElementSettings(
                    cms,
                    uriRes);

                CmsXmlContentPropertyHelper.saveProperties(cms, elemElement, properties, propertiesConf);
            }
        }
    }
319921
public CmsContainerPageBean removeModelGroupContainers(CmsContainerPageBean page) {

        Map<String, List<CmsContainerBean>> containersByParent = getContainerByParent(page);
        Set<String> modelInstances = new HashSet<String>();
        for (CmsContainerElementBean element : page.getElements()) {
            if (element.getIndividualSettings().containsKey(CmsContainerElement.MODEL_GROUP_ID)) {
                modelInstances.add(element.getInstanceId());
            }
        }

        Set<String> descendingInstances = new HashSet<String>();
        for (String modelInstance : modelInstances) {
            descendingInstances.addAll(collectDescendingInstances(modelInstance, containersByParent));
        }
        List<CmsContainerBean> containers = new ArrayList<CmsContainerBean>();
        for (CmsContainerBean container : page.getContainers().values()) {
            if ((container.getParentInstanceId() == null)
                || !descendingInstances.contains(container.getParentInstanceId())) {
                // iterate the container elements to replace the model group elements
                List<CmsContainerElementBean> elements = new ArrayList<CmsContainerElementBean>();
                for (CmsContainerElementBean element : container.getElements()) {
                    if (modelInstances.contains(element.getInstanceId())) {
                        CmsUUID modelId = new CmsUUID(
                            element.getIndividualSettings().get(CmsContainerElement.MODEL_GROUP_ID));
                        CmsContainerElementBean replacer = new CmsContainerElementBean(
                            modelId,
                            element.getFormatterId(),
                            element.getIndividualSettings(),
                            false);
                        elements.add(replacer);
                    } else {
                        elements.add(element);
                    }
                }
                containers.add(
                    new CmsContainerBean(
                        container.getName(),
                        container.getType(),
                        container.getParentInstanceId(),
                        container.isRootContainer(),
                        container.getMaxElements(),
                        elements));

            }
        }
        return new CmsContainerPageBean(containers);
    }
988967
public CmsContainerElement getSerializedElement(String data) throws SerializationException {

        return (CmsContainerElement)CmsRpcPrefetcher.getSerializedObjectFromString(getContainerpageService(), data);
    }
444066
public String getContent(String target, String element, Locale locale) {

        I_CmsResourceLoader loader;
        CmsFile file;
        target = toAbsolute(target);

        try {
            file = getCmsObject().readFile(target);
            loader = OpenCms.getResourceManager().getLoader(file);
        } catch (ClassCastException e) {
            // no loader implementation found
            return CmsMessages.formatUnknownKey(e.getMessage());
        } catch (CmsException e) {
            // file might not exist or no read permissions
            return CmsMessages.formatUnknownKey(e.getMessage());
        }

        try {
            byte[] result = loader.dump(getCmsObject(), file, element, locale, getRequest(), getResponse());
            return new String(result, getRequestContext().getEncoding());
        } catch (UnsupportedEncodingException uee) {
            // encoding unsupported
            return CmsMessages.formatUnknownKey(uee.getMessage());
        } catch (Throwable t) {
            // any other exception, check for hidden root cause first
            Throwable cause = CmsFlexController.getThrowable(getRequest());
            if (cause == null) {
                cause = t;
            }
            handleException(cause);
            return CmsMessages.formatUnknownKey(cause.getMessage());
        }
    }
515542
private CmsClientTemplateBean getTemplateBean(CmsObject cms, CmsResource resource) throws CmsException {

        CmsProperty titleProp = cms.readPropertyObject(resource, CmsPropertyDefinition.PROPERTY_TITLE, false);
        CmsProperty descProp = cms.readPropertyObject(resource, CmsPropertyDefinition.PROPERTY_DESCRIPTION, false);
        CmsProperty imageProp = cms.readPropertyObject(resource, CmsPropertyDefinition.PROPERTY_TEMPLATE_IMAGE, false);
        CmsProperty selectValueProp = cms.readPropertyObject(
            resource,
            CmsPropertyDefinition.PROPERTY_TEMPLATE_PROVIDER,
            false);
        String sitePath = cms.getSitePath(resource);
        String templateValue = sitePath;
        if (!selectValueProp.isNullProperty() && !CmsStringUtil.isEmptyOrWhitespaceOnly(selectValueProp.getValue())) {
            String selectValue = selectValueProp.getValue();
            CmsMacroResolver resolver = new CmsMacroResolver();
            resolver.addMacro(MACRO_TEMPLATEPATH, sitePath);
            templateValue = resolver.resolveMacros(selectValue);
        }
        return new CmsClientTemplateBean(
            titleProp.getValue(),
            descProp.getValue(),
            templateValue,
            imageProp.getValue());
    }
581697
public CmsSitemapTreeNodeData getData(CmsResource resource) {

        try {
            CmsVfsSitemapService svc = new CmsVfsSitemapService();
            CmsObject cms = OpenCms.initCmsObject(A_CmsUI.getCmsObject());
            cms.getRequestContext().setSiteRoot("");
            svc.setCms(cms);

            CmsClientSitemapEntry ent = svc.getChildren(resource.getRootPath(), resource.getStructureId(), 0);
            CmsSitemapTreeNodeData data = new CmsSitemapTreeNodeData(
                m_localeContext.getRootLocale(),
                m_localeContext.getComparisonLocale());
            data.setClientEntry(ent);
            data.initialize(cms);
            return data;
        } catch (Exception e) {
            LOG.error(e.getLocalizedMessage(), e);
            return null;
        }

    }
309286
public static String getSerializedContainerInfo(CmsContainer container) throws Exception {

        return CmsGwtActionElement.serialize(I_CmsContainerpageService.class.getMethod("getContainerInfo"), container);
    }
943079
private void ensureElementFormatter(CmsResource resource, HttpServletRequest req) {

        CmsJspStandardContextBean contextBean = CmsJspStandardContextBean.getInstance(req);
        CmsContainerElementBean element = contextBean.getElement();
        if (!resource.getStructureId().equals(element.getFormatterId())) {
            element.setFormatterId(resource.getStructureId());
        }
    }
430334
public I_CmsExtractionResult extractContent(CmsObject cms, CmsResource resource, I_CmsSearchIndex index)
    throws CmsException {

        logContentExtraction(resource, index);
        try {
            CmsFile file = readFile(cms, resource);
            CmsXmlPage page = CmsXmlPageFactory.unmarshal(cms, file);
            Locale locale = index.getLocaleForResource(cms, resource, page.getLocales());

            List<String> elements = page.getNames(locale);
            StringBuffer content = new StringBuffer();
            LinkedHashMap<String, String> items = new LinkedHashMap<String, String>();
            for (Iterator<String> i = elements.iterator(); i.hasNext();) {
                String elementName = i.next();
                String value = page.getStringValue(cms, elementName, locale);
                String extracted = CmsHtmlExtractor.extractText(value, page.getEncoding());
                if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(extracted)) {
                    items.put(elementName, extracted);
                    content.append(extracted);
                    content.append('\n');
                }
            }

            return new CmsExtractionResult(content.toString(), items);

        } catch (Exception e) {
            throw new CmsIndexException(
                Messages.get().container(Messages.ERR_TEXT_EXTRACTION_1, resource.getRootPath()),
                e);
        }
    }
544384
public String getContentByContainer(CmsFile elementFile, String elementId, CmsContainer container) {

        CmsContainerElementBean element = CmsADESessionCache.getCache(m_req, m_cms).getCacheContainerElement(elementId);
        element = element.clone();
        element.setTemporaryFile(elementFile);
        CmsFormatterConfiguration configs = getFormatterConfiguration(element.getResource());
        return getContentByContainer(element, container, configs);
    }
662277
public void showElementInfo(final CmsContainerPageElementPanel element) {

        CmsUUID structureId;
        if (element.isModelGroup() && !element.getModelGroupId().isNullUUID()) {
            structureId = element.getModelGroupId();
        } else {
            structureId = element.getStructureId();
        }
        I_CmsDropContainer dropContainer = element.getParentTarget();
        Map<String, String> contextParams = new HashMap<>();
        if (dropContainer instanceof CmsContainerPageContainer) {
            CmsContainerPageContainer cnt = (CmsContainerPageContainer)dropContainer;
            String containerId = cnt.getContainerId();
            String elemId = element.getId();
            contextParams.put(CmsGwtConstants.ATTR_ELEMENT_ID, elemId);
            contextParams.put(CmsGwtConstants.ATTR_CONTAINER_ID, containerId);
            String pageRootPath = CmsStringUtil.joinPaths(
                CmsCoreProvider.get().getSiteRoot(),
                CmsCoreProvider.get().getUri());
            contextParams.put(CmsGwtConstants.ATTR_PAGE_ROOT_PATH, pageRootPath);
        }
        CmsResourceInfoDialog.load(structureId, true, null, contextParams, new CloseHandler<PopupPanel>() {

            public void onClose(CloseEvent<PopupPanel> event) {

                reloadElements(element.getId());
            }
        });
    }
1197938
public CmsContainerPageBean readModelGroups(CmsContainerPageBean page) {

        List<CmsContainerBean> resultContainers = new ArrayList<CmsContainerBean>();
        for (CmsContainerBean container : page.getContainers().values()) {
            boolean hasModels = false;
            List<CmsContainerElementBean> elements = new ArrayList<CmsContainerElementBean>();
            for (CmsContainerElementBean element : container.getElements()) {
                try {
                    element.initResource(m_cms);
                    if (isModelGroupResource(element.getResource())) {
                        hasModels = true;
                        CmsContainerPageBean modelGroupPage = getContainerPageBean(element.getResource());
                        CmsContainerElementBean baseElement = getModelBaseElement(
                            modelGroupPage,
                            element.getResource());
                        if (baseElement == null) {
                            LOG.error(
                                "Error rendering model group '"
                                    + element.getResource().getRootPath()
                                    + "', base element could not be determind.");
                            continue;
                        }
                        String baseInstanceId = baseElement.getInstanceId();
                        CmsContainerElementBean replaceElement = getModelReplacementElement(
                            element,
                            baseElement,
                            false);
                        if (m_sessionCache != null) {
                            m_sessionCache.setCacheContainerElement(replaceElement.editorHash(), replaceElement);
                        }
                        elements.add(replaceElement);
                        resultContainers.addAll(
                            readModelContainers(
                                baseInstanceId,
                                element.getInstanceId(),
                                modelGroupPage,
                                baseElement.isCopyModel()));
                    } else {
                        elements.add(element);
                    }
                } catch (CmsException e) {
                    LOG.info(e.getLocalizedMessage(), e);
                }
            }
            if (hasModels) {
                resultContainers.add(
                    new CmsContainerBean(
                        container.getName(),
                        container.getType(),
                        container.getParentInstanceId(),
                        container.isRootContainer(),
                        container.getMaxElements(),
                        elements));
            } else {
                resultContainers.add(container);
            }
        }
        return new CmsContainerPageBean(resultContainers);
    }
544912
@Override
    public int doEndTag() throws JspException {

        ServletRequest req = pageContext.getRequest();

        // This will always be true if the page is called through OpenCms
        if (CmsFlexController.isCmsRequest(req)) {
            try {
                // Get link-string from the body and reset body
                String link = getBodyContent().getString();
                getBodyContent().clear();
                // Calculate the link substitution
                String newlink = linkTagAction(link, req, getBaseUri(), getDetailPage(), m_locale);
                // Write the result back to the page
                getBodyContent().print(newlink);
                getBodyContent().writeOut(pageContext.getOut());

            } catch (Exception ex) {
                if (LOG.isErrorEnabled()) {
                    LOG.error(Messages.get().getBundle().key(Messages.ERR_PROCESS_TAG_1, "link"), ex);
                }
                throw new JspException(ex);
            }
        }
        return EVAL_PAGE;
    }
180912
private void createNewContainerElements(CmsObject cms, CmsXmlContainerPage page, String sitePath)
    throws CmsException {

        CmsADEConfigData configData = OpenCms.getADEManager().lookupConfiguration(cms, cms.addSiteRoot(sitePath));
        Locale contentLocale = OpenCms.getLocaleManager().getDefaultLocale(cms, CmsResource.getFolderPath(sitePath));
        CmsObject cloneCms = OpenCms.initCmsObject(cms);
        cloneCms.getRequestContext().setLocale(contentLocale);
        CmsContainerPageBean pageBean = page.getContainerPage(cms);
        boolean needsChanges = false;
        List<CmsContainerBean> updatedContainers = new ArrayList<CmsContainerBean>();
        for (CmsContainerBean container : pageBean.getContainers().values()) {
            List<CmsContainerElementBean> updatedElements = new ArrayList<CmsContainerElementBean>();
            for (CmsContainerElementBean element : container.getElements()) {
                if (element.isCreateNew() && !element.isGroupContainer(cms) && !element.isInheritedContainer(cms)) {
                    needsChanges = true;
                    String typeName = OpenCms.getResourceManager().getResourceType(element.getResource()).getTypeName();
                    CmsResourceTypeConfig typeConfig = configData.getResourceType(typeName);
                    if (typeConfig == null) {
                        throw new IllegalArgumentException(
                            "Can not copy template model element '"
                                + element.getResource().getRootPath()
                                + "' because the resource type '"
                                + typeName
                                + "' is not available in this sitemap.");
                    }

                    CmsResource newResource = typeConfig.createNewElement(
                        cloneCms,
                        element.getResource(),
                        CmsResource.getParentFolder(cms.getRequestContext().addSiteRoot(sitePath)));
                    CmsContainerElementBean newBean = new CmsContainerElementBean(
                        newResource.getStructureId(),
                        element.getFormatterId(),
                        element.getIndividualSettings(),
                        false);
                    updatedElements.add(newBean);
                } else {
                    updatedElements.add(element);
                }
            }

            CmsContainerBean updatedContainer = new CmsContainerBean(
                container.getName(),
                container.getType(),
                container.getParentInstanceId(),
                container.isRootContainer(),
                container.getMaxElements(),
                updatedElements);
            updatedContainers.add(updatedContainer);
        }
        if (needsChanges) {
            CmsContainerPageBean updatedPage = new CmsContainerPageBean(updatedContainers);
            page.writeContainerPage(cms, updatedPage);
        }
    }