You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by ju...@apache.org on 2014/02/12 00:13:58 UTC
svn commit: r1567452 [2/2] - in /jspwiki/trunk: ./ jspwiki-war/
jspwiki-war/src/main/java/org/apache/wiki/forms/
jspwiki-war/src/main/java/org/apache/wiki/plugin/
jspwiki-war/src/main/java/org/apache/wiki/rss/
jspwiki-war/src/main/java/org/apache/wiki/...
Added: jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/util/XhtmlUtil.java
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/util/XhtmlUtil.java?rev=1567452&view=auto
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/util/XhtmlUtil.java (added)
+++ jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/util/XhtmlUtil.java Tue Feb 11 23:13:58 2014
@@ -0,0 +1,217 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.wiki.util;
+
+import org.jdom2.Element;
+import org.jdom2.output.Format;
+import org.jdom2.output.XMLOutputter;
+
+/**
+ * A utility class to generate XHTML objects and ultimately, serialised markup.
+ * This class is incomplete but serves as a basic utility for JSPWiki, to be
+ * expanded upon as needed.
+ * <p>
+ * This uses JDOM2 as its backing implementation.
+ * </p>
+ *
+ * <h3>Example</h3>
+ * <p>
+ * To generate a single element, an Element with PCDATA content, and then
+ * embed the latter in the former:
+ * </p>
+ * <pre>
+ * Element div = XhtmlUtil.element(XHTML.div);
+ * Element p = XhtmlUtil.element(XHTML.p,"Some content");
+ * div.addContent(p);
+ * </pre>
+ * <p>
+ * There is also a convenient link and link target constructor methods:
+ * </p>
+ * <pre>
+ * Element link = XhtmlUtil.link("hrefValue","linkText");
+ * Element target = XhtmlUtil.target("targetIdValue","linkText");
+ * </pre>
+ *
+ * @since 2.10
+ */
+public final class XhtmlUtil {
+
+ private XhtmlUtil() {}
+
+ /**
+ * Serializes the Element to a String using a compact serialization format.
+ *
+ * @param element the element to serialize.
+ * @return the serialized Element.
+ */
+ public static String serialize( Element element ) {
+ return serialize( element, false );
+ }
+
+ /**
+ * Serializes the Element to a String. If <tt>pretty</tt> is true,
+ * uses a pretty whitespace format, otherwise a compact format.
+ *
+ * @param element the element to serialize.
+ * @param pretty if true, use a pretty whitespace format.
+ * @return the serialized Element.
+ */
+ public static String serialize( Element element, boolean pretty ) {
+ return serialize( element,pretty ? Format.getPrettyFormat() : Format.getCompactFormat() );
+ }
+
+ /**
+ * Serializes the Element to a String. Allows to use a custom <tt>format</tt>.
+ *
+ * @param element the element to serialize.
+ * @param format custom <tt>format</tt> used to serialize the Element.
+ * @return the serialized Element.
+ */
+ public static String serialize( Element element, Format format ) {
+ XMLOutputter out = new XMLOutputter( format );
+ return out.outputString( element );
+ }
+
+ /**
+ * Return an Element with an element type name matching the parameter.
+ *
+ * @param element the XHTML element type.
+ * @return a JDOM2 Element.
+ */
+ public static Element element( XHTML element ) {
+ return element( element, null );
+ }
+
+ /**
+ * Return an Element with an element type name matching the parameter,
+ * and optional PCDATA (parsed character data, a String) content.
+ *
+ * @param element the XHTML element type.
+ * @param content the optional PCDATA content.
+ * @return a JDOM2 Element.
+ */
+ public static Element element( XHTML element, String content ) {
+ Element elt = new Element( element.name() );
+ if( content != null ) {
+ elt.addContent( content );
+ }
+ return elt;
+ }
+
+ /**
+ * Return an XHTML link with a required 'href' attribute value and optional link (PCDATA) content.
+ *
+ * @param href the required 'href' value.
+ * @param content the optional link (PCDATA) content.
+ * @return a JDOM2 Element.
+ */
+ public static Element link( String href, String content ) {
+ if( href == null ) {
+ throw new IllegalArgumentException("missing 'href' attribute value.");
+ }
+ return fLink(href,content,null);
+ }
+
+ /**
+ * Return an XHTML link target with a required 'id' attribute value.
+ *
+ * @param id the required 'id' link target value.
+ * @return a JDOM2 Element.
+ */
+ public static Element target( String id, String content ) {
+ if( id == null ) {
+ throw new IllegalArgumentException( "missing 'id' attribute value." );
+ }
+ return fLink( null, content, id );
+ }
+
+ /**
+ * Return an XHTML link with an optional 'href' attribute, optional
+ * link content, and optional 'id' link target value.
+ *
+ * @param href the optional 'href' value.
+ * @param content the optional link (PCDATA) content.
+ * @param id the optional 'id' link target value.
+ * @return a JDOM2 Element.
+ */
+ private static Element fLink( String href, String content, String id ) {
+ Element a = element( XHTML.a );
+ if( href != null ) {
+ a.setAttribute( XHTML.ATTR_href, href );
+ }
+ if( content != null ) {
+ a.addContent( content );
+ }
+ if( id != null ) {
+ a.setAttribute( XHTML.ATTR_id, id );
+ }
+ return a;
+ }
+
+ /**
+ * Return an XHTML <tt>img</tt> element with an required 'src' attribute
+ * and optional 'alt' alternative text value.
+ *
+ * @param src the required 'src' value.
+ * @param alt the optional 'alt' alternative text value.
+ * @return a JDOM2 Element.
+ */
+ public static Element img( String src, String alt ) {
+ Element img = element( XHTML.img );
+ if( src == null ) {
+ throw new IllegalArgumentException( "missing 'src' attribute value." );
+ }
+ img.setAttribute( XHTML.ATTR_href, src );
+ if( alt != null ) {
+ img.setAttribute( XHTML.ATTR_alt, alt );
+ }
+ return img;
+ }
+
+ /**
+ * Return an XHTML form <tt>input</tt> element with optional 'type', 'name' and 'value' attributes.
+ *
+ * @param type the optional 'type' value.
+ * @param name the optional 'name' value.
+ * @param value the optional 'value' value.
+ * @return a JDOM2 Element.
+ */
+ public static Element input( String type, String name, String value ) {
+ Element input = element( XHTML.input );
+ if( type != null ) {
+ input.setAttribute( XHTML.ATTR_type, type );
+ }
+ if( name != null ) {
+ input.setAttribute( XHTML.ATTR_name, name );
+ }
+ if( value != null ) {
+ input.setAttribute( XHTML.ATTR_value, value );
+ }
+ return input;
+ }
+
+ public static void setClass( Element element, String classValue ) {
+ if( classValue == null ) {
+ throw new IllegalArgumentException( "missing 'class' attribute value." );
+ }
+ element.setAttribute( XHTML.ATTR_class, classValue );
+ }
+
+}
\ No newline at end of file
Modified: jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/util/XmlUtil.java
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/util/XmlUtil.java?rev=1567452&r1=1567451&r2=1567452&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/util/XmlUtil.java (original)
+++ jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/util/XmlUtil.java Tue Feb 11 23:13:58 2014
@@ -16,17 +16,8 @@
specific language governing permissions and limitations
under the License.
*/
-package org.apache.wiki.util;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
+package org.apache.wiki.util;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
@@ -38,14 +29,26 @@ import org.jdom2.input.SAXBuilder;
import org.jdom2.xpath.XPathExpression;
import org.jdom2.xpath.XPathFactory;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
/**
- * Utility class to parse XML files.
- *
+ * Utility class to parse XML files.
+ * <p>
+ * This uses JDOM2 as its backing implementation.
+ * </p>
+ *
* @since 2.10
*/
-public final class XmlUtil {
-
+public final class XmlUtil
+{
private static final Logger log = Logger.getLogger( XmlUtil.class );
private XmlUtil() {}
@@ -58,32 +61,32 @@ public final class XmlUtil {
* @param requestedNodes requestd nodes on the xml file
* @return the requested nodes of the XML file.
*/
- public static List< Element > parse( String xml, String requestedNodes ) {
+ public static List<Element> parse( String xml, String requestedNodes )
+ {
if( StringUtils.isNotEmpty( xml ) && StringUtils.isNotEmpty( requestedNodes ) ) {
- Set< Element > readed = new HashSet< Element >();
+ Set<Element> readed = new HashSet<Element>();
SAXBuilder builder = new SAXBuilder();
try {
Enumeration< URL > resources = XmlUtil.class.getClassLoader().getResources( xml );
while( resources.hasMoreElements() ) {
URL resource = resources.nextElement();
-
log.debug( "reading " + resource.toString() );
Document doc = builder.build( resource );
XPathFactory xpfac = XPathFactory.instance();
- XPathExpression< Element > xp = xpfac.compile( requestedNodes, Filters.element() );
+ XPathExpression<Element> xp = xpfac.compile( requestedNodes, Filters.element() );
readed.addAll( xp.evaluate( doc ) ); // filter out repeated items
}
- return new ArrayList< Element >( readed );
+ return new ArrayList<Element>( readed );
} catch ( IOException ioe ) {
log.error( "Couldn't load all " + xml + " resources", ioe );
} catch ( JDOMException jdome ) {
log.error( "error parsing " + xml + " resources", jdome );
}
}
-
- return Collections.< Element >emptyList();
+ return Collections.<Element>emptyList();
}
+
/**
* Parses the given stream and returns the requested nodes. If there's an error accessing or parsing the stream, an
* empty list is returned.
@@ -92,23 +95,22 @@ public final class XmlUtil {
* @param requestedNodes requestd nodes on the xml stream.
* @return the requested nodes of the XML stream.
*/
- public static List< Element > parse( InputStream xmlStream, String requestedNodes ) {
+ public static List<Element> parse( InputStream xmlStream, String requestedNodes )
+ {
if( xmlStream != null && StringUtils.isNotEmpty( requestedNodes ) ) {
SAXBuilder builder = new SAXBuilder();
try {
- Document doc = builder.build( xmlStream );
+ Document doc = builder.build(xmlStream);
XPathFactory xpfac = XPathFactory.instance();
- XPathExpression< Element > xp = xpfac.compile( requestedNodes, Filters.element() );
-
+ XPathExpression< Element > xp = xpfac.compile(requestedNodes,Filters.element());
return xp.evaluate( doc );
} catch ( IOException ioe ) {
log.error( "Couldn't load all " + xmlStream + " resources", ioe );
} catch ( JDOMException jdome ) {
log.error( "error parsing " + xmlStream + " resources", jdome );
}
- }
-
- return Collections.< Element >emptyList();
+ }
+ return Collections.<Element>emptyList();
}
-}
+}
\ No newline at end of file
Modified: jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/plugin/RecentChangesPluginTest.java
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/plugin/RecentChangesPluginTest.java?rev=1567452&r1=1567451&r2=1567452&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/plugin/RecentChangesPluginTest.java (original)
+++ jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/plugin/RecentChangesPluginTest.java Tue Feb 11 23:13:58 2014
@@ -34,90 +34,85 @@ import org.apache.wiki.api.engine.Plugin
public class RecentChangesPluginTest extends TestCase {
Properties props = TestEngine.getTestProperties();
- TestEngine testEngine;
+ TestEngine testEngine;
- WikiContext context;
+ WikiContext context;
- PluginManager manager;
+ PluginManager manager;
- public void setUp() throws Exception {
+ public void setUp() throws Exception {
CacheManager.getInstance().removalAll();
- testEngine = new TestEngine(props);
+ testEngine = new TestEngine(props);
- testEngine.saveText("TestPage01", "Some Text for testing 01");
- testEngine.saveText("TestPage02", "Some Text for testing 02");
- testEngine.saveText("TestPage03", "Some Text for testing 03");
-
- manager = new DefaultPluginManager(testEngine, props);
- }
-
- public void tearDown() {
- testEngine.deleteTestPage("TestPage01");
- testEngine.deleteTestPage("TestPage02");
- testEngine.deleteTestPage("TestPage03");
-
- TestEngine.emptyWorkDir();
- }
-
- /**
- * Plain test without parameters
- *
- * @throws Exception
- */
- public void testSimple() throws Exception {
- context = new WikiContext(testEngine, new WikiPage(testEngine, "TestPage01"));
-
- String res = manager.execute(context, "{INSERT org.apache.wiki.plugin.RecentChangesPlugin}");
-
- // we don't want to compare the complete html returned, but check if
- // certain Strings are present and other
- // Strings are not present
- assertTrue(res.contains("<table cellpadding='4' class='recentchanges'>"));
- assertTrue(res.contains("<a href='/Wiki.jsp?page=TestPage01'>Test Page 01</a>"));
- assertTrue(res.contains("<a href='/Wiki.jsp?page=TestPage02'>Test Page 02</a>"));
- assertTrue(res.contains("<a href='/Wiki.jsp?page=TestPage03'>Test Page 03</a>"));
-
- }
-
- /**
- * Test with the include parameter
- *
- * @throws Exception
- */
- public void testParmInClude() throws Exception {
- context = new WikiContext(testEngine, new WikiPage(testEngine, "TestPage02"));
-
- String res = manager
- .execute(context,
- "{INSERT org.apache.wiki.plugin.RecentChangesPlugin include='TestPage02*'}");
-
- assertTrue(res.contains("<table cellpadding='4' class='recentchanges'>"));
- assertFalse(res.contains("<a href='/Wiki.jsp?page=TestPage01'>Test Page 01</a>"));
- assertTrue(res.contains("<a href='/Wiki.jsp?page=TestPage02'>Test Page 02</a>"));
- assertFalse(res.contains("<a href='/Wiki.jsp?page=TestPage03'>Test Page 03</a>"));
-
- }
-
- /**
- * Test with the exclude parameter
- *
- * @throws Exception
- */
- public void testParmExClude() throws Exception {
- context = new WikiContext(testEngine, new WikiPage(testEngine, "TestPage03"));
-
- String res = manager
- .execute(context,
- "{INSERT org.apache.wiki.plugin.RecentChangesPlugin exclude='TestPage03*'}");
-
- assertTrue(res.contains("<table cellpadding='4' class='recentchanges'>"));
- assertTrue(res.contains("<a href='/Wiki.jsp?page=TestPage01'>Test Page 01</a>"));
- assertTrue(res.contains("<a href='/Wiki.jsp?page=TestPage02'>Test Page 02</a>"));
- assertFalse(res.contains("<a href='/Wiki.jsp?page=TestPage03'>Test Page 03</a>"));
-
- }
-
- public static Test suite() {
- return new TestSuite(RecentChangesPluginTest.class);
- }
+ testEngine.saveText("TestPage01", "Some Text for testing 01");
+ testEngine.saveText("TestPage02", "Some Text for testing 02");
+ testEngine.saveText("TestPage03", "Some Text for testing 03");
+
+ manager = new DefaultPluginManager(testEngine, props);
+ }
+
+ public void tearDown() {
+ testEngine.deleteTestPage("TestPage01");
+ testEngine.deleteTestPage("TestPage02");
+ testEngine.deleteTestPage("TestPage03");
+
+ TestEngine.emptyWorkDir();
+ }
+
+ /**
+ * Plain test without parameters
+ *
+ * @throws Exception
+ */
+ public void testSimple() throws Exception {
+ context = new WikiContext(testEngine, new WikiPage(testEngine, "TestPage01"));
+
+ String res = manager.execute(context, "{INSERT org.apache.wiki.plugin.RecentChangesPlugin}");
+
+ // we don't want to compare the complete html returned, but check if
+ // certain Strings are present and other Strings are not present
+ assertTrue(res.contains("<table class=\"recentchanges\" cellpadding=\"4\">"));
+ assertTrue(res.contains("<a href=\"/Wiki.jsp?page=TestPage01\">Test Page 01</a>"));
+ assertTrue(res.contains("<a href=\"/Wiki.jsp?page=TestPage02\">Test Page 02</a>"));
+ assertTrue(res.contains("<a href=\"/Wiki.jsp?page=TestPage03\">Test Page 03</a>"));
+ }
+
+ /**
+ * Test with the include parameter
+ *
+ * @throws Exception
+ */
+ public void testParmInClude() throws Exception {
+ context = new WikiContext(testEngine, new WikiPage(testEngine, "TestPage02"));
+
+ String res = manager.execute( context,
+ "{INSERT org.apache.wiki.plugin.RecentChangesPlugin include='TestPage02*'}" );
+
+ assertTrue(res.contains("<table class=\"recentchanges\" cellpadding=\"4\">"));
+ assertFalse(res.contains("<a href=\"/Wiki.jsp?page=TestPage01\">Test Page 01</a>"));
+ assertTrue(res.contains("<a href=\"/Wiki.jsp?page=TestPage02\">Test Page 02</a>"));
+ assertFalse(res.contains("<a href=\"/Wiki.jsp?page=TestPage03\">Test Page 03</a>"));
+ }
+
+ /**
+ * Test with the exclude parameter
+ *
+ * @throws Exception
+ */
+ public void testParmExClude() throws Exception {
+ context = new WikiContext(testEngine, new WikiPage(testEngine, "TestPage03"));
+
+ String res = manager.execute( context,
+ "{INSERT org.apache.wiki.plugin.RecentChangesPlugin exclude='TestPage03*'}" );
+
+ assertTrue(res.contains("<table class=\"recentchanges\" cellpadding=\"4\">"));
+ assertTrue(res.contains("<a href=\"/Wiki.jsp?page=TestPage01\">Test Page 01</a>"));
+ assertTrue(res.contains("<a href=\"/Wiki.jsp?page=TestPage02\">Test Page 02</a>"));
+ assertFalse(res.contains("<a href=\"/Wiki.jsp?page=TestPage03\">Test Page 03</a>"));
+ }
+
+ public static Test suite() {
+ return new TestSuite(RecentChangesPluginTest.class);
+ }
+
}
Modified: jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/rss/RSSGeneratorTest.java
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/rss/RSSGeneratorTest.java?rev=1567452&r1=1567451&r2=1567452&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/rss/RSSGeneratorTest.java (original)
+++ jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/rss/RSSGeneratorTest.java Tue Feb 11 23:13:58 2014
@@ -27,7 +27,11 @@ import java.util.Date;
import java.util.List;
import java.util.Properties;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
import net.sf.ehcache.CacheManager;
+
import org.apache.wiki.TestEngine;
import org.apache.wiki.WikiContext;
import org.apache.wiki.WikiEngine;
@@ -35,10 +39,6 @@ import org.apache.wiki.plugin.WeblogEntr
import org.apache.wiki.plugin.WeblogPlugin;
import org.apache.wiki.providers.FileSystemProvider;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
/**
*
* @since
Added: jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/ui/admin/beans/PluginBeanTest.java
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/ui/admin/beans/PluginBeanTest.java?rev=1567452&view=auto
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/ui/admin/beans/PluginBeanTest.java (added)
+++ jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/ui/admin/beans/PluginBeanTest.java Tue Feb 11 23:13:58 2014
@@ -0,0 +1,38 @@
+package org.apache.wiki.ui.admin.beans;
+
+import java.util.Properties;
+
+import javax.management.NotCompliantMBeanException;
+
+import junit.framework.TestCase;
+
+import org.apache.wiki.TestEngine;
+import org.apache.wiki.WikiContext;
+import org.apache.wiki.WikiPage;
+import org.apache.wiki.api.exceptions.WikiException;
+
+
+public class PluginBeanTest extends TestCase {
+
+ Properties props = TestEngine.getTestProperties();
+
+ TestEngine testEngine;
+
+ public void testDoGet() throws WikiException, NotCompliantMBeanException {
+ testEngine = new TestEngine( props );
+ WikiContext context = new WikiContext( testEngine, new WikiPage( testEngine, "TestPage01" ) );
+ PluginBean pb = new PluginBean( testEngine );
+ String expectedHtml = "<div>" +
+ "<h4>Plugins</h4>" +
+ "<table border=\"1\">" +
+ "<tr><th>Name</th><th>Alias</th><th>Author</th><th>Notes</th></tr>" +
+ "<tr><td>IfPlugin</td><td>If</td><td>Janne Jalkanen</td><td></td></tr>" +
+ "<tr><td>Note</td><td></td><td>Janne Jalkanen</td><td></td></tr>" +
+ "<tr><td>SamplePlugin</td><td>samplealias</td><td>Janne Jalkanen</td><td></td></tr>" +
+ "<tr><td>SamplePlugin2</td><td>samplealias2</td><td>Janne Jalkanen</td><td></td></tr>" +
+ "</table>" +
+ "</div>";
+ assertEquals( expectedHtml, pb.doGet( context ) );
+ }
+
+}
Modified: jspwiki/trunk/pom.xml
URL: http://svn.apache.org/viewvc/jspwiki/trunk/pom.xml?rev=1567452&r1=1567451&r2=1567452&view=diff
==============================================================================
--- jspwiki/trunk/pom.xml (original)
+++ jspwiki/trunk/pom.xml Tue Feb 11 23:13:58 2014
@@ -91,12 +91,6 @@
</dependency>
<dependency>
- <groupId>ecs</groupId>
- <artifactId>ecs</artifactId>
- <version>1.4.2</version>
- </dependency>
-
- <dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>