📄 cmssearchresultview.java
字号:
CmsLocaleManager.PARAMETER_LOCALE).append("=").append(m_jsp.getRequestContext().getLocale()).toString(),
search));
result.append("\">>>");
result.append(messages.key(org.opencms.search.Messages.GUI_HELP_BUTTON_NEXT_0));
result.append("</a>\n");
}
result.append("</p>\n");
}
}
// include the post forms for the page links:
Iterator values = m_formCache.values().iterator();
while (values.hasNext()) {
result.append(values.next());
}
return result.toString();
}
/**
* Returns true if the links to search results shall point to exported content, false else. <p>
* @return true if the links to search results shall point to exported content, false else
*/
public boolean isExportLinks() {
return m_exportLinks;
}
/**
* Set wether the links to search results point to exported content or not. <p>
*
* @param exportLinks The value that decides Set wether the links to search results point to exported content or not.
*/
public void setExportLinks(boolean exportLinks) {
m_exportLinks = exportLinks;
}
/**
* Set a proprietary resource uri for the search page. <p>
*
* This is optional but allows to override the standard search result links
* (for next or previous pages) that point to
* <code>getJsp().getRequestContext().getUri()</code> whenever the search
* uri is element of some template and should not be linked directly.<p>
*
* @param uri the proprietary resource uri for the search page
*/
public void setSearchRessourceUrl(String uri) {
m_searchRessourceUrl = uri;
}
/**
* Returns the resource uri to the search page with respect to the
* optionally configured value <code>{@link #setSearchRessourceUrl(String)}</code>
* with the request parameters of the given argument.<p>
*
* This is a workaround for Tomcat bug 35775
* (http://issues.apache.org/bugzilla/show_bug.cgi?id=35775). After it has been
* fixed the version 1.1 should be restored (or at least this codepath should be switched back.<p>
*
*
* @param link the suggestion of the search result bean ( a previous, next or page number url)
* @return the resource uri to the search page with respect to the
* optionally configured value <code>{@link #setSearchRessourceUrl(String)}</code>
* with the request parameters of the given argument
*/
private String getSearchPageLink(String link, CmsSearch search) {
if (m_searchRessourceUrl != null) {
// for the form to generate we need params.
String pageParams = "";
int paramIndex = link.indexOf('?');
if (paramIndex > 0) {
pageParams = link.substring(paramIndex);
}
StringBuffer formurl = new StringBuffer(m_searchRessourceUrl);
if (m_searchRessourceUrl.indexOf('?') != -1) {
// the search page url already has a query string, don't start params of search-generated link
// with '?'
pageParams = new StringBuffer("&").append(pageParams.substring(1)).toString();
}
formurl.append(pageParams).toString();
String formname = toPostParameters(formurl.toString(), search);
link = new StringBuffer("javascript:document.forms['").append(formname).append("'].submit()").toString();
}
return link;
}
/**
* Generates a html form (named form<n>) with parameters found in
* the given GET request string (appended params with "?value=param&value2=param2).
* >n< is the number of forms that already have been generated.
* This is a content-expensive bugfix for http://issues.apache.org/bugzilla/show_bug.cgi?id=35775
* and should be replaced with the 1.1 revision as soon that bug is fixed.<p>
*
* The forms action will point to the given uri's path info part: All links in the page
* that includes this generated html and that are related to the get request should
* have "src='#'" and "onclick=documents.forms['<getRequestUri>'].submit()". <p>
*
* The generated form lands in the internal <code>Map {@link #m_formCache}</code> as mapping
* from uris to Strings and has to be appended to the output at a valid position. <p>
*
* Warning: Does not work with multiple values mapped to one parameter ("key = value1,value2..").<p>
*
*
*
* @param getRequestUri a request uri with optional query, will be used as name of the form too
*
* @return the formname of the the generated form that contains the parameters of the given request uri or
* the empty String if there weren't any get parameters in the given request uri.
*/
private String toPostParameters(String getRequestUri, CmsSearch search) {
/**
* A simple wrapper around html for a form and it's name for value
* side of form cache, necessary as order in Map is arbitrary,
* SortedMap unusable as backlinks have higher order, lower formname... <p>
*/
final class HTMLForm {
/** The html of the generated form. **/
String m_formHtml;
/** The name of the generated form. **/
String m_formName;
/**
* Creates an instance with the given formname and the given html code for the form. <p>
*
* @param formName the form name of the form
* @param formHtml the form html of the form
*/
HTMLForm(String formName, String formHtml) {
m_formName = formName;
m_formHtml = formHtml;
}
/**
* Returns the form html.<p>
*
* @return the form html
*
* @see java.lang.Object#toString()
*/
public String toString() {
return m_formHtml;
}
}
StringBuffer result;
String formname = "";
if (!m_formCache.containsKey(getRequestUri)) {
result = new StringBuffer();
int index = getRequestUri.indexOf('?');
String query = "";
String path = "";
if (index > 0) {
query = getRequestUri.substring(index + 1);
path = getRequestUri.substring(0, index);
formname = new StringBuffer("searchform").append(m_formCache.size()).toString();
result.append("\n<form method=\"post\" name=\"").append(formname).append("\" action=\"");
result.append(path).append("\">\n");
// "key=value" pairs as tokens:
StringTokenizer entryTokens = new StringTokenizer(query, "&", false);
while (entryTokens.hasMoreTokens()) {
StringTokenizer keyValueToken = new StringTokenizer(entryTokens.nextToken(), "=", false);
if (keyValueToken.countTokens() != 2) {
continue;
}
// Undo the possible already performed url encoding for the given url
String key = CmsEncoder.decode(keyValueToken.nextToken());
String value = CmsEncoder.decode(keyValueToken.nextToken());
if ("action".equals(key)) {
// cannot use the "search"-action value in combination with CmsWidgetDialog: prepareCommit would be left out!
value = CmsWidgetDialog.DIALOG_SAVE;
}
result.append(" <input type=\"hidden\" name=\"");
result.append(key).append("\" value=\"");
result.append(value).append("\" />\n");
}
// custom searchindex code for making category widget - compatible
// this is needed for transforming e.g. the CmsSearch-generated
// "&category=a,b,c" to widget fields categories.0..categories.n.
List categories = search.getParameters().getCategories();
Iterator it = categories.iterator();
int count = 0;
while (it.hasNext()) {
result.append(" <input type=\"hidden\" name=\"");
result.append("categories.").append(count).append("\" value=\"");
result.append(it.next()).append("\" />\n");
count++;
}
List roots = search.getParameters().getRoots();
it = roots.iterator();
count = 0;
while (it.hasNext()) {
result.append(" <input type=\"hidden\" name=\"");
result.append("roots.").append(count).append("\" value=\"");
result.append(it.next()).append("\" />\n");
count++;
}
result.append(" <input type=\"hidden\" name=\"");
result.append("searchfieldcontent.").append(0).append("\" value=\"");
result.append(search.getParameters().getSearchFieldContent()).append("\" />\n");
result.append(" <input type=\"hidden\" name=\"");
result.append("searchfieldmeta.").append(0).append("\" value=\"");
result.append(search.getParameters().getSearchFieldMeta()).append("\" />\n");
result.append(" <input type=\"hidden\" name=\"");
result.append("searchfieldtitle.").append(0).append("\" value=\"");
result.append(search.getParameters().getSearchFieldTitle()).append("\" />\n");
result.append(" <input type=\"hidden\" name=\"");
result.append("searchfieldkeywords.").append(0).append("\" value=\"");
result.append(search.getParameters().getSearchFieldKeywords()).append("\" />\n");
result.append(" <input type=\"hidden\" name=\"");
result.append("searchfielddescription.").append(0).append("\" value=\"");
result.append(search.getParameters().getSearchFieldDescription()).append("\" />\n");
result.append(" <input type=\"hidden\" name=\"");
result.append("sortfields.").append(0).append("\" value=\"");
result.append(search.getParameters().getSortName()).append("\" />\n");
search.getParameters().getSearchFieldContent();
result.append("</form>\n");
HTMLForm form = new HTMLForm(formname, result.toString());
m_formCache.put(getRequestUri, form);
return formname;
}
// empty String for no get parameters
return formname;
} else {
HTMLForm form = (HTMLForm)m_formCache.get(getRequestUri);
return form.m_formName;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -