use of org.jdom2.filter.Filter in project JMRI by JMRI.
the class TabbedPreferences method init.
/**
* Initialize, including loading classes provided by a
* {@link java.util.ServiceLoader}.
* <p>
* Keeps a current state to prevent doing its work twice.
*
* @return The current state, which should be INITIALISED if all is well.
*/
@SuppressWarnings("rawtypes")
public synchronized int init() {
if (initialisationState == INITIALISED) {
return INITIALISED;
}
if (initialisationState != UNINITIALISED) {
return initialisationState;
}
this.setInitalisationState(INITIALISING);
list = new JList<>();
listScroller = new JScrollPane(list);
listScroller.setPreferredSize(new Dimension(100, 100));
buttonpanel = new JPanel();
buttonpanel.setLayout(new BoxLayout(buttonpanel, BoxLayout.Y_AXIS));
buttonpanel.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 3));
detailpanel = new JPanel();
detailpanel.setLayout(new CardLayout());
detailpanel.setBorder(BorderFactory.createEmptyBorder(6, 3, 6, 6));
save = new JButton(ConfigBundle.getMessage("ButtonSave"), new ImageIcon(FileUtil.findURL("program:resources/icons/misc/gui3/SaveIcon.png", FileUtil.Location.INSTALLED)));
save.addActionListener((ActionEvent e) -> {
savePressed(invokeSaveOptions());
});
setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
Set<PreferencesPanel> delayed = new HashSet<>();
for (PreferencesPanel panel : InstanceManager.getList(jmri.swing.PreferencesPanel.class)) {
if (panel instanceof PreferencesSubPanel) {
String parent = ((PreferencesSubPanel) panel).getParentClassName();
if (!this.getPreferencesPanels().containsKey(parent)) {
delayed.add(panel);
} else {
((PreferencesSubPanel) panel).setParent(this.getPreferencesPanels().get(parent));
}
}
if (!delayed.contains(panel)) {
this.addPreferencesPanel(panel);
}
}
for (PreferencesPanel panel : ServiceLoader.load(PreferencesPanel.class)) {
if (panel instanceof PreferencesSubPanel) {
String parent = ((PreferencesSubPanel) panel).getParentClassName();
if (!this.getPreferencesPanels().containsKey(parent)) {
delayed.add(panel);
} else {
((PreferencesSubPanel) panel).setParent(this.getPreferencesPanels().get(parent));
}
}
if (!delayed.contains(panel)) {
this.addPreferencesPanel(panel);
}
}
while (!delayed.isEmpty()) {
Set<PreferencesPanel> iterated = new HashSet<>(delayed);
iterated.stream().filter((panel) -> (panel instanceof PreferencesSubPanel)).forEach((panel) -> {
String parent = ((PreferencesSubPanel) panel).getParentClassName();
if (this.getPreferencesPanels().containsKey(parent)) {
((PreferencesSubPanel) panel).setParent(this.getPreferencesPanels().get(parent));
delayed.remove(panel);
this.addPreferencesPanel(panel);
}
});
}
preferencesArray.stream().forEach((preferences) -> {
detailpanel.add(preferences.getPanel(), preferences.getPrefItem());
});
updateJList();
add(buttonpanel);
add(new JSeparator(JSeparator.VERTICAL));
add(detailpanel);
list.setSelectedIndex(0);
selection(preferencesArray.get(0).getPrefItem());
this.setInitalisationState(INITIALISED);
return initialisationState;
}
use of org.jdom2.filter.Filter in project JMRI by JMRI.
the class JmriUserPreferencesManager method savePreferencesState.
private void savePreferencesState() {
this.setChangeMade(true);
if (this.allowSave) {
Element element = new Element(CLASSPREFS_ELEMENT, CLASSPREFS_NAMESPACE);
this.classPreferenceList.keySet().stream().forEach((name) -> {
ClassPreferences cp = this.classPreferenceList.get(name);
if (!cp.multipleChoiceList.isEmpty() || !cp.preferenceList.isEmpty()) {
Element clazz = new Element("preferences");
clazz.setAttribute("class", name);
if (!cp.multipleChoiceList.isEmpty()) {
Element choices = new Element("multipleChoice");
// only save non-default values
cp.multipleChoiceList.stream().filter((mc) -> (mc.getDefaultValue() != mc.getValue())).forEach((mc) -> {
choices.addContent(new Element("option").setAttribute("item", mc.getItem()).setAttribute("value", Integer.toString(mc.getValue())));
});
if (!choices.getChildren().isEmpty()) {
clazz.addContent(choices);
}
}
if (!cp.preferenceList.isEmpty()) {
Element reminders = new Element("reminderPrompts");
cp.preferenceList.stream().filter((pl) -> (pl.getState())).forEach((pl) -> {
reminders.addContent(new Element("reminder").addContent(pl.getItem()));
});
if (!reminders.getChildren().isEmpty()) {
clazz.addContent(reminders);
}
}
element.addContent(clazz);
}
});
if (!element.getChildren().isEmpty()) {
this.saveElement(element);
}
}
}
use of org.jdom2.filter.Filter in project jPOS by jpos.
the class OneShotChannelAdaptorMK2 method addFilters.
private void addFilters(FilteredChannel channel, Element e, QFactory fact) throws ConfigurationException {
for (Object o : e.getChildren("filter")) {
Element f = (Element) o;
String clazz = f.getAttributeValue("class");
ISOFilter filter = (ISOFilter) fact.newInstance(clazz);
fact.setLogger(filter, f);
fact.setConfiguration(filter, f);
String direction = f.getAttributeValue("direction");
if (direction == null) {
channel.addFilter(filter);
} else if ("incoming".equalsIgnoreCase(direction)) {
channel.addIncomingFilter(filter);
} else if ("outgoing".equalsIgnoreCase(direction)) {
channel.addOutgoingFilter(filter);
} else if ("both".equalsIgnoreCase(direction)) {
channel.addIncomingFilter(filter);
channel.addOutgoingFilter(filter);
}
}
}
use of org.jdom2.filter.Filter in project jspwiki by apache.
the class DefaultFilterManager method registerFilters.
private void registerFilters() {
log.info("Registering filters");
List<Element> filters = XmlUtil.parse(PLUGIN_RESOURCE_LOCATION, "/modules/filter");
//
for (Iterator<Element> i = filters.iterator(); i.hasNext(); ) {
Element pluginEl = i.next();
String className = pluginEl.getAttributeValue("class");
PageFilterInfo filterInfo = PageFilterInfo.newInstance(className, pluginEl);
if (filterInfo != null) {
registerFilter(filterInfo);
}
}
}
use of org.jdom2.filter.Filter in project jspwiki by apache.
the class XmlUtil method parse.
/**
* Parses the given XML file and returns the requested nodes. If there's an error accessing or parsing the file, an
* empty list is returned.
*
* @param xml file to parse; matches all resources from classpath, filters repeated items.
* @param requestedNodes requestd nodes on the xml file
* @return the requested nodes of the XML file.
*/
public static List<Element> parse(String xml, String requestedNodes) {
if (StringUtils.isNotEmpty(xml) && StringUtils.isNotEmpty(requestedNodes)) {
Set<Element> readed = new HashSet<Element>();
SAXBuilder builder = new SAXBuilder();
try {
Enumeration<URL> resources = XmlUtil.class.getClassLoader().getResources(xml);
while (resources.hasMoreElements()) {
URL resource = resources.nextElement();
log.debug("reading " + resource.toString());
Document doc = builder.build(resource);
XPathFactory xpfac = XPathFactory.instance();
XPathExpression<Element> xp = xpfac.compile(requestedNodes, Filters.element());
// filter out repeated items
readed.addAll(xp.evaluate(doc));
}
return new ArrayList<Element>(readed);
} catch (IOException ioe) {
log.error("Couldn't load all " + xml + " resources", ioe);
} catch (JDOMException jdome) {
log.error("error parsing " + xml + " resources", jdome);
}
}
return Collections.<Element>emptyList();
}
Aggregations