jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jalka...@apache.org
Subject svn commit: r764517 - in /incubator/jspwiki/trunk: src/java/org/apache/wiki/JCRWikiPage.java src/java/org/apache/wiki/content/ContentManager.java tests/java/org/apache/wiki/WikiEngineTest.java
Date Mon, 13 Apr 2009 16:26:43 GMT
Author: jalkanen
Date: Mon Apr 13 16:26:42 2009
New Revision: 764517

URL: http://svn.apache.org/viewvc?rev=764517&view=rev
Log:
When a page is saved, now checks for a valid content type.

Modified:
    incubator/jspwiki/trunk/src/java/org/apache/wiki/JCRWikiPage.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiEngineTest.java

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/JCRWikiPage.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/JCRWikiPage.java?rev=764517&r1=764516&r2=764517&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/JCRWikiPage.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/JCRWikiPage.java Mon Apr 13 16:26:42
2009
@@ -61,7 +61,7 @@
 
     private static final String ATTR_CONTENT = "wiki:content";
 
-    private static final String CONTENTTYPE  = "wiki:contentType";
+    public  static final String CONTENTTYPE  = "wiki:contentType";
     
 
     public static final String REFERSTO = "wiki:refersTo";
@@ -600,7 +600,9 @@
 
     public boolean isAttachment() throws ProviderException
     {
-        if( getContentType().equals( ContentManager.JSPWIKI_CONTENT_TYPE ) ) return false;
+        String contentType = getContentType();
+        
+        if( ContentManager.JSPWIKI_CONTENT_TYPE.equals( contentType ) ) return false;
         
         return true;
     }

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java?rev=764517&r1=764516&r2=764517&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java Mon Apr 13
16:26:42 2009
@@ -1158,6 +1158,8 @@
      */
     public JCRWikiPage addPage( WikiPath path, String contentType ) throws PageAlreadyExistsException,
ProviderException
     {
+        checkValidContentType( contentType );
+        
         try
         {
             Session session = m_sessionManager.getSession();
@@ -1166,7 +1168,8 @@
             
             //nd.addMixin( "mix:versionable" );
             nd.addMixin( "mix:referenceable" );
-
+            nd.setProperty( JCRWikiPage.CONTENTTYPE, contentType );
+            
             JCRWikiPage page = new JCRWikiPage(m_engine, nd);
             
             return page;
@@ -1177,6 +1180,14 @@
         }
     }
 
+    /** Throws an exception if the content type is not a fully valid content type. */
+    private void checkValidContentType( String type ) throws ProviderException
+    {
+        if( type == null ) throw new ProviderException("null content type");
+        
+        if( type.indexOf('/') == -1 ) throw new ProviderException("Not RFC compliant type");
+    }
+    
     /**
      *  Get content from the repository.
      *  

Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiEngineTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiEngineTest.java?rev=764517&r1=764516&r2=764517&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiEngineTest.java (original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiEngineTest.java Mon Apr 13 16:26:42
2009
@@ -41,6 +41,8 @@
 
     TestEngine m_engine;
 
+    private static final WikiPath PATH_FOOBAR  = WikiPath.valueOf( "Foobar" );
+    private static final WikiPath PATH_FOOBARS = WikiPath.valueOf( "Foobars" );
 
     public WikiEngineTest( String s )
     {
@@ -120,10 +122,10 @@
         m_engine.saveText( "Foobar", "1" );
         m_engine.saveText( "Foobars", "2" );
 
-        assertEquals( "plural mistake", "Foobars",
+        assertEquals( "plural mistake", PATH_FOOBARS,
                       m_engine.getFinalPageName( WikiPath.valueOf("Foobars") ) );
 
-        assertEquals( "singular mistake", "Foobar",
+        assertEquals( "singular mistake", PATH_FOOBAR,
                       m_engine.getFinalPageName( WikiPath.valueOf("Foobar" )) );
     }
 
@@ -132,9 +134,9 @@
     {
         m_engine.saveText( "Foobar", "1" );
 
-        assertEquals( "plural mistake", "Foobar",
+        assertEquals( "plural mistake", PATH_FOOBAR,
                       m_engine.getFinalPageName( WikiPath.valueOf("Foobars") ) );
-        assertEquals( "singular mistake", "Foobar",
+        assertEquals( "singular mistake", PATH_FOOBAR,
                       m_engine.getFinalPageName( WikiPath.valueOf("Foobar") ) );
     }
 
@@ -143,9 +145,9 @@
     {
         m_engine.saveText( "Foobars", "1" );
 
-        assertEquals( "plural mistake", "Foobars",
+        assertEquals( "plural mistake", PATH_FOOBARS,
                       m_engine.getFinalPageName( WikiPath.valueOf("Foobars") ) );
-        assertEquals( "singular mistake", "Foobars",
+        assertEquals( "singular mistake", PATH_FOOBARS,
                       m_engine.getFinalPageName( WikiPath.valueOf("Foobar") ) );
     }
     
@@ -245,7 +247,7 @@
         m_engine.deletePage( "Test" );
         Object[] result = m_engine.scanWikiLinks( m_engine.createPage( WikiPath.valueOf(
"Test" ) ), src ).toArray();
         
-        assertEquals( "item 0", "Foobar", result[0] );
+        assertEquals( "item 0", PATH_FOOBAR, result[0] );
         assertEquals( "item 1", "This is a link", result[1] );
     }
 



Mime
View raw message