use of org.apache.openmeetings.db.entity.label.StringLabel in project openmeetings by apache.
the class LabelDao method upload.
public static void upload(Locale l, InputStream is) throws Exception {
List<StringLabel> labels = getLabels(is);
// get the URL of existing resource
URL u = appClass.getResource(getLabelFileName(Locale.ENGLISH));
File el = new File(u.toURI());
File f = new File(el.getParentFile(), getLabelFileName(l));
if (!f.exists()) {
f.createNewFile();
}
labelCache.put(l, labels);
storeLabels(l);
}
use of org.apache.openmeetings.db.entity.label.StringLabel in project openmeetings by apache.
the class LabelDao method storeLabels.
private static void storeLabels(Locale l) throws Exception {
Document d = XmlExport.createDocument();
Element r = XmlExport.createRoot(d);
List<StringLabel> labels = new ArrayList<>(labelCache.get(l));
Collections.sort(labels, new LabelComparator());
for (StringLabel sl : labels) {
r.addElement(ENTRY_ELEMENT).addAttribute(KEY_ATTR, sl.getKey()).addCDATA(sl.getValue());
}
URL u = appClass.getResource(getLabelFileName(l));
XmlExport.toXml(new File(u.toURI()), d);
}
use of org.apache.openmeetings.db.entity.label.StringLabel in project openmeetings by apache.
the class LabelDao method getLabels.
private static List<StringLabel> getLabels(InputStream is) throws IOException {
final List<StringLabel> labels = new ArrayList<>();
Properties props = new Properties();
props.loadFromXML(is);
props.forEach((k, v) -> labels.add(new StringLabel((String) k, (String) v)));
return labels;
}
use of org.apache.openmeetings.db.entity.label.StringLabel in project openmeetings by apache.
the class LangPanel method onInitialize.
@Override
protected void onInitialize() {
// Create feedback panels
add(feedback.setOutputMarkupId(true));
language = new AbstractMap.SimpleEntry<>(1L, Locale.ENGLISH);
final LabelsForm form = new LabelsForm("form", this, new StringLabel(null, null));
form.showNewRecord();
add(form);
final SearchableDataView<StringLabel> dataView = new SearchableDataView<StringLabel>("langList", new SearchableDataProvider<StringLabel>(LabelDao.class) {
private static final long serialVersionUID = 1L;
@Override
public long size() {
return LabelDao.count(language.getValue(), search);
}
@Override
public Iterator<? extends StringLabel> iterator(long first, long count) {
return LabelDao.get(language.getValue(), search, (int) first, (int) count, getSort()).iterator();
}
}) {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(final Item<StringLabel> item) {
final StringLabel fv = item.getModelObject();
item.add(new Label("key"));
item.add(new Label("value"));
item.add(new AjaxEventBehavior(EVT_CLICK) {
private static final long serialVersionUID = 1L;
@Override
protected void onEvent(AjaxRequestTarget target) {
form.setModelObject(fv);
form.hideNewRecord();
target.add(form, listContainer);
reinitJs(target);
}
});
item.add(AttributeModifier.append(ATTR_CLASS, getRowClass(fv.getId(), form.getModelObject().getId())));
}
};
add(listContainer.add(dataView).setOutputMarkupId(true));
PagedEntityListPanel navigator = new PagedEntityListPanel("navigator", dataView) {
private static final long serialVersionUID = 1L;
@Override
protected void onEvent(AjaxRequestTarget target) {
dataView.modelChanging();
target.add(listContainer);
}
};
DataViewContainer<StringLabel> container = new DataViewContainer<>(listContainer, dataView, navigator);
container.addLink(new OmOrderByBorder<>("orderByName", "key", container)).addLink(new OmOrderByBorder<>("orderByValue", "value", container));
add(container.getLinks());
add(navigator);
langForm = new LangForm("langForm", listContainer, this);
langForm.add(fileUploadField);
langForm.add(new UploadProgressBar("progress", langForm, fileUploadField));
fileUploadField.add(new AjaxFormSubmitBehavior(langForm, "change") {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target) {
FileUpload download = fileUploadField.getFileUpload();
try {
if (download == null || download.getInputStream() == null) {
feedback.error("File is empty");
return;
}
LabelDao.upload(language.getValue(), download.getInputStream());
} catch (Exception e) {
log.error("Exception on panel language editor import ", e);
feedback.error(e);
}
// repaint the feedback panel so that it is hidden
target.add(listContainer, feedback);
}
});
// Add a component to download a file without page refresh
final AjaxDownloadBehavior download = new AjaxDownloadBehavior(new ResourceStreamResource() {
private static final long serialVersionUID = 1L;
{
setContentDisposition(ATTACHMENT);
setCacheDuration(NONE);
}
@Override
protected IResourceStream getResourceStream(Attributes attributes) {
final String name = LabelDao.getLabelFileName(language.getValue());
setFileName(name);
return new AbstractResourceStream() {
private static final long serialVersionUID = 1L;
private transient InputStream is;
@Override
public InputStream getInputStream() throws ResourceStreamNotFoundException {
try {
is = Application.class.getResourceAsStream(name);
return is;
} catch (Exception e) {
throw new ResourceStreamNotFoundException(e);
}
}
@Override
public void close() throws IOException {
if (is != null) {
is.close();
is = null;
}
}
};
}
});
langForm.add(download);
langForm.add(new AjaxButton("export") {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target) {
download.initiate(target);
// repaint the feedback panel so that it is hidden
target.add(feedback);
}
@Override
protected void onError(AjaxRequestTarget target) {
// repaint the feedback panel so errors are shown
target.add(feedback);
}
});
add(langForm);
final AddLanguageDialog addLang = new AddLanguageDialog("addLang", this);
add(addLang, new AjaxLink<Void>("addLangBtn") {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
addLang.open(target);
}
});
add(BootstrapFileUploadBehavior.INSTANCE);
add(new ConfirmableAjaxBorder("deleteLangBtn", getString("80"), getString("833")) {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target) {
LabelDao.delete(language.getValue());
List<Map.Entry<Long, Locale>> langs = LangForm.getLanguages();
language = langs.isEmpty() ? null : langs.get(0);
langForm.updateLanguages(target);
target.add(listContainer);
}
});
super.onInitialize();
}
use of org.apache.openmeetings.db.entity.label.StringLabel in project openmeetings by apache.
the class LabelsForm method onRefreshSubmit.
@Override
protected void onRefreshSubmit(AjaxRequestTarget target, Form<?> form) {
this.setModelObject(new StringLabel(key, value));
target.add(this);
reinitJs(target);
}
Aggregations