当前位置: 首页>>代码示例>>Java>>正文


Java Element.getAttribute方法代码示例

本文整理汇总了Java中org.jdom2.Element.getAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java Element.getAttribute方法的具体用法?Java Element.getAttribute怎么用?Java Element.getAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jdom2.Element的用法示例。


在下文中一共展示了Element.getAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getRequiredAttribute

import org.jdom2.Element; //导入方法依赖的package包/类
public static Attribute getRequiredAttribute(Element el, String name, String...aliases) throws InvalidXMLException {
    aliases = ArrayUtils.append(aliases, name);

    Attribute attr = null;
    for(String alias : aliases) {
        Attribute a = el.getAttribute(alias);
        if(a != null) {
            if(attr == null) {
                attr = a;
            } else {
                throw new InvalidXMLException("attributes '" + attr.getName() + "' and '" + alias + "' are aliases for the same thing, and cannot be combined", el);
            }
        }
    }

    if(attr == null) {
        throw new InvalidXMLException("attribute '" + name + "' is required", el);
    }

    return attr;
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:22,代码来源:XMLUtils.java

示例2: parseDefinition

import org.jdom2.Element; //导入方法依赖的package包/类
public static ProximityAlarmDefinition parseDefinition(MapModuleContext context, Element elAlarm) throws InvalidXMLException {
    ProximityAlarmDefinition definition = new ProximityAlarmDefinition();
    FilterParser filterParser = context.needModule(FilterParser.class);
    definition.detectFilter = filterParser.parseProperty(elAlarm, "detect");
    definition.alertFilter = filterParser.property(elAlarm, "notify").optionalGet(() -> new InverseFilter(definition.detectFilter));
    definition.detectRegion = context.needModule(RegionParser.class).property(elAlarm, "region").required();
    definition.alertMessage = elAlarm.getAttributeValue("message"); // null = no message

    if(definition.alertMessage != null) {
        definition.alertMessage = ChatColor.translateAlternateColorCodes('`', definition.alertMessage);
    }
    Attribute attrFlareRadius = elAlarm.getAttribute("flare-radius");
    definition.flares = attrFlareRadius != null;
    if(definition.flares) {
        definition.flareRadius = XMLUtils.parseNumber(attrFlareRadius, Double.class);
    }

    return definition;
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:20,代码来源:ProximityAlarmModule.java

示例3: filter

import org.jdom2.Element; //导入方法依赖的package包/类
@Override
public Element filter(Object content) {
	Element result = super.filter(content);
	if(result == null) return null;
	Attribute att = result.getAttribute("point");
	if(att == null) return null;
	if(att.getValue().equals(extensionPointName)) return result;
	else return null;
}
 
开发者ID:eclipse,项目名称:gemoc-studio-modeldebugging,代码行数:10,代码来源:PluginXMLHelper.java

示例4: getAttribute

import org.jdom2.Element; //导入方法依赖的package包/类
public static @Nullable Attribute getAttribute(Element parent, Collection<String> names) {
    for(String name : names) {
        final Attribute attr = parent.getAttribute(name);
        if(attr != null) return attr;
    }
    return null;
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:8,代码来源:XMLUtils.java

示例5: parseMaterialMatcher

import org.jdom2.Element; //导入方法依赖的package包/类
public static MaterialMatcher parseMaterialMatcher(Element el, MaterialMatcher empty) throws InvalidXMLException {
    Set<MaterialMatcher> matchers = new HashSet<>();

    final Attribute attrMaterial = el.getAttribute("material");
    if(attrMaterial != null) {
        matchers.add(parseMaterialPattern(attrMaterial));
    }

    for(Element elChild : el.getChildren()) {
        switch(elChild.getName()) {
            case "all-materials":
            case "all-items":
                return AllMaterialMatcher.INSTANCE;

            case "all-blocks":
                matchers.add(BlockMaterialMatcher.INSTANCE);
                break;

            case "material":
            case "item":
                matchers.add(parseMaterialPattern(elChild));
                break;

            default:
                throw new InvalidXMLException("Unknown material matcher tag", elChild);
        }
    }

    return CompoundMaterialMatcher.of(matchers, empty);
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:31,代码来源:XMLUtils.java

示例6: parseLocalizedText

import org.jdom2.Element; //导入方法依赖的package包/类
public static BaseComponent parseLocalizedText(Element el) throws InvalidXMLException {
    final Attribute translate = el.getAttribute("translate");
    if(translate != null) {
        return new TranslatableComponent(translate.getValue());
    } else {
        return new Component(el.getTextNormalize());
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:9,代码来源:XMLUtils.java

示例7: fly

import org.jdom2.Element; //导入方法依赖的package包/类
@MethodParser
public Kit fly(Element el) throws InvalidXMLException {
    final boolean canFly = XMLUtils.parseBoolean(el.getAttribute("can-fly"), true);
    final Boolean flying = XMLUtils.parseBoolean(el.getAttribute("flying"), null);
    org.jdom2.Attribute flySpeedAtt = el.getAttribute("fly-speed");
    float flySpeedMultiplier = 1;
    if(flySpeedAtt != null) {
        flySpeedMultiplier = XMLUtils.parseNumber(el.getAttribute("fly-speed"), Float.class, Range.closed(FlyKit.MIN, FlyKit.MAX));
    }

    return new FlyKit(canFly, flying, flySpeedMultiplier);
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:13,代码来源:KitDefinitionParser.java

示例8: isReference

import org.jdom2.Element; //导入方法依赖的package包/类
@Override
public boolean isReference(Element el) throws InvalidXMLException {
    if(el.getAttribute(idAttributeName()) == null ||
       hasParentsOrChildren(el)) return false;

    if(legacy) {
        // Default conditions are too strict for legacy XML (why?)
        return "kit".equals(el.getName());
    }

    return super.isReference(el);
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:13,代码来源:KitParser.java

示例9: parseItem

import org.jdom2.Element; //导入方法依赖的package包/类
public ItemStack parseItem(Element el, Material type, short damage) throws InvalidXMLException {
    int amount = XMLUtils.parseNumber(el.getAttribute("amount"), Integer.class, 1);

    // If the item is a potion with non-zero damage, and there is
    // no modern potion ID, decode the legacy damage value.
    final Potion legacyPotion;
    if(type == Material.POTION && damage > 0 && el.getAttribute("potion") == null) {
        try {
            legacyPotion = Potion.fromDamage(damage);
        } catch(IllegalArgumentException e) {
            throw new InvalidXMLException("Invalid legacy potion damage value " + damage + ": " + e.getMessage(), el, e);
        }

        // If the legacy splash bit is set, convert to a splash potion
        if(legacyPotion.isSplash()) {
            type = Material.SPLASH_POTION;
            legacyPotion.setSplash(false);
        }

        // Potions always have damage 0
        damage = 0;
    } else {
        legacyPotion = null;
    }

    ItemStack itemStack = new ItemStack(type, amount, damage);
    if(itemStack.getType() != type) {
        throw new InvalidXMLException("Invalid item/block", el);
    }

    final ItemMeta meta = itemStack.getItemMeta();
    if(meta != null) { // This happens if the item is "air"
        parseItemMeta(el, meta);

        // If we decoded a legacy potion, apply it now, but only if there are no custom effects.
        // This emulates the old behavior of custom effects overriding default effects.
        if(legacyPotion != null) {
            final PotionMeta potionMeta = (PotionMeta) meta;
            if(!potionMeta.hasCustomEffects()) {
                potionMeta.setBasePotionData(new PotionData(legacyPotion.getType(),
                                                            legacyPotion.hasExtendedDuration(),
                                                            legacyPotion.getLevel() == 2));
            }
        }

        itemStack.setItemMeta(meta);
    }

    return itemStack;
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:51,代码来源:GlobalItemParser.java

示例10: translate

import org.jdom2.Element; //导入方法依赖的package包/类
@MethodParser
public TranslatedRegion translate(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(regionParser.parseReferenceAndChildUnion(el), offset);
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:10,代码来源:RegionDefinitionParser.java

示例11: parseFilter

import org.jdom2.Element; //导入方法依赖的package包/类
@MethodParser("filter")
public Filter parseFilter(Element el) throws InvalidXMLException {
    if(el.getAttribute("parents") != null || el.getChild("allow") != null || el.getChild("deny") != null) {
        // A weird node thing
        return new FilterNode(parseParents(el),
                              parseGrandchildren(el, "allow"),
                              parseGrandchildren(el, "deny"));
    } else {
        // An alias for <all> (is this actually used anywhere?)
        return parseAll(el);
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:13,代码来源:LegacyFilterDefinitionParser.java

示例12: isReference

import org.jdom2.Element; //导入方法依赖的package包/类
@Override
public boolean isReference(Element el) {
    // References look different, and are a lot harder to distinguish from other things
    return el.getName().equalsIgnoreCase("filter") &&
           el.getChildren().isEmpty() &&
           el.getAttribute("parents") == null &&
           el.getAttribute("name") != null;
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:9,代码来源:LegacyFilterParser.java

示例13: parse

import org.jdom2.Element; //导入方法依赖的package包/类
public void parse(Element el) throws InvalidXMLException {
    final Region region;
    if(useId()) {
        // Multiple regions are unioned, but the default is NOT an empty union
        region = regionParser.property(el).optionalUnion(EverywhereRegion.INSTANCE);
    } else {
        region = regionParser.parseReferenceAndChildUnion(el);
    }

    BaseComponent message = XMLUtils.parseFormattedText(el, "message");

    boolean earlyWarning = XMLUtils.parseBoolean(el.getAttribute("early-warning"), false);
    Filter effectFilter = filterParser.parseOptionalProperty(el, "filter").orElse(null);

    kitParser.property(el, "kit").optional().ifPresent(rethrowConsumer(
        kit -> add(el, EventRule.newKitRegion(EventRuleScope.EFFECT, region, effectFilter, kit, false))
    ));

    kitParser.property(el, "lend-kit").validate(RemovableValidation.get()).optional().ifPresent(rethrowConsumer(
        kit -> add(el, EventRule.newKitRegion(EventRuleScope.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, EventRule.newVelocityRegion(EventRuleScope.EFFECT, region, effectFilter, velocity));
    }

    for(String tag : EventRuleScope.byTag.keySet()) {
        Filter filter;
        if(useId()) {
            filter = filterParser.parseOptionalProperty(el, tag).orElse(null);
        } 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 = ChainFilter.reverse(filters);
                }
            }
        }

        if(filter != null) {
            for(EventRuleScope scope : EventRuleScope.byTag.get(tag)) {
                add(el, EventRule.newEventFilter(scope, region, filter, message, earlyWarning));
            }
        }
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:61,代码来源:EventRuleParser.java

示例14: parseNumericRange

import org.jdom2.Element; //导入方法依赖的package包/类
public static <T extends Number & Comparable<T>> Range<T> parseNumericRange(Element el, Class<T> type, Range<T> def) throws InvalidXMLException {
    Attribute lt = el.getAttribute("lt");
    Attribute lte = getAttribute(el, "lte", "max");
    Attribute gt = el.getAttribute("gt");
    Attribute gte = getAttribute(el, "gte", "min");

    if(lt != null && lte != null) throw new InvalidXMLException("Conflicting upper bound for numeric range", el);
    if(gt != null && gte != null) throw new InvalidXMLException("Conflicting lower bound for numeric range", el);

    BoundType lowerBoundType, upperBoundType;
    T lowerBound, upperBound;

    if(gt != null) {
        lowerBound = parseNumber(gt, type, (T) null);
        lowerBoundType = BoundType.OPEN;
    } else {
        lowerBound = parseNumber(gte, type, (T) null);
        lowerBoundType = BoundType.CLOSED;
    }

    if(lt != null) {
        upperBound = parseNumber(lt, type, (T) null);
        upperBoundType = BoundType.OPEN;
    } else {
        upperBound = parseNumber(lte, type, (T) null);
        upperBoundType = BoundType.CLOSED;
    }

    if(lowerBound == null) {
        if(upperBound == null) {
            return def;
        } else {
            return Range.upTo(upperBound, upperBoundType);
        }
    } else {
        if(upperBound == null) {
            return Range.downTo(lowerBound, lowerBoundType);
        } else {
            return Range.range(lowerBound, lowerBoundType, upperBound, upperBoundType);
        }
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:43,代码来源:XMLUtils.java

示例15: hasParentsOrChildren

import org.jdom2.Element; //导入方法依赖的package包/类
protected boolean hasParentsOrChildren(Element el) {
    return el.getAttribute("parent") != null ||
           el.getAttribute("parents") != null ||
           !el.getChildren().isEmpty();
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:6,代码来源:KitParser.java


注:本文中的org.jdom2.Element.getAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。