/** * Generates a button for the OpenCms editor.<p> * * @param href the href link for the button, if none is given the button will be disabled * @param target the href link target for the button, if none is given the target will be same window * @param image the image name for the button, skin path will be automatically added as prefix * @param label the label for the text of the button * @param type 0: image only (default), 1: image and text, 2: text only * @param useCustomImage if true, the button has to be placed in the editors "custom pics" folder * * @return a button for the OpenCms editor */ public String button(String href, String target, String image, String label, int type, boolean useCustomImage) { if (useCustomImage) { // search the picture in the "custom pics" folder return button(href, target, image, label, type, getPicsUri()); } else { // search the picture in the common "buttons" folder return button(href, target, image, label, type); } }
/** * Returns the editor action for a "cancel" button.<p> * * This overwrites the cancel method of the CmsDialog class.<p> * * Always use this value, do not write anything directly in the html page.<p> * * @return the default action for a "cancel" button */ public String buttonActionCancel() { String target = null; if (Boolean.valueOf(getParamDirectedit()).booleanValue()) { // editor is in direct edit mode if (CmsStringUtil.isNotEmpty(getParamBacklink())) { // set link to the specified back link target target = getParamBacklink(); } else { // set link to the edited resource target = getParamResource(); } } else { // in workplace mode, show explorer view target = OpenCms.getLinkManager().substituteLink(getCms(), CmsWorkplace.JSP_WORKPLACE_URI); } return "onclick=\"top.location.href='" + getJsp().link(target) + "';\""; }
/** * Returns the path to the images used by this editor.<p> * * @return the path to the images used by this editor */ public String getPicsUri() { if (m_picsUri == null) { m_picsUri = getEditorResourceUri() + "pics/"; } return m_picsUri; }
/** * Creates a temporary file which is needed while working in an editor with preview option.<p> * * @return the file name of the temporary file * @throws CmsException if something goes wrong */ protected String createTempFile() throws CmsException { return OpenCms.getWorkplaceManager().createTempFile(getCms(), getParamResource(), getSettings().getProject()); }
/** * Deletes a temporary file from the OpenCms VFS, needed when exiting an editor.<p> */ protected void deleteTempFile() { try { // switch to the temporary file project switchToTempProject(); // delete the temporary file getCms().deleteResource(getParamTempfile(), CmsResource.DELETE_PRESERVE_SIBLINGS); } catch (CmsException e) { // should usually never happen if (LOG.isInfoEnabled()) { LOG.info(e); } } finally { try { // switch back to the current project switchToCurrentProject(); } catch (CmsException e) { // should usually never happen if (LOG.isInfoEnabled()) { LOG.info(e); } } } }
editor.actionSave(); editor.actionClear(true); params.append(editor.getParamResource()); params.append("&action="); params.append(CmsDialog.DIALOG_CONFIRMED); params.append("&directpublish=true&publishsiblings=true"); params.append("&title="); params.append(CmsEncoder.escapeWBlanks(editor.key(Messages.GUI_MESSAGEBOX_TITLE_PUBLISHRESOURCE_0) + ": " + editor.getParamResource(), CmsEncoder.ENCODING_UTF_8)); params.append("&").append(CmsDialog.PARAM_REDIRECT).append("=").append(CmsStringUtil.TRUE); params.append("&closelink="); if (Boolean.valueOf(editor.getParamDirectedit()).booleanValue()) { String linkTarget; if (!"".equals(editor.getParamBacklink())) { linkTarget = jsp.link(editor.getParamBacklink()); } else { linkTarget = jsp.link(editor.getParamResource());
CmsObject cms = getCms(); CmsFile tempFile; List<CmsProperty> properties; try { switchToTempProject(); tempFile = cms.readFile(getParamTempfile(), CmsResourceFilter.ALL); properties = cms.readPropertyObjects(getParamTempfile(), false); } finally { switchToCurrentProject(); if (cms.existsResource(getParamResource(), CmsResourceFilter.ALL)) { cms.writePropertyObjects(getParamResource(), properties); CmsFile orgFile = cms.readFile(getParamResource(), CmsResourceFilter.ALL); orgFile.setContents(tempFile.getContents()); getCloneCms().writeFile(orgFile); } else { switchToTempProject(); cms.changeLock(getParamTempfile()); getParamTempfile(), I_CmsPrincipal.PRINCIPAL_GROUP, OpenCms.getDefaultUsers().getGroupUsers()); switchToCurrentProject();
if (Boolean.valueOf(getParamDirectedit()).booleanValue()) { if (CmsStringUtil.isNotEmpty(getParamBacklink())) { setParamCloseLink(getJsp().link(getParamBacklink())); } else { setParamCloseLink(getJsp().link(getParamResource())); getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this); getJsp().include(FILE_DIALOG_CLOSE); } else { if (CmsStringUtil.isNotEmpty(getParamBacklink())) { setParamCloseLink(getJsp().link(getParamBacklink())); getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this); getJsp().include(FILE_DIALOG_CLOSE); } else { sendForward(CmsFrameset.JSP_WORKPLACE_URI, new HashMap());
/** * Shows the selected error page in case of an exception.<p> * * @param editor initialized instance of the editor class * @param exception the current exception * @throws JspException if inclusion of the error page fails */ protected void showErrorPage(Object editor, Exception exception) throws JspException { // save initialized instance of the editor class in request attribute for included sub-elements getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, editor); // reading of file contents failed, show error dialog setAction(ACTION_SHOW_ERRORMESSAGE); setParamTitle(key(Messages.GUI_TITLE_EDIT_1, new Object[] {CmsResource.getName(getParamResource())})); if (exception != null) { getJsp().getRequest().setAttribute(ATTRIBUTE_THROWABLE, exception); if (CmsLog.getLog(editor).isWarnEnabled()) { CmsLog.getLog(editor).warn(exception.getLocalizedMessage(), exception); } } // include the common error dialog getJsp().include(FILE_DIALOG_SCREEN_ERRORPAGE); } }
String filename = CmsEncoder.decode(paramValue, getCms().getRequestContext().getEncoding()); if (PARAM_TEMPFILE.equals(paramName) || CmsStringUtil.isEmpty(getParamTempfile())) { setFileEncoding(getFileEncoding(getCms(), filename)); return CmsEncoder.decode(paramValue, getCms().getRequestContext().getEncoding());
String filename = getParamResource(); CmsResource res = getCms().readResource(filename, CmsResourceFilter.IGNORE_EXPIRATION); if (getCms().existsResource(temporaryFilename, CmsResourceFilter.IGNORE_EXPIRATION)) { res = getCms().readResource(temporaryFilename, CmsResourceFilter.IGNORE_EXPIRATION); CmsFile file = getCms().readFile(res); CmsXmlContent xmlContent = CmsXmlContentFactory.unmarshal(getCms(), file); int locales = xmlContent.getLocales().size(); return button(href, target, image, label, type, getSkinUri() + "buttons/");
if (actionClass != null) { url = actionClass.getButtonUrl(getJsp(), getParamResource()); name = actionClass.getButtonName(); active = actionClass.isButtonActive(getJsp(), getParamResource()); } else { url = getSkinUri() + "buttons/publish_in.png"; name = Messages.GUI_EXPLORER_CONTEXT_PUBLISH_0; return button("javascript:" + jsFunction, null, image, name, type, url.substring( 0, url.lastIndexOf("/") + 1)); } else { return button(null, null, image, name, type, url.substring(0, url.lastIndexOf("/") + 1));
List<Locale> locales = OpenCms.getLocaleManager().getAvailableLocales(getCms(), resourceName); List<String> options = new ArrayList<String>(locales.size()); List<String> selectList = new ArrayList<String>(locales.size()); try { CmsResource res = getCms().readResource(resourceName, CmsResourceFilter.IGNORE_EXPIRATION); String temporaryFilename = CmsWorkplace.getTemporaryFileName(resourceName); if (getCms().existsResource(temporaryFilename, CmsResourceFilter.IGNORE_EXPIRATION)) { res = getCms().readResource(temporaryFilename, CmsResourceFilter.IGNORE_EXPIRATION); CmsFile file = getCms().readFile(res); CmsXmlContent xmlContent = CmsXmlContentFactory.unmarshal(getCms(), file); contentLocales = xmlContent.getLocales(); } catch (CmsException e) { selectList.add(curLocale.toString()); StringBuffer buf = new StringBuffer(); buf.append(curLocale.getDisplayName(getLocale())); if (!contentLocales.contains(curLocale)) { buf.append(EMPTY_LOCALE); setParamElementlanguage(selectList.get(0)); return buildSelect(attributes, options, selectList, currentIndex, false);
if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getParamResource())) { editedResource = getCms().readResource(getParamResource()); HttpSession session = getSession(); info = (CmsEditorSessionInfo)session.getAttribute( CmsEditorSessionInfo.getEditorSessionInfoKey(editedResource));
/** * @see org.opencms.workplace.CmsWorkplace#checkLock(String, CmsLockType) */ @Override public void checkLock(String resource, CmsLockType type) throws CmsException { CmsResource res = getCms().readResource(resource, CmsResourceFilter.ALL); CmsLock lock = getCms().getLock(res); if (!lock.isNullLock()) { setParamModified(Boolean.TRUE.toString()); } // for resources with siblings make sure all sibling have at least a // temporary lock if ((res.getSiblingCount() > 1) && (lock.isInherited())) { super.checkLock(resource, CmsLockType.TEMPORARY); } else { super.checkLock(resource, type); } }
/** * @see org.opencms.workplace.editors.CmsEditor#commitTempFile() */ @Override protected void commitTempFile() throws CmsException { super.commitTempFile(); m_file = getCloneCms().readFile(getParamResource()); m_content = CmsXmlContentFactory.unmarshal(getCloneCms(), m_file); }
/** * Returns a cloned cms instance that prevents the time range resource filter check.<p> * * Use it always for unmarshalling and file writing.<p> * * @return a cloned cms instance that prevents the time range resource filter check * * @throws CmsException if something goes wrong */ protected CmsObject getCloneCms() throws CmsException { CmsObject cloneCms = OpenCms.initCmsObject(getCms()); cloneCms.getRequestContext().setRequestTime(CmsResource.DATE_RELEASED_EXPIRED_IGNORE); return cloneCms; }
editor.actionSave(); editor.actionClear(true); params.append("?").append(CmsDialog.PARAM_RESOURCE).append("=").append(editor.getParamResource()); params.append("&").append(CmsDialog.PARAM_ACTION).append("=").append(CmsDialog.DIALOG_CONFIRMED); params.append("&").append(CmsWorkplace.PARAM_DIRECTPUBLISH).append("=").append(CmsStringUtil.TRUE); params.append("&").append(CmsWorkplace.PARAM_PUBLISHSIBLINGS).append("=").append( editor.getSettings().getUserSettings().getDialogPublishSiblings()); params.append( CmsEncoder.escapeWBlanks( editor.key(Messages.GUI_MESSAGEBOX_TITLE_PUBLISHRESOURCE_0) + ": " + editor.getParamResource(), CmsEncoder.ENCODING_UTF_8)); params.append("&").append(CmsDialog.PARAM_REDIRECT).append("=").append(CmsStringUtil.TRUE); params.append("&").append(CmsDialog.PARAM_CLOSELINK).append("="); if (Boolean.valueOf(editor.getParamDirectedit()).booleanValue()) { String linkTarget; if (!"".equals(editor.getParamBacklink())) { linkTarget = jsp.link(editor.getParamBacklink()); } else { linkTarget = jsp.link(editor.getParamResource()); if (CmsLinkManager.isWorkplaceLink(editor.getParamBacklink())) { publishLink += params.toString() + CmsEncoder.escapeWBlanks(jsp.link(editor.getParamBacklink()), CmsEncoder.ENCODING_UTF_8); } else { publishLink += params.toString()
CmsObject cms = getCms(); CmsFile tempFile; List properties; try { switchToTempProject(); tempFile = cms.readFile(getParamTempfile(), CmsResourceFilter.ALL); properties = cms.readPropertyObjects(getParamTempfile(), false); } finally { switchToCurrentProject(); if (cms.existsResource(getParamResource(), CmsResourceFilter.ALL)) { cms.writePropertyObjects(getParamResource(), properties); CmsFile orgFile = cms.readFile(getParamResource(), CmsResourceFilter.ALL); orgFile.setContents(tempFile.getContents()); getCloneCms().writeFile(orgFile); } else { cms.getRequestContext().setCurrentProject(cms.readProject(getSettings().getProject())); cms.changeLock(getParamTempfile()); cms.rmacc(getParamTempfile(), I_CmsPrincipal.PRINCIPAL_GROUP, OpenCms.getDefaultUsers().getGroupUsers()); cms.rmacc( getParamTempfile(), I_CmsPrincipal.PRINCIPAL_GROUP, OpenCms.getDefaultUsers().getGroupProjectmanagers());
if (Boolean.valueOf(getParamDirectedit()).booleanValue()) { if (CmsStringUtil.isNotEmpty(getParamBacklink())) { setParamCloseLink(getJsp().link(getParamBacklink())); } else { setParamCloseLink(getJsp().link(getParamResource())); getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this); getJsp().include(FILE_DIALOG_CLOSE); } else { if (CmsStringUtil.isNotEmpty(getParamBacklink())) { setParamCloseLink(getJsp().link(getParamBacklink())); getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this); getJsp().include(FILE_DIALOG_CLOSE); } else { sendForward(CmsWorkplace.JSP_WORKPLACE_URI, new HashMap<String, String[]>()); clearEditorSessionInfo();