Initial revision


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/jelly/trunk@136436 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/jelly-tags/memory/.cvsignore b/jelly-tags/memory/.cvsignore
new file mode 100755
index 0000000..aa9b084
--- /dev/null
+++ b/jelly-tags/memory/.cvsignore
@@ -0,0 +1,4 @@
+maven.log
+target
+velocity.log
+lib
diff --git a/jelly-tags/memory/project.xml b/jelly-tags/memory/project.xml
new file mode 100644
index 0000000..e92a9e0
--- /dev/null
+++ b/jelly-tags/memory/project.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<project>
+  <!--
+    BRITTLE! must include ${basedir} location or Maven will
+    not run this script outside of the base directory
+  -->
+  <extend>${basedir}/../tag-project.xml</extend>
+  <id>commons-jelly-tags-memory</id>
+  <name>commons-jelly-tags-memory</name>
+  <currentVersion>1.0-SNAPSHOT</currentVersion>
+  <package>org.apache.commons.jelly.tags.memory</package>
+
+  <description>
+      This is a Jelly interface for Runtime's memory functions.
+  </description>
+  <shortDescription>Commons Jelly Memory Tag Library</shortDescription>
+  
+  <versions>
+  </versions>
+
+</project>
diff --git a/jelly-tags/memory/src/java/org/apache/commons/jelly/tags/memory/FreeMemoryTag.java b/jelly-tags/memory/src/java/org/apache/commons/jelly/tags/memory/FreeMemoryTag.java
new file mode 100644
index 0000000..dbe8ac9
--- /dev/null
+++ b/jelly-tags/memory/src/java/org/apache/commons/jelly/tags/memory/FreeMemoryTag.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2002,2005 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.commons.jelly.tags.memory;
+
+import org.apache.commons.jelly.JellyTagException;
+import org.apache.commons.jelly.TagSupport;
+import org.apache.commons.jelly.XMLOutput;
+
+/**
+ * Tag supporting displaying free memory.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ */
+public class FreeMemoryTag extends TagSupport {
+
+    private static final int MB = 1024 * 1024;
+    private static final int KB = 1024;
+
+    private String style = "mb";
+
+    public void setStyle(String style) {
+        if (style == null) {
+            style = "mb";
+        }
+        this.style = style.toLowerCase();
+    }
+
+    public String getStyle() {
+        return this.style;
+    }
+ 
+    // Tag interface
+    //-------------------------------------------------------------------------
+    public void doTag(XMLOutput output) throws JellyTagException {
+
+        Runtime r = Runtime.getRuntime();
+
+        try {
+            long total = r.totalMemory();
+            long free = total - r.freeMemory();
+
+            if (style.equals("kb")) {
+                free /= KB;
+                total /= KB;
+            }
+            else if (style.equals("mb")) {
+                free /= MB;
+                total /= MB;
+            }
+            
+            output.write( free + style + "/" + total + style );
+        }
+        catch ( Exception e ) {
+            throw new JellyTagException( "Error writing to output", e );
+        }
+    }
+
+}
diff --git a/jelly-tags/memory/src/java/org/apache/commons/jelly/tags/memory/GcTag.java b/jelly-tags/memory/src/java/org/apache/commons/jelly/tags/memory/GcTag.java
new file mode 100644
index 0000000..92e9c30
--- /dev/null
+++ b/jelly-tags/memory/src/java/org/apache/commons/jelly/tags/memory/GcTag.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2002,2005 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.commons.jelly.tags.memory;
+
+import org.apache.commons.jelly.JellyTagException;
+import org.apache.commons.jelly.TagSupport;
+import org.apache.commons.jelly.XMLOutput;
+
+/**
+ * Tag to invoke garbage collection.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ */
+public class GcTag extends TagSupport {
+
+    // Tag interface
+    //-------------------------------------------------------------------------
+    public void doTag(XMLOutput output) throws JellyTagException {
+
+        Runtime r = Runtime.getRuntime();
+        r.gc();
+    }
+
+}
diff --git a/jelly-tags/memory/src/java/org/apache/commons/jelly/tags/memory/MemoryTagLibrary.java b/jelly-tags/memory/src/java/org/apache/commons/jelly/tags/memory/MemoryTagLibrary.java
new file mode 100644
index 0000000..c9858b8
--- /dev/null
+++ b/jelly-tags/memory/src/java/org/apache/commons/jelly/tags/memory/MemoryTagLibrary.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2002,2005 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.commons.jelly.tags.memory;
+
+import org.apache.commons.jelly.TagLibrary;
+
+/**
+ * A Jelly custom tag library that performs memory related tasks.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ * @version $Revision: 1.1 $
+ */
+public class MemoryTagLibrary extends TagLibrary {
+    public MemoryTagLibrary() {
+        registerTag("gc", GcTag.class);
+        registerTag("showFree", FreeMemoryTag.class);
+    }
+}
diff --git a/jelly-tags/memory/xdocs/changes.xml b/jelly-tags/memory/xdocs/changes.xml
new file mode 100644
index 0000000..3304aad
--- /dev/null
+++ b/jelly-tags/memory/xdocs/changes.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- 
+/*
+ * Copyright 2001-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.
+ */
+ -->
+
+<document>
+  <properties>
+    <title>Changes</title>
+    <author email="brett@apache.org">Brett Porter</author>
+  </properties>
+  <body>
+    <release version="1.0-SNAPSHOT" date="in CVS">
+      <action dev="brett" type="add">Initial release</action>
+    </release>
+  </body>
+</document>
diff --git a/jelly-tags/memory/xdocs/index.xml b/jelly-tags/memory/xdocs/index.xml
new file mode 100644
index 0000000..28c4925
--- /dev/null
+++ b/jelly-tags/memory/xdocs/index.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+<!--
+  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.
+-->
+
+<document>
+  <properties>
+    <title>Memory Tag Library</title>
+    <author email="brett@apache.org">Brett Porter</author>
+  </properties>
+
+  <body>
+    <section name="Overview">
+      <p>
+        This is a Jelly interface for the Runtime memory functions.
+      </p>
+    </section>
+  </body>
+</document>
+
diff --git a/jelly-tags/memory/xdocs/navigation.xml b/jelly-tags/memory/xdocs/navigation.xml
new file mode 100644
index 0000000..3b678f8
--- /dev/null
+++ b/jelly-tags/memory/xdocs/navigation.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+  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.
+-->
+<project name="Memory Tag Library">
+
+  <title>Memory Tag Library</title>
+  
+  <body>
+    <menu name="Memory Tag Library">
+      <item name="Overview"                href="/index.html"/>
+      <item name="Tags"                    href="/tags.html"/>
+    </menu>
+  </body>
+</project>