cmshistorylist.java
来自「找了很久才找到到源代码」· Java 代码 · 共 826 行 · 第 1/3 页
JAVA
826 行
* Public constructor with JSP variables.<p>
*
* @param context the JSP page context
* @param req the JSP request
* @param res the JSP response
*/
public CmsHistoryList(PageContext context, HttpServletRequest req, HttpServletResponse res) {
this(new CmsJspActionElement(context, req, res));
}
/**
* Returns the link to an historical file.<p>
*
* @param cms the cms context
* @param structureId the structure id of the file
* @param version the version number of the file
*
* @return the link to an historical file
*/
public static String getHistoryLink(CmsObject cms, CmsUUID structureId, String version) {
String resourcePath;
CmsResource resource;
try {
resource = cms.readResource(structureId);
resourcePath = resource.getRootPath();
} catch (CmsException e) {
throw new CmsRuntimeException(e.getMessageContainer(), e);
}
StringBuffer link = new StringBuffer();
link.append(CmsHistoryResourceHandler.HISTORY_HANDLER);
link.append(resourcePath);
link.append('?');
link.append(CmsHistoryResourceHandler.PARAM_VERSION);
link.append('=');
link.append(getVersion("" + version));
return link.toString();
}
/**
* Returns the version number from a version parameter.<p>
*
* @param version might be negative for the online version
* @param locale if the result is for display purposes, the locale has to be <code>!= null</code>
*
* @return the display name
*/
public static String getDisplayVersion(String version, Locale locale) {
int ver = Integer.parseInt(version);
if (ver == CmsHistoryResourceHandler.PROJECT_OFFLINE_VERSION) {
return Messages.get().getBundle(locale).key(Messages.GUI_PROJECT_OFFLINE_0);
}
if (ver < 0) {
ver *= -1;
if (locale != null) {
return Messages.get().getBundle(locale).key(Messages.GUI_PROJECT_ONLINE_1, new Integer(ver));
}
}
return "" + ver;
}
/**
* Returns the version number from a version parameter.<p>
*
* @param version might be negative for the online version
*
* @return the positive value
*/
public static int getVersion(String version) {
int ver = Integer.parseInt(version);
return Math.abs(ver);
}
/**
* @see org.opencms.workplace.list.A_CmsListDialog#executeListMultiActions()
*/
public void executeListMultiActions() throws IOException, ServletException {
if (getParamListAction().equals(LIST_MACTION_COMPARE)) {
CmsListItem item1 = (CmsListItem)getSelectedItems().get(0);
CmsListItem item2 = (CmsListItem)getSelectedItems().get(1);
Map params = new HashMap();
if (((Comparable)item2.get(LIST_COLUMN_VERSION)).compareTo(item1.get(LIST_COLUMN_VERSION)) > 0) {
params.put(PARAM_VERSION_1, item1.get(LIST_COLUMN_VERSION));
params.put(PARAM_VERSION_2, item2.get(LIST_COLUMN_VERSION));
params.put(PARAM_ID_1, item1.get(LIST_COLUMN_STRUCTURE_ID));
params.put(PARAM_ID_2, item2.get(LIST_COLUMN_STRUCTURE_ID));
} else {
params.put(PARAM_VERSION_1, item2.get(LIST_COLUMN_VERSION));
params.put(PARAM_VERSION_2, item1.get(LIST_COLUMN_VERSION));
params.put(PARAM_ID_1, item2.get(LIST_COLUMN_STRUCTURE_ID));
params.put(PARAM_ID_2, item1.get(LIST_COLUMN_STRUCTURE_ID));
}
params.put(PARAM_ACTION, DIALOG_INITIAL);
params.put(PARAM_STYLE, CmsToolDialog.STYLE_NEW);
params.put(PARAM_RESOURCE, getParamResource());
getToolManager().jspForwardTool(this, "/history/comparison", params);
}
refreshList();
}
/**
* @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
*/
public void executeListSingleActions() throws IOException, ServletException {
if (getParamListAction().equals(LIST_ACTION_RESTORE)) {
try {
performRestoreOperation();
Map params = new HashMap();
params.put(PARAM_ACTION, DIALOG_INITIAL);
getToolManager().jspForwardPage(this, "/system/workplace/views/explorer/explorer_files.jsp", params);
} catch (CmsException e) {
LOG.error(e.getMessage(), e);
throw new CmsRuntimeException(e.getMessageContainer());
}
}
refreshList();
}
/**
* @see org.opencms.workplace.list.A_CmsListDialog#defaultActionHtmlStart()
*/
protected String defaultActionHtmlStart() {
return getList().listJs() + dialogContentStart(getParamTitle());
}
/**
* @see org.opencms.workplace.list.A_CmsListDialog#fillDetails(java.lang.String)
*/
protected void fillDetails(String detailId) {
// get content
List items = getList().getAllContent();
Iterator itItems = items.iterator();
CmsListItem item;
while (itItems.hasNext()) {
item = (CmsListItem)itItems.next();
if (detailId.equals(GUI_LIST_HISTORY_DETAIL_PROJECT_0)) {
fillDetailProject(item, detailId);
}
}
}
/**
* @see org.opencms.workplace.list.A_CmsListDialog#getListItems()
*/
protected List getListItems() throws CmsException {
List result = new ArrayList();
List historicalVersions = getCms().readAllAvailableVersions(getParamResource());
Iterator itVersions = historicalVersions.iterator();
while (itVersions.hasNext()) {
I_CmsHistoryResource histRes = (I_CmsHistoryResource)itVersions.next();
// the publish tag for the history project
int publishTag = histRes.getPublishTag();
CmsHistoryProject project = getCms().readHistoryProject(publishTag);
String filetype = String.valueOf(histRes.getTypeId());
String dateLastModified = getMessages().getDateTime(histRes.getDateLastModified());
String datePublished = getMessages().getDateTime(project.getPublishingDate());
CmsListItem item = getList().newItem("" + histRes.getVersion());
int factor = 1;
if (result.isEmpty() && !histRes.getState().isDeleted()) {
factor = -1;
}
CmsVersionWrapper version = new CmsVersionWrapper(factor * histRes.getVersion());
//version
item.set(LIST_COLUMN_VERSION, version);
// filename
item.set(LIST_COLUMN_DATE_PUBLISHED, datePublished);
// nicename
item.set(LIST_COLUMN_DATE_LAST_MODIFIED, dateLastModified);
// group
item.set(LIST_COLUMN_FILE_TYPE, filetype);
// user
item.set(LIST_COLUMN_USER, CmsPrincipal.readPrincipalIncludingHistory(
getCms(),
histRes.getUserLastModified()).getName());
// path
item.set(LIST_COLUMN_RESOURCE_PATH, getCms().getRequestContext().removeSiteRoot(histRes.getRootPath()));
// size
item.set(LIST_COLUMN_SIZE, new Integer(histRes.getLength()).toString());
// invisible publish tag (for reading history project in fillDetails)
item.set(LIST_COLUMN_PUBLISH_TAG, new Integer(publishTag));
// invisible structure id
item.set(LIST_COLUMN_STRUCTURE_ID, histRes.getStructureId().toString());
result.add(item);
}
if (result.isEmpty()) {
CmsResource onlineResource = null;
// this is to prevent problems after an update without keeping historical info
CmsProject project = getCms().getRequestContext().currentProject();
try {
getCms().getRequestContext().setCurrentProject(getCms().readProject(CmsProject.ONLINE_PROJECT_ID));
onlineResource = getCms().readResource(getParamResource(), CmsResourceFilter.IGNORE_EXPIRATION);
CmsListItem item = getList().newItem("" + onlineResource.getVersion());
//version
item.set(LIST_COLUMN_VERSION, new CmsVersionWrapper(-1 * onlineResource.getVersion()));
// filename
item.set(LIST_COLUMN_DATE_PUBLISHED, "-");
// nicename
item.set(
LIST_COLUMN_DATE_LAST_MODIFIED,
getMessages().getDateTime(onlineResource.getDateLastModified()));
// group
item.set(LIST_COLUMN_FILE_TYPE, String.valueOf(onlineResource.getTypeId()));
// user
item.set(LIST_COLUMN_USER, CmsPrincipal.readPrincipalIncludingHistory(
getCms(),
onlineResource.getUserLastModified()).getName());
// size
item.set(LIST_COLUMN_SIZE, new Integer(onlineResource.getLength()).toString());
// path
item.set(LIST_COLUMN_RESOURCE_PATH, getCms().getSitePath(onlineResource));
// invisible structure id
item.set(LIST_COLUMN_STRUCTURE_ID, onlineResource.getStructureId().toString());
result.add(item);
} catch (CmsVfsResourceNotFoundException e) {
// ignore, most likely the file is new
} finally {
getCms().getRequestContext().setCurrentProject(project);
}
}
CmsResource offlineResource = getCms().readResource(getParamResource(), CmsResourceFilter.IGNORE_EXPIRATION);
// hide the size for folders
getList().getMetadata().getColumnDefinition(LIST_COLUMN_SIZE).setVisible(offlineResource.isFile());
// hide the preview button for folders
getList().getMetadata().getColumnDefinition(LIST_COLUMN_ICON).setVisible(offlineResource.isFile());
// display offline version, if state is not unchanged
if (!offlineResource.getState().isUnchanged()) {
CmsListItem item = getList().newItem("" + offlineResource.getVersion());
//version
item.set(LIST_COLUMN_VERSION, new CmsVersionWrapper(CmsHistoryResourceHandler.PROJECT_OFFLINE_VERSION));
// filename
item.set(LIST_COLUMN_DATE_PUBLISHED, "-");
// nicename
item.set(LIST_COLUMN_DATE_LAST_MODIFIED, getMessages().getDateTime(offlineResource.getDateLastModified()));
// group
item.set(LIST_COLUMN_FILE_TYPE, String.valueOf(offlineResource.getTypeId()));
// user
item.set(LIST_COLUMN_USER, getCms().readUser(offlineResource.getUserLastModified()).getName());
// size
item.set(LIST_COLUMN_SIZE, new Integer(offlineResource.getLength()).toString());
// path
item.set(LIST_COLUMN_RESOURCE_PATH, getCms().getSitePath(offlineResource));
// invisible structure id
item.set(LIST_COLUMN_STRUCTURE_ID, offlineResource.getStructureId().toString());
result.add(item);
}
boolean comparable = (result.size() > 1);
getList().getMetadata().getColumnDefinition(LIST_COLUMN_SEL1).setVisible(comparable);
getList().getMetadata().getColumnDefinition(LIST_COLUMN_SEL2).setVisible(comparable);
getList().getMetadata().getMultiAction(LIST_MACTION_COMPARE).setVisible(comparable);
return result;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?