Merge pull request #281 from ankurkaushal/master

Reformat according to google style guide
This commit is contained in:
Ilkka Seppälä
2015-11-02 21:39:17 +02:00
438 changed files with 8257 additions and 8382 deletions

View File

@ -1,20 +1,16 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional information regarding
* copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
* copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package domainapp.webapp;
@ -53,6 +49,7 @@ import de.agilecoders.wicket.themes.markup.html.bootswatch.BootswatchThemeProvid
*
* <p>
* See:
*
* <pre>
* &lt;filter>
* &lt;filter-name>wicket&lt;/filter-name>
@ -67,87 +64,96 @@ import de.agilecoders.wicket.themes.markup.html.bootswatch.BootswatchThemeProvid
*/
public class SimpleApplication extends IsisWicketApplication {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
/**
* uncomment for a (slightly hacky) way of allowing logins using query args, eg:
*
* <tt>?user=sven&pass=pass</tt>
*
* <p>
* for demos only, obvious.
*/
private final static boolean DEMO_MODE_USING_CREDENTIALS_AS_QUERYARGS = false;
/**
* uncomment for a (slightly hacky) way of allowing logins using query args, eg:
*
* <tt>?user=sven&pass=pass</tt>
*
* <p>
* for demos only, obvious.
*/
private final static boolean DEMO_MODE_USING_CREDENTIALS_AS_QUERYARGS = false;
@Override
protected void init() {
super.init();
@Override
protected void init() {
super.init();
IBootstrapSettings settings = Bootstrap.getSettings();
settings.setThemeProvider(new BootswatchThemeProvider(BootswatchTheme.Flatly));
IBootstrapSettings settings = Bootstrap.getSettings();
settings.setThemeProvider(new BootswatchThemeProvider(BootswatchTheme.Flatly));
}
@Override
public Session newSession(final Request request, final Response response) {
if (!DEMO_MODE_USING_CREDENTIALS_AS_QUERYARGS) {
return super.newSession(request, response);
}
@Override
public Session newSession(final Request request, final Response response) {
if(!DEMO_MODE_USING_CREDENTIALS_AS_QUERYARGS) {
return super.newSession(request, response);
}
// else demo mode
final AuthenticatedWebSessionForIsis s = (AuthenticatedWebSessionForIsis) super.newSession(request, response);
IRequestParameters requestParameters = request.getRequestParameters();
final org.apache.wicket.util.string.StringValue user = requestParameters.getParameterValue("user");
final org.apache.wicket.util.string.StringValue password = requestParameters.getParameterValue("pass");
s.signIn(user.toString(), password.toString());
return s;
// else demo mode
final AuthenticatedWebSessionForIsis s =
(AuthenticatedWebSessionForIsis) super.newSession(request, response);
IRequestParameters requestParameters = request.getRequestParameters();
final org.apache.wicket.util.string.StringValue user =
requestParameters.getParameterValue("user");
final org.apache.wicket.util.string.StringValue password =
requestParameters.getParameterValue("pass");
s.signIn(user.toString(), password.toString());
return s;
}
@Override
public WebRequest newWebRequest(HttpServletRequest servletRequest, String filterPath) {
if (!DEMO_MODE_USING_CREDENTIALS_AS_QUERYARGS) {
return super.newWebRequest(servletRequest, filterPath);
}
@Override
public WebRequest newWebRequest(HttpServletRequest servletRequest, String filterPath) {
if(!DEMO_MODE_USING_CREDENTIALS_AS_QUERYARGS) {
return super.newWebRequest(servletRequest, filterPath);
}
// else demo mode
try {
String uname = servletRequest.getParameter("user");
if (uname != null) {
servletRequest.getSession().invalidate();
}
} catch (Exception e) {
}
WebRequest request = super.newWebRequest(servletRequest, filterPath);
return request;
// else demo mode
try {
String uname = servletRequest.getParameter("user");
if (uname != null) {
servletRequest.getSession().invalidate();
}
} catch (Exception e) {
}
@Override
protected Module newIsisWicketModule() {
final Module isisDefaults = super.newIsisWicketModule();
final Module overrides = new AbstractModule() {
@Override
protected void configure() {
bind(String.class).annotatedWith(Names.named("applicationName")).toInstance("Simple App");
bind(String.class).annotatedWith(Names.named("applicationCss")).toInstance("css/application.css");
bind(String.class).annotatedWith(Names.named("applicationJs")).toInstance("scripts/application.js");
bind(String.class).annotatedWith(Names.named("welcomeMessage")).toInstance(readLines(getClass(), "welcome.html"));
bind(String.class).annotatedWith(Names.named("aboutMessage")).toInstance("Simple App");
bind(InputStream.class).annotatedWith(Names.named("metaInfManifest")).toProvider(Providers.of(getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF")));
}
};
WebRequest request = super.newWebRequest(servletRequest, filterPath);
return request;
}
return Modules.override(isisDefaults).with(overrides);
}
@Override
protected Module newIsisWicketModule() {
final Module isisDefaults = super.newIsisWicketModule();
private static String readLines(final Class<?> contextClass, final String resourceName) {
try {
List<String> readLines = Resources.readLines(Resources.getResource(contextClass, resourceName), Charset.defaultCharset());
final String aboutText = Joiner.on("\n").join(readLines);
return aboutText;
} catch (IOException e) {
return "This is a simple app";
}
final Module overrides = new AbstractModule() {
@Override
protected void configure() {
bind(String.class).annotatedWith(Names.named("applicationName")).toInstance("Simple App");
bind(String.class).annotatedWith(Names.named("applicationCss")).toInstance(
"css/application.css");
bind(String.class).annotatedWith(Names.named("applicationJs")).toInstance(
"scripts/application.js");
bind(String.class).annotatedWith(Names.named("welcomeMessage")).toInstance(
readLines(getClass(), "welcome.html"));
bind(String.class).annotatedWith(Names.named("aboutMessage")).toInstance("Simple App");
bind(InputStream.class).annotatedWith(Names.named("metaInfManifest")).toProvider(
Providers.of(getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF")));
}
};
return Modules.override(isisDefaults).with(overrides);
}
private static String readLines(final Class<?> contextClass, final String resourceName) {
try {
List<String> readLines =
Resources.readLines(Resources.getResource(contextClass, resourceName),
Charset.defaultCharset());
final String aboutText = Joiner.on("\n").join(readLines);
return aboutText;
} catch (IOException e) {
return "This is a simple app";
}
}
}