Getting a popup for downloading the font file(ttf) in a spring-boot application - css

I'm getting a popup for downloading the fonts files(ttf) in a spring-boot application, the font file is related to bootstrap3.
I tried to add MimeTypes like this but still getting the popup for first time I open the application.
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.context.embedded.MimeMappings;
import org.springframework.stereotype.Component;
#Component
public class ServletCustomizer implements EmbeddedServletContainerCustomizer {
#Override
public void customize(ConfigurableEmbeddedServletContainer container) {
MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
mappings.add("woff","application/x-font-woff");
mappings.add("eot","application/vnd.ms-fontobject");
mappings.add("ttf","application/x-font-ttf");
container.setMimeMappings(mappings);
}
}
I'm using Spring-boot 1.3.3.RELEASE+thymeleaf.
Anyone know how to resolve this issue?

I resolved the issue by adding this line to my security config
http.authorizeRequests().antMatchers("/fonts/**").permitAll();

Related

How to Access JavaFX Virtual Keyboard (FXVK) Using Open JDK 15 or beyond?

I use the javafx virtual keyboard with open jdk 8. At times I have to access the virtual keyboard to prevent it from displaying when certain text fields get focus. An example of this is a screen where an operator has to scan in multiple barcodes. This virtual keyboard gets in the way. With open jdk 8 we were able to disable the virtual keyboard like this:
FXVK.detach(); //after importing "com.sun.javafx.scene.control.skin.FXVK"
We are now upgrading to open jdk 15 and building our UI with gradle. "com.sun.javafx.scene.control.skin.FXVK" is no longer accessible with a modular project with gradle. I don't believe using a different virtual keyboard is an option so can anyone explain how to access this FXVK class after java 8?
Is there a way to use --add-exports or --patch-module with a JAR to patch JavaFX to gain access to the internal class?
Below is the code for a sample project that shows this problem.
This is the JavaFX Application class that simply displays a text field and shows the code I could use with java 8 to not show the virtual keyboard.
package com.test.sampleapp.application;
////not accessible in java 15
//import com.sun.javafx.scene.control.skin.FXVK;
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class Main extends Application{
public static void main(String[] args)
{
launch(args);
}
#Override
public void start(Stage primaryStage) throws Exception
{
Label label = new Label("Text field below");
TextField textField = new TextField();
VBox vbox = new VBox(label);
vbox.getChildren().add(textField);
Scene scene = new Scene(vbox);
primaryStage.setScene(scene);
primaryStage.show();
textField.focusedProperty().addListener(new ChangeListener<Boolean>()
{
#Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue,
Boolean newValue)
{
// If focused
if (newValue)
{
//Need this to disable the virtual keyboard when using a textfield with scanning
//FXVK.detach();
}
}
});
}
}
Then I needed to add a wrapper class to have the virtual keyboard show up. Please note that most of the time I do use the virtual keyboard when text fields get focus, it's other times where I need to be able to programmatically disable it during certain situations.
The wrapper class:
package com.test.sampleapp.application;
import java.lang.reflect.Method;
public class AppWrapper
{
public static void main(String[] args) throws Exception
{
Class<?> app = Class.forName("com.test.sampleapp.application.Main");
Method main = app.getDeclaredMethod("main", String[].class);
System.setProperty("com.sun.javafx.isEmbedded", "true");
System.setProperty("com.sun.javafx.touch", "true");
System.setProperty("com.sun.javafx.virtualKeyboard", "javafx");
Object[] arguments = new Object[]{args};
main.invoke(null, arguments);
}
}
Let me know if you need anything else such as the build.gradle file however this is mostly just an issue using java 9 or beyond.
The FXVK class still exists in the same package, so the only issue is that its package is not exported by the javafx.controls module. If you must use this internal class, then you can pass an appropriate --add-exports JVM argument both at compile-time and at run-time.
Here's a simple application that calls FXVK#detach():
// Will fail at compile-time if the '--add-exports` argument is not
// passed to 'javac'
import com.sun.javafx.scene.control.skin.FXVK;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class Main extends Application {
#Override
public void start(Stage primaryStage) {
var root = new StackPane(new Label("Hello, World!"));
primaryStage.setScene(new Scene(root, 600, 400));
primaryStage.show();
// Will fail at run-time if the '--add-exports' argument is
// not passed to 'java'
FXVK.detach();
}
}
Assuming you put the Main.java file in your working directory, you can compile it with:
javac -p <path-to-fx> --add-modules javafx.controls --add-exports javafx.controls/com.sun.javafx.scene.control.skin=ALL-UNNAMED Main.java
And run it with:
java -p <path-to-fx> --add-modules javafx.controls --add-exports javafx.controls/com.sun.javafx.scne.control.skin=ALL-UNNAMED Main
If your code is modular then you can get rid of the --add-modules and you must change ALL-UNNAMED to the name of your module. Plus, make sure to launch your application via --module (or -m). Note the -p above is shorthand for --module-path.
If you use a build tool (e.g., Maven, Gradle, etc.), then you'll have to lookup how to set these JVM arguments for that tool. You'll also have to take into account how you deploy your application. For instance, if you use jpackage then you can use its --java-options argument to set the --add-exports option for when your application is launched.
You may also need to tell your IDE that you are giving yourself access to the internal package. Otherwise, your IDE will likely yell at you for trying to use an inaccessible type.

error: cannot find symbol FirebaseAdMobPlugin.registerNativeAdFactory(flutterEngine, "moviesTorrentAdFactory", NativeAdFactoryExample());

I'm using flutter , and I tried to use Native Ads following this doc
all ads are working fine but Native ad doesn't work and it fails building the app showing this error
error: cannot find symbol FirebaseAdMobPlugin.registerNativeAdFactory(flutterEngine, "moviesTorrentAdFactory", NativeAdFactoryExample());
this is MyActivity.java file :
package tech.devm.movies_torrent;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.firebaseadmob.FirebaseAdMobPlugin;
import com.google.android.gms.ads.formats.UnifiedNativeAd;
import com.google.android.gms.ads.formats.UnifiedNativeAdView;
import io.flutter.plugins.firebaseadmob.FirebaseAdMobPlugin.NativeAdFactory;
import java.util.Map;
public class MainActivity extends FlutterActivity {
#Override
public void configureFlutterEngine(FlutterEngine flutterEngine) {
flutterEngine.getPlugins().add(new FirebaseAdMobPlugin());
FirebaseAdMobPlugin.registerNativeAdFactory(flutterEngine, "moviesTorrentAdFactory", NativeAdFactoryExample());
}
#Override
public void cleanUpFlutterEngine(FlutterEngine flutterEngine) {
FirebaseAdMobPlugin.unregisterNativeAdFactory(flutterEngine, "moviesTorrentAdFactory");
}
}
class NativeAdFactoryExample implements NativeAdFactory {
#Override
public UnifiedNativeAdView createNativeAd(
UnifiedNativeAd nativeAd, Map<String, Object> customOptions) {
// Create UnifiedNativeAdView
}
}
is there should be any changes to Manifest.xml file ? or am I missing something ?
I've cleared the build using (flutter clean ) many times but nothing works
any help would be much appreciated
I was also having the exact same issue. This is how I fix it!
Seems that this error is related with the NativeAdFactory file (eg: ListTileNativeAdFactory.java) and the layout at app/src/main/res/layout/list_title_native_ad.xml
If you go to the Google Codelabs example at https://github.com/googlecodelabs/admob-inline-ads-in-flutter/tree/main/complete and copy those files exactly like the example you will solve that problem.

JxBrowser does not launch from another class

I have a problem that I cannot launch my JxBrowser from another class but it works fine on its own class. I will give the code for the internet browser class here
import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.swing.BrowserView;
import javax.swing.*;
import java.awt.*;
public class InternetBrowser
{
//properties
Browser browser;
BrowserView browserView;
JFrame frame;
//constructor
public InternetBrowser()
{
browser = new Browser();
browserView = new BrowserView(browser);
frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(browserView, BorderLayout.CENTER);
frame.setSize(500, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
browser.loadURL("https://www.youtube.com/embed/bO7yYDIOuXo");
}
public static void main( String [] args )
{
InternetBrowser browser = new InternetBrowser();
}
}
The error that I get is
Class StartIPCTask is implemented in both /private/var/folders/cs/1z68c1xs2q3crwrwm__fx_t80000gn/T/jxmaps-chromium-49.0.2623.110.unknown/data/Temp/libjxmaps-common64-397f2f15-9ac5-4806-91f6-88c8aaa29714.dylib (0x1288d5630) and /private/var/folders/cs/1z68c1xs2q3crwrwm__fx_t80000gn/T/browsercore-64.0.3282.24.6.21/data/Temp/libbrowsercore-common64-01e73e7f-2b85-4bd3-ac76-05d908fa4928.dylib (0x16b2576c8). One of the two will be used. Which one is undefined.
I need to define which one of the directories that the class should use but I do not know how. I am using the latest version of Netbeans. Also at the top of the class that im trying to construct a browser, the imports are highlighted as "unused import". Thank you for your help!
I realized that this is a bug seen in OSX.. The program works without any problem in windows computers.
In general, this warning doesn't affect the program, so you can just ignore it. If you don't want to receive it at all, then please try using the jxbrowser.jni.singleton.fix=false VM parameter.

Configure Spring MVC application to make changes to html files/templates without recompiling

I have a very simple Spring 4.0 Boot project. I would like to start the application and be able to make changes to the html files located in /templates/ on the fly, without having to stop and restart the application. Changes to static assets, like java scripts or css files, is no problem.
Below are the details of my program:
There are no XML configuration files. This class is used for configuration.
#Configuration
public class MVCConfiguration extends WebMvcConfigurerAdapter{
#Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("assets/**")
.addResourceLocations("classpath:/templates/assets/");
registry.addResourceHandler("/css/**")
.addResourceLocations("/css/");
registry.addResourceHandler("/img/**")
.addResourceLocations("/img/");
registry.addResourceHandler("/js/**")
.addResourceLocations("/js/");
}
}
This is my controller.
#Controller
public class ControlFreak {
#RequestMapping(value = "/", method = RequestMethod.GET)
public String index(){
return "index";
}
}
I have index.html located in templates/
I run the application using this class.
#Configuration
#EnableAutoConfiguration
#ComponentScan
public class Application {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(Application.class, args);
}
}
What you are trying to achieve is easily done using an IDE and will save a heck of a lot of time during development.
First of all you need to configure Spring Boot to not cache Thymeleaf templates by setting:
spring.thymeleaf.cache=false
Then you just need to start the application using the IDE in debug mode (just Debug the class with the main method) and whenever you make change to a Thymeleaf Template you just need to instruct the IDE to reload the project.
In IntelliJ IDEA, that is done from the Reload Changed Classes option in the Run menu.
I think you can configure Eclipse to automatically update the project on each change, but it's been a while since I have used it.
Path to project
project.base-dir=file:///C:/temp/auth/
Templates reloading during development
spring.thymeleaf.prefix=${project.base-dir}/src/main/resources/templates/
spring.thymeleaf.cache=false
Static resources reloading during development
spring.resources.static-locations=${project.base-dir}/src/main/resources/static/
spring.resources.cache-period=0

How to use fonts in external SWF files

What I would like to do is a flex app, that uses fonts that are available in external swf.
What I have succeded so far is:
to create a AS class hat holds the embedded font:
package
{
import flash.display.Sprite;
public class _Arial extends Sprite
{
[Embed(source='C:/WINDOWS/Fonts/ARIAL.TTF', fontName='_Arial', unicodeRange='U+0020-U+002F,U+0030-U+0039,U+003A-U+0040,U+0041-U+005A,U+005B-U+0060,U+0061-U+007A,U+007B-U+007E')]
public static var _MyArial:Class;
}
}
compiled this into a swf with following command: mxmlc.exe -static-link-runtime-shared-libraries=true _Arial.as
When I try to load the font from my flex app, this fails with following error message:
ArgumentError: Error #1508: The value specified for argument font is invalid.
at flash.text::Font$/registerFont()
at valueObjects::FontLoader/fontLoaded()[C:\Documents and Settings\nutrina\Adobe Flash Builder 4\flex_pdf\src\valueObjects\FontLoader.as:33]
This is the code where I try to load the SWF file:
package
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
import flash.text.*;
import mx.collections.ArrayCollection;
import mx.core.FontAsset;
public class FontLoader extends Sprite {
public function FontLoader(url:String) {
super();
loadFont(url);
}
private function loadFont(url:String):void {
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, fontLoaded);
loader.load(new URLRequest(url));
}
private function fontLoaded(event:Event):void {
var fontList:ArrayCollection = new ArrayCollection(Font.enumerateFonts(true));
var FontLibrary:Class = event.target.applicationDomain.getDefinition("_Arial") as Class;
trace("FontList: " + fontList)
trace("FontLibrary: " + FontLibrary)
trace("FontLibrary._Arial: " + FontLibrary._MyArial)
Font.registerFont(FontLibrary._MyArial);
fontList = new ArrayCollection(Font.enumerateFonts(true));
trace("Font list: " + fontList)
}
}
}
The font file is definitely not corrupt because if I put the _Arial class from the code above into the Flex application, the embedding works. So my guess is that probably I missed some compilation options?
I am using Adobe Flash Builder 4.
I would appreciate any help on this matter.
Thanks,
Gerald
Could be a problem with class name conflicts. I wrestled with an external font loading issue for hours. Turns out my font class was called "Main", and so was the application that was trying to load it. The font never got registered correctly.

Resources