Author: rdonkin
Date: Sun Aug 5 20:25:49 2012
New Revision: 1369670
URL: http://svn.apache.org/viewvc?rev=1369670&view=rev
Log:
Start adding support for an additional primary copyright notice, needed for
some licenses.
Modified:
creadur/whisker/trunk/apache-whisker-model/src/main/java/org/apache/creadur/whisker/model/Descriptor.java
creadur/whisker/trunk/apache-whisker-xml/src/main/java/org/apache/creadur/whisker/fromxml/JDomBuilder.java
creadur/whisker/trunk/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderWorkTest.java
Modified:
creadur/whisker/trunk/apache-whisker-model/src/main/java/org/apache/creadur/whisker/model/Descriptor.java
URL:
http://svn.apache.org/viewvc/creadur/whisker/trunk/apache-whisker-model/src/main/java/org/apache/creadur/whisker/model/Descriptor.java?rev=1369670&r1=1369669&r2=1369670&view=diff
==============================================================================
---
creadur/whisker/trunk/apache-whisker-model/src/main/java/org/apache/creadur/whisker/model/Descriptor.java
(original)
+++
creadur/whisker/trunk/apache-whisker-model/src/main/java/org/apache/creadur/whisker/model/Descriptor.java
Sun Aug 5 20:25:49 2012
@@ -29,6 +29,8 @@ public class Descriptor {
/** Principle license for main work. */
private final License primaryLicense;
+ /** Optional additional primary copyright notice*/
+ private final String primaryCopyrightNotice;
/** Individual or group with main responsible for main work. */
private final String primaryOrganisationId;
/** A NOTICE for the main work, for inclusion alongside the LICENSE. */
@@ -42,7 +44,7 @@ public class Descriptor {
/**
* Constructs a description of the expected licensing qualities of a
- * distribution.
+ * distribution, with no additional primary copyright notice.
*
* @param primaryLicense
* not null
@@ -60,13 +62,55 @@ public class Descriptor {
* not null, possibly empty
*/
public Descriptor(final License primaryLicense,
- final String primaryOrganisationId, final String primaryNotice,
+ final String primaryOrganisationId,
+ final String primaryNotice,
+ final Map<String, License> licenses,
+ final Map<String, String> notices,
+ final Map<String, Organisation> organisations,
+ final Collection<WithinDirectory> contents) {
+ this( primaryLicense,
+ null,
+ primaryOrganisationId,
+ primaryNotice,
+ licenses,
+ notices,
+ organisations,
+ contents);
+ }
+
+ /**
+ * Constructs a description of the expected licensing qualities of a
+ * distribution, with a primary additional copyright notice.
+ *
+ * @param primaryLicense
+ * not null
+ * @param primaryCopyrightNotice
+ * optional primary copyright notice, possibly null
+ *
+ * @param primaryOrganisationId
+ * not null
+ * @param primaryNotice
+ * possibly null
+ * @param licenses
+ * not null, possibly empty
+ * @param notices
+ * not null, possibly empty
+ * @param organisations
+ * not null, possibly empty
+ * @param contents
+ * not null, possibly empty
+ */
+ public Descriptor(final License primaryLicense,
+ final String primaryCopyrightNotice,
+ final String primaryOrganisationId,
+ final String primaryNotice,
final Map<String, License> licenses,
final Map<String, String> notices,
final Map<String, Organisation> organisations,
final Collection<WithinDirectory> contents) {
super();
this.primaryLicense = primaryLicense;
+ this.primaryCopyrightNotice = primaryCopyrightNotice;
this.primaryOrganisationId = primaryOrganisationId;
this.primaryNotice = primaryNotice;
this.licenses = licenses;
@@ -75,6 +119,16 @@ public class Descriptor {
}
/**
+ * Gets an additional copyright notice needed
+ * for some primary licenses.
+ * @return optional primary copyright notice,
+ * possibly null
+ */
+ public String getPrimaryCopyrightNotice() {
+ return primaryCopyrightNotice;
+ }
+
+ /**
* Gets the principle NOTICE for the main work.
*
* @return the primaryNotice
Modified:
creadur/whisker/trunk/apache-whisker-xml/src/main/java/org/apache/creadur/whisker/fromxml/JDomBuilder.java
URL:
http://svn.apache.org/viewvc/creadur/whisker/trunk/apache-whisker-xml/src/main/java/org/apache/creadur/whisker/fromxml/JDomBuilder.java?rev=1369670&r1=1369669&r2=1369670&view=diff
==============================================================================
---
creadur/whisker/trunk/apache-whisker-xml/src/main/java/org/apache/creadur/whisker/fromxml/JDomBuilder.java
(original)
+++
creadur/whisker/trunk/apache-whisker-xml/src/main/java/org/apache/creadur/whisker/fromxml/JDomBuilder.java
Sun Aug 5 20:25:49 2012
@@ -49,6 +49,7 @@ import org.jdom.input.SAXBuilder;
*/
public class JDomBuilder {
+ private static final String COPYRIGHT_NOTICE_NAME = "copyright-notice";
/**
*
*/
@@ -240,7 +241,7 @@ public class JDomBuilder {
*/
private String copyrightNotice(final Element element) {
final String result;
- final Element copyrightNoticeElement =
element.getChild("copyright-notice");
+ final Element copyrightNoticeElement =
element.getChild(COPYRIGHT_NOTICE_NAME);
if (copyrightNoticeElement == null) {
result = null;
} else {
@@ -361,7 +362,7 @@ public class JDomBuilder {
*/
public License primaryLicense(Document document,
Map<String, License> licenses) {
- final String idAttributeValue =
document.getRootElement().getChild(PRIMARY_LICENSE_NAME).getAttributeValue("id");
+ final String idAttributeValue =
getPrimaryLicenseElement(document).getAttributeValue("id");
final License results = licenses.get(idAttributeValue);
if (results == null) {
throw new MissingIDException(LICENSE_ELEMENT_NAME,
PRIMARY_LICENSE_NAME, idAttributeValue);
@@ -370,6 +371,34 @@ public class JDomBuilder {
}
/**
+ * Gets the element representing the primary license.
+ * @param document not null
+ * @return not null
+ */
+ private Element getPrimaryLicenseElement(final Document document) {
+ return document.getRootElement().getChild(PRIMARY_LICENSE_NAME);
+ }
+
+ /**
+ * Gets the additional primary copyright notice
+ * from the document.
+ * @param document not null
+ * @return optional primary copyright notice, possibly null
+ */
+ public String primaryCopyrightNotice(final Document document) {
+ final String result;
+ final Element copyrightElement =
+
getPrimaryLicenseElement(document).getChild(COPYRIGHT_NOTICE_NAME);
+ if (copyrightElement == null) {
+ result = null;
+ } else {
+ result = copyrightElement.getTextTrim();
+ }
+ return result;
+ }
+
+
+ /**
* Collects notices in the given documents.
* @param document, not null
* @return notices indexed by id, immutable, not null, possibly empty
Modified:
creadur/whisker/trunk/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderWorkTest.java
URL:
http://svn.apache.org/viewvc/creadur/whisker/trunk/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderWorkTest.java?rev=1369670&r1=1369669&r2=1369670&view=diff
==============================================================================
---
creadur/whisker/trunk/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderWorkTest.java
(original)
+++
creadur/whisker/trunk/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderWorkTest.java
Sun Aug 5 20:25:49 2012
@@ -228,6 +228,23 @@ public class JDomBuilderWorkTest extends
assertNotNull("Builder should find primary license", result);
assertEquals("Builder should find primary licenser", expected, result);
}
+
+ public void testNoPrimaryCopyright() throws Exception {
+ final String primaryCopyrightNotice =
subject.primaryCopyrightNotice(new Document().setRootElement(new
Element("manifest").
+ addContent(new Element("primary-license").setAttribute("id",
"The primary ID"))));
+ assertNull("Builder should only set primary copyright when present",
primaryCopyrightNotice);
+ }
+
+ public void testPrimaryCopyright() throws Exception {
+ final String copyrightNoticeSet = "Some Copyright Claim";
+ final String result = subject.primaryCopyrightNotice(new
Document().setRootElement(new Element("manifest").
+ addContent(
+ new Element("primary-license").setAttribute("id", "The
primary ID")
+ .addContent(
+ new
Element("copyright-notice").addContent(copyrightNoticeSet)))));
+ assertEquals("Builder should set primary copyright notice", result,
copyrightNoticeSet);
+ }
+
public void testThrowsMissingIDExceptionWhenPrimaryLicenseMissing() throws
Exception {
final String id = "The primary ID";