mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
ALF-9351: Reverse merged 29767 as it doesn't work, is suboptimal and platform encoding dependent
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29807 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -18,11 +18,8 @@
|
||||
*/
|
||||
package org.alfresco.repo.security.permissions.impl.model;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
@@ -53,15 +50,11 @@ import org.alfresco.service.namespace.DynamicNamespacePrefixResolver;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
import org.dom4j.Attribute;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentException;
|
||||
import org.dom4j.DocumentType;
|
||||
import org.dom4j.Element;
|
||||
import org.dom4j.io.SAXReader;
|
||||
import org.dom4j.tree.DefaultDocumentType;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
/**
|
||||
* The implementation of the model DAO Reads and stores the top level model information Encapsulates access to this
|
||||
@@ -100,8 +93,6 @@ public class PermissionModel implements ModelDAO
|
||||
// Instance variables
|
||||
|
||||
private String model;
|
||||
private String dtdSchema;
|
||||
private boolean validate = true;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
@@ -1151,26 +1142,6 @@ public class PermissionModel implements ModelDAO
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the dtd schema that is used to validate permission model
|
||||
*
|
||||
* @param dtdSchema
|
||||
*/
|
||||
public void setDtdSchema(String dtdSchema)
|
||||
{
|
||||
this.dtdSchema = dtdSchema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether model should be validated on initialization against specified dtd
|
||||
*
|
||||
* @param validate
|
||||
*/
|
||||
public void setValidate(boolean validate)
|
||||
{
|
||||
this.validate = validate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the dictionary service
|
||||
*
|
||||
@@ -1290,7 +1261,6 @@ public class PermissionModel implements ModelDAO
|
||||
private Document createDocument(String model)
|
||||
{
|
||||
InputStream is = this.getClass().getClassLoader().getResourceAsStream(model);
|
||||
URL dtdSchemaUrl = this.getClass().getClassLoader().getResource(dtdSchema);
|
||||
if (is == null)
|
||||
{
|
||||
throw new PermissionModelException("File not found: " + model);
|
||||
@@ -1298,63 +1268,21 @@ public class PermissionModel implements ModelDAO
|
||||
SAXReader reader = new SAXReader();
|
||||
try
|
||||
{
|
||||
if (validate)
|
||||
{
|
||||
if (dtdSchemaUrl != null)
|
||||
{
|
||||
is = processModelDocType(is, dtdSchemaUrl.toString());
|
||||
reader.setValidation(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new PermissionModelException("Couldn't obtain DTD schema to validate permission model.");
|
||||
}
|
||||
}
|
||||
|
||||
Document document = reader.read(is);
|
||||
is.close();
|
||||
return document;
|
||||
}
|
||||
catch (DocumentException e)
|
||||
{
|
||||
throw new PermissionModelException("Failed to create permission model document: " + model, e);
|
||||
throw new PermissionModelException("Failed to create permission model document ", e);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new PermissionModelException("Failed to close permission model document: " + model, e);
|
||||
throw new PermissionModelException("Failed to close permission model document ", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Replace or add correct DOCTYPE to the xml to allow validation against dtd
|
||||
*/
|
||||
private InputStream processModelDocType(InputStream is, String dtdSchemaUrl) throws DocumentException, IOException
|
||||
{
|
||||
SAXReader reader = new SAXReader();
|
||||
// read document without validation
|
||||
Document doc = reader.read(is);
|
||||
DocumentType docType = doc.getDocType();
|
||||
if (docType != null)
|
||||
{
|
||||
// replace DOCTYPE setting the full path to the xsd
|
||||
docType.setSystemID(dtdSchemaUrl);
|
||||
}
|
||||
else
|
||||
{
|
||||
// add the DOCTYPE
|
||||
docType = new DefaultDocumentType(doc.getRootElement().getName(), dtdSchemaUrl);
|
||||
doc.setDocType(docType);
|
||||
}
|
||||
|
||||
File tempFile = TempFileProvider.createTempFile("permissionModel-", ".tmp");
|
||||
|
||||
// copy the modified permission model to the temp file
|
||||
FileCopyUtils.copy(doc.asXML().getBytes(), tempFile);
|
||||
|
||||
return new FileInputStream(tempFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default access status
|
||||
*
|
||||
|
Reference in New Issue
Block a user