Search in sources :

Example 31 with Filter

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;
}
Also used : JScrollPane(javax.swing.JScrollPane) ListSelectionModel(javax.swing.ListSelectionModel) CardLayout(java.awt.CardLayout) LoggerFactory(org.slf4j.LoggerFactory) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ConfigBundle(apps.ConfigBundle) JTabbedPane(javax.swing.JTabbedPane) ImageIcon(javax.swing.ImageIcon) BorderLayout(java.awt.BorderLayout) ListSelectionEvent(javax.swing.event.ListSelectionEvent) PreferencesSubPanel(jmri.swing.PreferencesSubPanel) BoxLayout(javax.swing.BoxLayout) PreferencesPanel(jmri.swing.PreferencesPanel) AppConfigBase(apps.AppConfigBase) JComponent(javax.swing.JComponent) InstanceManager(jmri.InstanceManager) JButton(javax.swing.JButton) Logger(org.slf4j.Logger) JList(javax.swing.JList) Set(java.util.Set) ServiceLoader(java.util.ServiceLoader) BorderFactory(javax.swing.BorderFactory) ActionEvent(java.awt.event.ActionEvent) JScrollPane(javax.swing.JScrollPane) Dimension(java.awt.Dimension) List(java.util.List) FileUtil(jmri.util.FileUtil) JLabel(javax.swing.JLabel) JSeparator(javax.swing.JSeparator) JPanel(javax.swing.JPanel) Element(org.jdom2.Element) JPanel(javax.swing.JPanel) CardLayout(java.awt.CardLayout) ImageIcon(javax.swing.ImageIcon) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) PreferencesPanel(jmri.swing.PreferencesPanel) JButton(javax.swing.JButton) Dimension(java.awt.Dimension) JSeparator(javax.swing.JSeparator) PreferencesSubPanel(jmri.swing.PreferencesSubPanel) HashSet(java.util.HashSet)

Example 32 with Filter

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);
        }
    }
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) ProfileManager(jmri.profile.ProfileManager) Point(java.awt.Point) HashMap(java.util.HashMap) JmriJFrame(jmri.util.JmriJFrame) Constructor(java.lang.reflect.Constructor) ArrayList(java.util.ArrayList) JDOMException(org.jdom2.JDOMException) JDOMUtil(jmri.util.jdom.JDOMUtil) ProfileUtils(jmri.profile.ProfileUtils) Map(java.util.Map) Bean(jmri.beans.Bean) Profile(jmri.profile.Profile) Method(java.lang.reflect.Method) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) BoxLayout(javax.swing.BoxLayout) InstanceManager(jmri.InstanceManager) UserPreferencesManager(jmri.UserPreferencesManager) Logger(org.slf4j.Logger) JmriException(jmri.JmriException) TableColumnPreferences(jmri.swing.JmriJTablePersistenceManager.TableColumnPreferences) Set(java.util.Set) JOptionPane(javax.swing.JOptionPane) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SortOrder(javax.swing.SortOrder) Dimension(java.awt.Dimension) List(java.util.List) FileUtil(jmri.util.FileUtil) JLabel(javax.swing.JLabel) ConfigureManager(jmri.ConfigureManager) JmriJTablePersistenceManager(jmri.swing.JmriJTablePersistenceManager) Entry(java.util.Map.Entry) JCheckBox(javax.swing.JCheckBox) DataConversionException(org.jdom2.DataConversionException) NodeIdentity(jmri.util.node.NodeIdentity) JPanel(javax.swing.JPanel) Toolkit(java.awt.Toolkit) Element(org.jdom2.Element) Element(org.jdom2.Element)

Example 33 with Filter

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);
        }
    }
}
Also used : ISOFilter(org.jpos.iso.ISOFilter) Element(org.jdom2.Element)

Example 34 with 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);
        }
    }
}
Also used : Element(org.jdom2.Element)

Example 35 with Filter

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();
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException) URL(java.net.URL) XPathFactory(org.jdom2.xpath.XPathFactory) HashSet(java.util.HashSet)

Aggregations

Element (org.jdom2.Element)43 Document (org.jdom2.Document)24 List (java.util.List)22 IOException (java.io.IOException)20 ArrayList (java.util.ArrayList)19 LogManager (org.apache.logging.log4j.LogManager)17 Logger (org.apache.logging.log4j.Logger)17 JDOMException (org.jdom2.JDOMException)17 Collectors (java.util.stream.Collectors)16 File (java.io.File)11 MCRException (org.mycore.common.MCRException)11 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)11 Collections (java.util.Collections)10 MCRObject (org.mycore.datamodel.metadata.MCRObject)10 Map (java.util.Map)9 MCRAccessException (org.mycore.access.MCRAccessException)9 MCRConstants (org.mycore.common.MCRConstants)9 MCRDerivate (org.mycore.datamodel.metadata.MCRDerivate)9 MCRMetadataManager (org.mycore.datamodel.metadata.MCRMetadataManager)9 Files (java.nio.file.Files)8