* if any errors occurs.
*/
private Response getArtifactInfo(Node node, final String mavenPath, final String gadget, Node shaNode)
throws Exception
{
NodeRepresentation nodeRepresentation = nodeRepresentationService.getNodeRepresentation(node, null);
NodeRepresentation shNodeRepresentation = null;
if (shaNode != null)
shNodeRepresentation = nodeRepresentationService.getNodeRepresentation(shaNode, null);
final PipedOutputStream po = new PipedOutputStream();
final PipedInputStream pi = new PipedInputStream(po);
long lastModified = nodeRepresentation.getLastModified();
long contentLength = nodeRepresentation.getContentLenght();
try
{
if (node.canAddMixin("exo:mavencounter"))
{
node.addMixin("exo:mavencounter");
node.getSession().save();
}
int count = (int)node.getProperty("exo:downloadcounter").getLong();
XMLOutputFactory factory = XMLOutputFactory.newInstance();
factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
XMLStreamWriter xsw = factory.createXMLStreamWriter(po, Constants.DEFAULT_ENCODING);
xsw.writeStartDocument(Constants.DEFAULT_ENCODING, "1.0");
xsw.writeDTD("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "
+ "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
xsw.writeCharacters("\n");
xsw.writeStartElement("html");
xsw.writeDefaultNamespace(XHTML_NS);
xsw.writeStartElement("head");
xsw.writeStartElement("style");
xsw.writeAttribute("type", "text/css");
xsw.writeCharacters("a {text-decoration: none; color: #10409C;}" + "a:hover {text-decoration: underline;}"
+ ".centered { text-align: center; }" + ".underlined { border-bottom : 1px solid #cccccc; }\n");
xsw.writeEndElement(); // style
xsw.writeStartElement("title");
xsw.writeCharacters("Maven2 Artifact Information");
xsw.writeEndElement(); // title
xsw.writeEndElement(); // head
xsw.writeStartElement("body");
xsw.writeStartElement("b");
xsw.writeCharacters("Artifact Information :");
xsw.writeEndElement();
xsw.writeEmptyElement("br");
xsw.writeCharacters("Name: " + node.getName());
xsw.writeEmptyElement("br");
xsw.writeCharacters("Size: " + contentLength);
xsw.writeEmptyElement("br");
xsw.writeCharacters("Last modified: " + new Date(lastModified).toString());
xsw.writeEmptyElement("br");
xsw.writeCharacters("Download: ");
xsw.writeStartElement("a");
xsw.writeAttribute("href", mavenPath.endsWith("/") ? mavenPath.substring(0, mavenPath.length() - 1)
: mavenPath);
xsw.writeCharacters("Link");
xsw.writeEndElement(); // a
if (shNodeRepresentation != null)
{
xsw.writeEmptyElement("br");
xsw.writeCharacters("Checksum: " + getStreamAsString(shNodeRepresentation.getInputStream()));
xsw.writeEmptyElement("br");
}
xsw.writeEmptyElement("br");
xsw.writeCharacters("Downloads count : " + count);