mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 06:53:09 +00:00
[DS-217] Hardcoded String in the license bitstream
git-svn-id: http://scm.dspace.org/svn/repo/dspace/trunk@4644 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
@@ -1443,42 +1443,6 @@ public class Item extends DSpaceObject
|
||||
return bsArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a copy of the license a user granted in this item.
|
||||
*
|
||||
* @param license
|
||||
* the license the user granted
|
||||
* @param eperson
|
||||
* the eperson who granted the license
|
||||
* @throws SQLException
|
||||
* @throws IOException
|
||||
* @throws AuthorizeException
|
||||
*/
|
||||
public void licenseGranted(String license, EPerson eperson)
|
||||
throws SQLException, IOException, AuthorizeException
|
||||
{
|
||||
// Put together text to store
|
||||
String licenseText = "License granted by " + eperson.getFullName()
|
||||
+ " (" + eperson.getEmail() + ") on "
|
||||
+ DCDate.getCurrent().toString() + " (GMT):\n\n" + license;
|
||||
|
||||
// Store text as a bitstream
|
||||
byte[] licenseBytes = licenseText.getBytes();
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(licenseBytes);
|
||||
Bitstream b = createSingleBitstream(bais, "LICENSE");
|
||||
|
||||
// Now set the format and name of the bitstream
|
||||
b.setName("license.txt");
|
||||
b.setSource("Written by org.dspace.content.Item");
|
||||
|
||||
// Find the License format
|
||||
BitstreamFormat bf = BitstreamFormat.findByShortDescription(ourContext,
|
||||
"License");
|
||||
b.setFormat(bf);
|
||||
|
||||
b.update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove just the DSpace license from an item This is useful to update the
|
||||
* current DSpace license, in case the user must accept the DSpace license
|
||||
|
142
dspace-api/src/main/java/org/dspace/content/LicenseUtils.java
Normal file
142
dspace-api/src/main/java/org/dspace/content/LicenseUtils.java
Normal file
@@ -0,0 +1,142 @@
|
||||
package org.dspace.content;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Formatter;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.license.FormattableArgument;
|
||||
import org.dspace.content.license.LicenseArgumentFormatter;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.eperson.EPerson;
|
||||
|
||||
/**
|
||||
* Utility class to manage generation and storing of the license text that the
|
||||
* submitter has to grant/granted for archiving the item
|
||||
*
|
||||
* @author bollini
|
||||
*
|
||||
*/
|
||||
public class LicenseUtils
|
||||
{
|
||||
/**
|
||||
* Return the text of the license that the user has granted/must grant
|
||||
* before for submit the item. The license text is build using the template
|
||||
* defined for the collection if any or the wide site configuration. In the
|
||||
* license text the following substitution can be used. {0} the eperson
|
||||
* firstname<br>
|
||||
* {1} the eperson lastname<br>
|
||||
* {2} the eperson email<br>
|
||||
* {3} the current date<br>
|
||||
* {4} the collection object that will be formatted using the appropriate
|
||||
* LicenseArgumentFormatter plugin (if defined)<br>
|
||||
* {5} the item object that will be formatted using the appropriate
|
||||
* LicenseArgumentFormatter plugin (if defined)<br>
|
||||
* {6} the eperson object that will be formatted using the appropriate
|
||||
* LicenseArgumentFormatter plugin (if defined)<br>
|
||||
* {x} any addittion argument supplied wrapped in the
|
||||
* LicenseArgumentFormatter based on his type (map key)
|
||||
*
|
||||
* @see LicenseArgumentFormatter
|
||||
* @param locale
|
||||
* @param collection
|
||||
* @param item
|
||||
* @param eperson
|
||||
* @param additionalInfo
|
||||
* @return the license text obtained substituting the provided argument in
|
||||
* the license template
|
||||
*/
|
||||
public static String getLicenseText(Locale locale, Collection collection,
|
||||
Item item, EPerson eperson, Map<String, Object> additionalInfo)
|
||||
{
|
||||
Formatter formatter = new Formatter(locale);
|
||||
|
||||
// EPerson firstname, lastname, email and the current date
|
||||
// will be available as separate arguments to make more simple produce
|
||||
// "tradition" text license
|
||||
// collection, item and eperson object will be also available
|
||||
int numArgs = 7 + (additionalInfo != null ? additionalInfo.size() : 0);
|
||||
Object[] args = new Object[numArgs];
|
||||
args[0] = eperson.getFirstName();
|
||||
args[1] = eperson.getLastName();
|
||||
args[2] = eperson.getEmail();
|
||||
args[3] = new java.util.Date();
|
||||
args[4] = new FormattableArgument("collection", collection);
|
||||
args[5] = new FormattableArgument("item", item);
|
||||
args[6] = new FormattableArgument("eperson", eperson);
|
||||
|
||||
if (additionalInfo != null)
|
||||
{
|
||||
int i = 1;
|
||||
for (String key : additionalInfo.keySet())
|
||||
{
|
||||
args[6 + 1] = new FormattableArgument(key, additionalInfo
|
||||
.get(key));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
String licenseTemplate = collection.getLicense();
|
||||
|
||||
return formatter.format(licenseTemplate, args).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method if no additional arguments has need to be supplied to the
|
||||
* license template. (i.e. call the full getLicenseText suppling
|
||||
* <code>null</code> for the additionalInfo argument)
|
||||
*
|
||||
* @param locale
|
||||
* @param collection
|
||||
* @param item
|
||||
* @param eperson
|
||||
* @return
|
||||
*/
|
||||
public static String getLicenseText(Locale locale, Collection collection,
|
||||
Item item, EPerson eperson)
|
||||
{
|
||||
return getLicenseText(locale, collection, item, eperson, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a copy of the license a user granted in the item.
|
||||
*
|
||||
* @param context
|
||||
* the dspace context
|
||||
* @param item
|
||||
* the item object of the license
|
||||
* @param licenseText
|
||||
* the license the user granted
|
||||
* @throws SQLException
|
||||
* @throws IOException
|
||||
* @throws AuthorizeException
|
||||
*/
|
||||
public static void grantLicense(Context context, Item item,
|
||||
String licenseText) throws SQLException, IOException,
|
||||
AuthorizeException
|
||||
{
|
||||
// Put together text to store
|
||||
// String licenseText = "License granted by " + eperson.getFullName()
|
||||
// + " (" + eperson.getEmail() + ") on "
|
||||
// + DCDate.getCurrent().toString() + " (GMT):\n\n" + license;
|
||||
|
||||
// Store text as a bitstream
|
||||
byte[] licenseBytes = licenseText.getBytes();
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(licenseBytes);
|
||||
Bitstream b = item.createSingleBitstream(bais, "LICENSE");
|
||||
|
||||
// Now set the format and name of the bitstream
|
||||
b.setName("license.txt");
|
||||
b.setSource("Written by org.dspace.content.LicenseUtils");
|
||||
|
||||
// Find the License format
|
||||
BitstreamFormat bf = BitstreamFormat.findByShortDescription(context,
|
||||
"License");
|
||||
b.setFormat(bf);
|
||||
|
||||
b.update();
|
||||
}
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
package org.dspace.content.license;
|
||||
|
||||
import java.util.Formattable;
|
||||
import java.util.Formatter;
|
||||
|
||||
import org.dspace.core.PluginManager;
|
||||
|
||||
/**
|
||||
* Wrapper class to make formattable any argument used in the license template.
|
||||
* The formatter behavior is delegated to a specific class on "type" basis
|
||||
* using the PluginManager
|
||||
*
|
||||
* @see Formattable
|
||||
* @see LicenseArgumentFormatter
|
||||
* @author bollini
|
||||
*
|
||||
*/
|
||||
public class FormattableArgument implements Formattable
|
||||
{
|
||||
private String type;
|
||||
|
||||
private Object object;
|
||||
|
||||
public FormattableArgument(String type, Object object)
|
||||
{
|
||||
this.type = type;
|
||||
this.object = object;
|
||||
}
|
||||
|
||||
public void formatTo(Formatter formatter, int flags, int width,
|
||||
int precision)
|
||||
{
|
||||
LicenseArgumentFormatter laf = (LicenseArgumentFormatter) PluginManager
|
||||
.getNamedPlugin(LicenseArgumentFormatter.class, type);
|
||||
if (laf != null)
|
||||
{
|
||||
laf.formatTo(formatter, flags, width, object, type);
|
||||
}
|
||||
else
|
||||
{
|
||||
formatter.format(object.toString());
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
package org.dspace.content.license;
|
||||
|
||||
import java.util.Formatter;
|
||||
|
||||
public interface LicenseArgumentFormatter
|
||||
{
|
||||
|
||||
/**
|
||||
* Format the object following the <code>java.util.Formatter</code> rules.
|
||||
* The object type is expected to be know to the implementer can is free to
|
||||
* assume safe to cast as appropriate. If a <code>null</code> object is
|
||||
* supplied is expected that the implementer will work as if a "sample data"
|
||||
* was requested.
|
||||
*
|
||||
* @see Formatter
|
||||
* @param formatter
|
||||
* the current formatter that need to process the object
|
||||
* @param flags
|
||||
* the flags option for the formatter
|
||||
* @param width
|
||||
* the width option for the formatter
|
||||
* @param object
|
||||
* the object to be formatted
|
||||
* @param type
|
||||
* the type of the object (this is an alias not the class name! -
|
||||
* i.e. item, collection, eperson, etc.)
|
||||
*/
|
||||
void formatTo(Formatter formatter, int flags, int width, Object object,
|
||||
String type);
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
package org.dspace.content.license;
|
||||
|
||||
import java.util.Formatter;
|
||||
|
||||
import org.dspace.content.DSpaceObject;
|
||||
|
||||
/**
|
||||
* This is a simple implementation of the LicenseArgumentFormatter for a
|
||||
* DSpaceObject. The formatter options width/precision are not take in care.
|
||||
*
|
||||
* @author bollini
|
||||
*
|
||||
*/
|
||||
public class SimpleDSpaceObjectLicenseFormatter implements
|
||||
LicenseArgumentFormatter
|
||||
{
|
||||
public void formatTo(Formatter formatter, int flags, int width,
|
||||
Object object, String type)
|
||||
{
|
||||
if (object == null)
|
||||
{
|
||||
formatter.format("sample "+type);
|
||||
}
|
||||
else
|
||||
{
|
||||
DSpaceObject dso = (DSpaceObject) object;
|
||||
String name = dso.getName();
|
||||
if (name != null)
|
||||
{
|
||||
formatter.format(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
formatter.format("");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -50,6 +50,7 @@ import org.dspace.app.util.SubmissionInfo;
|
||||
import org.dspace.app.util.Util;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.LicenseUtils;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.core.LogManager;
|
||||
import org.dspace.eperson.EPerson;
|
||||
@@ -198,11 +199,11 @@ public class LicenseStep extends AbstractProcessingStep
|
||||
// accepted it previously)
|
||||
item.removeDSpaceLicense();
|
||||
|
||||
// FIXME: Probably need to take this from the form at some point
|
||||
String license = subInfo.getSubmissionItem().getCollection()
|
||||
.getLicense();
|
||||
String license = LicenseUtils.getLicenseText(context
|
||||
.getCurrentLocale(), subInfo.getSubmissionItem()
|
||||
.getCollection(), item, submitter);
|
||||
|
||||
item.licenseGranted(license, submitter);
|
||||
LicenseUtils.grantLicense(context, item, license);
|
||||
|
||||
// commit changes
|
||||
context.commit();
|
||||
|
@@ -310,7 +310,7 @@ jsp.dspace-admin.item-select.heading = Select an Item
|
||||
jsp.dspace-admin.item-select.id = Internal ID:
|
||||
jsp.dspace-admin.item-select.text = <strong>The ID you entered isn't a valid item ID.</strong> If you're trying to edit a community or collection, you need to use the <a href="{0}">communities/collections admin page</a>.
|
||||
jsp.dspace-admin.item-select.title = Select Item
|
||||
jsp.dspace-admin.license-edit.description = Edit the default license by using the text box below. The license cannot be empty. <br />Please ensure the license meets the legal conditions of your country. <br />Changing this license will not affect those items already published and collections with their own licenses.
|
||||
jsp.dspace-admin.license-edit.description = Edit the default license by using the text box below. The license cannot be empty. <br />Please ensure the license meets the legal conditions of your country. <br />Changing this license will not affect those items already published and collections with their own licenses. <br/>There are some substitution variables that can be used to create personalized licenses, check the help pages for details.<br/>It is recommended to use a dummy submission to check the license change: <b>check the resulting license in the Accept/reject Licence step.</b>
|
||||
jsp.dspace-admin.license-edit.edited = The Default License has been updated
|
||||
jsp.dspace-admin.license-edit.empty = You must enter a license!
|
||||
jsp.dspace-admin.license-edit.heading = Default License Editor
|
||||
|
@@ -54,9 +54,11 @@ import org.dspace.app.webui.servlet.SubmissionController;
|
||||
import org.dspace.app.webui.submit.JSPStep;
|
||||
import org.dspace.app.webui.submit.JSPStepManager;
|
||||
import org.dspace.app.webui.util.JSPManager;
|
||||
import org.dspace.app.webui.util.UIUtil;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.LicenseUtils;
|
||||
import org.dspace.content.WorkspaceItem;
|
||||
import org.dspace.core.ConfigurationManager;
|
||||
import org.dspace.core.Context;
|
||||
@@ -223,15 +225,11 @@ public class JSPLicenseStep extends JSPStep
|
||||
HttpServletResponse response, SubmissionInfo subInfo)
|
||||
throws SQLException, ServletException, IOException
|
||||
{
|
||||
// determine collection & get license
|
||||
Collection c = subInfo.getSubmissionItem().getCollection();
|
||||
String license = c.getLicenseCollection();
|
||||
|
||||
if ((license == null) || license.equals(""))
|
||||
{
|
||||
// Fallback to site-wide default
|
||||
license = ConfigurationManager.getLicenseText(I18nUtil.getDefaultLicense(context));
|
||||
}
|
||||
String license = LicenseUtils.getLicenseText(
|
||||
context.getCurrentLocale(), subInfo.getSubmissionItem()
|
||||
.getCollection(),
|
||||
subInfo.getSubmissionItem().getItem(), subInfo
|
||||
.getSubmissionItem().getSubmitter());
|
||||
request.setAttribute("license", license);
|
||||
|
||||
JSPStepManager.showJSP(request, response, subInfo, LICENSE_JSP);
|
||||
|
@@ -125,7 +125,20 @@
|
||||
|
||||
<p><strong>Copyright Text</strong> is simply text that will appear at the bottom of the collection's home page.</p>
|
||||
|
||||
<p><strong>License</strong> is the <em>deposit license</em> (the license that submitters must grant when they submit an item) for this collection. This overrides the site default (which is stored in <em>[dspace]</em>/config/default.license and must be edited by a systems adminstrator). If you leave this field blank, the site default license is used.</p>
|
||||
<p><strong>License</strong> is the <em>deposit license</em> (the license that submitters must grant when they submit an item) for this collection. This overrides the site default (which is stored in <em>[dspace]</em>/config/default.license and must be edited by a systems adminstrator). If you leave this field blank, the site default license is used.
|
||||
There are some substitution variables that can be used to create personalized licenses:</p>
|
||||
<ul>
|
||||
<li><strong>%1$s</strong> will be translated in the "submitter first name"</li>
|
||||
<li><strong>%2$s</strong> will be translated in the "submitter last name"</li>
|
||||
<li><strong>%3$s</strong> will be translated in the "submitter email" </li>
|
||||
<li><strong>%4$s</strong> will be translated in the current date</li>
|
||||
<li><strong>%5$s</strong> will be translated in the collection info</li>
|
||||
<li><strong>%6$s</strong> will be translated in the item info </li>
|
||||
<li><strong>%7$s</strong> will be translated in the eperson info</li>
|
||||
</ul>
|
||||
<p>If you need to embed in the license text the % symbol you need to escape it with a second %, i.e. you need to write %%.
|
||||
It is recommended to use a dummy submission to check the license change: <strong>check the resulting license in the Accept/reject Licence step.</strong>
|
||||
</p>
|
||||
|
||||
<p><strong>Provenance</strong> is a free-text field you can put any provenance information in you feel like. It is not visible to end-users.</p>
|
||||
|
||||
@@ -419,7 +432,19 @@
|
||||
<p>You can use this tool to edit the default license of DSpace</p>
|
||||
<p>The default license is used when no collection specific license is defined.</p>
|
||||
<p>Note that changing the default license has no effect on allready published items.</p>
|
||||
|
||||
<p>Some substitution variables are available to make possible configure a contextual submission license:</p>
|
||||
<ul>
|
||||
<li><strong>%1$s</strong> will be translated in the "submitter first name"</li>
|
||||
<li><strong>%2$s</strong> will be translated in the "submitter last name"</li>
|
||||
<li><strong>%3$s</strong> will be translated in the "submitter email" </li>
|
||||
<li><strong>%4$s</strong> will be translated in the current date</li>
|
||||
<li><strong>%5$s</strong> will be translated in the collection info</li>
|
||||
<li><strong>%6$s</strong> will be translated in the item info </li>
|
||||
<li><strong>%7$s</strong> will be translated in the eperson info</li>
|
||||
</ul>
|
||||
<p>If you need to embed in the license text the % symbol you need to escape it with a second %, i.e. you need to write %%.
|
||||
It is recommended to use a dummy submission to check the license change: <strong>check the resulting license in the Accept/reject Licence step.</strong>
|
||||
</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
@@ -57,6 +57,7 @@ import org.dspace.app.xmlui.wing.element.Division;
|
||||
import org.dspace.app.xmlui.wing.element.List;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.LicenseUtils;
|
||||
import org.dspace.license.CreativeCommons;
|
||||
import org.dspace.core.LogManager;
|
||||
import org.xml.sax.SAXException;
|
||||
@@ -150,7 +151,9 @@ public class LicenseStep extends AbstractSubmissionStep
|
||||
// Get the full text for the actuial licese
|
||||
Collection collection = submission.getCollection();
|
||||
String actionURL = contextPath + "/handle/"+collection.getHandle() + "/submit/" + knot.getId() + ".continue";
|
||||
String licenseText = collection.getLicense();
|
||||
String licenseText = LicenseUtils.getLicenseText(context
|
||||
.getCurrentLocale(), collection, submission.getItem(),
|
||||
submission.getSubmitter());
|
||||
|
||||
Division div = body.addInteractiveDivision("submit-license",actionURL, Division.METHOD_POST,"primary submission");
|
||||
div.setHead(T_submission_head);
|
||||
|
@@ -1838,7 +1838,7 @@
|
||||
<message key="xmlui.dri2xhtml.METS-1.0.community-logo-alt">The community's logo</message>
|
||||
<message key="xmlui.dri2xhtml.METS-1.0.no-logo-alt">No logo</message>
|
||||
<message key="xmlui.dri2xhtml.METS-1.0.news">News</message>
|
||||
<message key="xmlui.dri2xhtml.METS-1.0.copyright">Copyright and License</message>
|
||||
<message key="xmlui.dri2xhtml.METS-1.0.copyright">Copyright</message>
|
||||
|
||||
<!-- Internationalization elements specific to the Qualified Dublin Core metadata handler.
|
||||
DS-METS-1.0-QDC.xsl -->
|
||||
|
@@ -766,11 +766,6 @@
|
||||
<xsl:copy-of select="dim:field[@element='rights'][not(@qualifier)]/node()"/>
|
||||
</p>
|
||||
</xsl:if>
|
||||
<xsl:if test="string-length(dim:field[@element='rights'][@qualifier='license'])>0">
|
||||
<p class="license-text">
|
||||
<xsl:copy-of select="dim:field[@element='rights'][@qualifier='license']/node()"/>
|
||||
</p>
|
||||
</xsl:if>
|
||||
</div>
|
||||
</xsl:if>
|
||||
</xsl:template>
|
||||
|
@@ -116,6 +116,7 @@
|
||||
- [DS-270] Make delegate admin permissions configurable
|
||||
- [DS-436] SWORD Authenticator doesn't support the special groups infrastructure
|
||||
- [DS-415] Create groups via admin UI authorization denied
|
||||
- [DS-217] Hardcoded String in the license bitstream
|
||||
|
||||
(Tim Donohue)
|
||||
- [DS-218] Cannot add/remove email subscriptions from Profile page in XMLUI
|
||||
|
@@ -1167,7 +1167,13 @@ plugin.sequence.org.dspace.plugin.CommunityHomeProcessor = \
|
||||
plugin.sequence.org.dspace.plugin.CollectionHomeProcessor = \
|
||||
org.dspace.app.webui.components.RecentCollectionSubmissions
|
||||
|
||||
|
||||
#### Submission License substitution variables ####
|
||||
# it is possible include contextual information in the submission license using substitution variables
|
||||
# the text substitution is driven by a plugin implementation
|
||||
plugin.named.org.dspace.content.license.LicenseArgumentFormatter = \
|
||||
org.dspace.content.license.SimpleDSpaceObjectLicenseFormatter = collection, \
|
||||
org.dspace.content.license.SimpleDSpaceObjectLicenseFormatter = item, \
|
||||
org.dspace.content.license.SimpleDSpaceObjectLicenseFormatter = eperson
|
||||
|
||||
#### Syndication Feed (RSS) Settings ######
|
||||
|
||||
|
Reference in New Issue
Block a user