Example usage for org.jdom2 Element getAttribute

List of usage examples for org.jdom2 Element getAttribute

Introduction

In this page you can find the example usage for org.jdom2 Element getAttribute.

Prototype

public Attribute getAttribute(final String attname) 

Source Link

Document

This returns the attribute for this element with the given name and within no namespace, or null if no such attribute exists.

Usage

From source file:password.pwm.config.PwmSetting.java

License:Open Source License

public int getLevel() {
    final Element settingElement = PwmSettingXml.readSettingXml(this);
    final Attribute levelAttribute = settingElement.getAttribute("level");
    return levelAttribute != null ? Integer.parseInt(levelAttribute.getValue()) : 0;
}

From source file:password.pwm.config.PwmSettingCategory.java

License:Open Source License

public int getLevel() {
    final Element settingElement = PwmSettingXml.readCategoryXml(this);
    final Attribute levelAttribute = settingElement.getAttribute("level");
    return levelAttribute != null ? Integer.parseInt(levelAttribute.getValue()) : 0;
}

From source file:password.pwm.config.PwmSettingCategory.java

License:Open Source License

public boolean isHidden() {
    final Element settingElement = PwmSettingXml.readCategoryXml(this);
    final Attribute requiredAttribute = settingElement.getAttribute("hidden");
    return requiredAttribute != null && "true".equalsIgnoreCase(requiredAttribute.getValue());
}

From source file:password.pwm.config.value.ActionValue.java

License:Open Source License

public static StoredValueFactory factory() {
    return new StoredValueFactory() {
        public ActionValue fromJson(final String input) {
            if (input == null) {
                return new ActionValue(Collections.<ActionConfiguration>emptyList());
            } else {
                List<ActionConfiguration> srcList = JsonUtil.deserialize(input,
                        new TypeToken<List<ActionConfiguration>>() {
                        });//from   ww  w . j a  va 2 s  . c  om

                srcList = srcList == null ? Collections.<ActionConfiguration>emptyList() : srcList;
                while (srcList.contains(null)) {
                    srcList.remove(null);
                }
                return new ActionValue(Collections.unmodifiableList(srcList));
            }
        }

        public ActionValue fromXmlElement(Element settingElement, final String input)
                throws PwmOperationalException {
            final boolean oldType = PwmSettingSyntax.STRING_ARRAY.toString()
                    .equals(settingElement.getAttributeValue("syntax"));
            final List valueElements = settingElement.getChildren("value");
            final List<ActionConfiguration> values = new ArrayList<>();
            for (final Object loopValue : valueElements) {
                final Element loopValueElement = (Element) loopValue;
                final String value = loopValueElement.getText();
                if (value != null && value.length() > 0) {
                    if (oldType) {
                        if (loopValueElement.getAttribute("locale") == null) {
                            values.add(ActionConfiguration.parseOldConfigString(value));
                        }
                    } else {
                        values.add(JsonUtil.deserialize(value, ActionConfiguration.class));
                    }
                }
            }
            return new ActionValue(values);
        }
    };
}

From source file:password.pwm.config.value.CustomLinkValue.java

License:Open Source License

public static StoredValueFactory factory() {
    return new StoredValueFactory() {
        public CustomLinkValue fromJson(final String input) {
            if (input == null) {
                return new CustomLinkValue(Collections.emptyList());
            } else {
                List<CustomLinkConfiguration> srcList = JsonUtil.deserialize(input,
                        new TypeToken<List<CustomLinkConfiguration>>() {
                        });/*from   w  w  w. j ava 2 s . c o  m*/
                srcList = srcList == null ? Collections.emptyList() : srcList;
                while (srcList.contains(null)) {
                    srcList.remove(null);
                }
                return new CustomLinkValue(Collections.unmodifiableList(srcList));
            }
        }

        public CustomLinkValue fromXmlElement(final Element settingElement, final PwmSecurityKey key)
                throws PwmOperationalException {
            final List valueElements = settingElement.getChildren("value");
            final List<CustomLinkConfiguration> values = new ArrayList<>();
            for (final Object loopValue : valueElements) {
                final Element loopValueElement = (Element) loopValue;
                final String value = loopValueElement.getText();
                if (value != null && value.length() > 0 && loopValueElement.getAttribute("locale") == null) {
                    values.add(JsonUtil.deserialize(value, CustomLinkConfiguration.class));
                }
            }
            final CustomLinkValue CustomLinkValue = new CustomLinkValue(values);
            return CustomLinkValue;
        }
    };
}

From source file:password.pwm.config.value.EmailValue.java

License:Open Source License

public static StoredValueFactory factory() {
    return new StoredValueFactory() {
        public EmailValue fromJson(final String input) {
            if (input == null) {
                return new EmailValue(Collections.<String, EmailItemBean>emptyMap());
            } else {
                Map<String, EmailItemBean> srcList = JsonUtil.deserialize(input,
                        new TypeToken<Map<String, EmailItemBean>>() {
                        });//from  w w w  .  j  av a 2s.c om

                srcList = srcList == null ? Collections.<String, EmailItemBean>emptyMap() : srcList;
                srcList.remove(null);
                return new EmailValue(Collections.unmodifiableMap(srcList));
            }
        }

        public EmailValue fromXmlElement(Element settingElement, final String input)
                throws PwmOperationalException {
            final Map<String, EmailItemBean> values = new TreeMap<>();
            {
                final List valueElements = settingElement.getChildren("value");
                for (final Object loopValue : valueElements) {
                    final Element loopValueElement = (Element) loopValue;
                    final String value = loopValueElement.getText();
                    if (value != null && value.length() > 0) {
                        String localeValue = loopValueElement.getAttribute("locale") == null ? ""
                                : loopValueElement.getAttribute("locale").getValue();
                        values.put(localeValue, JsonUtil.deserialize(value, EmailItemBean.class));
                    }
                }
            }
            // read old format values.  can be removed someday....      this code iterates through the entire settings xml document to find old format versions
            {
                final Map<String, String> fromMap = new HashMap<>();
                final Map<String, String> subjectMap = new HashMap<>();
                final Map<String, String> bodyPlainMap = new HashMap<>();
                final Map<String, String> bodyHtmlMap = new HashMap<>();
                for (final Object loopSettingObj : settingElement.getParentElement().getChildren()) {
                    Element loopSetting = (Element) loopSettingObj;
                    if (loopSetting.getAttribute("key") != null) {
                        if (loopSetting.getAttribute("key").getValue()
                                .equals(settingElement.getAttribute("key").getValue() + ".from")) {
                            final List valueElements = loopSetting.getChildren("value");
                            for (final Object loopValue : valueElements) {
                                final Element loopValueElement = (Element) loopValue;
                                final String value = loopValueElement.getText();
                                if (value != null && value.length() > 0) {
                                    String localeValue = settingElement.getAttribute("locale") == null ? ""
                                            : settingElement.getAttribute("locale").getValue();
                                    fromMap.put(localeValue, value);
                                }
                            }
                        }
                        if (loopSetting.getAttribute("key").getValue()
                                .equals(settingElement.getAttribute("key").getValue() + ".subject")) {
                            final List valueElements = loopSetting.getChildren("value");
                            for (final Object loopValue : valueElements) {
                                final Element loopValueElement = (Element) loopValue;
                                final String value = loopValueElement.getText();
                                if (value != null && value.length() > 0) {
                                    String localeValue = settingElement.getAttribute("locale") == null ? ""
                                            : settingElement.getAttribute("locale").getValue();
                                    subjectMap.put(localeValue, value);
                                }
                            }
                        }
                        if (loopSetting.getAttribute("key").getValue()
                                .equals(settingElement.getAttribute("key").getValue() + ".plainBody")) {
                            final List valueElements = loopSetting.getChildren("value");
                            for (final Object loopValue : valueElements) {
                                final Element loopValueElement = (Element) loopValue;
                                final String value = loopValueElement.getText();
                                if (value != null && value.length() > 0) {
                                    String localeValue = settingElement.getAttribute("locale") == null ? ""
                                            : settingElement.getAttribute("locale").getValue();
                                    bodyPlainMap.put(localeValue, value);
                                }
                            }
                        }
                        if (loopSetting.getAttribute("key").getValue()
                                .equals(settingElement.getAttribute("key").getValue() + ".htmlBody")) {
                            final List valueElements = loopSetting.getChildren("value");
                            for (final Object loopValue : valueElements) {
                                final Element loopValueElement = (Element) loopValue;
                                final String value = loopValueElement.getText();
                                if (value != null && value.length() > 0) {
                                    String localeValue = settingElement.getAttribute("locale") == null ? ""
                                            : settingElement.getAttribute("locale").getValue();
                                    bodyHtmlMap.put(localeValue, value);
                                }
                            }
                        }
                    }
                }
                final Set<String> seenLocales = new HashSet<>();
                seenLocales.addAll(fromMap.keySet());
                seenLocales.addAll(subjectMap.keySet());
                seenLocales.addAll(bodyPlainMap.keySet());
                seenLocales.addAll(bodyHtmlMap.keySet());
                //final String defaultJson = PwmSetting.forKey(settingElement.getAttribute("key").getValue()).getDefaultValue(PwmSetting.Template.NOVL);
                //final Map<String,EmailItemBean> defaultList = gson.fromJson(defaultJson, new TypeToken<Map<String,EmailItemBean>>() {}.getType());
                //final EmailItemBean defaultBean = defaultList.read("");
                /*
                for (final String localeStr : seenLocales) {
                    values.put(localeStr,new EmailItemBean(
                null,
                fromMap.containsKey(localeStr) ? fromMap.read(localeStr) : defaultBean.getFrom(),
                subjectMap.containsKey(localeStr) ? subjectMap.read(localeStr) : defaultBean.getSubject(),
                bodyPlainMap.containsKey(localeStr)? bodyPlainMap.read(localeStr) : defaultBean.getBodyPlain(),
                bodyHtmlMap.containsKey(localeStr) ? bodyHtmlMap.read(localeStr) : defaultBean.getBodyHtml()
                ));
                }
                */
            }
            return new EmailValue(values);
        }
    };
}

From source file:password.pwm.config.value.FormValue.java

License:Open Source License

public static StoredValueFactory factory() {
    return new StoredValueFactory() {
        public FormValue fromJson(final String input) {
            if (input == null) {
                return new FormValue(Collections.<FormConfiguration>emptyList());
            } else {
                List<FormConfiguration> srcList = JsonUtil.deserialize(input,
                        new TypeToken<List<FormConfiguration>>() {
                        });//from w  w w  .j a  v a2s.com
                srcList = srcList == null ? Collections.<FormConfiguration>emptyList() : srcList;
                while (srcList.contains(null)) {
                    srcList.remove(null);
                }
                return new FormValue(Collections.unmodifiableList(srcList));
            }
        }

        public FormValue fromXmlElement(Element settingElement, final String key)
                throws PwmOperationalException {
            final boolean oldType = PwmSettingSyntax.LOCALIZED_STRING_ARRAY.toString()
                    .equals(settingElement.getAttributeValue("syntax"));
            final List valueElements = settingElement.getChildren("value");
            final List<FormConfiguration> values = new ArrayList<>();
            for (final Object loopValue : valueElements) {
                final Element loopValueElement = (Element) loopValue;
                final String value = loopValueElement.getText();
                if (value != null && value.length() > 0 && loopValueElement.getAttribute("locale") == null) {
                    if (oldType) {
                        values.add(FormConfiguration.parseOldConfigString(value));
                    } else {
                        values.add(JsonUtil.deserialize(value, FormConfiguration.class));
                    }
                }
            }
            final FormValue formValue = new FormValue(values);
            formValue.needsXmlUpdate = oldType;
            return formValue;
        }
    };
}

From source file:pdf2xml.TopElementComparator.java

License:Open Source License

public int compare(Element e1, Element e2) {
    int top1 = Integer.parseInt(e1.getAttribute("top").getValue());
    int top2 = Integer.parseInt(e2.getAttribute("top").getValue());
    return (top1 - top2);
}

From source file:pdf2xml.TopElementComparator.java

License:Open Source License

private int doPage(int lines_before, Element page) {
    int page_number = Integer.parseInt(page.getAttribute("number").getValue());

    this.fonts.addAll(getFonts(page));

    List<Text_Column> text_columns = generateColumns(page, 1);
    for (Text_Column tc : text_columns) {
        this.lines.addAll(tc.lines);
    }//from  w  w w .j  av  a 2s  .  com

    boolean multi_modus = false;
    int d = 0;
    int sum_of_distances = 0;

    for (int o = lines_before; o < this.lines.size(); o++) {
        Line l = this.lines.get(o);

        Text_Element.processLineTexts(l.texts);

        if (l.texts.size() > 1) {
            // multi-line
            if (multi_modus == true) {
                Multiline_Block current_mlb = this.mlbs.get(this.mlbs.size() - 1);
                sum_of_distances += d;
                current_mlb.add(l);
            } else {
                Multiline_Block mlb = new Multiline_Block();
                sum_of_distances = 0;
                mlb.init(l, o, page_number);
                this.mlbs.add(mlb);
                multi_modus = true;
            }
        } else if (l.texts.size() == 1) {
            // single-line
            if (multi_modus == true) {

                Line pl = this.lines.get(o - 1);
                sum_of_distances += d;
                Text_Element t = l.texts.get(0);
                int top_distance = l.first_top - pl.bottom;

                boolean control = false;

                int belongs = 0;

                for (int k = 0; k < pl.texts.size(); k++) {

                    Text_Element n = pl.texts.get(k);
                    int left_distance = Math.abs(n.left - t.left);
                    int right_distance = Math.abs((n.left + n.width) - (t.left + t.width));

                    if (top_distance < t.height / 2 && n.typ.equals(t.typ) && n.typ == Type.TEXT
                            && ((left_distance < 3) || (right_distance < 3))) {

                        String s = n.value + "\n" + t.value;
                        n.value = s;

                        n.count_lines++;
                        this.lines.remove(o);
                        o--;
                        n.add(t);
                        pl.add(t);
                        control = true;
                    }
                    if (Text_Element.intersect(t, n)) {
                        belongs++;
                    }
                } // end of for
                if (control == false) {

                    /*   if (belongs == 1)  {
                    Multiline_Block current_mlb = (Multiline_Block) this.mlbs.lastElement();
                    actualize_mlb_values(current_mlb, l);
                    }
                    else {*/
                    //if (belongs == 0 || count_single_lines > 5) {
                    Multiline_Block current_mlb = this.mlbs.get(this.mlbs.size() - 1);
                    int mlb_element_count = current_mlb.end - current_mlb.begin;
                    if (mlb_element_count > 0) {
                        current_mlb.avg_distance = sum_of_distances / mlb_element_count;
                    } else {
                        current_mlb.avg_distance = d;
                    }
                    multi_modus = false;
                    // }
                }
            } else {
                // do nothing
            }
        }
    }

    multi_modus = false;
    lines_before = this.lines.size();
    return lines_before;
}

From source file:pdf2xml.TopElementComparator.java

License:Open Source License

private List<Text_Column> generateColumns(Element page, int column_count) {
    List<Text_Column> text_columns = new ArrayList<Text_Column>();
    int page_width = Integer.parseInt(page.getAttribute("width").getValue());
    int text_columns_width = page_width / column_count;

    for (int i = 0; i < column_count; i++) {
        Text_Column tc = new Text_Column(text_columns_width);
        text_columns.add(tc);/*from w w  w  . j a v  a 2s  .c  o m*/
    }
    int distance = 0;
    Text_Column current_tc;

    List<Element> text_elements = new LinkedList<Element>(page.getChildren("text"));
    Collections.sort(text_elements, new TopElementComparator());

    for (Element e : text_elements) {
        Text_Element current_t = Text_Element.getTextElement(e, fonts);

        int right_column = Math.abs(current_t.left / text_columns_width);

        if (right_column < text_columns.size()) {

            current_tc = text_columns.get(right_column);

            if (current_tc.lines.size() > 0) {
                Line l = current_tc.lines.get(current_tc.lines.size() - 1);

                if (l.contains(current_t)) {
                    // exactly in the boundaries of the line
                    l.texts.add(current_t);
                    l.add(current_t);
                } else {
                    Line new_line = new Line();
                    new_line.texts.add(current_t);
                    new_line.init(current_t);
                    current_tc.lines.add(new_line);
                    distance += new_line.first_top - l.last_top;
                }
            } else {
                Line new_line = new Line();
                new_line.texts.add(current_t);
                new_line.init(current_t);
                current_tc.lines.add(new_line);
            } // if current_tc.lines
        } // if right_column ...
    } // for e_array.length
    return text_columns;
}