* * @author Arthur Schiwon * @author Christoph Wurst * @author Joas Schilling * @author John Molakvoæ * @author Roeland Jago Douma * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . * */ namespace OC\Core\Controller; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCSController as Controller; use OCP\Collaboration\AutoComplete\AutoCompleteEvent; use OCP\Collaboration\AutoComplete\IManager; use OCP\Collaboration\Collaborators\ISearch; use OCP\EventDispatcher\IEventDispatcher; use OCP\IRequest; use OCP\Share\IShare; class AutoCompleteController extends Controller { /** @var ISearch */ private $collaboratorSearch; /** @var IManager */ private $autoCompleteManager; /** @var IEventDispatcher */ private $dispatcher; public function __construct(string $appName, IRequest $request, ISearch $collaboratorSearch, IManager $autoCompleteManager, IEventDispatcher $dispatcher) { parent::__construct($appName, $request); $this->collaboratorSearch = $collaboratorSearch; $this->autoCompleteManager = $autoCompleteManager; $this->dispatcher = $dispatcher; } /** * @NoAdminRequired * * @param string $search * @param string $itemType * @param string $itemId * @param string|null $sorter can be piped, top prio first, e.g.: "commenters|share-recipients" * @param array $shareTypes * @param int $limit * @return DataResponse */ public function get($search, $itemType, $itemId, $sorter = null, $shareTypes = [IShare::TYPE_USER], $limit = 10): DataResponse { // if enumeration/user listings are disabled, we'll receive an empty // result from search() – thus nothing else to do here. [$results,] = $this->collaboratorSearch->search($search, $shareTypes, false, $limit, 0); $event = new AutoCompleteEvent([ 'search' => $search, 'results' => $results, 'itemType' => $itemType, 'itemId' => $itemId, 'sorter' => $sorter, 'shareTypes' => $shareTypes, 'limit' => $limit, ]); $this->dispatcher->dispatch(IManager::class . '::filterResults', $event); $results = $event->getResults(); $exactMatches = $results['exact']; unset($results['exact']); $results = array_merge_recursive($exactMatches, $results); if ($sorter !== null) { $sorters = array_reverse(explode('|', $sorter)); $this->autoCompleteManager->runSorters($sorters, $results, [ 'itemType' => $itemType, 'itemId' => $itemId, ]); } // transform to expected format $results = $this->prepareResultArray($results); return new DataResponse($results); } protected function prepareResultArray(array $results): array { $output = []; foreach ($results as $type => $subResult) { foreach ($subResult as $result) { $output[] = [ 'id' => (string) $result['value']['shareWith'], 'label' => $result['label'], 'icon' => $result['icon'] ?? '', 'source' => $type, 'status' => $result['status'] ?? '', 'subline' => $result['subline'] ?? '', ]; } } return $output; } } -annotation'>feature/bootstrap-annotation Vaadin 6, 7, 8 is a Java framework for modern Java web applications: https://github.com/vaadin/frameworkwww-data
aboutsummaryrefslogtreecommitdiffstats
blob: 1dec2e61acaa2b1ac8a3aa2ce3c173da34e60d2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
---
title: Logging
order: 13
layout: page
---

[[advanced.logging]]
= Logging

(((, id="term.advanced.logging", range="startofrange")))


You can do logging in Vaadin application using the standard
[package]#java.util.logging# facilities. Configuring logging is as easy as
putting a file named [filename]#logging.properties# in the default package of
your Vaadin application ( [filename]#src# in an Eclipse project or
[filename]#src/main/java# or [filename]#src/main/resources# in a Maven project).
This file is read by the [classname]#Logger# class when a new instance of it is
initialize.

[[advanced.logging.tomcat]]
== Logging in Apache Tomcat

For logging Vaadin applications deployed in Apache Tomcat, you do not need to do
anything special to log to the same place as Tomcat itself. If you need to write
the Vaadin application related messages elsewhere, just add a custom
[filename]#logging.properties# file to the default package of your Vaadin
application.

If you would like to pipe the log messages through another logging solution, see
<<advanced.logging.slf4j>> below.


[[advanced.logging.liferay]]
== Logging in Liferay

Liferay mutes logging through [package]#java.util.logging# by default. In order
to enable logging, you need to add a [filename]#logging.properties# file of your
own to the default package of your Vaadin application. This file should define
at least one destination where to save the log messages.

You can also log through SLF4J, which is used in and bundled with Liferay.
Follow the instructions in <<advanced.logging.slf4j>>.


[[advanced.logging.slf4j]]
== Piping to Log4j using SLF4J

((("Log4j")))
((("SLF4J")))
Piping output from [package]#java.util.logging# to Log4j is easy with SLF4J (
http://slf4j.org/). The basic way to go about this is to add the SLF4J JAR file
as well as the [filename]#jul-to-slf4j.jar# file, which implements the bridge
from [package]#java.util.logging#, to SLF4J. You will also need to add a third
logging implementation JAR file, that is, [filename]#slf4j-log4j12-x.x.x.jar#,
to log the actual messages using Log4j. For more info on this, please visit the
SLF4J site.

In order to get the [package]#java.util.logging# to SLF4J bridge installed, you
need to add the following snippet of code to your [classname]#UI# class at the
very top:

//TODO: Sure it's UI class and not the servlet?

[source, java]
----
  static {
    SLF4JBridgeHandler.install();
  }
----

This will make sure that the bridge handler is installed and working before
Vaadin starts to process any logging calls.


[WARNING]
.Please note!
====
This can seriously impact on the cost of disabled logging statements (60-fold
increase) and a measurable impact on enabled log statements (20% overall
increase). However, Vaadin doesn't log very much, so the effect on performance
will be negligible.

====




[[advanced.logging.core]]
== Using Logger

You can do logging with a simple pattern where you register a static logger
instance in each class that needs logging, and use this logger wherever logging
is needed in the class. For example:


[source, java]
----
public class MyClass {
  private final static Logger logger =
          Logger.getLogger(MyClass.class.getName());

  public void myMethod() {
    try {
      // do something that might fail
    } catch (Exception e) {
      logger.log(Level.SEVERE, "FAILED CATASTROPHICALLY!", e);
    }
  }
}
----
ifdef::vaadin7[]

((("static")))
((("memory
leak")))
((("PermGen")))
Having a [literal]#++static++# logger instance for each class needing logging
saves a bit of memory and time compared to having a logger for every logging
class instance. However, it could cause the application to leak PermGen memory
with some application servers when redeploying the application. The problem is
that the [classname]#Logger# may maintain hard references to its instances. As
the [classname]#Logger# class is loaded with a classloader shared between
different web applications, references to classes loaded with a per-application
classloader would prevent garbage-collecting the classes after redeploying,
hence leaking memory. As the size of the PermGen memory where class object are
stored is fixed, the leakage will lead to a server crash after many
redeployments. The issue depends on the way how the server manages classloaders,
on the hardness of the back-references.
So, if you experience PermGen issues, or want to play it on the safe
side, you should consider using non-static [classname]#Logger# instances.
//As discussed in Forum thread 1175841 (24.2.2012).
endif::vaadin7[]


(((range="endofrange", startref="term.advanced.logging")))