001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.solr.handler.admin;
017:
018: import java.net.URL;
019: import java.util.ArrayList;
020: import java.util.Map;
021:
022: import org.apache.solr.core.SolrInfoMBean;
023: import org.apache.solr.core.SolrInfoRegistry;
024: import org.apache.solr.handler.RequestHandlerBase;
025: import org.apache.solr.handler.RequestHandlerUtils;
026: import org.apache.solr.request.SolrParams;
027: import org.apache.solr.request.SolrQueryRequest;
028: import org.apache.solr.request.SolrQueryResponse;
029: import org.apache.solr.util.SimpleOrderedMap;
030:
031: /**
032: * similar to "admin/registry.jsp"
033: *
034: * NOTE: the response format is still likely to change. It should be designed so
035: * that it works nicely with an XSLT transformation. Until we have a nice
036: * XSLT front end for /admin, the format is still open to change.
037: *
038: * @author ryan
039: * @version $Id: PluginInfoHandler.java 533815 2007-04-30 17:57:52Z ryan $
040: * @since solr 1.2
041: */
042: public class PluginInfoHandler extends RequestHandlerBase {
043: @Override
044: public void handleRequestBody(SolrQueryRequest req,
045: SolrQueryResponse rsp) throws Exception {
046: RequestHandlerUtils.addExperimentalFormatWarning(rsp);
047: SolrParams params = req.getParams();
048:
049: boolean stats = params.getBool("stats", false);
050: rsp.add("plugins", getSolrInfoBeans(stats));
051: }
052:
053: private static SimpleOrderedMap<Object> getSolrInfoBeans(
054: boolean stats) {
055: SimpleOrderedMap<Object> list = new SimpleOrderedMap<Object>();
056: for (SolrInfoMBean.Category cat : SolrInfoMBean.Category
057: .values()) {
058: SimpleOrderedMap<Object> category = new SimpleOrderedMap<Object>();
059: list.add(cat.name(), category);
060: Map<String, SolrInfoMBean> reg = SolrInfoRegistry
061: .getRegistry();
062: synchronized (reg) {
063: for (Map.Entry<String, SolrInfoMBean> entry : reg
064: .entrySet()) {
065: SolrInfoMBean m = entry.getValue();
066: if (m.getCategory() != cat)
067: continue;
068:
069: String na = "Not Declared";
070: SimpleOrderedMap<Object> info = new SimpleOrderedMap<Object>();
071: category.add(entry.getKey(), info);
072:
073: info.add("name", (m.getName() != null ? m.getName()
074: : na));
075: info.add("version", (m.getVersion() != null ? m
076: .getVersion() : na));
077: info.add("description",
078: (m.getDescription() != null ? m
079: .getDescription() : na));
080:
081: info.add("sourceId", (m.getSourceId() != null ? m
082: .getSourceId() : na));
083: info.add("source", (m.getSource() != null ? m
084: .getSource() : na));
085:
086: URL[] urls = m.getDocs();
087: if ((urls != null) && (urls.length > 0)) {
088: ArrayList<String> docs = new ArrayList<String>(
089: urls.length);
090: for (URL u : urls) {
091: docs.add(u.toExternalForm());
092: }
093: info.add("docs", docs);
094: }
095:
096: if (stats) {
097: info.add("stats", m.getStatistics());
098: }
099: }
100: }
101: }
102: return list;
103: }
104:
105: //////////////////////// SolrInfoMBeans methods //////////////////////
106:
107: @Override
108: public String getDescription() {
109: return "Registry";
110: }
111:
112: @Override
113: public String getVersion() {
114: return "$Revision: 533815 $";
115: }
116:
117: @Override
118: public String getSourceId() {
119: return "$Id: PluginInfoHandler.java 533815 2007-04-30 17:57:52Z ryan $";
120: }
121:
122: @Override
123: public String getSource() {
124: return "$URL: https://svn.apache.org/repos/asf/lucene/solr/branches/branch-1.2/src/java/org/apache/solr/handler/admin/PluginInfoHandler.java $";
125: }
126: }
|