/* Generate a web page that contains links for the appropriate copyrights
Copyright (c) 2003-2014 The Regents of the University of California.
All rights reserved.
Permission is hereby granted, without written agreement and without
license or royalty fees, to use, copy, modify, and distribute this
software and its documentation for any purpose, provided that the above
copyright notice and the following two paragraphs appear in all copies
of this software.
IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
ENHANCEMENTS, OR MODIFICATIONS.
PT_COPYRIGHT_VERSION_2
COPYRIGHTENDKEY
*/
package ptolemy.actor.gui;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import ptolemy.data.ArrayToken;
import ptolemy.data.RecordToken;
import ptolemy.data.StringToken;
import ptolemy.data.expr.Parameter;
import ptolemy.kernel.attributes.VersionAttribute;
import ptolemy.kernel.util.StringAttribute;
import ptolemy.util.FileUtilities;
///////////////////////////////////////////////////////////////////
//// GenerateCopyrights
/**
Generate an HTML file that contains links to the appropriate
copyrights for entities in the configuration.
This class looks for particular classes, and if the class is found
in the classpath, then a corresponding html file is included
in the list of copyrights.
@author Christopher Hylands
@version $Id: GenerateCopyrights.java 70402 2014-10-23 00:52:20Z cxh $
@since Ptolemy II 2.0
@Pt.ProposedRating Red (cxh)
@Pt.AcceptedRating Red (cxh)
*/
public class GenerateCopyrights {
///////////////////////////////////////////////////////////////////
//// public methods ////
/** Generate HTML about the copyrights for classes that might
* be present in the configuration. This method contains
* a list of classes and corresponding copyrights. If
* a class in the list is present, then we generate html
* that contains a link to the copyright. Note that if the
* copyright file need not be present on the local machine,
* we generate a link to the copy on the Ptolemy website.
*
*
If the configuration contains an _applicationName attribute
* then that attributed is used as the name of the application
* in the generated text. If _applicationName is not present,
* then the default name is "Ptolemy II".
*
*
If the configuration contains an _applicationCopyright
* StringAttribute, then the value of that attributed is used
* as the location of the copyright html file. If
* _applicationCopyright is not present, then
* "ptolemy/configs/doc/copyright.htm" is used.
*
*
If the configuration has a parameter called
* _applicationCopyrights that is an array of records where
* each element is a record
*
* {actor="ptolemy.actor.lib.Foo", copyright="foo.htm"}
*
* then we add that actor/copyright pair to the list of potential
* copyrights.
*
* @param configuration The configuration to look for the
* _applicationName and _applicationCopyright attributes in.
* @return A String containing HTML that describes what
* copyrights are used by Entities in the configuration
*/
public static String generateHTML(Configuration configuration) {
// A Map of copyrights, where the key is a URL naming
// the copyright and the value is a List of entities
// that use that as a copyright.
HashMap> copyrightsMap = new HashMap>();
// Add the classnames and copyrights.
// Alphabetical by className.
_addIfPresent(copyrightsMap, "com.cureos.numerics.Cobyla",
"com/cureos/jcobyla-license.htm");
_addIfPresent(copyrightsMap, "com.github.ojdcheck.OpenJavaDocCheck",
"lib/ojdcheck-license.htm");
_addIfPresent(copyrightsMap, "com.sun.jna.Pointer",
"lib/jna-license.htm");
_addIfPresent(copyrightsMap, "com.sleepycat.db.Environment",
"ptdb/lib/db-dbxml-license.htm");
_addIfPresent(copyrightsMap, "diva.gui.ExtensionFileFilter",
"diva/gui/ExtensionFileFilter-license.htm");
_addIfPresent(copyrightsMap, "com.google.protobuf.MessageOrBuilder",
"lib/protobuf-license.htm");
_addIfPresent(copyrightsMap, "g4ltl.SolverUtility",
"lib/g4ltl-license.htm");
_addIfPresent(copyrightsMap, "hla.rti.jlc.RtiFactory",
"lib/jcerti-license.htm");
_addIfPresent(copyrightsMap, "interfaces.util.ChicUI",
"lib/chic-license.htm");
_addIfPresent(copyrightsMap, "io.socket.SocketIO",
"lib/socketio-license.htm");
_addIfPresent(copyrightsMap, "javax.servlet.http.HttpServlet",
"lib/javax.servlet-api-license.htm");
_addIfPresent(copyrightsMap, "jni.GenericJNIActor",
"jni/launcher/launcher-copyright.htm");
_addIfPresent(copyrightsMap, "mescal.domains.mescalPE.kernel.parser",
"mescal/configs/doc/cup-copyright.htm");
_addIfPresent(copyrightsMap,
"net.jimblackler.Utils.YieldAdapterIterator",
"net/jimblackler/Utils/jimblacklerUtils-license.htm");
_addIfPresent(copyrightsMap, "oscP5.OscP5", "lib/oscP5-license.htm");
_addIfPresent(copyrightsMap, "org.apache.oltu.oauth2.common.OAuth",
"lib/org.apache.oltu.oauth2-license.htm");
_addIfPresent(copyrightsMap, "org.eclipse.jetty.server.Server",
"lib/jetty-all-license.htm");
_addIfPresent(copyrightsMap, "org.json.JSONObject",
"org/json/json-license.htm");
_addIfPresent(copyrightsMap, "org.jsoup.parser.Parser",
"lib/jsoup-license.htm");
_addIfPresent(copyrightsMap, "org.mozilla.javascript.Context",
"lib/js-license.htm");
_addIfPresent(copyrightsMap, "org.junit.runner.JUnitCore",
"lib/junit-license.htm");
_addIfPresent(copyrightsMap, "org.netbeans.api.visual.widget.Scene",
"lib/netbeans-visual-library-license.htm");
_addIfPresent(copyrightsMap, "org.ptolemy.fmi.driver.OutputRow",
"org/ptolemy/fmi/driver/fmusdk-license.htm");
_addIfPresent(copyrightsMap,
"org.satlive.jsat.objects.ExternalLiteral",
"mescal/configs/doc/jsat-copyright.htm");
// Vertx
_addIfPresent(copyrightsMap,
"com.fasterxml.jackson.core.base.GeneratorBase",
"lib/jackson-2.2.2-license.htm");
_addIfPresent(copyrightsMap,
"io.netty.handler.traffic.ChannelTrafficShapingHandler",
"lib/netty-all-4.0.20.Final-license.htm");
_addIfPresent(copyrightsMap,
"org.vertx.java.spi.cluster.impl.hazelcast.HazelcastAsyncMap",
"lib/hazelcast-3.2.3-license.htm");
_addIfPresent(copyrightsMap, "org.vertx.java.core.Vertx",
"lib/vertx-2.1.2-license.htm");
_addIfPresent(copyrightsMap, "ptolemy.actor.gui.BrowserLauncher",
"ptolemy/actor/gui/BrowserLauncher-license.htm");
_addIfPresent(copyrightsMap, "ptolemy.actor.gui.run.PtolemyFormEditor",
"com/jgoodies/jgoodies-copyright.htm");
_addIfPresent(copyrightsMap, "ptolemy.actor.gui.run.RunLayoutFrame",
"org/mlc/mlc-copyright.htm");
_addIfPresent(copyrightsMap, "ptolemy.actor.lib.colt.ColtRandomSource",
"ptolemy/actor/lib/colt/colt-copyright.htm");
_addIfPresent(copyrightsMap,
"ptolemy.actor.lib.database.DatabaseManager",
"com.mysql.jdbc.Driver",
"ptolemy/actor/lib/database/mysql-copyright.htm");
_addIfPresent(copyrightsMap, "ptolemy.actor.lib.excel.Excel",
"ptolemy/actor/lib/excel/jxl-copyright.htm");
_addIfPresent(copyrightsMap,
"ptolemy.actor.lib.fmi.fmipp.FMUModelExchange",
"ptolemy/actor/lib/fmi/fmipp/fmipp-license.htm");
_addIfPresent(copyrightsMap, "ptolemy.actor.lib.io.comm.SerialComm",
"ptolemy/actor/lib/io/comm/rxtx-copyright.htm");
_addIfPresent(copyrightsMap, "ptolemy.actor.lib.jai.JAIImageToken",
"ptolemy/actor/lib/jai/jai-copyright.htm");
_addIfPresent(copyrightsMap, "ptolemy.actor.lib.jmf.JMFImageToken",
"ptolemy/actor/lib/jmf/jmf-copyright.htm");
_addIfPresent(copyrightsMap, "ptolemy.actor.lib.joystick.Joystick",
"ptolemy/actor/lib/joystick/joystick-copyright.htm");
_addIfPresent(copyrightsMap,
"ptolemy.actor.lib.logic.fuzzy.FuzzyLogic",
"ptolemy/actor/lib/logic/fuzzy/FuzzyEngine-copyright.htm");
_addIfPresent(copyrightsMap, "javax.mail.Address",
"lib/javamail-license.htm");
_addIfPresent(copyrightsMap, "ptolemy.actor.lib.opencv.OpenCVReader",
"ptolemy/actor/lib/opencv/opencv-copyright.htm");
_addIfPresent(copyrightsMap,
"ptolemy.actor.lib.opencv.javacv.CameraReader",
"ptolemy/actor/lib/opencv/javacv/javacv-copyright.htm");
_addIfPresent(copyrightsMap, "ptolemy.actor.lib.python.PythonScript",
"ptolemy/actor/lib/python/jython-license.htm");
_addIfPresent(copyrightsMap, "ptolemy.actor.lib.x10.X10Interface",
"ptolemy/actor/lib/x10/x10-copyright.htm");
_addIfPresent(copyrightsMap, "ptolemy.actor.ptalon.PtalonActor",
"ptolemy/actor/ptalon/ptalon-copyright.html");
_addIfPresent(copyrightsMap,
"ptolemy.backtrack.eclipse.ast.TypeAnalyzer",
"ptolemy/backtrack/eclipse/ast/eclipse-copyright.htm");
_addIfPresent(copyrightsMap, "ptolemy.backtrack.util.ClassFileLoader",
"ptolemy/backtrack/util/gcj-copyright.html");
_addIfPresent(copyrightsMap,
"ptolemy.caltrop.actors.AbstractCalInterpreter",
"ptolemy/caltrop/cup-copyright.htm");
_addIfPresent(copyrightsMap, "ptolemy.caltrop.actors.CalInterpreter",
"ptolemy/caltrop/saxon-copyright.htm");
_addIfPresent(copyrightsMap, "ptolemy.copernicus.kernel.KernelMain",
"ptolemy/copernicus/kernel/soot-copyright.html");
_addIfPresent(copyrightsMap, "ptolemy.data.ontologies.Concept",
"ptolemy/data/ontologies/doc/udunits2Database/udunits-license.htm");
_addIfPresent(copyrightsMap, "ptolemy.domains.gr.kernel.GRActor",
"ptolemy/domains/gr/lib/java3d-copyright.htm");
_addIfPresent(copyrightsMap,
"ptolemy.domains.gr.lib.quicktime.MovieViewScreen2D",
"ptolemy/domains/gr/lib/quicktime/quicktime-copyright.htm");
_addIfPresent(copyrightsMap,
"ptolemy.domains.gr.lib.vr.GRTexture2D.java",
"ptolemy/domains/gr/lib/vr/vr-copyright.htm");
_addIfPresent(copyrightsMap, "ptolemy.domains.gro.kernel.GRODirector",
"ptolemy/domains/gro/JOGL-copyright.htm");
_addIfPresent(copyrightsMap,
"ptolemy.domains.psdf.kernel.PSDFScheduler",
"ptolemy/domains/psdf/mapss-copyright.htm");
_addIfPresent(copyrightsMap,
"ptolemy.domains.ptinyos.util.nc2moml.MoMLLib",
"ptolemy/domains/ptinyos/lib/jdom-copyright.htm");
_addIfPresent(copyrightsMap, "ptolemy.gui.ExtensionFilenameFilter",
"ptolemy/gui/ExtensionFilenameFilter-license.htm");
_addIfPresent(copyrightsMap,
"ptolemy.homer.widgets.ResizableImageWidget",
"ptolemy/homer/widgets/ResizableImageWidget-license.htm");
_addIfPresent(copyrightsMap, "ptolemy.matlab.Expression",
"ptolemy/matlab/matlab-copyright.htm");
_addIfPresent(copyrightsMap, "ptolemy.media.Audio",
"ptolemy/media/Audio-license.htm");
_addIfPresent(copyrightsMap, "ptolemy.util.test.junit.TclTests",
"lib/JUnitParams-license.htm");
_addIfPresent(copyrightsMap,
"ptolemy.vergil.basic.export.html.ExportHTMLAction",
"ptolemy/vergil/basic/export/html/javascript/javascript-license.htm");
_addIfPresent(copyrightsMap,
"ptolemy.vergil.basic.export.html.ExportToWeb",
"ptolemy/vergil/basic/export/html/javascript/fancybox/fancybox-license.htm");
_addIfPresent(copyrightsMap,
"ptolemy.vergil.basic.export.itextpdf.ExportPDFAction",
"ptolemy/vergil/basic/export/itextpdf/itextpdf-copyright.htm");
_addIfPresent(copyrightsMap,
"ptolemy.vergil.basic.layout.kieler.KielerLayout",
"lib/guava-license.htm");
_addIfPresent(copyrightsMap,
"ptolemy.vergil.basic.layout.kieler.KielerGraphUtil",
"ptolemy/vergil/basic/layout/kieler/kieler-copyright.htm");
_addIfPresent(copyrightsMap, "ptolemy.vergil.pdfrenderer.PDFAttribute",
"ptolemy/vergil/pdfrenderer/PDFRenderer-copyright.htm");
_addIfPresent(copyrightsMap, "tcl.lang.Shell", "lib/ptjacl-license.htm");
_addIfPresent(copyrightsMap, "thales.vergil.SingleWindowApplication",
"thales/thalesSingleWindow-license.htm");
_addIfPresent(copyrightsMap, "org.jivesoftware.smack.XMPPConnection",
"lib/smack-license.htm");
// Check for the _applicationCopyrights parameter
try {
Parameter applicationCopyrights = (Parameter) configuration
.getAttribute("_applicationCopyrights", Parameter.class);
if (applicationCopyrights != null) {
ArrayToken copyrightTokens = (ArrayToken) applicationCopyrights
.getToken();
for (int i = 0; i < copyrightTokens.length(); i++) {
StringToken actorToken = (StringToken) ((RecordToken) copyrightTokens
.getElement(i)).get("actor");
StringToken copyrightToken = (StringToken) ((RecordToken) copyrightTokens
.getElement(i)).get("copyright");
_addIfPresent(copyrightsMap, actorToken.stringValue(),
copyrightToken.stringValue());
}
}
} catch (Exception ex) {
// This application has no _applicationCopyrights
}
// We also create a file that contains all the copyrights.
StringBuffer masterCopyrightBuffer = new StringBuffer();
StringBuffer masterCopyrightTable = new StringBuffer();
// Read in the header
String copyrightStartFileName = "$CLASSPATH/ptolemy/actor/gui/masterCopyrightStart.htm.in";
try {
// Probably wrong to read it as bytes and convert to a
// string, but we have a convenient method, so we use it.
masterCopyrightBuffer.append(new String(FileUtilities
.binaryReadURLToByteArray(FileUtilities.nameToURL(
copyrightStartFileName, null, null))));
} catch (IOException ex) {
// Print only a message, we want to print the copyrights
System.err.println("Could not read " + copyrightStartFileName
+ ": " + ex);
}
StringBuffer htmlBuffer = new StringBuffer(
generatePrimaryCopyrightHTML(configuration));
// Sort by the copyright file name, which should start with the package name.
FileNameComparator fileNameComparator = new FileNameComparator();
TreeMap> sortedCopyrightsMap = new TreeMap>(
fileNameComparator);
sortedCopyrightsMap.putAll(copyrightsMap);
if (copyrightsMap.size() != sortedCopyrightsMap.size()) {
// Print only a message, we want to print the copyrights.
System.err
.println("GenerateCopyrights: the size of the unsorted copyright table "
+ "and the sorted copyright table are not the same? Perhaps there are two "
+ "or more copyrights with the same file name? (foo/copyright.htm and "
+ "bar/copyright.htm will not work.)");
}
Iterator copyrights = sortedCopyrightsMap.entrySet().iterator();
if (copyrights.hasNext()) {
// DSP configuration might not include other actors.
htmlBuffer
.append("Below we list features and the "
+ "corresponding copyright "
+ " of the package that is used. If a feature is not "
+ "listed below, then the "
+ _getApplicationName(configuration)
+ " copyright is the "
+ "only copyright."
+ "
\n"
+ " \n"
+ " Copyright of package used by the feature | \n"
+ " Feature | \n" + "
\n");
while (copyrights.hasNext()) {
Map.Entry entry = (Map.Entry) copyrights.next();
String copyrightURL = (String) entry.getKey();
Set entitiesSet = (Set) entry.getValue();
StringBuffer entityBuffer = new StringBuffer();
Iterator entities = entitiesSet.iterator();
while (entities.hasNext()) {
if (entityBuffer.length() > 0) {
entityBuffer.append(", ");
}
String entityClassName = (String) entities.next();
// If we have javadoc, link to it.
// Assuming that entityClassName contains a dot separated
// classpath here.
String docName = "doc.codeDoc." + entityClassName;
String codeDoc = _findURL(docName.replace('.', '/')
+ ".html");
entityBuffer.append(""
+ entityClassName + "");
}
//System.out.println("GenerateCopyrights: url: " + copyrightURL);
String foundCopyright = _findURL(copyrightURL);
if (copyrightURL.contains("backtrack")
&& !copyrightURL.contains("http")) {
// If the backtrack copyright is not local, then don't print it.
continue;
}
htmlBuffer.append("\n" + " "
+ _canonicalizeURLToPTII(foundCopyright)
+ " | \n" + " " + entityBuffer
+ " | \n" + "
\n");
try {
String copyright = new String(
FileUtilities.binaryReadURLToByteArray(new URL(
foundCopyright)));
// Append the text between the body tags.
// Look for or
int startIndex = 0;
if ((startIndex = copyright.indexOf("")) == -1) {
if ((startIndex = copyright.indexOf("")) != -1) {
startIndex += "".length();
} else {
// Print only a message, we want to print the copyrights.
System.out
.println("Could not find body or head in "
+ foundCopyright + " "
+ copyright.substring(0, 200));
startIndex = 0;
}
} else {
startIndex += "".length();
}
// Look for or