workflow.js
来自「Hippo CMS是一个以信息为中心的开源内容管理系统。Hippo CMS目标是」· JavaScript 代码 · 共 577 行 · 第 1/2 页
JS
577 行
// Map<String, Map<PropertyName, Property>>
var webdavProperties = new HashMap();
// Set<String>
var locations = new HashSet();
// Set<PropertyName>
var propertyNames = new HashSet();
generic.forEach(matchingInstances, function(instanceIdAsObject) {
var instanceId = instanceIdAsObject.longValue();
authorizer.gatherLocationsAndPropertyNames(instanceId, locations, propertyNames,
authorizerContext);
});
if (!locations.isEmpty() && !propertyNames.isEmpty()) {
var request = "<D:searchrequest xmlns:D=\"DAV:\"><D:basicsearch><D:select><D:prop>";
var propertyNamesIterator = propertyNames.iterator();
while (propertyNamesIterator.hasNext()) {
var propertyName = propertyNamesIterator.next();
request += "<" + propertyName.getLocalName() + " xmlns=\"" + propertyName.getNamespaceURI() + "\" />";
}
request += "</D:prop></D:select><D:from>";
var locationsIterator = locations.iterator();
while (locationsIterator.hasNext()) {
var location = locationsIterator.next();
request += "<D:scope><D:href>" + location + "</D:href><D:depth>0</D:depth></D:scope>";
}
request += "</D:from><D:limit><D:nresults>1000</D:nresults></D:limit></D:basicsearch></D:searchrequest>";
var httpState = authentication.getHttpState();
var httpClient = new Packages.org.apache.commons.httpclient.HttpClient();
httpClient.setState(httpState);
avalon.usingComponentDo(Packages.nl.hippo.cms.repositorylocation.CommonRepositoryLocationRoles.EDITOR_REPOSITORY_LOCATION_ROLE, function(editorRepoLocation) {
var editorRepoInfo = editorRepoLocation.getRepositoryInformation();
var searchMethod = new Packages.org.apache.webdav.lib.methods.SearchMethod(editorRepoInfo.getAbsoluteBaseUri(), request);
searchMethod.setDoAuthentication(true);
var searchResult = httpClient.executeMethod(searchMethod);
if (searchResult >= 200 && searchResult <= 299) {
var resultLocationsEnum = searchMethod.getAllResponseURLs();
while (resultLocationsEnum.hasMoreElements()) {
var resultLocation = resultLocationsEnum.nextElement();
var relativeResultLocation = null;
var locationsIterator = locations.iterator();
while (locationsIterator.hasNext()) {
var location = locationsIterator.next();
if (resultLocation.endsWith(location)) {
relativeResultLocation = location;
}
}
var locationProperties = new HashMap();
webdavProperties.put(relativeResultLocation, locationProperties);
var propertiesEnum = searchMethod.getResponseProperties(resultLocation);
while (propertiesEnum.hasMoreElements()) {
var property = propertiesEnum.nextElement();
var propertyName = new Packages.org.apache.webdav.lib.PropertyName(property.getNamespaceURI(),
property.getLocalName());
locationProperties.put(propertyName, property);
}
}
} else {
logging.error(function() {
return "Error: " + searchResult + ", occurred during execution of DASL: " + request + ", for workflow privileges.";
});
}
});
}
generic.forEach(matchingInstances, function(instanceIdAsObject) {
var instanceId = instanceIdAsObject.longValue();
var isAuthorized = false;
var privilegeNamespace = queryDefinition.getAuthorization().getNamespace();
var privilegeNamePrefix = queryDefinition.getAuthorization().getNamePrefix();
var privilegeName = queryDefinition.getAuthorization().getName();
var instanceProperties = workflowComp.getPropertySet(instanceId);
if (privilegeName == null) {
var siteId = instanceProperties.getString("siteId");
privilegeName = privilegeNamePrefix + siteId;
}
try {
isAuthorized = authorizer.isAuthorizedFor(instanceId, privilegeNamespace, privilegeName,
webdavProperties, authorizerContext);
}
catch (e) {
if (e instanceof Throwable) {
e.printStackTrace();
}
throw e;
}
if (isAuthorized) {
var location = instanceProperties.getString("location");
// if location is a relative URI, make it absolute
if (!location.startsWith("http://") && !location.startsWith("webdav://")) {
avalon.usingComponentDo(Packages.nl.hippo.cms.repositorylocation.CommonRepositoryLocationRoles.EDITOR_REPOSITORY_LOCATION_ROLE, function(editorRepoLocation) {
var editorRepoInfo = editorRepoLocation.getRepositoryInformation();
location = editorRepoInfo.getAbsoluteUri(location);
if (location.startsWith("http://")) {
location = "webdav://" + location.substring(7);
}
});
}else if (location.startsWith("http://")) {
location = "webdav://" + location.substring(7);
}
var data;
if (queryDefinition.getDataRetrieverClassName() != null) {
var dataRetriever = workflowComp.loadComponent(instanceId, queryDefinition.getDataRetrieverClassName());
config.usingCurrentSiteDo(function(siteConfiguration) {
config.usingRepositoryDo(siteConfiguration.getRepository(), function(repositoryConfiguration) {
var rootUri = repositoryConfiguration.getRoot();
if (dataRetriever instanceof Packages.nl.hippo.cms.workflows.shared.QueryDataRetriever2) {
data = dataRetriever.getData(project, instanceId, location, rootUri, authentication.getHttpState());
}
else {
data = dataRetriever.getData(location, rootUri, authentication.getHttpState());
}
});
});
}
else {
data = new HashMap();
}
var locationWithData = { location:location, workflowId:instanceId, data:data };
authorizedLocations.add(locationWithData);
}
});
}
else {
generic.forEach(matchingInstances, function(instanceIdAsObject) {
var instanceId = instanceIdAsObject.longValue();
var isAuthorized = false;
var privilegeNamespace = queryDefinition.getAuthorization().getNamespace();
var privilegeNamePrefix = queryDefinition.getAuthorization().getNamePrefix();
var privilegeName = queryDefinition.getAuthorization().getName();
var instanceProperties = workflowComp.getPropertySet(instanceId);
if (privilegeName == null) {
var siteId = instanceProperties.getString("siteId");
privilegeName = privilegeNamePrefix + siteId;
}
try {
isAuthorized = authorizer.authorizeAction(instanceId, privilegeNamespace, privilegeName, authorizerContext);
}
catch (e) {
if (e instanceof Throwable) {
e.printStackTrace();
}
throw e;
}
if (isAuthorized) {
var location = instanceProperties.getString("location");
// if location is a relative URI, make it absolute
if (!location.startsWith("http://") && !location.startsWith("webdav://")) {
avalon.usingComponentDo(Packages.nl.hippo.cms.repositorylocation.CommonRepositoryLocationRoles.EDITOR_REPOSITORY_LOCATION_ROLE, function(editorRepoLocation) {
var editorRepoInfo = editorRepoLocation.getRepositoryInformation();
location = editorRepoInfo.getAbsoluteUri(location);
if (location.startsWith("http://")) {
location = "webdav://" + location.substring(7);
}
});
}else if (location.startsWith("http://")) {
location = "webdav://" + location.substring(7);
}
var data;
if (queryDefinition.getDataRetrieverClassName() != null) {
var dataRetriever = workflowComp.loadComponent(instanceId, queryDefinition.getDataRetrieverClassName());
config.usingCurrentSiteDo(function(siteConfiguration) {
config.usingRepositoryDo(siteConfiguration.getRepository(), function(repositoryConfiguration) {
var rootUri = repositoryConfiguration.getRoot();
if (dataRetriever instanceof Packages.nl.hippo.cms.workflows.shared.QueryDataRetriever2) {
data = dataRetriever.getData(project, instanceId, location, rootUri, authentication.getHttpState());
}
else {
data = dataRetriever.getData(location, rootUri, authentication.getHttpState());
}
});
});
}
else {
data = new HashMap();
}
var locationWithData = { location:location, workflowId:instanceId, data:data };
authorizedLocations.add(locationWithData);
}
});
}
// Convert XML representation of query to query
cocoon.sendPage('results/query', { query:queryDefinition, locations:authorizedLocations });
}
}
else {
cocoon.sendStatus(404);
}
}
}
});
}
// - Internal functions -----------------------------------------------
function addRequiredDocumentParametersIfMissing(parameters, location) {
if (parameters.get("location") == null)
{
parameters.put("location", location);
}
addRequiredParametersIfMissing(parameters);
}
function addRequiredParametersIfMissing(parameters) {
if (parameters.get("repositoryRootUrl") == null)
{
avalon.usingComponentDo(CommonRepositoryLocationRoles.EDITOR_REPOSITORY_LOCATION_ROLE, function(editorRepo)
{
var baseUri = editorRepo.getRepositoryInformation().getAbsoluteBaseUri();
parameters.put("repositoryRootUrl", baseUri);
});
}
var projectName = getCurrentProject().getName();
if (parameters.get("projectname") == null)
{
parameters.put("projectname", projectName);
}
if (parameters.get("projectName") == null)
{
parameters.put("projectName", projectName);
}
if (parameters.get("propertiesCache") == null)
{
parameters.put("propertiesCache", new HashMap());
}
if (parameters.get("httpstate") == null)
{
parameters.put("httpstate", authentication.getHttpState());
}
}
// - Helper functions -------------------------------------------------
function usingWorkflowDo(processor) {
try {
var server = spring.getBean("serverManager").getServer();
var project = server.getProjectByDomain(cocoon.request.getServerName());
var workflowComp = project.getWorkflowRepository();
processor(workflowComp);
}
/** /// Insert/remove space after asterisks toe disable/enable code
catch (e) {
if (e instanceof Throwable) {
e.printStackTrace();
}
else {
print(e);
}
throw e;
}
/**/
finally {
}
}
function getCurrentProject() {
var server = spring.getBean("serverManager").getServer();
var project = server.getProjectByDomain(cocoon.request.getServerName());
return project;
}
function removeParameters(uri) {
var result = uri;
// Convert to JavaScript string
uri = "" + uri;
var indexOfQuestionMark = uri.indexOf("?");
if (indexOfQuestionMark != -1) {
result = uri.substring(0, indexOfQuestionMark);
}
return result;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?