📄 cmsadminsyncproperties.java
字号:
}
if((syncPath == null) || ("".equals(syncPath))) {
syncPath = reg.getSystemValue(C_SYNCHRONISATION_PATH);
if(syncPath == null){
syncPath = "";
}
}
if((allResources == null) || ("".equals(allResources))) {
allResources = "";
if (!((projectId == null) || ("".equals(projectId)))){
Hashtable resources = reg.getSystemValues(C_SYNCHRONISATION_RESOURCE);
numRes = resources.size();
if (numRes > 0){
allResources = new String();
for (int i=1; i < numRes+1; i++) {
String path = (String)resources.get(C_SYNCHRONISATION_RESOURCETAG+i);
// try to read this resource from the project
try{
cms.readFileHeader(path, Integer.parseInt(projectId));
allResources = allResources + path + ";";
} catch (CmsException exc){
}
}
// remove the last semikolon
if (allResources.endsWith(";")){
allResources = allResources.substring(0,allResources.lastIndexOf(";"));
}
}
}
}
if(!"done".equals(templateSelector)){
// Check if the user requested a project change in the dialog
// and set the currentProject
if(projectId != null && !("".equals(projectId))) {
if(!(Integer.parseInt(projectId) == reqCont.currentProject().getId())) {
reqCont.setCurrentProject(Integer.parseInt(projectId));
}
}
}
templateDocument.setData(C_SYNCPROJECT, projectId);
templateDocument.setData(C_SYNCRESOURCES, allResources);
templateDocument.setData(C_SYNCPATH, syncPath);
session.putValue(C_SYNCPROJECT, projectId);
session.putValue(C_SYNCPATH, syncPath);
session.putValue(C_SYNCRESOURCES, allResources);
// Now load the template file and start the processing
return startProcessing(cms, templateDocument, elementName, parameters, templateSelector);
}
/**
* Indicates if the results of this class are cacheable.
*
* @param cms CmsObject Object for accessing system resources
* @param templateFile Filename of the template file
* @param elementName Element name of this template in our parent template.
* @param parameters Hashtable with all template class parameters.
* @param templateSelector template section that should be processed.
* @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
*/
public boolean isCacheable(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) {
return false;
}
/**
* Gets all groups, that may work for a project.
* <P>
* The given vectors <code>names</code> and <code>values</code> will
* be filled with the appropriate information to be used for building
* a select box.
*
* @param cms CmsObject Object for accessing system resources.
* @param names Vector to be filled with the appropriate values in this method.
* @param values Vector to be filled with the appropriate values in this method.
* @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
* @return Index representing the current value in the vectors.
* @throws CmsException
*/
public Integer getProjects(CmsObject cms, CmsXmlLanguageFile lang, Vector names, Vector values, Hashtable parameters) throws CmsException {
// get all projects
Vector projects = cms.getAllAccessibleProjects();
int retValue = -1;
CmsProject curProject = cms.getRequestContext().currentProject();
String defaultProject = curProject.getId()+"";
I_CmsSession session = cms.getRequestContext().getSession(true);
String enteredProject = (String)session.getValue(C_SYNCPROJECT);
if(enteredProject != null && !"".equals(enteredProject)) {
// if an error has occurred before, take the previous entry of the user
defaultProject = enteredProject;
}
// fill the names and values
int n = 0;
for(int z = 0;z < projects.size();z++) {
CmsProject loopProject = (CmsProject)projects.elementAt(z);
if(!loopProject.isOnlineProject()) {
String loopProjectName = loopProject.getName();
String loopProjectId = loopProject.getId() + "";
if(defaultProject.equals(loopProjectId)) {
retValue = n;
cms.getRequestContext().setCurrentProject(Integer.parseInt(loopProjectId));
}
names.addElement(loopProjectName);
values.addElement(loopProjectId);
n++;
}
}
return new Integer(retValue);
}
/**
* Gets the resources.
* <P>
* The given vectors <code>names</code> and <code>values</code> will
* be filled with the appropriate information to be used for building
* a select box.
*
* @param cms CmsObject Object for accessing system resources.
* @param names Vector to be filled with the appropriate values in this method.
* @param values Vector to be filled with the appropriate values in this method.
* @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
* @return Index representing the current value in the vectors.
* @throws CmsException
*/
public Integer getResources(CmsObject cms, CmsXmlLanguageFile lang, Vector names,
Vector values, Hashtable parameters) throws CmsException {
I_CmsSession session = cms.getRequestContext().getSession(true);
String enteredResources = (String)session.getValue(C_SYNCRESOURCES);
Vector resources = parseResources(enteredResources);
// fill the names and values
for(int z = 0;z < resources.size();z++) {
String resourceName = (String)resources.elementAt(z);
names.addElement(resourceName);
values.addElement(resourceName);
}
return new Integer(-1);
}
/** Parse the string which holds all resources
*
* @param resources containts the full pathnames of all the resources, separated by semicolons
* @return A vector with the same resources
*/
private Vector parseResources(String resources) {
Vector ret = new Vector();
if(resources != null) {
StringTokenizer resTokenizer = new StringTokenizer(resources, ";");
while(resTokenizer.hasMoreElements()) {
String path = (String)resTokenizer.nextElement();
ret.addElement(path);
}
}
return ret;
}
/** Check whether some of the resources are redundant because a superfolder has also
* been selected.
*
* @param resources containts the full pathnames of all the resources
* @return A vector with the same resources, but the paths in the return value are disjoint
*/
private void checkRedundancies(Vector resources) {
int i, j;
if(resources == null) {
return ;
}
Vector redundant = new Vector();
int n = resources.size();
if(n < 2) {
// no check needed, because there is only one resource or
// no resources selected, return empty Vector
return ;
}
for(i = 0;i < n;i++) {
redundant.addElement(new Boolean(false));
}
for(i = 0;i < n - 1;i++) {
for(j = i + 1;j < n;j++) {
if(((String)resources.elementAt(i)).length() <
((String)resources.elementAt(j)).length()) {
if(((String)resources.elementAt(j)).startsWith((String)resources.elementAt(i))) {
redundant.setElementAt(new Boolean(true), j);
}
}
else {
if(((String)resources.elementAt(i)).startsWith((String)resources.elementAt(j))) {
redundant.setElementAt(new Boolean(true), i);
}
}
}
}
for(i = n - 1;i >= 0;i--) {
if(((Boolean)redundant.elementAt(i)).booleanValue()) {
resources.removeElementAt(i);
}
}
}
/**
* Check if this resource should is writeable.
* @param cms The CmsObject
* @param res The resource to be checked.
* @return True or false.
* @throws CmsException if something goes wrong.
*/
private boolean checkWriteable(CmsObject cms, String resPath, int projectId) {
boolean access = false;
int accessflags;
try {
CmsResource res = cms.readFileHeader(resPath, projectId);
accessflags = res.getAccessFlags();
boolean groupAccess = false;
Enumeration allGroups = cms.getGroupsOfUser(cms.getRequestContext().currentUser().getName()).elements();
while((!groupAccess) && allGroups.hasMoreElements()) {
groupAccess = cms.readGroup(res).equals((CmsGroup)allGroups.nextElement());
}
if(((accessflags & C_ACCESS_PUBLIC_WRITE) > 0)
|| (cms.getRequestContext().isAdmin())
|| (cms.readOwner(res).equals(cms.getRequestContext().currentUser())
&& (accessflags & C_ACCESS_OWNER_WRITE) > 0)
|| (groupAccess && (accessflags & C_ACCESS_GROUP_WRITE) > 0)) {
access = true;
}
}
catch(CmsException e) {
access = false;
}
return access;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -