use of com.servoy.j2db.dataprocessing.JSDataSet in project servoy-client by Servoy.
the class JSI18N method getSystemMessages.
/**
* Returns a dataset with rows that contains 3 columns: 'key' (i18n key), 'reference' (reference text for that key) and 'locale ([CURRENT_LOCALE])' (where [CURRENT_LOCALE] is the current language) - with the system messages of servoy.
* This means all servoy messages, with all available translations.
*
* @sample
* var set = i18n.getSystemMessages();
* for(var i=1;i<=set.getMaxRowIndex();i++)
* {
* application.output(set.getValue(i, 1) + " " + set.getValue(i, 2)+ " " + set.getValue(i, 3));
* }
*
* @return a JSDataSet with all the system messages.
*/
@JSFunction
public JSDataSet getSystemMessages() {
Locale locale = application.getLocale();
TreeMap<Object, Object> defaultJarMessages = new TreeMap<Object, Object>();
try {
Properties properties = new Properties();
// $NON-NLS-1$
properties.load(Messages.class.getClassLoader().getResourceAsStream("com/servoy/j2db/messages.properties"));
defaultJarMessages.putAll(properties);
} catch (Exception e) {
// Debug.error(e);
}
Properties currentLocaleJarMessages = new Properties();
try {
currentLocaleJarMessages.load(// $NON-NLS-1$ //$NON-NLS-2$
Messages.class.getClassLoader().getResourceAsStream("com/servoy/j2db/messages_" + locale.getLanguage() + ".properties"));
} catch (Exception e) {
// Debug.error(e);
}
try {
// $NON-NLS-1$ //$NON-NLS-2$
currentLocaleJarMessages.load(Messages.class.getClassLoader().getResourceAsStream("com/servoy/j2db/messages_" + locale + ".properties"));
} catch (Exception e) {
// Debug.error(e);
}
Object[][] rowData = new Object[defaultJarMessages.size()][3];
int k = 0;
Iterator<Entry<Object, Object>> it = defaultJarMessages.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<Object, Object> entry = it.next();
Object key = entry.getKey();
rowData[k][0] = key;
rowData[k][1] = entry.getValue();
rowData[k][2] = currentLocaleJarMessages.get(key);
k++;
}
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$//$NON-NLS-4$
String[] cols = new String[] { "key", "reference", "locale (" + locale.getDisplayLanguage(locale) + ")" };
BufferedDataSet set = new BufferedDataSet(cols, Arrays.asList(rowData));
return new JSDataSet(application, set);
}
use of com.servoy.j2db.dataprocessing.JSDataSet in project servoy-client by Servoy.
the class JSI18N method getLanguages.
/**
* Returns a dataset with rows that contains a language key (en) and the displayname (English) column.
*
* See http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt for a list that could be returned.
*
* @sample
* var set = i18n.getLanguages();
* for(var i=1;i<=set.getMaxRowIndex();i++)
* {
* application.output(set.getValue(i, 1) + " " + set.getValue(i, 2));
* }
*
* @return a JSDataSet with all the languages.
*
* @link http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt
*/
@JSFunction
public JSDataSet getLanguages() {
Locale[] locales = Locale.getAvailableLocales();
TreeMap<String, String> languages = new TreeMap<String, String>(StringComparator.INSTANCE);
for (Locale element : locales) {
String name = element.getDisplayLanguage(element);
languages.put(element.getLanguage(), name);
}
ArrayList<Object[]> list = new ArrayList<Object[]>();
Iterator<Entry<String, String>> it = languages.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, String> entry = it.next();
list.add(new Object[] { entry.getKey(), entry.getValue() });
}
// $NON-NLS-1$ //$NON-NLS-2$
BufferedDataSet set = new BufferedDataSet(new String[] { "language_key", "language_name" }, list);
return new JSDataSet(application, set);
}
use of com.servoy.j2db.dataprocessing.JSDataSet in project servoy-client by Servoy.
the class WebFormUI method getFormContext.
@Override
public JSDataSet getFormContext() {
IDataSet set = new // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$//$NON-NLS-5$//$NON-NLS-6$
BufferedDataSet(// $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$//$NON-NLS-5$//$NON-NLS-6$
new String[] { "windowname", "formname", "containername", "tabname", "tabindex", "tabindex1based" }, new ArrayList<Object[]>());
set.addRow(new Object[] { null, formController.getName(), null, null, null, null });
Object currentContainer = parentContainerOrWindowName;
WebFormUI currentForm = this;
while (currentContainer instanceof WebFormComponent) {
WebFormComponent currentComponent = (WebFormComponent) currentContainer;
int index = currentComponent.getFormIndex(currentForm);
currentForm = currentComponent.findParent(WebFormUI.class);
if (currentForm != null) {
set.addRow(0, new Object[] { null, currentForm.formController.getName(), currentComponent.getName(), null, new Integer(index), new Integer(index + 1) });
currentContainer = currentForm.getParentContainer();
} else {
currentContainer = null;
}
}
if (currentContainer instanceof String) {
// fill in window name
for (int i = 0; i < set.getRowCount(); i++) {
set.getRow(i)[0] = currentContainer;
}
}
return new JSDataSet(formController.getApplication(), set);
}
use of com.servoy.j2db.dataprocessing.JSDataSet in project servoy-client by Servoy.
the class JSSecurity method js_getElementUUIDs.
/**
* Returns the form elements UUID's as dataset, the one with no name is the form itself.
*
* @sample var formElementsUUIDDataSet = security.getElementUUIDs('orders_form');
*
* @param formname the formname to retieve the dataset for
* @return dataset with element info
*/
public // return dataset with name, uuid (note: null name is form uuid)
JSDataSet js_getElementUUIDs(// return dataset with name, uuid (note: null name is form uuid)
String formname) {
Form f = application.getFlattenedSolution().getForm(formname);
if (f == null)
f = application.getFormManager().getPossibleForm(formname);
if (f != null) {
List elements = new ArrayList();
elements.add(new Object[] { null, f.getUUID() });
Iterator<? extends IPersist> it = f.isResponsiveLayout() ? f.getFlattenedObjects(NameComparator.INSTANCE).iterator() : f.getAllObjects();
while (it.hasNext()) {
IPersist elem = it.next();
int type = elem.getTypeID();
if (type == IRepository.GRAPHICALCOMPONENTS || type == IRepository.FIELDS || type == IRepository.PORTALS || type == IRepository.RECTSHAPES || type == IRepository.SHAPES || type == IRepository.BEANS || type == IRepository.TABPANELS || type == IRepository.WEBCOMPONENTS) {
if (elem instanceof ISupportName && ((ISupportName) elem).getName() != null) {
elements.add(new Object[] { ((ISupportName) elem).getName(), elem.getUUID() });
}
}
}
IDataSet set = new BufferedDataSet(new String[] { "name", "uuid" }, elements);
return new JSDataSet(application, set);
}
return new JSDataSet(application);
}
use of com.servoy.j2db.dataprocessing.JSDataSet in project servoy-client by Servoy.
the class JSSecurity method js_setSecuritySettings.
/**
* Sets the security settings; the entries contained in the given dataset will override those contained in the current security settings.
*
* NOTE: The security.getElementUUIDs and security.setSecuritySettings functions can be used to define custom security that overrides Servoy security.
* For additional information see the function security.getElementUUIDs.
*
* @sample
* var colNames = new Array();
* colNames[0] = 'uuid';
* colNames[1] = 'flags';
* var dataset = databaseManager.createEmptyDataSet(0,colNames);
*
* var row = new Array();
* row[0] = '413a4d69-becb-4ae4-8fdd-980755d6a7fb';//normally retreived via security.getElementUUIDs(...)
* row[1] = JSSecurity.VIEWABLE|JSSecurity.ACCESSIBLE; // use bitwise 'or' for both
* dataset.addRow(row);//setting element security
*
* row = new Array();
* row[0] = 'example_data.orders';
* row[1] = JSSecurity.READ|JSSecurity.INSERT|JSSecurity.UPDATE|JSSecurity.DELETE|JSSecurity.TRACKING; //use bitwise 'or' for multiple flags
* dataset.addRow(row);//setting table security
*
* security.setSecuritySettings(dataset);//to be called in solution startup method
*
* @param dataset the dataset with security settings
*/
public // uuid/server.tablename , integer(flags)
void js_setSecuritySettings(// uuid/server.tablename , integer(flags)
Object dataset) {
if (dataset instanceof JSDataSet) {
dataset = ((JSDataSet) dataset).getDataSet();
}
if (dataset instanceof IDataSet) {
application.getFoundSetManager().getEditRecordList().clearSecuritySettings();
Map<Object, Integer> sp = new HashMap<Object, Integer>();
IDataSet ds = (IDataSet) dataset;
if (ds.getColumnCount() < 2)
return;
for (int i = 0; i < ds.getRowCount(); i++) {
Object[] row = ds.getRow(i);
if (row[0] != null && row[1] != null) {
Integer val = new Integer(Utils.getAsInteger(row[1]));
try {
boolean matched = false;
if (row[0] instanceof UUID) {
sp.put(row[0], val);
matched = true;
} else if (row[0].toString().indexOf('-') > 0) {
UUID uuid = UUID.fromString(row[0].toString());
sp.put(uuid, val);
matched = true;
} else {
String datasource = row[0].toString();
if (datasource.indexOf('.') != -1) {
String[] server_table = datasource.split("\\.");
if (server_table.length == 2) {
IServer server = application.getSolution().getServer(server_table[0]);
if (server != null) {
ITable table = server.getTable(server_table[1]);
if (table != null) {
Iterator<String> it = table.getRowIdentColumnNames();
if (it.hasNext()) {
sp.put(Utils.getDotQualitfied(table.getServerName(), table.getName(), it.next()), val);
matched = true;
}
}
}
}
}
}
if (!matched) {
Debug.error("security.setSecuritySettings: could not apply security settings for '" + row[0] + "'");
}
} catch (Exception e) {
Debug.error(e);
}
}
}
application.getFlattenedSolution().overrideSecurityAccess(sp);
}
}
Aggregations