User Profiles using properties in Java - java

I am making a math game in Java and I want to create the ability for the user to create a local account (or log in to an existing one), which would have a unique properties file. How would I do this?

You have a couple of options to look into. Java comes with the necessary libraries with which you can create, open, read and write to files. Using the File class, you could create an account file, for instance "User1.properties", and save the information in an easy to parse format. If you're looking to go one further, you can look into using XML or JSON, which are commonly used formats for saving information in this way. Here's some helpful links to get you started.
Using files in Java
Using XML in Java
Using JSON in Java
Another option you have available is to use a database in a similar fashion to websites. The type of database you use is up to you, although MySQL is an example of one commonly used database. Once again, here is a link to help you get started with MySQL in Java.
Regardless of what you use, you will need to take the username and password provided (or whatever combination of login credentials you would like your system to use), and compare them with those stored in your file or database.

Related

Can I implement impex from java in hybris

I want to create an impex from java in hybris, because my requirement is to add the featureproperty dynamically , instead of doing it from HMC.
I have never done impex from code and I have seen no example on the internet for reference,
If impex cannot be done from java then what is the best bet for me to make it dynamic.
I am new to hybris. Any reference or hint will do for me. Please help,
Thank you
Impex is used for importing and exporting data. You have multiple options to import data using Impex files.
Manual import during Initialization/Update process
The Initialization/Update process is used to create all data, that is needed for starting the platform. During this process hybris creates tables/columns in the database, the type system and it also imports data. This data is classified as "Essential Data" that is essential for the system to start (like currencies, languages, users), and project data, which is necessary for a specific extension to run. When you want to use the accelerator, all the data, that is needed is created in the myacceleratorinitialdata extension. With this extension you can create a basic web shop (like web sites, stores, catalogs) and even sample data (like sample products/prices/stock, sample cms pages/components, sample media items).
Using hot folder
The hot folder is often used for automatic/periodic import of data. On the servers hard drive there is a folder which is monitored for changes. When a CSV file is put to this folder, the data in this folder is imported into the database. However you have to configure how it is imported. It is often used to import updates for product, price or stock data.
Manual import by uploading file in the hybris admin console
In the hybris admin console there is a page where you can import a snippet of impex content. It is often used to do mainenance work (like manually disabling a number of products). The default URL pointing to that service is:
https://localhost:9002/console/impex/import
Impex API
If you REALLY need to import Impex data via Java code, there is an API:
https://help.hybris.com/6.5.0/hcd/8bee24e986691014b97bcd2c7e6ff732.html
In my many years of writing hybris applications, I never had to use this API. Often it is more suitable to use one of the above mentioned mechanisms OR the ModelService (see below).
Keep in mind, that every data item you want to create, can be created using the ModelService. It's very simple to write data to the database using the ModelService. Here is an simplified example for how to create a new product using the ModelService:
ProductModel product = modelService.create(ProductModel.class);
product.setCode("123");
product.setDescription("A product imported using ModelService");
product.setCatalogVersion(catalogVersion);
modelService.save(product);
For every data type, there is a Java class with the suffix "Model" (e.g. ProductModel, StockLevelModel, PriceRowModel, MediaModel). These model classes have getter and setter methods for every attribute of that data type (e.g. product.setCode(...)). Even relations to other data types can be retrieved/saved using getter/setter methods (e.g. product.setCatalogVersion(...)).
We can create impex using Java springs. You can check hot folder implementation where impex is generated through the OOTB java classes.
you can check in yaccelerator core integration spring files for better understanding.

How to store setting credentials in Java?

I am making a school management project and I want to add a setting panel in my project, but unable to determine how to store the settings for a project in java?
how can i make it possible?
Easiest way would be with the Preferences API. You can save and load things without worrying how they're stored.
You can use many different things to store persistent data. Persistent means data will be stored after your app stopped running.
XML file:
JAXB
A database like: JAVA SQL
JSON file: JSON API
Java Properties: Properties Docs
However I recommend you JAXB, because I think it is the easiest way.

Best way to get values from a external file in java

I have a java code which I'm currently running as a jar. This code checks for a specific file in the given directory which is currently hard coded in the code.
To give more flexibility and not to touch the code. I would like to have the folers list managed by a different file and the code reads this config file and gets the list of folders each time and execute it.
I would like to know which is the best possible option of maintaining the folder list outside the code so that anyone can update it. Can a properties be used for this ? can we dynamically take values from a property file
In Java you have the java.util.Properties that allow you to load flat key/value data from external resources.
If you need something that can be dynamically updated, there's also the more sophisticated Preferences library. This one allows you to:
Keep data organized in tree structures (it's a tree of nodes, each node storing its own key/value preferences).
Make use of basic types (primitive types, strings and binary data).
Make use of platform-dependent "native" stores transparently (under the hood, it's going to use the file system on Unix systems and registries on Windows by default).
Plug in your own backing store if needed.
Get any data changes performed within the application persisted transparently.
Register node/preference change listeners and react to any change if needed.
The API is quite old and hasn't been updated, but it doesn't mean it's deprecated. It is used mostly with GUI applications (notably, IntelliJ IDEA was storing its configuration using Preferences the last time I checked).
There's also an attempt to revive this library that I made with a project called cross-preferences by integrating modern distributed config stores (such as zookeeper, etcd or consul) as backing stores for java.util.prefs.Preferences and providing a web console for preference management.

Perfomance of XSLT-includes vs XSLT-extesions with Java

I have a big XML file that lacks information, most of these data are codes and I need to generate a PDF file with the descriptions.
On the other hand, I have all descriptions needed accesible from my java application, the question is: What of the following options is most fast?
Using XSTL-extension for access to the information storaged in a Map
Using XSTL-extension for access to the information storaged in a local database
Using XSTL-include for read a file generated by my java process that contains variables with name=ids and Select=descriptions.
I'm worried about the performance because I'm talking about a lot of ids (data).
I had the same problem few time ago and I decided to use your third option:
Using XSTL-include for read a file generated by my java process that contains variables with name=ids and Select=descriptions.
because in this way yo can be indepedent of you core, not like with extensions.

Properties location

I need to create a properties file to store username/passwords for DBs and other websites for my application.
Is there a good place to put this?
I was thinking of putting in /usr/local/myapp/myapp.properties
However...this doesnt really make much sense for Windows boxes. However, I don't want to store it under a particular user's account as I want it to be global for all users.
Any thoughts?
Store it wherever you like, and point your application to it via a vm parameter: -Dproperties.location=/usr/local/...
Then you can read it with System.getProperty("properties.location")
If you use the built-in Preferences class, the values will be automatically saved in the appropriate place on the user's system.
Edit:
Oops, I missed the "global to all users" requirement. This will not work on all systems in that case.
I have written on this property framework for the last year.
It will provide of multiple ways to load properties, and have them strongly typed as well. Which also include a way to encrypt/decrypt a password property.
Have a look at http://sourceforge.net/projects/jhpropertiestyp/
JHPropertiesTyped will give the developer strongly typed properties.
Easy to integrate in existing projects.
Handled by a large series for property types.
Gives the ability to one-line initialize properties via property IO implementations.
Gives the developer the ability to create own property types and property io's.
Web demo is also available, screenshots shown above.
Also have a standard implementation for a web front end to manage properties, if you choose to use it.
Complete documentation, tutorial, javadoc, faq etc is a available on the project webpage.

Categories