Search in sources :

Example 76 with Attribute

use of com.mindbright.security.x509.Attribute in project PGM by PGMDev.

the class RegionParser method parseTranslate.

@MethodParser("translate")
public TranslatedRegion parseTranslate(Element el) throws InvalidXMLException {
    Attribute offsetAttribute = el.getAttribute("offset");
    if (offsetAttribute == null) {
        throw new InvalidXMLException("Translate region must have an offset", el);
    }
    Vector offset = XMLUtils.parseVector(offsetAttribute);
    return new TranslatedRegion(this.parseChildren(el), offset);
}
Also used : Attribute(org.jdom2.Attribute) InvalidXMLException(tc.oc.pgm.util.xml.InvalidXMLException) Vector(org.bukkit.util.Vector) MethodParser(tc.oc.pgm.util.MethodParser)

Example 77 with Attribute

use of com.mindbright.security.x509.Attribute in project PGM by PGMDev.

the class RegionParser method parseRegionProperty.

@Nullable
public Region parseRegionProperty(Element rootElement, @Nullable FeatureValidation<RegionDefinition> validation, Region def, String... names) throws InvalidXMLException {
    Attribute propertyAttribute = null;
    Element propertyElement = null;
    for (String name : names) {
        if (rootElement.getAttribute(name) != null && rootElement.getChild(name) != null) {
            throw new InvalidXMLException("Multiple defined region properties for " + name, rootElement);
        }
        if ((rootElement.getAttribute(name) != null || rootElement.getChild(name) != null) && (propertyAttribute != null || propertyElement != null)) {
            throw new InvalidXMLException("Multiple defined region properties for " + Arrays.toString(names), rootElement);
        }
        if (rootElement.getAttribute(name) != null) {
            propertyAttribute = rootElement.getAttribute(name);
        } else if (rootElement.getChild(name) != null) {
            propertyElement = rootElement.getChild(name);
        }
    }
    Region region = def;
    Node node = null;
    if (propertyAttribute != null) {
        region = this.parseReference(propertyAttribute);
        node = new Node(propertyAttribute);
    } else if (propertyElement != null) {
        region = this.parseChildren(propertyElement);
        node = new Node(propertyElement);
    }
    if (region != null && validation != null) {
        validate(region, validation, node);
    }
    return region;
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) Node(tc.oc.pgm.util.xml.Node) InvalidXMLException(tc.oc.pgm.util.xml.InvalidXMLException) Region(tc.oc.pgm.api.region.Region) Nullable(javax.annotation.Nullable)

Example 78 with Attribute

use of com.mindbright.security.x509.Attribute in project PGM by PGMDev.

the class RegionFilterApplicationParser method parse.

public void parse(Element el) throws InvalidXMLException {
    Region region = parseRegion(el);
    Component message = XMLUtils.parseFormattedText(el, "message");
    boolean earlyWarning = XMLUtils.parseBoolean(el.getAttribute("early-warning"), false);
    Filter effectFilter = filterParser.parseFilterProperty(el, "filter");
    Kit kit = factory.getKits().parseKitProperty(el, "kit");
    if (kit != null) {
        add(el, new RegionFilterApplication(RFAScope.EFFECT, region, effectFilter, kit, false));
    }
    kit = factory.getKits().parseKitProperty(el, "lend-kit");
    if (kit != null) {
        add(el, new RegionFilterApplication(RFAScope.EFFECT, region, effectFilter, kit, true));
    }
    Attribute attrVelocity = el.getAttribute("velocity");
    if (attrVelocity != null) {
        // Legacy support
        String velocityText = attrVelocity.getValue();
        if (velocityText.charAt(0) == '@')
            velocityText = velocityText.substring(1);
        Vector velocity = XMLUtils.parseVector(attrVelocity, velocityText);
        add(el, new RegionFilterApplication(RFAScope.EFFECT, region, effectFilter, velocity));
    }
    for (String tag : RFAScope.byTag.keySet()) {
        Filter filter;
        if (useId()) {
            filter = filterParser.parseFilterProperty(el, tag);
        } else {
            // Legacy syntax allows a list of filter names in the attribute
            Node node = Node.fromAttr(el, tag);
            if (node == null) {
                filter = null;
            } else {
                List<Filter> filters = new ArrayList<>();
                for (String name : Splitter.on(" ").split(node.getValue())) {
                    filters.add(filterParser.parseReference(node, name));
                }
                switch(filters.size()) {
                    case 0:
                        filter = null;
                        break;
                    case 1:
                        filter = filters.get(0);
                        break;
                    default:
                        filter = new FilterNode(filters, Collections.<Filter>emptyList(), Collections.<Filter>emptyList());
                }
            }
        }
        if (filter != null) {
            for (RFAScope scope : RFAScope.byTag.get(tag)) {
                add(el, new RegionFilterApplication(scope, region, filter, message, earlyWarning));
            }
        }
    }
}
Also used : Attribute(org.jdom2.Attribute) Node(tc.oc.pgm.util.xml.Node) FilterNode(tc.oc.pgm.filters.FilterNode) FilterNode(tc.oc.pgm.filters.FilterNode) ArrayList(java.util.ArrayList) TeamFilter(tc.oc.pgm.filters.TeamFilter) DenyFilter(tc.oc.pgm.filters.DenyFilter) Filter(tc.oc.pgm.api.filter.Filter) StaticFilter(tc.oc.pgm.filters.StaticFilter) Kit(tc.oc.pgm.kits.Kit) Region(tc.oc.pgm.api.region.Region) Component(net.kyori.adventure.text.Component) Vector(org.bukkit.util.Vector)

Example 79 with Attribute

use of com.mindbright.security.x509.Attribute in project rascal by usethesource.

the class DOM method nodeToAttribute.

private Attribute nodeToAttribute(IConstructor n) {
    IConstructor ns = (IConstructor) n.get(0);
    IString name = (IString) n.get(1);
    IString data = (IString) n.get(2);
    return new Attribute(name.getValue(), data.getValue(), namespaceToNamespace(ns));
}
Also used : IConstructor(io.usethesource.vallang.IConstructor) Attribute(org.jdom2.Attribute) IString(io.usethesource.vallang.IString)

Example 80 with Attribute

use of com.mindbright.security.x509.Attribute in project rascal by usethesource.

the class DOM method convertElement.

private IConstructor convertElement(Element e, boolean trim) {
    IListWriter kids = vf.listWriter();
    for (Object o : e.getAttributes()) {
        Attribute attr = (Attribute) o;
        IString key = vf.string(attr.getName());
        IString val = vf.string(attr.getValue());
        kids.insert(vf.constructor(Factory.Node_attribute, convertNamespace(attr.getNamespace()), key, val));
    }
    int len = e.getContentSize();
    for (int i = 0; i < len; i++) {
        try {
            kids.append(convertContent(e.getContent(i), trim));
        } catch (Skip c) {
            // Ugh, terrible, but I'm in hurry
            continue;
        }
    }
    IString name = vf.string(e.getName());
    return vf.constructor(Factory.Node_element, convertNamespace(e.getNamespace()), name, kids.done());
}
Also used : Attribute(org.jdom2.Attribute) IListWriter(io.usethesource.vallang.IListWriter) IString(io.usethesource.vallang.IString)

Aggregations

Attribute (org.jdom2.Attribute)316 Element (org.jdom2.Element)210 Attribute (ucar.nc2.Attribute)65 IOException (java.io.IOException)55 ArrayList (java.util.ArrayList)51 Document (org.jdom2.Document)43 Variable (ucar.nc2.Variable)39 List (java.util.List)31 HashMap (java.util.HashMap)25 Namespace (org.jdom2.Namespace)24 File (java.io.File)21 Array (ucar.ma2.Array)21 DataConversionException (org.jdom2.DataConversionException)19 Test (org.junit.Test)19 Dimension (ucar.nc2.Dimension)19 Map (java.util.Map)17 JDOMException (org.jdom2.JDOMException)16 XmlDslUtils.addMigrationAttributeToElement (com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement)15 Editor (jmri.jmrit.display.Editor)15 NamedIcon (jmri.jmrit.catalog.NamedIcon)13