1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portlet.wiki.engines.mediawiki.matchers;
16  
17  import com.liferay.portal.kernel.portlet.LiferayPortletURL;
18  import com.liferay.portal.kernel.util.CallbackMatcher;
19  import com.liferay.portal.kernel.util.CharPool;
20  
21  import java.util.regex.MatchResult;
22  
23  import javax.portlet.PortletURL;
24  
25  /**
26   * <a href="PortletURLMatcher.java.html"><b><i>View Source</i></b></a>
27   *
28   * @author Jonathan Potter
29   * @author Brian Wing Shun Chan
30   */
31  public class PortletURLMatcher extends CallbackMatcher {
32  
33      public PortletURLMatcher(PortletURL portletURL) {
34          _portletURL = portletURL;
35  
36          LiferayPortletURL liferayPortletURL = (LiferayPortletURL)portletURL;
37  
38          liferayPortletURL.setParameter("title", _TITLE_PLACEHOLDER, false);
39      }
40  
41      public String replaceMatches(CharSequence charSequence) {
42          return replaceMatches(charSequence, _callBack);
43      }
44  
45      private static final String _TITLE_PLACEHOLDER = "__TITLE_PLACEHOLDER__";
46  
47      private Callback _callBack = new Callback() {
48  
49          public String foundMatch(MatchResult matchResult) {
50              String portletURLString = _portletURL.toString();
51  
52              String title = matchResult.group(1);
53  
54              title = title.replace(CharPool.UNDERLINE, CharPool.PLUS);
55  
56              String url = portletURLString.replace(_TITLE_PLACEHOLDER, title);
57  
58              return "<a href=\"" + url + "\"";
59          }
60  
61      };
62  
63      private PortletURL _portletURL;
64  
65  }