📄 cmsmanagerslideimpl.java
字号:
Vector permissions = new Vector();
while (e.hasMoreElements())
{
org.apache.slide.security.NodePermission node =
(org.apache.slide.security.NodePermission) e.nextElement();
Permission p = (Permission) CmsFactory.getCmsOmInstance("Permission");
p.setAction(node.getActionUri());
p.setActor(node.getSubjectUri());
p.setInheritable(node.isInheritable());
p.setNegative(node.isNegative());
permissions.add(p);
}
return permissions;
}
catch (Exception e)
{
throw new JetspeedCMSException("Impossible to get the security information " + uri);
}
}
/**
* Grant permission to an uri
* @param userNode User reference
* @param uri on which permission has to be set
* @param userUri User uri reference
* @param actionUri Action used in the permission (read, modify, write, ...)
* @param inheritable true if the permission has to be apply on child uri
* @param negative true if the permission is negative
*/
public void grantPermission (String objectUri , String userUri,
String actionUri, boolean inheritable,
boolean negative)
throws JetspeedCMSException
{
try
{
String userNode = this.getSlideUserNode();
// Get the SlideToken in function of a SubjectNode string
SlideToken slideToken = this.getSlideToken( userNode );
// uri parameter can be point to a linkNode => retrieve its target
// objectnode
ObjectNode objectNode = structure.retrieve(slideToken, objectUri, true);
// uri parameter can be point to a linkNode => retrieve its target
// objectnode
SubjectNode subjectNode = (SubjectNode) structure.retrieve(slideToken, userUri, true);
// Retrieve the Action Node
ActionNode actionNode = (ActionNode) structure.retrieve(slideToken, actionUri);
// Grant the permission
NodePermission perm = new NodePermission(objectNode, subjectNode,
actionNode, inheritable,
negative);
security.grantPermission(slideToken, perm);
}
catch ( Exception e)
{
throw new JetspeedCMSException("Impossible to grant the permission");
}
}
/**
* Create a new resource in the repository
* @param userNode User reference
* @param resource object describing the new resource
*/
public void createResource (Resource resource)
throws JetspeedCMSException
{
try
{
String userNode = this.getSlideUserNode();
// Get the SlideToken in function of a SubjectNode string
SlideToken slideToken = this.getSlideToken( userNode );
// Create the new resource ( Slide subjectNode )
SubjectNode subject = new SubjectNode();
structure.create(slideToken, subject, resource.getUri());
// ---- Create the new content revision descriptor
NodeRevisionDescriptor descriptor = (( SlideResource )resource).getDesciptor();
descriptor.setProperty(this.PROPERTY_CLASS_NAME,
resource.getClass().getName());
if (resource instanceof Catalog)
{
// Get content length
descriptor.setProperty("getcontentlength", new Long(0));
// Resource type (collection) - use xml element recognize by webdav client
descriptor.setProperty(new NodeProperty("resourcetype", "<collection/>", true));
}
else
{
// Get content length
descriptor.setProperty("getcontentlength", new Long(0));
// Last modification date
descriptor.setLastModified(new Date());
// Etag generation
String etag = resource.getUri().hashCode() + "_"
//+ revisionNumber.hashCode() + "_"
+ descriptor.getContentLength();
descriptor.setProperty(new NodeProperty("getetag", etag, true));
descriptor.setProperty(new NodeProperty("getcontenttype", "", true));
// Resource type (collection or other type of content)
descriptor.setProperty(new NodeProperty("resourcetype", "", true));
// Source
descriptor.setProperty(new NodeProperty("source", "", true));
// Content Language
//revisionDescriptor.setProperty("getcontentlanguage", stream., true);
// Owner
//String owner = slideToken.getCredentialsToken().getPublicCredentials();
//descriptorescriptor.setProperty(new NodeProperty("owner", owner, true));
// For Microsoft tools
// Is hidden
NodeProperty property = new NodeProperty("ishidden", "0", "MICROSOFT");
descriptor.setProperty(property);
// Is collection
property = new NodeProperty("iscollection", "0", "MICROSOFT");
descriptor.setProperty(property);
// Is read only
property = new NodeProperty("isreadonly", "0", "MICROSOFT");
descriptor.setProperty(property);
// Last accessed
property = new NodeProperty("lastaccessed", (new Date()).toString(),
"MICROSOFT");
descriptor.setProperty(property);
}
content.create(slideToken, resource.getUri(), descriptor, null);
// Grant permission if needed
Vector permissions = resource.getPermissions();
for (Enumeration e = permissions.elements(); e.hasMoreElements();)
{
Permission p = (Permission) e.nextElement();
this.grantPermission(resource.getUri(), p.getActor(),
p.getAction(), p.isInheritable(), p.isNegative());
}
}
catch (Exception e)
{
throw new JetspeedCMSException("Impossible to create the content resource");
}
}
/**
* Create a new resource in the repository with a content stream
* @param userNode User reference
* @param resource object describing the new resource
* @param stream stream which match to the resource content
*/
public void createResource (Resource resource, FileItem stream)
throws JetspeedCMSException
{
try
{
String userNode = this.getSlideUserNode();
// Get the SlideToken in function of a SubjectNode string
SlideToken slideToken = this.getSlideToken( userNode );
// Create the new resource ( Slide subjectNode )
SubjectNode subject = new SubjectNode();
structure.create(slideToken, subject, resource.getUri());
// Create the new content revision descriptor
NodeRevisionDescriptor descriptor = ((SlideResource) resource).getDesciptor();
descriptor.setProperty(this.PROPERTY_CLASS_NAME,
resource.getClass().getName());
// Get content length
descriptor.setProperty("getcontentlength", new Long(stream.getSize()));
// Last modification date
descriptor.setLastModified(new Date());
// Etag generation
String etag = resource.getUri().hashCode() + "_"
//+ revisionNumber.hashCode() + "_"
+ descriptor.getContentLength();
descriptor.setProperty(new NodeProperty("getetag", etag, true));
String contentType = stream.getContentType();
descriptor.setProperty(new NodeProperty("getcontenttype", contentType, true));
// Resource type (collection or other type of content
descriptor.setProperty(new NodeProperty("resourcetype", "", true));
// Source
descriptor.setProperty(new NodeProperty("source", "", true));
// displayname : use in a webdav client
String displayName = stream.getFileName().substring( stream.getFileName().lastIndexOf("\\")+1 );
descriptor.setProperty(new NodeProperty("displayname",
"<![CDATA[" + displayName+ "]]>"));
// Content Language
//revisionDescriptor.setProperty("getcontentlanguage", stream., true);
// Owner
//String owner = slideToken.getCredentialsToken().getPublicCredentials();
//descriptorescriptor.setProperty(new NodeProperty("owner", owner, true));
// For Microsoft tools
// Is hidden
NodeProperty property = new NodeProperty("ishidden", "0", "MICROSOFT");
descriptor.setProperty(property);
// Is collection
property = new NodeProperty("iscollection", "0", "MICROSOFT");
descriptor.setProperty(property);
// Is read only
property = new NodeProperty("isreadonly", "0", "MICROSOFT");
descriptor.setProperty(property);
// Last accessed
property = new NodeProperty("lastaccessed", (new Date()).toString(),
"MICROSOFT");
descriptor.setProperty(property);
// Add the content stream
NodeRevisionContent revisionContent = new NodeRevisionContent();
revisionContent.setContent(stream.getInputStream());
// Add all stuff in the slide repository
content.create(slideToken, resource.getUri(), descriptor, revisionContent);
// Grant permission if needed
Vector permissions = resource.getPermissions();
for (Enumeration e = permissions.elements(); e.hasMoreElements();)
{
Permission p = (Permission) e.nextElement();
this.grantPermission(resource.getUri(), p.getActor(),
p.getAction(), p.isInheritable(), p.isNegative());
}
}
catch (Exception e)
{
throw new JetspeedCMSException("Impossible to create the content resource");
}
}
/**
* Create a new link in the repository
* @param userNode User reference
* @param link object describing the new link
*/
public void createLink (Link link)
throws JetspeedCMSException
{
try
{
String userNode = this.getSlideUserNode();
// Get the SlideToken in function of a SubjectNode string
SlideToken slideToken = this.getSlideToken( userNode );
ObjectNode resourceNode = (ObjectNode) structure.retrieve(slideToken,
link.getTargetResourceUri() );
LinkNode linkNode = new LinkNode();
structure.createLink(slideToken, linkNode, link.getUri(), resourceNode);
}
catch (Exception e)
{
throw new JetspeedCMSException("Impossible to get the link");
}
}
// ------------------------------------------------------------------------------------------------
//
// PRIVATE METHODS
//
// ------------------------------------------------------------------------------------------------
/**
* Create a new SlideToken instance in function
* of a SubjectNode
*
* @param user reference
* @return a Slide toke object
*/
private SlideToken getSlideToken (String userNode)
{
CredentialsToken credToken = new CredentialsToken(new String(userNode));
return new SlideTokenImpl(credToken);
}
/**
* Populate the a catalog whith its childrens
*
*
* @param userNode user node reference
* @param children Collection which match to children uri
* @param catalog root catalog
* @param withSubCatalog if true, retrieve sub-catalog nodes
* @param withContent if false, retrieve only catalogs
* @param numberOfLevels number of level to retrieve
* (-1 : retrieve the complete graph from the root "catalog"
*
*/
private void getChildren(String userNode, Enumeration children,
Catalog catalog, boolean withSubCatalog,
boolean withContent,int numberOfLevels)
throws JetspeedCMSException
{
if (Log.getLogger().isDebugEnabled())
{
Log.debug("Slide.getChildren for : " + catalog.getUri());
}
if (numberOfLevels != -1)
{
numberOfLevels--;
}
while (children.hasMoreElements())
{
String childUri = (String) children.nextElement();
if (Log.getLogger().isDebugEnabled())
{
Log.debug("Slide.getChildren - Child found : " + childUri);
}
try
{
Resource resource = this.getResource(childUri);
if (resource instanceof Catalog)
{
if (withSubCatalog)
{
// numberOfLevels == -1 means all levels in the repository tree
if ((numberOfLevels == -1) || (numberOfLevels > 0))
{
int tmp = numberOfLevels;
this.populateCatalog((Catalog) resource,
withSubCatalog,
withContent,
numberOfLevels );
}
if (Log.getLogger().isDebugEnabled())
{
Log.debug("Slide.add Children : " + resource.getKey());
}
catalog.addResource( resource.getKey(), resource);
}
}
else
{
if (withContent)
{
catalog.addResource(resource.getKey(), resource);
}
}
}
catch (JetspeedCMSException e)
{
// if the exception is AccessDenied : continue the loop for other children
// else it is a more serious exception => throws the exception to the caller
if (!e.isAccessDenied())
{
throw new JetspeedCMSException("Impossible to get the children information ");
}
}
}
}
/**
* Return the Slide User node depending of the current Jetspeed user session
*
* @return the slide user node
*/
private String getSlideUserNode()
{
JetspeedRunData data = ((JetspeedRunDataService) TurbineServices.getInstance()
.getService(RunDataService.SERVICE_NAME))
.getCurrentRunData();
return Utility.getUserUri(data.getUser().getUserName());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -