001: /*
002: * Copyright 2004 Outerthought bvba and Schaubroeck nv
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.outerj.daisy.frontend;
017:
018: import org.outerj.daisy.frontend.util.AbstractDaisyApple;
019: import org.outerj.daisy.frontend.util.FormHelper;
020: import org.outerj.daisy.frontend.util.XmlObjectXMLizable;
021: import org.outerj.daisy.frontend.util.XslUtil;
022: import org.outerj.daisy.frontend.components.siteconf.SiteConf;
023: import org.outerj.daisy.frontend.components.docbasket.DocumentBasketEntry;
024: import org.outerj.daisy.frontend.components.docbasket.DocumentBasketHelper;
025: import org.outerj.daisy.repository.Repository;
026: import org.outerj.daisy.repository.DocumentCollection;
027: import org.outerj.daisy.repository.RepositoryException;
028: import org.outerj.daisy.repository.schema.RepositorySchema;
029: import org.outerj.daisy.repository.schema.FieldType;
030: import org.outerj.daisy.repository.schema.PartType;
031: import org.outerj.daisy.repository.schema.DocumentType;
032: import org.outerj.daisy.repository.variant.VariantManager;
033: import org.outerj.daisy.repository.variant.Branch;
034: import org.outerj.daisy.repository.variant.Language;
035: import org.outerj.daisy.repository.query.QueryManager;
036: import org.outerj.daisy.repository.query.QueryHelper;
037: import org.apache.cocoon.components.flow.apples.AppleRequest;
038: import org.apache.cocoon.components.flow.apples.AppleResponse;
039: import org.apache.cocoon.components.flow.apples.StatelessAppleController;
040: import org.apache.cocoon.forms.formmodel.Form;
041: import org.apache.cocoon.forms.FormContext;
042: import org.apache.avalon.framework.service.Serviceable;
043: import org.apache.avalon.framework.service.ServiceManager;
044: import org.apache.avalon.framework.service.ServiceException;
045: import org.apache.avalon.framework.context.Contextualizable;
046: import org.outerx.daisy.x10.SearchResultDocument;
047:
048: import java.util.*;
049:
050: public class QuerySearchApple extends AbstractDaisyApple implements
051: StatelessAppleController, Serviceable, Contextualizable {
052: private ServiceManager serviceManager;
053: private static List<AutocompleteEntry> DEFAULT_AUTOCOMPLETE_ENTRIES = new ArrayList<AutocompleteEntry>();
054: static {
055: // core syntax
056: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
057: "select", null));
058: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry("where",
059: null));
060: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
061: "order by", null));
062: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry("limit",
063: null));
064: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
065: "option", null));
066:
067: // query options
068: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
069: "include_retired", "query option"));
070: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
071: "search_last_version", "query option"));
072: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
073: "style_hint", "query option"));
074: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
075: "annotate_link_fields", "query option"));
076: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
077: "chunk_offset", "query option"));
078: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
079: "chunk_length", "query option"));
080:
081: // built-in operators/conditions
082: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry("like",
083: null));
084: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
085: "not like", null));
086: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
087: "between", null));
088: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
089: "not between", null));
090: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry("in",
091: null));
092: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
093: "not in", null));
094: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
095: "is null", null));
096: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
097: "is not null", null));
098: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
099: "has all ()", null));
100: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
101: "has exactly ()", null));
102: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
103: "has some ()", null));
104: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
105: "has any ()", null));
106: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
107: "has none ()", null));
108: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
109: "matchesPath()", null));
110: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry("=>",
111: "link dereferencing"));
112: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
113: "InCollection()", null));
114: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
115: "LinksTo()", null));
116: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
117: "LinksFrom()", null));
118: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
119: "LinksToVariant()", null));
120: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
121: "LinksFromVariant()", null));
122: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
123: "IsLinked()", null));
124: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
125: "IsNotLinked()", null));
126: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
127: "HasPart()", null));
128: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
129: "HasPartWithMimeType()", null));
130: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
131: "DoesNotHaveVariant()", null));
132: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry("true",
133: null));
134: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry("and",
135: null));
136: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry("or",
137: null));
138: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry("=",
139: "equals operator"));
140: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry("!=",
141: "not equals operator"));
142: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry("<",
143: "less than operator"));
144: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(">",
145: "greater than operator"));
146: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry("<=",
147: "less than or equals operator"));
148: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(">=",
149: "greater than or equals operator"));
150: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry("+",
151: "addition"));
152: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry("-",
153: "substraction"));
154: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry("*",
155: "multiplication"));
156: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry("/",
157: "division"));
158: DEFAULT_AUTOCOMPLETE_ENTRIES
159: .add(new AutocompleteEntry("LangInSync()",
160: "in sync with last major change of reference language?"));
161: DEFAULT_AUTOCOMPLETE_ENTRIES
162: .add(new AutocompleteEntry("LangInSync('live')",
163: "in sync with last-up-to-live major change of reference language?"));
164: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
165: "LangNotInSync()", null));
166: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
167: "LangNotInSync('live')", null));
168: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
169: "ReverseLangInSync('lang', 'last')", null));
170: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
171: "ReverseLangNotInSync('lang', 'last')", null));
172:
173: // functions
174: String FUNCTION = "function";
175: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
176: "Concat()", FUNCTION));
177: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
178: "Length()", FUNCTION));
179: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
180: "Left()", FUNCTION));
181: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
182: "Right()", FUNCTION));
183: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
184: "Substring()", FUNCTION));
185: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
186: "UpperCase()", FUNCTION));
187: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
188: "LowerCase()", FUNCTION));
189: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
190: "CurrentDate()", FUNCTION));
191: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
192: "CurrentDateTime()", FUNCTION));
193: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
194: "Year()", FUNCTION));
195: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
196: "Month()", FUNCTION));
197: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
198: "Week()", FUNCTION));
199: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
200: "DayOfWeek()", FUNCTION));
201: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
202: "DayOfMonth()", FUNCTION));
203: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
204: "DayOfYear()", FUNCTION));
205: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
206: "RelativeDate()", FUNCTION));
207: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
208: "RelativeDateTime()", FUNCTION));
209: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
210: "Random()", FUNCTION));
211: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry("Mod()",
212: FUNCTION));
213: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry("Abs()",
214: FUNCTION));
215: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
216: "Floor()", FUNCTION));
217: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
218: "Ceiling()", FUNCTION));
219: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
220: "Round()", FUNCTION));
221: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
222: "ContextDoc()", FUNCTION));
223: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
224: "UserId()", FUNCTION));
225: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
226: "Path()", FUNCTION));
227: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
228: "FullText()", FUNCTION));
229: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
230: "FullTextFragment()", FUNCTION));
231: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
232: "GetLinkPath()", FUNCTION));
233: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
234: "ReversePath()", FUNCTION));
235: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
236: "String()", FUNCTION));
237:
238: // identifiers
239: String IDENTIFIER = "identifier: ";
240: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry("id",
241: IDENTIFIER + "string"));
242: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
243: "namespace", IDENTIFIER + "string"));
244: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry("name",
245: IDENTIFIER + "string - versioned"));
246: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
247: "branch", IDENTIFIER + "string/symbolic"));
248: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
249: "branchId", IDENTIFIER + "long"));
250: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
251: "language", IDENTIFIER + "string/symbolic"));
252: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
253: "languageId", IDENTIFIER + "long"));
254: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry("link",
255: IDENTIFIER + "link (points to current doc)"));
256: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
257: "documentType", IDENTIFIER + "string/symbolic"));
258: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
259: "versionId", IDENTIFIER + "long"));
260: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
261: "creationTime", IDENTIFIER + "datetime"));
262: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
263: "ownerId", IDENTIFIER + "long"));
264: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
265: "ownerLogin", IDENTIFIER + "string/symbolic"));
266: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
267: "ownerName", IDENTIFIER + "string - not searchable"));
268: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
269: "summary", IDENTIFIER + "string - not searchable"));
270: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
271: "retired", IDENTIFIER + "boolean"));
272: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
273: "private", IDENTIFIER + "boolean"));
274: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
275: "lastModified", IDENTIFIER + "datetime"));
276: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
277: "lastModifierId", IDENTIFIER + "long"));
278: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
279: "lastModifierLogin", IDENTIFIER + "string/symbolic"));
280: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
281: "lastModifierName", IDENTIFIER
282: + "string - not searchable"));
283: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
284: "variantLastModified", IDENTIFIER + "datetime"));
285: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
286: "variantLastModifierId", IDENTIFIER + "long"));
287: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
288: "variantLastModifierLogin", IDENTIFIER
289: + "string/symbolic"));
290: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
291: "variantLastModifierName", IDENTIFIER
292: + "string - not searchable"));
293: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
294: "mimeType", "part sub-identifier"));
295: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry("size",
296: "part sub-identifier"));
297: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
298: "content", "part sub-identifier"));
299: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
300: "versionCreationTime", IDENTIFIER + "datetime"));
301: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
302: "versionCreatorId", IDENTIFIER + "long"));
303: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
304: "versionCreatorLogin", IDENTIFIER + "string/symbolic"));
305: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
306: "versionCreatorName", IDENTIFIER
307: + "string - not searchable"));
308: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
309: "versionState", IDENTIFIER + "string/symbolic"));
310: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
311: "totalSizeOfParts", IDENTIFIER + "long"));
312: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
313: "versionLastModified", IDENTIFIER + "datetime"));
314: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
315: "lockType", IDENTIFIER + "string/symbolic"));
316: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
317: "lockTimeAcquired", IDENTIFIER + "datetime"));
318: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
319: "lockDuration", IDENTIFIER + "long"));
320: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
321: "lockOwnerId", IDENTIFIER + "long"));
322: DEFAULT_AUTOCOMPLETE_ENTRIES
323: .add(new AutocompleteEntry("lockOwnerName", IDENTIFIER
324: + "string - not searchable"));
325: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
326: "lockOwnerLogin", IDENTIFIER + "string/symbolic"));
327: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
328: "collections", IDENTIFIER
329: + "string/symbolic - multivalue"));
330: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
331: "collections.valueCount", IDENTIFIER + "long"));
332: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry("score",
333: IDENTIFIER + "long - not searcheable"));
334: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
335: "variants", IDENTIFIER + "link - multivalue"));
336: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
337: "liveMajorChangeVersionId", IDENTIFIER + "long"));
338: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
339: "lastMajorChangeVersionId", IDENTIFIER + "long"));
340: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
341: "versionComment", IDENTIFIER + "string"));
342: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
343: "versionChangeType", IDENTIFIER + "string/symbolic"));
344: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
345: "referenceLanguage", IDENTIFIER + "string/symbolic"));
346: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
347: "referenceLanguageId", IDENTIFIER + "long"));
348: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
349: "syncedWith", IDENTIFIER + "link"));
350: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
351: "syncedWith.versionId", IDENTIFIER + "long"));
352: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
353: "syncedWith.languageId", IDENTIFIER + "long"));
354: DEFAULT_AUTOCOMPLETE_ENTRIES.add(new AutocompleteEntry(
355: "syncedWith.language", IDENTIFIER + "string/symbolic"));
356: }
357:
358: public void service(ServiceManager serviceManager)
359: throws ServiceException {
360: this .serviceManager = serviceManager;
361: }
362:
363: protected void processRequest(AppleRequest appleRequest,
364: AppleResponse appleResponse) throws Exception {
365: SiteConf siteConf = frontEndContext.getSiteConf();
366: Locale locale = frontEndContext.getLocale();
367: Repository repository = frontEndContext.getRepository();
368:
369: Form form = FormHelper.createForm(serviceManager,
370: "resources/form/querysearch_definition.xml");
371: boolean endProcessing = false;
372: if (request.getParameter("daisyquery") != null) { // if form is present on request
373: endProcessing = form.process(new FormContext(request,
374: locale));
375: } else {
376: // set a default query in the form
377: DocumentCollection collection = repository
378: .getCollectionManager().getCollection(
379: siteConf.getCollectionId(), false);
380: String branch = repository.getVariantManager().getBranch(
381: siteConf.getBranchId(), false).getName();
382: String language = repository.getVariantManager()
383: .getLanguage(siteConf.getLanguageId(), false)
384: .getName();
385: form
386: .getChild("daisyquery")
387: .setValue(
388: "select id, name where InCollection('"
389: + collection.getName()
390: + "') and documentType = 'SimpleDocument' and branch = "
391: + QueryHelper.formatString(branch)
392: + " and language = "
393: + QueryHelper
394: .formatString(language));
395: }
396:
397: Map<String, Object> viewData = new HashMap<String, Object>();
398: viewData.put("locale", locale);
399: viewData.put("autoCompleteEntries",
400: getAutocompleteEntries(repository));
401: viewData.put("pageContext", frontEndContext.getPageContext());
402: viewData.put("CocoonFormsInstance", form);
403:
404: boolean addToDocumentBasket = ((Boolean) form.getChild(
405: "addToDocumentBasket").getValue()).booleanValue();
406:
407: if (endProcessing) {
408: QueryManager queryManager = repository.getQueryManager();
409: SearchResultDocument searchResultDocument = queryManager
410: .performQuery((String) form.getChild("daisyquery")
411: .getValue(), locale);
412: viewData.put("pageXml", new XmlObjectXMLizable(
413: searchResultDocument));
414:
415: if (addToDocumentBasket) {
416: VariantManager variantManager = repository
417: .getVariantManager();
418: List<SearchResultDocument.SearchResult.Rows.Row> rows = searchResultDocument
419: .getSearchResult().getRows().getRowList();
420: DocumentBasketEntry[] entries = new DocumentBasketEntry[rows
421: .size()];
422: int i = 0;
423: for (SearchResultDocument.SearchResult.Rows.Row row : rows) {
424: String branch = variantManager.getBranch(
425: row.getBranchId(), false).getName();
426: String language = variantManager.getLanguage(
427: row.getLanguageId(), false).getName();
428: entries[i++] = new DocumentBasketEntry(row
429: .getDocumentId(), branch, language, -3, "");
430: }
431: DocumentBasketHelper.updateDocumentNames(entries,
432: request, repository);
433: DocumentBasketHelper.getDocumentBasket(request, true)
434: .appendEntries(entries);
435: }
436: }
437:
438: if (addToDocumentBasket)
439: appleResponse.redirectTo(getMountPoint() + "/"
440: + siteConf.getName() + "/documentBasket");
441: else
442: appleResponse.sendPage("Form-querysearch-Pipe", viewData);
443: }
444:
445: private List<AutocompleteEntry> getAutocompleteEntries(
446: Repository repository) throws RepositoryException {
447: List<AutocompleteEntry> entries = new ArrayList<AutocompleteEntry>(
448: DEFAULT_AUTOCOMPLETE_ENTRIES.size() + 100);
449: RepositorySchema schema = repository.getRepositorySchema();
450:
451: StringBuilder descr = new StringBuilder();
452:
453: for (FieldType fieldType : schema.getAllFieldTypes(false)
454: .getArray()) {
455: descr.setLength(0);
456: descr.append("field type: ");
457: descr.append(fieldType.getValueType());
458: if (fieldType.isMultiValue())
459: descr.append(" - multivalue");
460: if (fieldType.isHierarchical())
461: descr.append(" - hierarchical");
462: if (fieldType.isDeprecated())
463: descr.append(" - deprecated");
464: entries.add(new AutocompleteEntry(
465: "$" + fieldType.getName(), descr.toString()));
466: }
467:
468: for (PartType partType : schema.getAllPartTypes(false)
469: .getArray()) {
470: descr.setLength(0);
471: descr.append("part type");
472: if (partType.isDeprecated())
473: descr.append(" - deprecated");
474: entries.add(new AutocompleteEntry("%" + partType.getName(),
475: null));
476: }
477:
478: for (DocumentType documentType : schema.getAllDocumentTypes(
479: false).getArray()) {
480: descr.setLength(0);
481: descr.append("document type");
482: if (documentType.isDeprecated())
483: descr.append(" - deprecated");
484: entries.add(new AutocompleteEntry(documentType.getName(),
485: "document type"));
486: }
487:
488: for (DocumentCollection collection : repository
489: .getCollectionManager().getCollections(false)
490: .getArray()) {
491: entries.add(new AutocompleteEntry(collection.getName(),
492: "collection"));
493: }
494:
495: for (Branch branch : repository.getVariantManager()
496: .getAllBranches(false).getArray()) {
497: entries.add(new AutocompleteEntry(branch.getName(),
498: "branch"));
499: }
500:
501: for (Language language : repository.getVariantManager()
502: .getAllLanguages(false).getArray()) {
503: entries.add(new AutocompleteEntry(language.getName(),
504: "language"));
505: }
506:
507: entries.addAll(DEFAULT_AUTOCOMPLETE_ENTRIES);
508:
509: Collections.sort(entries);
510:
511: return entries;
512: }
513:
514: public static class AutocompleteEntry implements Comparable {
515: private String text;
516: private String description;
517: private String escapedText;
518: private String escapedDescription;
519:
520: public AutocompleteEntry(String text, String description) {
521: this .text = text;
522: this .description = description;
523: this .escapedText = XslUtil.escape(text);
524: this .escapedDescription = XslUtil.escape(description);
525: }
526:
527: public String getText() {
528: return text;
529: }
530:
531: public String getEscapedText() {
532: return escapedText;
533: }
534:
535: public String getDescription() {
536: return description;
537: }
538:
539: public String getEscapedDescription() {
540: return escapedDescription;
541: }
542:
543: public int compareTo(Object o) {
544: return this .text.compareTo(((AutocompleteEntry) o).text);
545: }
546: }
547: }
|