incubator-depot-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aj...@apache.org
Subject svn commit: rev 10595 - in incubator/depot/trunk/version/src: java/org/apache/depot/version/specification/formatting/format java/org/apache/depot/version/taglib resources/jsp
Date Tue, 11 May 2004 22:34:29 GMT
Author: ajack
Date: Tue May 11 15:34:27 2004
New Revision: 10595

Added:
   incubator/depot/trunk/version/src/java/org/apache/depot/version/taglib/
   incubator/depot/trunk/version/src/java/org/apache/depot/version/taglib/HtmlContent.java
   incubator/depot/trunk/version/src/java/org/apache/depot/version/taglib/VersionEnvironmentTag.java
   incubator/depot/trunk/version/src/java/org/apache/depot/version/taglib/VersionTag.java
   incubator/depot/trunk/version/src/resources/jsp/
   incubator/depot/trunk/version/src/resources/jsp/depot-version.tld
   incubator/depot/trunk/version/src/resources/jsp/version.jsp
Modified:
   incubator/depot/trunk/version/src/java/org/apache/depot/version/specification/formatting/format/VersionFormatImpl.java
Log:
Some simple taglibs for accessing version information.


Modified: incubator/depot/trunk/version/src/java/org/apache/depot/version/specification/formatting/format/VersionFormatImpl.java
==============================================================================
--- incubator/depot/trunk/version/src/java/org/apache/depot/version/specification/formatting/format/VersionFormatImpl.java
(original)
+++ incubator/depot/trunk/version/src/java/org/apache/depot/version/specification/formatting/format/VersionFormatImpl.java
Tue May 11 15:34:27 2004
@@ -160,7 +160,6 @@
 			out.println("Description:" + getVersionFormatDescription());
 
 			//:TODO: More?
-
 		}
 	}
 	/* (non-Javadoc)

Added: incubator/depot/trunk/version/src/java/org/apache/depot/version/taglib/HtmlContent.java
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/version/src/java/org/apache/depot/version/taglib/HtmlContent.java
Tue May 11 15:34:27 2004
@@ -0,0 +1,111 @@
+/*
+ * Copyright  2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.depot.version.taglib;
+
+
+
+/**
+ * @author ajack
+ */
+public class HtmlContent {
+	private StringBuffer m_buffer = null;
+
+	public HtmlContent() {
+		m_buffer = new StringBuffer();
+	}
+
+	public HtmlContent(StringBuffer buffer) {
+		m_buffer = buffer;
+	}
+
+	protected void generateSeparator() {
+		m_buffer.append("<HR/>\n");
+	}
+	
+	protected void generateBreak() {
+		m_buffer.append("<BR/>\n");
+	}
+
+	protected void generateTitle(String title) {
+		generateSeparator();
+		generateRawHtml("<H3>");
+		generateHtml(title);
+		generateRawHtml("</H3>");
+	}
+	
+	protected void generateLine(String line) {
+		generateHtml(line);
+		generateBreak();
+	}
+
+	protected void startDefinitions() {
+
+		m_buffer.append("<DL>");
+	}
+	
+	protected void stopDefinitions() {
+
+		m_buffer.append("</DL>");
+	}
+	
+	protected void generateDefinition(String term, String definition) {
+
+		m_buffer.append("<DT>");
+		m_buffer.append(term);
+		m_buffer.append("</DT><DD>");
+		m_buffer.append(definition);
+		m_buffer.append("</DD>\n");
+	}
+
+	protected void generateDefinition(String single) {
+
+		m_buffer.append("<DD>");
+		m_buffer.append(single);
+		m_buffer.append("</DD>\n");
+	}
+
+	protected void generateHtml(String html) {
+		//:TODO: Escape
+		m_buffer.append(html);
+	}
+
+	protected void generateRawHtml(String raw) {
+		m_buffer.append(raw);
+	}
+
+
+	public void generateError(String errorMsg)
+	{
+		generateError(errorMsg, null);
+	}
+
+	public void generateError(String errorMsg, Throwable t)
+	{
+		generateRawHtml("<EM>");
+		generateHtml(errorMsg);
+		generateRawHtml("<EM>");
+		generateBreak();
+		
+		if ( null != t) {
+			//:TODO: Stack trace
+		}
+	}
+	
+	public String toString() {
+		return m_buffer.toString();
+	}
+}

Added: incubator/depot/trunk/version/src/java/org/apache/depot/version/taglib/VersionEnvironmentTag.java
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/version/src/java/org/apache/depot/version/taglib/VersionEnvironmentTag.java
Tue May 11 15:34:27 2004
@@ -0,0 +1,257 @@
+/*
+ * Copyright  2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.depot.version.taglib;
+
+import java.io.IOException;
+import java.util.Iterator;
+
+import javax.servlet.jsp.tagext.Tag;
+import javax.servlet.jsp.tagext.TagSupport;
+
+import org.apache.depot.common.log.Logger;
+import org.apache.depot.common.util.classpath.PathContext;
+import org.apache.depot.common.util.classpath.PathPart;
+import org.apache.depot.common.util.classpath.PathSet;
+import org.apache.depot.common.util.debug.DebugUtils;
+import org.apache.depot.version.VersionException;
+import org.apache.depot.version.VersionMarker;
+import org.apache.depot.version.VersionRuntime;
+import org.apache.depot.version.constraint.ConstraintSet;
+import org.apache.depot.version.constraint.IContextConstraint;
+import org.apache.depot.version.context.ConstraintRegistry;
+import org.apache.depot.version.context.ExtensionRegistry;
+import org.apache.depot.version.context.VersionEnvironment;
+import org.apache.depot.version.context.VersionInformation;
+import org.apache.depot.version.context.VersionRegistry;
+import org.apache.depot.version.discovery.loading.VersionLoadContext;
+import org.apache.depot.version.extension.VirtualMachineExtension;
+import org.apache.depot.version.extension.VirtualMachineExtensionInformation;
+import org.apache.depot.version.util.IdentifierHelper;
+
+/**
+ * @author ajack
+ */
+public class VersionEnvironmentTag extends TagSupport {
+	private static boolean l_initialized = false;
+
+	private static VersionRuntime l_runtime = null;
+	private boolean m_annotated = false;
+
+	public VersionEnvironmentTag() {
+		if (!l_initialized)
+			initialize();
+	}
+
+	private synchronized void initialize() {
+		if (l_initialized)
+			return;
+
+		l_runtime = VersionRuntime.getRuntime();
+
+		l_initialized = true;
+	}
+
+	public int doStartTag() {
+
+		if (null == l_runtime) {
+			// Bad initialization
+			return Tag.SKIP_BODY;
+		}
+
+		try {
+			HtmlContent versionEnvTag = new HtmlContent();
+
+			try {
+				VersionEnvironment env = l_runtime.getEnvironment();
+
+				generateHtml(versionEnvTag, env);
+
+			} catch (VersionException ve) {
+				Logger.getLogger().error("VersionEnvironmentTag:error", ve);				
+				versionEnvTag.generateError("VersionEnvironmentTag:Failed to get environment", ve);
+			}
+
+			// Output the HTML...
+			pageContext.getOut().print(versionEnvTag.toString());
+		} catch (IOException ioe) {
+			Logger.getLogger().error("VersionEnvironmentTag error", ioe);
+		}
+
+		return Tag.SKIP_BODY;
+	}
+
+	private void generateHtml(HtmlContent htmlBuf, VersionEnvironment env) {
+
+		VersionMarker jvm = env.getJvmVersion();
+		htmlBuf.generateLine(jvm.toString());
+		VersionMarker jvmSpec = env.getJvmSpecificationVersion();
+		htmlBuf.generateLine(jvmSpec.toString());
+
+		generateHtml(htmlBuf, env.getPathContext());
+		generateHtml(htmlBuf, env.getExtensions());
+		generateHtml(htmlBuf, env.getVersions());
+		generateHtml(htmlBuf, env.getConstraints());
+	}
+
+	private void generateHtml(HtmlContent htmlBuf, PathContext pathContext) {
+		generateHtmlClassloader(htmlBuf, 0, pathContext.getClassLoader());
+		generateHtmlPathSet(htmlBuf, pathContext.getPathSet());
+	}
+
+	public void generateHtmlClassloader(HtmlContent htmlBuf, int depth,
+			ClassLoader classloader) {
+
+		String indent = DebugUtils.getIndent(depth);
+
+		HtmlContent out = new HtmlContent();
+
+		out.generateLine(indent);
+		out.generateLine(classloader.getClass().getName());
+		out.generateLine(" : ");
+		out.generateHtml(classloader.toString());
+
+		htmlBuf.generateLine("Classloader @ Depth (" + depth + ") :"
+				+ out.toString());
+
+		if (null != classloader.getParent()) {
+			generateHtmlClassloader(htmlBuf, depth + 1, classloader.getParent());
+		}
+	}
+
+	private void generateHtmlPathSet(HtmlContent htmlBuf, PathSet pathSet) {
+		htmlBuf.generateHtml("PathSet: " + pathSet.getName());
+
+		for (Iterator i = pathSet.iterator(); i.hasNext();) {
+			PathPart part = (PathPart) i.next();
+
+			htmlBuf.generateLine(" - " + part);
+		}
+	}
+
+	private void generateHtml(HtmlContent htmlBuf, VersionRegistry versions) {
+
+		if (versions.hasEntries()) {
+
+			htmlBuf.generateTitle("Versions:");
+
+			htmlBuf.startDefinitions();
+
+			for (Iterator i = versions.iterator(); i.hasNext();) {
+				Object entry = (Object) i.next();
+				if (entry instanceof VersionInformation) {
+					VersionInformation info = (VersionInformation) entry;
+					VersionLoadContext context = info.getLoadContext();
+					VersionMarker versionMarker = context.getVersionMarker();
+
+					String id = versionMarker.getId();
+					String version = versionMarker.getVersion().toString();
+
+					//
+					// Perhaps allow these to show, if verbose.
+					//
+					if (IdentifierHelper.isPartOfJdk(id))
+						continue;
+
+					htmlBuf.generateDefinition(id, version);
+				} else
+					htmlBuf.generateDefinition(entry.getClass().getName(),
+							entry.toString());
+			}
+
+			htmlBuf.stopDefinitions();
+
+		} else
+			htmlBuf.generateLine("No versions found in registry");
+	}
+
+	private void generateHtml(HtmlContent htmlBuf, ExtensionRegistry extensions) {
+
+		if (extensions.hasEntries()) {
+
+			htmlBuf.generateTitle("Virtual Machine Extensions:");
+
+			htmlBuf.startDefinitions();
+			
+			for (Iterator i = extensions.iterator(); i.hasNext();) {
+				Object entry = (Object) i.next();
+				if (entry instanceof VirtualMachineExtensionInformation) {
+					VirtualMachineExtensionInformation extensionInfo = (VirtualMachineExtensionInformation)
entry;
+					VirtualMachineExtension extension = extensionInfo.getExtensionLoadContext().getExtension();
+
+					//
+					// Perhaps allow these to show, if verbose.
+					//
+					if (IdentifierHelper.isPartOfJdk(extension.getName()))
+						continue;
+
+					htmlBuf.generateDefinition(extension.getName() + " : " + extension.getSpecificationTitle(),
+							extension.getSpecificationVersion().toString());
+
+					if (m_annotated) {
+						htmlBuf.generateDefinition(extension.getImplementationTitle(),
+								extension.getImplementationVersion().toString());
+
+						if (null != extension.getComment())
+							htmlBuf.generateDefinition("Comment:",
+									extension.getComment());
+					}
+				} else {
+					String id = entry.getClass().getName();
+					//
+					// Perhaps allow these to show, if verbose.
+					//
+					if (IdentifierHelper.isPartOfJdk(id))
+						continue;
+
+					htmlBuf.generateLine(id + ":" + entry.toString());
+				}
+			}
+			htmlBuf.stopDefinitions();
+		} else
+			htmlBuf.generateLine("No versions found in registry");
+	}
+
+	private void generateHtml(HtmlContent htmlBuf,
+			ConstraintRegistry constraints) {
+
+		if (constraints.hasEntries()) {
+
+			htmlBuf.generateTitle("Constraints:");
+
+			for (Iterator i = constraints.iterator(); i.hasNext();) {
+				generateHtml(htmlBuf, (ConstraintSet) i.next());
+			}
+		} else
+			htmlBuf.generateLine("No constraints in registry");
+	}
+
+	private void generateHtml(HtmlContent htmlBuf, ConstraintSet set) {
+
+		if (set.hasEntries()) {
+			htmlBuf.generateLine("ConstraintSet: " + set.getName());
+
+			htmlBuf.startDefinitions();
+			for (Iterator i = set.iterator(); i.hasNext();) {
+				IContextConstraint constraint = (IContextConstraint) i.next();
+				htmlBuf.generateDefinition(constraint.toString());
+			}
+			htmlBuf.stopDefinitions();
+		} else
+			htmlBuf.generateLine("No constraints in set");
+	}
+
+}

Added: incubator/depot/trunk/version/src/java/org/apache/depot/version/taglib/VersionTag.java
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/version/src/java/org/apache/depot/version/taglib/VersionTag.java
Tue May 11 15:34:27 2004
@@ -0,0 +1,95 @@
+/*
+ * Copyright  2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.depot.version.taglib;
+
+import java.io.IOException;
+
+import javax.servlet.jsp.tagext.Tag;
+import javax.servlet.jsp.tagext.TagSupport;
+
+import org.apache.depot.common.log.Logger;
+import org.apache.depot.version.VersionException;
+import org.apache.depot.version.VersionRuntime;
+import org.apache.depot.version.context.VersionInformation;
+
+/**
+ * @author ajack
+ */
+public class VersionTag extends TagSupport {
+	private static boolean l_initialized = false;
+
+	private static VersionRuntime l_runtime = null;
+
+	public VersionTag() {
+		if (!l_initialized)
+			initialize();
+	}
+
+	private synchronized void initialize() {
+		if (l_initialized)
+			return;
+
+		l_runtime = VersionRuntime.getRuntime();
+
+		l_initialized = true;
+	}
+
+	public int doStartTag() {
+
+		if (null == l_runtime) {
+			// Bad initialization
+			return Tag.SKIP_BODY;
+		}
+
+		try {
+			HtmlContent versionTag = new HtmlContent();
+
+			// The version we want...
+			Object id = getValue("id");
+
+			if (null != id)
+				try {
+					VersionInformation info = l_runtime.resolve(id.toString());
+
+					if (null != info) {
+						// Put this in a comment
+						versionTag.generateRawHtml("<!-- ");
+						versionTag.generateHtml(info.toString());
+						versionTag.generateRawHtml(" -->");
+					} else {
+						// Put this in a comment
+						versionTag.generateRawHtml("<!-- No Version found for [");
+						versionTag.generateHtml(id.toString());
+						versionTag.generateRawHtml("] -->");
+					}
+				} catch (VersionException ve) {
+					Logger.getLogger().error("VersionTag  error", ve);
+				}
+			else {
+				// Put this in a comment
+				versionTag.generateRawHtml("<!-- No Version id supplied to tag -->");
+			}
+
+			// Output the HTML...
+			pageContext.getOut().print(versionTag.toString());
+		} catch (IOException ioe) {
+			Logger.getLogger().error("VersionTag error", ioe);
+		}
+
+		return Tag.SKIP_BODY;
+	}
+}

Added: incubator/depot/trunk/version/src/resources/jsp/depot-version.tld
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/version/src/resources/jsp/depot-version.tld	Tue May 11 15:34:27
2004
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?> 
+  <!DOCTYPE taglib 
+  PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
+ "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd"> 
+
+<taglib>
+	<tlibversion>1.0</tlibversion> 
+  	<jspversion>1.1</jspversion> 
+  	<shortname>VersionTagLibrary</shortname> 
+
+  	<info>
+		Version Tag Library
+	</info>
+
+	<tag>
+  		<name>version</name> 
+  		<tagclass>org.apache.depot.version.taglib.VersionTag</tagclass> 
+  		<info>Version Tag</info> 
+		<attribute> 
+			<name>id</name> 
+			<required>true</required>
+		</attribute> 
+  	</tag>
+	<tag>
+  		<name>versionEnvironment</name> 
+  		<tagclass>org.apache.depot.version.taglib.VersionEnvironmentTag</tagclass>

+  		<info>Version Environment Tag</info> 
+  	</tag>
+</taglib>
\ No newline at end of file

Added: incubator/depot/trunk/version/src/resources/jsp/version.jsp
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/version/src/resources/jsp/version.jsp	Tue May 11 15:34:27 2004
@@ -0,0 +1,33 @@
+<html>
+<%@ page session="false" %>
+
+<%@ taglib uri="depot-version.tld" prefix="depot" %>
+
+ <%
+    /*
+ * Copyright 2002,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+%>
+<head>
+<title>Version Page</title>
+</head>
+<body bgcolor='#ffffff'>
+<depot:version id="org.apache.depot.version"/>
+<hr>
+<depot:versionEnvironment/>
+</body>
+</html>
+
+

Mime
View raw message