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 2017/07/16 11:55:00 UTC

[15/16] jspwiki git commit: private JSPWikiMarkupParser#findAttachment( String linktext ) moved to public AttachmentManager#getAttachmentInfoName( WikiContext context, String attachmentname )

private JSPWikiMarkupParser#findAttachment( String linktext ) moved to public AttachmentManager#getAttachmentInfoName( WikiContext context, String attachmentname )


Project: http://git-wip-us.apache.org/repos/asf/jspwiki/repo
Commit: http://git-wip-us.apache.org/repos/asf/jspwiki/commit/2424df60
Tree: http://git-wip-us.apache.org/repos/asf/jspwiki/tree/2424df60
Diff: http://git-wip-us.apache.org/repos/asf/jspwiki/diff/2424df60

Branch: refs/heads/master
Commit: 2424df60c9dabe4b57da095e327dbec8546a9227
Parents: 71ad322
Author: juanpablo <ju...@apache.org>
Authored: Thu Jul 13 19:45:18 2017 +0200
Committer: juanpablo <ju...@apache.org>
Committed: Sun Jul 16 13:26:33 2017 +0200

----------------------------------------------------------------------
 .../wiki/attachment/AttachmentManager.java      | 57 ++++++++++++++++----
 .../apache/wiki/parser/JSPWikiMarkupParser.java | 31 +----------
 2 files changed, 47 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jspwiki/blob/2424df60/jspwiki-war/src/main/java/org/apache/wiki/attachment/AttachmentManager.java
----------------------------------------------------------------------
diff --git a/jspwiki-war/src/main/java/org/apache/wiki/attachment/AttachmentManager.java b/jspwiki-war/src/main/java/org/apache/wiki/attachment/AttachmentManager.java
index f14023b..7cc7b60 100644
--- a/jspwiki-war/src/main/java/org/apache/wiki/attachment/AttachmentManager.java
+++ b/jspwiki-war/src/main/java/org/apache/wiki/attachment/AttachmentManager.java
@@ -14,7 +14,7 @@
     "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.    
+    under the License.
  */
 package org.apache.wiki.attachment;
 
@@ -27,6 +27,7 @@ import java.util.Collection;
 import java.util.Date;
 import java.util.List;
 import java.util.Properties;
+import java.util.Vector;
 
 import net.sf.ehcache.Cache;
 import net.sf.ehcache.CacheManager;
@@ -228,7 +229,6 @@ public class AttachmentManager
      *  @return Attachment, or null, if no such attachment exists.
      *  @throws ProviderException If something goes wrong.
      */
-
     public Attachment getAttachmentInfo( WikiContext context,
                                          String attachmentname )
         throws ProviderException
@@ -237,6 +237,41 @@ public class AttachmentManager
     }
 
     /**
+     *  Figures out the full attachment name from the context and attachment name.
+     *
+     *  @param context The current WikiContext
+     *  @param attachmentname The file name of the attachment.
+     *  @return Attachment, or null, if no such attachment exists.
+     *  @throws ProviderException If something goes wrong.
+     */
+    public String getAttachmentInfoName( WikiContext context,
+                                         String attachmentname )
+    {
+        Attachment att = null;
+
+        try
+        {
+            att = getAttachmentInfo( context, attachmentname );
+        }
+        catch( ProviderException e )
+        {
+            log.warn("Finding attachments failed: ",e);
+            return null;
+        }
+
+        if( att != null )
+        {
+            return att.getName();
+        }
+        else if( attachmentname.indexOf('/') != -1 )
+        {
+            return attachmentname;
+        }
+
+        return null;
+    }
+
+    /**
      *  Figures out the full attachment name from the context and
      *  attachment name.
      *
@@ -510,11 +545,11 @@ public class AttachmentManager
             // the caller should catch the exception and use the exception text as an i18n key
             throw new ProviderException(  "attach.parent.not.exist"  );
         }
-        
+
         m_provider.putAttachmentData( att, in );
 
         m_engine.getReferenceManager().updateReferences( att.getName(),
-                                                         new java.util.Vector() );
+                                                         new Vector() );
 
         WikiPage parent = new WikiPage( m_engine, att.getParentName() );
         m_engine.updateReferences( parent );
@@ -614,7 +649,7 @@ public class AttachmentManager
     /**
      *  Validates the filename and makes sure it is legal.  It trims and splits
      *  and replaces bad characters.
-     *  
+     *
      *  @param filename
      *  @return A validated name with annoying characters replaced.
      *  @throws WikiException If the filename is not legal (e.g. empty)
@@ -625,11 +660,11 @@ public class AttachmentManager
         if( filename == null || filename.trim().length() == 0 )
         {
             log.error("Empty file name given.");
-    
+
             // the caller should catch the exception and use the exception text as an i18n key
             throw new WikiException(  "attach.empty.file" );
         }
-    
+
         //
         //  Should help with IE 5.22 on OSX
         //
@@ -644,22 +679,22 @@ public class AttachmentManager
             // the caller should catch the exception and use the exception text as an i18n key
             throw new WikiException(  "attach.unwanted.file"  );
         }
-    
+
         //
         //  Some browser send the full path info with the filename, so we need
         //  to remove it here by simply splitting along slashes and then taking the path.
         //
-        
+
         String[] splitpath = filename.split( "[/\\\\]" );
         filename = splitpath[splitpath.length-1];
-        
+
         //
         //  Remove any characters that might be a problem. Most
         //  importantly - characters that might stop processing
         //  of the URL.
         //
         filename = StringUtils.replaceChars( filename, "#?\"'", "____" );
-    
+
         return filename;
     }
 }

http://git-wip-us.apache.org/repos/asf/jspwiki/blob/2424df60/jspwiki-war/src/main/java/org/apache/wiki/parser/JSPWikiMarkupParser.java
----------------------------------------------------------------------
diff --git a/jspwiki-war/src/main/java/org/apache/wiki/parser/JSPWikiMarkupParser.java b/jspwiki-war/src/main/java/org/apache/wiki/parser/JSPWikiMarkupParser.java
index 486af13..c63b615 100644
--- a/jspwiki-war/src/main/java/org/apache/wiki/parser/JSPWikiMarkupParser.java
+++ b/jspwiki-war/src/main/java/org/apache/wiki/parser/JSPWikiMarkupParser.java
@@ -55,8 +55,6 @@ import org.apache.wiki.WikiPage;
 import org.apache.wiki.api.exceptions.PluginException;
 import org.apache.wiki.api.exceptions.ProviderException;
 import org.apache.wiki.api.plugin.WikiPlugin;
-import org.apache.wiki.attachment.Attachment;
-import org.apache.wiki.attachment.AttachmentManager;
 import org.apache.wiki.auth.WikiSecurityException;
 import org.apache.wiki.auth.acl.Acl;
 import org.apache.wiki.i18n.InternationalizationManager;
@@ -1529,7 +1527,7 @@ public class JSPWikiMarkupParser extends MarkupParser {
                 //
                 //  Internal wiki link, but is it an attachment link?
                 //
-                String attachment = findAttachment( linkref );
+                String attachment = m_engine.getAttachmentManager().getAttachmentInfoName( m_context, linkref );
                 if( attachment != null )
                 {
                     callMutatorChain( m_attachmentLinkMutatorChain, attachment );
@@ -1597,33 +1595,6 @@ public class JSPWikiMarkupParser extends MarkupParser {
         return m_currentElement;
     }
 
-    private String findAttachment( String linktext )
-    {
-        AttachmentManager mgr = m_engine.getAttachmentManager();
-        Attachment att = null;
-
-        try
-        {
-            att = mgr.getAttachmentInfo( m_context, linktext );
-        }
-        catch( ProviderException e )
-        {
-            log.warn("Finding attachments failed: ",e);
-            return null;
-        }
-
-        if( att != null )
-        {
-            return att.getName();
-        }
-        else if( linktext.indexOf('/') != -1 )
-        {
-            return linktext;
-        }
-
-        return null;
-    }
-
     /**
      *  Pushes back any string that has been read.  It will obviously
      *  be pushed back in a reverse order.