org.jdom2.Attribute

Here are the examples of the java api org.jdom2.Attribute taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

125 Examples 7

19 Source : CourseWaypoint.java
with GNU General Public License v3.0
from yankee42

public static CourseWaypoint fromElement(final Element element) {
    double x = 0, y = 0;
    Double height = null;
    final Map<String, String> properties = new HashMap<>();
    for (final Attribute attribute : element.getAttributes()) {
        if (attribute.getName().equals("pos")) {
            final String[] values = attribute.getValue().split(" ");
            if (values.length != 2 && values.length != 3) {
                throw new RuntimeException("Cannot parse position <" + attribute.getValue() + "> in element <" + element.getName() + ">");
            }
            x = Double.parseDouble(values[0]);
            y = Double.parseDouble(values[values.length - 1]);
            if (values.length == 3) {
                height = Double.parseDouble(values[1]);
            }
        } else {
            properties.put(attribute.getName(), attribute.getValue());
        }
    }
    return new CourseWaypoint(x, y, height, properties);
}

19 Source : DatasetScanConfigBuilder.java
with BSD 3-Clause "New" or "Revised" License
from Unidata

/*
   * <xsd:complexType name="addLatestType">
   * <xsd:attribute name="name" type="xsd:string"/>
   * <xsd:attribute name="top" type="xsd:boolean"/>
   * <xsd:attribute name="serviceName" type="xsd:string"/>
   * <xsd:attribute name="lastModifiedLimit" type="xsd:float"/> <!-- minutes -->
   * </xsd:complexType>
   */
private DatasetScanConfig.AddLatest readDatasetScanAddLatest(Element addLatestElem) {
    String latestName = "latest.xml";
    String serviceName = "Resolver";
    boolean latestOnTop = true;
    boolean isResolver = true;
    String tmpLatestName = addLatestElem.getAttributeValue("name");
    if (tmpLatestName != null)
        latestName = tmpLatestName;
    String tmpserviceName = addLatestElem.getAttributeValue("serviceName");
    if (tmpserviceName != null)
        serviceName = tmpserviceName;
    // Does latest go on top or bottom of list.
    Attribute topAtt = addLatestElem.getAttribute("top");
    if (topAtt != null) {
        try {
            latestOnTop = topAtt.getBooleanValue();
        } catch (DataConversionException e) {
            latestOnTop = true;
        }
    }
    // Get lastModifed limit.
    String lastModLimitVal = addLatestElem.getAttributeValue("lastModifiedLimit");
    long lastModLimit = -1;
    if (lastModLimitVal != null)
        // convert minutes to millisecs
        lastModLimit = Long.parseLong(lastModLimitVal) * 60 * 1000;
    return new DatasetScanConfig.AddLatest(latestName, serviceName, latestOnTop, lastModLimit);
}

19 Source : XMLUtils.java
with GNU Affero General Public License v3.0
from PGMDev

public static Boolean parseBoolean(@Nullable Attribute attr, Boolean def) throws InvalidXMLException {
    return attr == null ? def : parseBoolean(new Node(attr));
}

19 Source : XMLUtils.java
with GNU Affero General Public License v3.0
from PGMDev

public static <T extends Number> T parseNumber(Attribute attr, Clreplaced<T> type, T def) throws InvalidXMLException {
    if (attr == null) {
        return def;
    } else {
        return parseNumber(attr, type);
    }
}

19 Source : XMLUtils.java
with GNU Affero General Public License v3.0
from PGMDev

public static <T extends Enum<T>> T parseEnum(Attribute attr, Clreplaced<T> type, String readableType) throws InvalidXMLException {
    return parseEnum(new Node(attr), type, readableType);
}

19 Source : XMLUtils.java
with GNU Affero General Public License v3.0
from PGMDev

public static SingleMaterialMatcher parseMaterialPattern(Attribute attr) throws InvalidXMLException {
    return parseMaterialPattern(new Node(attr));
}

19 Source : XMLUtils.java
with GNU Affero General Public License v3.0
from PGMDev

public static Vector parseVector(Attribute attr) throws InvalidXMLException {
    return attr == null ? null : parseVector(attr, attr.getValue());
}

19 Source : XMLUtils.java
with GNU Affero General Public License v3.0
from PGMDev

public static Vector parseVector(Attribute attr, String value) throws InvalidXMLException {
    return attr == null ? null : parseVector(new Node(attr), value);
}

19 Source : XMLUtils.java
with GNU Affero General Public License v3.0
from PGMDev

public static DyeColor parseDyeColor(Attribute attr, DyeColor def) throws InvalidXMLException {
    return attr == null ? def : parseDyeColor(attr);
}

19 Source : XMLUtils.java
with GNU Affero General Public License v3.0
from PGMDev

public static Duration parseDuration(Attribute attr) throws InvalidXMLException {
    return parseDuration(attr, null);
}

19 Source : XMLUtils.java
with GNU Affero General Public License v3.0
from PGMDev

public static <T extends Number> T parseNumber(Attribute attr, Clreplaced<T> type) throws InvalidXMLException {
    return parseNumber(new Node(attr), type);
}

19 Source : XMLUtils.java
with GNU Affero General Public License v3.0
from PGMDev

public static <T extends Number & Comparable<T>> T parseNumber(Attribute attr, Clreplaced<T> type, Range<T> range) throws InvalidXMLException {
    return parseNumberInRange(new Node(attr), type, range);
}

19 Source : Node.java
with GNU Affero General Public License v3.0
from PGMDev

public String getDescription() {
    if (node instanceof Element) {
        return describe((Element) node);
    } else {
        Attribute attr = (Attribute) node;
        return "'" + attr.getName() + "' attribute of " + describe(attr.getParent());
    }
}

19 Source : Node.java
with GNU Affero General Public License v3.0
from PGMDev

@Nullable
public static Node fromNullable(Attribute attr) {
    return attr == null ? null : new Node(attr);
}

19 Source : TeamModule.java
with GNU Affero General Public License v3.0
from PGMDev

// ---------------------
// ---- XML Parsing ----
// ---------------------
public TeamFactory parseTeam(Attribute attr, MapFactory factory) throws InvalidXMLException {
    if (attr == null) {
        return null;
    }
    return Teams.getTeam(new Node(attr), factory);
}

19 Source : LegacyRegionParser.java
with GNU Affero General Public License v3.0
from PGMDev

public Region parseReference(Attribute attr) throws InvalidXMLException {
    String name = attr.getValue();
    Region region = this.regionContext.get(name);
    if (region == null) {
        throw new InvalidXMLException("Unknown region '" + name + "'", attr);
    } else {
        return region;
    }
}

19 Source : FeatureRegionParser.java
with GNU Affero General Public License v3.0
from PGMDev

@Override
public Region parseReference(Attribute attr) throws InvalidXMLException {
    return factory.getFeatures().addReference(new XMLRegionReference(factory.getFeatures(), new Node(attr), RegionDefinition.clreplaced));
}

19 Source : PointParser.java
with GNU Affero General Public License v3.0
from PGMDev

AngleProvider parseStaticAngleProvider(Attribute attr) throws InvalidXMLException {
    Float angle = XMLUtils.parseNumber(attr, Float.clreplaced, (Float) null);
    return angle == null ? null : new StaticAngleProvider(angle);
}

19 Source : LegacyKitParser.java
with GNU Affero General Public License v3.0
from PGMDev

@Override
public Kit parse(Element el) throws InvalidXMLException {
    Kit kit;
    Attribute attrName = el.getAttribute("name");
    if (attrName != null && maybeReference(el)) {
        kit = parseReference(new Node(el), attrName.getValue());
    } else {
        kit = parseDefinition(el);
        if (attrName != null) {
            try {
                kitContext.add(attrName.getValue(), kit);
            } catch (IllegalArgumentException e) {
                // Probably a duplicate name
                throw new InvalidXMLException(e.getMessage(), el);
            }
        } else {
            kitContext.add(kit);
        }
    }
    return kit;
}

19 Source : Node.java
with GNU Affero General Public License v3.0
from OvercastNetwork

public String describe() {
    if (node instanceof Element) {
        return describe((Element) node);
    } else {
        Attribute attr = (Attribute) node;
        return "'" + attr.getName() + "' attribute of " + describe(attr.getParent());
    }
}

19 Source : Node.java
with GNU Affero General Public License v3.0
from OvercastNetwork

@Nullable
public static Node fromNullable(Attribute attr) {
    return attr == null ? null : Node.of(attr);
}

19 Source : Node.java
with GNU Affero General Public License v3.0
from OvercastNetwork

public static Node of(Attribute attribute) {
    return new Node(attribute);
}

19 Source : MCRSetAttributeValue.java
with GNU General Public License v3.0
from MyCoRe-Org

public static MCRChangeData setValue(Attribute attribute, String value) {
    MCRChangeData data = new MCRChangeData("set-attribute", attribute);
    attribute.setValue(value);
    return data;
}

19 Source : MCRRemoveAttribute.java
with GNU General Public License v3.0
from MyCoRe-Org

public static MCRChangeData remove(Attribute attribute) {
    MCRChangeData data = new MCRChangeData("removed-attribute", attribute);
    attribute.detach();
    return data;
}

19 Source : MCRChangeData.java
with GNU General Public License v3.0
from MyCoRe-Org

private static String attribute2text(Attribute attribute) {
    Element x = new Element("x").setAttribute(attribute.clone());
    String text = element2text(x);
    return text.substring(3, text.length() - 2).trim();
}

19 Source : MCRAddedAttribute.java
with GNU General Public License v3.0
from MyCoRe-Org

public static MCRChangeData added(Attribute attribute) {
    return new MCRChangeData("added-attribute", attribute);
}

19 Source : MCRMerger.java
with GNU General Public License v3.0
from MyCoRe-Org

/**
 * Copies those attributes from the other's element into this' element that do not exist in this' element.
 */
protected void mergeAttributes(MCRMerger other) {
    for (Attribute attribute : other.element.getAttributes()) {
        if (this.element.getAttribute(attribute.getName(), attribute.getNamespace()) == null) {
            this.element.setAttribute(attribute.clone());
        }
    }
}

19 Source : MCRXPathBuilderTest.java
with GNU General Public License v3.0
from MyCoRe-Org

@Test
public void testXPath() {
    Element root = new Element("root");
    Element replacedle1 = new Element("replacedle");
    Element replacedle2 = new Element("replacedle");
    Element author = new Element("contributor");
    Attribute role = new Attribute("role", "author");
    Attribute lang = new Attribute("lang", "de", Namespace.XML_NAMESPACE);
    author.setAttribute(role);
    author.setAttribute(lang);
    root.addContent(replacedle1);
    root.addContent(author);
    root.addContent(replacedle2);
    new Doreplacedent(root);
    replacedertEquals("/root", MCRXPathBuilder.buildXPath(root));
    replacedertEquals("/root/contributor[1]", MCRXPathBuilder.buildXPath(author));
    replacedertEquals("/root/replacedle[1]", MCRXPathBuilder.buildXPath(replacedle1));
    replacedertEquals("/root/replacedle[2]", MCRXPathBuilder.buildXPath(replacedle2));
    replacedertEquals("/root/contributor[1]/@role", MCRXPathBuilder.buildXPath(role));
    replacedertEquals("/root/contributor[1]/@xml:lang", MCRXPathBuilder.buildXPath(lang));
    root.detach();
    replacedertEquals("root", MCRXPathBuilder.buildXPath(root));
    replacedertEquals("root/contributor[1]", MCRXPathBuilder.buildXPath(author));
}

19 Source : IngesterV1_7.java
with MIT License
from MovieLabs

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.movielabs.mddflib.avails.xml.streaming.StreamingRowIngester#buildreplacedet()
	 */
@Override
protected Element buildreplacedet() {
    Namespace availNS = builder.getAvailsNSpace();
    Element replacedetEl = new Element("replacedet", availNS);
    Element wtEl = new Element("WorkType", availNS);
    wtEl.setText(workType);
    builder.addToPedigree(wtEl, workTypePedigree);
    replacedetEl.addContent(wtEl);
    /*
		 * Source key for 'contentID' depends (unfortunately) on the WorkType of the
		 * replacedet.
		 */
    String colKey = locateContentID(workType);
    Pedigree pg = getPedigreedData(colKey);
    if (Pedigree.isSpecified(pg)) {
        String contentID = pg.getRawValue();
        Attribute attEl = new Attribute("contentID", contentID);
        replacedetEl.setAttribute(attEl);
        builder.addToPedigree(attEl, pg);
        builder.addToPedigree(replacedetEl, pg);
    }
    builder.createreplacedetMetadata(replacedetEl, workType, this);
    pg = getPedigreedData("Avail/BundledALIDs");
    if (Pedigree.isSpecified(pg)) {
        String[] alidList = pg.getRawValue().split(";");
        for (int i = 0; i < alidList.length; i++) {
            Element breplacedetEl = new Element("Bundledreplacedet", availNS);
            builder.addToPedigree(breplacedetEl, pg);
            Element bAlidEl = new Element("BundledALID", availNS);
            bAlidEl.setText(alidList[i]);
            builder.addToPedigree(bAlidEl, pg);
            breplacedetEl.addContent(bAlidEl);
            replacedetEl.addContent(breplacedetEl);
        }
    }
    return replacedetEl;
}

19 Source : RowToXmlHelperV1_7.java
with MIT License
from MovieLabs

/*
	 * (non-Javadoc)
	 * 
	 * @see com.movielabs.mddflib.avails.xml.AbstractRowHelper#buildreplacedet()
	 */
protected Element buildreplacedet() {
    Namespace availNS = xb.getAvailsNSpace();
    Element replacedetEl = new Element("replacedet", availNS);
    Element wtEl = new Element("WorkType", availNS);
    wtEl.setText(workType);
    xb.addToPedigree(wtEl, workTypePedigree);
    replacedetEl.addContent(wtEl);
    /*
		 * Source key for 'contentID' depends (unfortunately) on the WorkType of the
		 * replacedet.
		 */
    String colKey = locateContentID(workType);
    Pedigree pg = getPedigreedData(colKey);
    if (isSpecified(pg)) {
        String contentID = pg.getRawValue();
        Attribute attEl = new Attribute("contentID", contentID);
        replacedetEl.setAttribute(attEl);
        xb.addToPedigree(attEl, pg);
        xb.addToPedigree(replacedetEl, pg);
    }
    xb.createreplacedetMetadata(replacedetEl, workType, this);
    pg = getPedigreedData("Avail/BundledALIDs");
    if (isSpecified(pg)) {
        String[] alidList = pg.getRawValue().split(";");
        for (int i = 0; i < alidList.length; i++) {
            Element breplacedetEl = new Element("Bundledreplacedet", availNS);
            xb.addToPedigree(breplacedetEl, pg);
            Element bAlidEl = new Element("BundledALID", availNS);
            bAlidEl.setText(alidList[i]);
            xb.addToPedigree(bAlidEl, pg);
            breplacedetEl.addContent(bAlidEl);
            replacedetEl.addContent(breplacedetEl);
        }
    }
    return replacedetEl;
}

19 Source : RowToXmlHelperV1_7.java
with MIT License
from MovieLabs

/**
 * Add 1 or more Term elements to a Transaction.
 * <p>
 * As of Excel v 1.6. Terms are a mess. There are two modes for defining:
 * </p>
 * <ol>
 * <li>Use 'PriceType' cell to define a <tt>termName</tt> and then get value
 * from 'PriceValue' cell, or</li>
 * <li>the use of columns implicitly linked to specific <tt>termName</tt></li>
 * </ol>
 * An example of the 2nd approach is the 'WatchDuration' column. What makes the
 * handling even more complex is that a term that was handled via 'PriceType' in
 * one version of the Excel may be handled via a dedicated column in another
 * version.
 *
 * @param transactionEl
 */
protected void addAllTerms(Element transactionEl) {
    String prefix = "AvailTrans/";
    /*
		 * May be multiple 'terms'. Start with one specified via the PriceType
		 */
    Pedigree pg = getPedigreedData(prefix + "PriceType");
    pg = filterDeprecated(pg);
    if (isSpecified(pg)) {
        String tName = pg.getRawValue();
        Element termEl = new Element("Term", xb.getAvailsNSpace());
        /*
			 * Any term may be prefixed with 'TPR-' to indicate temp price reduction
			 */
        String baseTName = tName.replaceFirst("TPR-", "");
        switch(baseTName) {
            case "Tier":
            case "Category":
            case "LicenseFee":
            case "NA":
                process(termEl, "Text", xb.getAvailsNSpace(), prefix + "PriceValue");
                break;
            case "WSP":
                if (workType.equals("Episode")) {
                    tName = "EpisodeWSP";
                } else if (workType.equals("Season")) {
                    tName = "SeasonWSP";
                }
            case "EpisodeWSP":
            case "SeasonWSP":
            case "SRP":
            case "DMRP":
            case "SMRP":
                Element moneyEl = process(termEl, "Money", xb.getAvailsNSpace(), prefix + "PriceValue");
                Pedigree curPGee = getPedigreedData(prefix + "PriceCurrency");
                if (moneyEl != null && isSpecified(curPGee)) {
                    Attribute curAt = new Attribute("currency", curPGee.getRawValue());
                    moneyEl.setAttribute(curAt);
                    xb.addToPedigree(curAt, curPGee);
                }
                break;
            case "Season Only":
                break;
            default:
                String errMsg = "Unrecognized PriceType '" + tName + "'";
                Cell target = (Cell) pg.getSource();
                logger.logIssue(LogMgmt.TAG_XLSX, LogMgmt.LEV_ERR, target, errMsg, null, null, DefaultXmlBuilder.moduleId);
                return;
        }
        termEl.setAttribute("termName", tName);
        xb.addToPedigree(termEl, pg);
        transactionEl.addContent(termEl);
    }
    /*
		 * Now look for Terms specified via other columns....
		 */
    Element termEl = addTerm(transactionEl, prefix + "SuppressionLiftDate", "SuppressionLiftDate", "Event");
    termEl = addTerm(transactionEl, prefix + "AnnounceDate", "AnnounceDate", "Event");
    termEl = addTerm(transactionEl, prefix + "SpecialPreOrderFulfillDate", "PreOrderFulfillDate", "Event");
    termEl = addTerm(transactionEl, prefix + "SRP", "SRP", "Money");
    termEl = addTerm(transactionEl, prefix + "RentalDuration", "RentalDuration", "Duration");
    termEl = addTerm(transactionEl, prefix + "WatchDuration", "WatchDuration", "Duration");
    termEl = addTerm(transactionEl, prefix + "FixedEndDate", "FixedEndDate", "Event");
}

19 Source : ReaderJdomUtil.java
with Apache License 2.0
from i-novus-llc

public static String getAttributeString(Element element, String attribute) {
    if (element == null)
        return null;
    Attribute attr = element.getAttribute(attribute);
    if (attr != null) {
        return getText(attr);
    }
    return null;
}

19 Source : WitsmlQuery.java
with Apache License 2.0
from hashmapinc

private void applyAttributeConstraints(Element element) {
    replacedert element != null : "root cannot be null";
    Iterator iterator = this.attributeConstraints.iterator();
    while (iterator.hasNext()) {
        WitsmlQuery.AttributeConstraint attributeConstraint = (WitsmlQuery.AttributeConstraint) iterator.next();
        String elementName = attributeConstraint.getElementName();
        Element foundElement = findElement(element, elementName);
        if (foundElement != null) {
            String attributeName = attributeConstraint.getAttributeName();
            Attribute attribute = foundElement.getAttribute(attributeName);
            if (attribute != null) {
                attribute.setValue(attributeConstraint.getText());
            }
        }
    }
}

19 Source : XmlAttribute.java
with MIT License
from Avicus

private static Optional<String> getValue(XmlElement element, String name) {
    Attribute jdom = element.getJdomElement().getAttribute(name);
    return jdom == null ? Optional.empty() : Optional.of(jdom.getValue());
}

18 Source : XMLUtils.java
with GNU Affero General Public License v3.0
from PGMDev

public static Duration parseDuration(Attribute attr, Duration def) throws InvalidXMLException {
    return parseDuration(Node.fromNullable(attr), def);
}

18 Source : XMLUtils.java
with GNU Affero General Public License v3.0
from PGMDev

/**
 * Parse a numeric range from attributes on the given element specifying the bounds of the range,
 * specifically:
 *
 * <p>gt gte lt lte
 */
public static <T extends Number & Comparable<T>> Range<T> parseNumericRange(Element el, Clreplaced<T> type) throws InvalidXMLException {
    Attribute lt = el.getAttribute("lt");
    Attribute lte = el.getAttribute("lte");
    Attribute gt = el.getAttribute("gt");
    Attribute gte = el.getAttribute("gte");
    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 Range.all();
        } else {
            return Range.upTo(upperBound, upperBoundType);
        }
    } else {
        if (upperBound == null) {
            return Range.downTo(lowerBound, lowerBoundType);
        } else {
            return Range.range(lowerBound, lowerBoundType, upperBound, upperBoundType);
        }
    }
}

18 Source : XMLUtils.java
with GNU Affero General Public License v3.0
from PGMDev

public static Attribute getRequiredAttribute(Element el, String... aliases) throws InvalidXMLException {
    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 '" + aliases[0] + "' is required", el);
    }
    return attr;
}

18 Source : XMLUtils.java
with GNU Affero General Public License v3.0
from PGMDev

public static Vector parseVector(Attribute attr, Vector def) throws InvalidXMLException {
    return attr == null ? def : parseVector(attr);
}

18 Source : XMLUtils.java
with GNU Affero General Public License v3.0
from PGMDev

public static DyeColor parseDyeColor(Attribute attr) throws InvalidXMLException {
    String name = attr.getValue().replace(" ", "_").toUpperCase();
    try {
        return DyeColor.valueOf(name);
    } catch (IllegalArgumentException e) {
        throw new InvalidXMLException("Invalid dye color '" + attr.getValue() + "'", attr);
    }
}

18 Source : Node.java
with GNU Affero General Public License v3.0
from OvercastNetwork

private static boolean equals(Attribute a, Attribute b) {
    if (a == null || b == null)
        return false;
    if (a == b)
        return true;
    if (!a.getName().equals(b.getName()))
        return false;
    return equals(a.getParent(), b.getParent());
}

18 Source : ProximityAlarmModule.java
with GNU Affero General Public License v3.0
from OvercastNetwork

public static ProximityAlarmDefinition parseDefinition(MapModuleContext context, Element elAlarm) throws InvalidXMLException {
    ProximityAlarmDefinition definition = new ProximityAlarmDefinition();
    FilterParser filterParser = context.needModule(FilterParser.clreplaced);
    definition.detectFilter = filterParser.parseProperty(elAlarm, "detect");
    definition.alertFilter = filterParser.property(elAlarm, "notify").optionalGet(() -> new InverseFilter(definition.detectFilter));
    definition.detectRegion = context.needModule(RegionParser.clreplaced).property(elAlarm, "region").required();
    // null = no message
    definition.alertMessage = elAlarm.getAttributeValue("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.clreplaced);
    }
    return definition;
}

18 Source : MCRSetAttributeValue.java
with GNU General Public License v3.0
from MyCoRe-Org

public void undo(MCRChangeData data) {
    Attribute attribute = data.getAttribute();
    data.getContext().removeAttribute(attribute.getName(), attribute.getNamespace());
    data.getContext().setAttribute(attribute);
}

18 Source : MCRAddedAttribute.java
with GNU General Public License v3.0
from MyCoRe-Org

public void undo(MCRChangeData data) {
    Attribute attribute = data.getAttribute();
    data.getContext().removeAttribute(attribute.getName(), attribute.getNamespace());
}

18 Source : MCRXPathBuilder.java
with GNU General Public License v3.0
from MyCoRe-Org

/**
 * Builds an absolute XPath expression for the given attribute within a JDOM XML structure.
 * For each element that is not the root element, the XPath will also contain a position predicate.
 * For all namespaces commonly used in MyCoRe, their namespace prefixes will be used.
 *
 * @param attribute a JDOM attribute
 * @return absolute XPath of that attribute. In case there is a root Doreplacedent, it will begin with a "/".
 */
public static String buildXPath(Attribute attribute) {
    String parentXPath = buildXPath(attribute.getParent());
    if (!parentXPath.isEmpty()) {
        parentXPath += "/";
    }
    return parentXPath + "@" + attribute.getQualifiedName();
}

18 Source : ReaderJdomUtil.java
with Apache License 2.0
from i-novus-llc

public static String getText(Attribute attr) {
    return processText(attr.getValue());
}

18 Source : ConditionalsFactory.java
with MIT License
from Avicus

public static Conditional parseConditional(Element element) throws XmlException {
    List<Attribute> attributes = element.getAttributes();
    if (attributes.size() != 1) {
        throw new XmlException(new XmlElement(element), "Conditionals must have 1 and only 1 variable.");
    }
    Attribute variable = attributes.get(0);
    switch(variable.getName()) {
        case "season":
        case "month":
        case "holiday":
            return new DateConditional(variable.getName(), variable.getValue(), element.getChildren());
        default:
            return new ConfigValueConditional(variable.getName(), variable.getValue(), element.getChildren());
    }
}

17 Source : RegionParser.java
with GNU Affero General Public License v3.0
from PGMDev

@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;
}

17 Source : PointParser.java
with GNU Affero General Public License v3.0
from PGMDev

/**
 * Parse any number of {@link PointProvider}s in attributes or children of the given names.
 */
public List<PointProvider> parseMultiProperty(Element el, PointProviderAttributes attributes, String... aliases) throws InvalidXMLException {
    attributes = parseAttributes(el, attributes);
    List<PointProvider> providers = new ArrayList<>();
    for (Attribute attr : XMLUtils.getAttributes(el, aliases)) {
        providers.add(new RegionPointProvider(validate(regionParser.parseReference(attr), new Node(attr)), attributes));
    }
    for (Element child : XMLUtils.getChildren(el, aliases)) {
        providers.add(new RegionPointProvider(validate(regionParser.parseChild(child), new Node(child)), parseAttributes(child, attributes)));
    }
    return providers;
}

17 Source : RegionDefinitionParser.java
with GNU Affero General Public License v3.0
from OvercastNetwork

@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);
}

17 Source : PortalModule.java
with GNU Affero General Public License v3.0
from OvercastNetwork

private static DoubleTransform parseDoubleTransform(Element el, String attributeName, DoubleTransform def) throws InvalidXMLException {
    Attribute attr = el.getAttribute(attributeName);
    if (attr == null) {
        return def;
    }
    String text = attr.getValue();
    try {
        if (text.startsWith("@")) {
            double value = Double.parseDouble(text.substring(1));
            return new DoubleTransform.Constant(value);
        } else {
            double value = Double.parseDouble(text);
            return new DoubleTransform.Translate(value);
        }
    } catch (NumberFormatException e) {
        throw new InvalidXMLException("Invalid portal coordinate", attr, e);
    }
}

See More Examples