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


Java Attribute类代码示例

本文整理汇总了Java中org.jdom2.Attribute的典型用法代码示例。如果您正苦于以下问题:Java Attribute类的具体用法?Java Attribute怎么用?Java Attribute使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: setPerformanceTimeRangeOnNode

import org.jdom2.Attribute; //导入依赖的package包/类
/**
 * Acquires the reporting parameters within the xml and inserts into a given node
 *
 * @param element XML document that contains the reporting parameters act
 * @param thisNode Reporting parameter node
 */
private void setPerformanceTimeRangeOnNode(Element element, Node thisNode) {
	String performanceStartExprStr = getXpath(PERFORMANCE_START);
	String performanceEndExprStr = getXpath(PERFORMANCE_END);

	Consumer<? super Attribute> performanceStartConsumer =
			p -> {
				String start = p.getValue();
				thisNode.putValue(PERFORMANCE_START, start, false);
				//start is formatted as follows: yyyyMMddHHmmss
				thisNode.putValue(PERFORMANCE_YEAR, start.substring(0, 4));
			};
	Consumer<? super Attribute> performanceEndConsumer =
			p -> thisNode.putValue(PERFORMANCE_END, p.getValue(), false);

	setOnNode(element, performanceStartExprStr, performanceStartConsumer, Filters.attribute(), false);
	setOnNode(element, performanceEndExprStr, performanceEndConsumer, Filters.attribute(), false);
}
 
开发者ID:CMSgov,项目名称:qpp-conversion-tool,代码行数:24,代码来源:ReportingParametersActDecoder.java

示例2: executeAttributeTest

import org.jdom2.Attribute; //导入依赖的package包/类
public void executeAttributeTest(String jsonPath, String expectedValue) {
	String xPath = PathCorrelator.prepPath(jsonPath, wrapper);

	Attribute attribute = null;
	try {
		attribute = evaluateXpath(xPath, Filters.attribute());
	} catch (IOException | XmlException e) {
		fail(e.getMessage());
	}

	if (attribute == null) {
		System.out.println("no attribute for path: " + jsonPath
				+ "\n xpath: " + xPath);
	}

	if (!expectedValue.equals(attribute.getValue())) {
		System.err.println("( " + jsonPath + " ) value ( " + expectedValue +
				" ) does not equal ( " + attribute.getValue() +
				" ) at \n( " + xPath + " ). \nPlease investigate.");
	}

	assertThat(attribute.getValue()).isNotNull();
}
 
开发者ID:CMSgov,项目名称:qpp-conversion-tool,代码行数:24,代码来源:JsonPathToXpathHelper.java

示例3: getRequiredAttribute

import org.jdom2.Attribute; //导入依赖的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

示例4: parseFormattedText

import org.jdom2.Attribute; //导入依赖的package包/类
/**
 * Parse a piece of formatted text, which can be either plain text with legacy
 * formatting codes, or JSON chat components.
 */
public static BaseComponent parseFormattedText(@Nullable Node node, BaseComponent def) throws InvalidXMLException {
    if(node == null) return def;

    // <blah translate="x"/> is shorthand for <blah>{"translate":"x"}</blah>
    if(node.isElement()) {
        final Attribute translate = node.asElement().getAttribute("translate");
        if(translate != null) {
            return new TranslatableComponent(translate.getValue());
        }
    }

    String text = node.getValueNormalize();
    if(looksLikeJson(text)) {
        try {
            return Components.concat(ComponentSerializer.parse(node.getValue()));
        } catch(JsonParseException e) {
            throw new InvalidXMLException(e.getMessage(), node, e);
        }
    } else {
        return Components.concat(TextComponent.fromLegacyText(BukkitUtils.colorize(text)));
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:27,代码来源:XMLUtils.java

示例5: parseDefinition

import org.jdom2.Attribute; //导入依赖的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

示例6: ClonedElement

import org.jdom2.Attribute; //导入依赖的package包/类
public ClonedElement(Element el) {
    super(el.getName(), el.getNamespace());
    setParent(el.getParent());

    final BoundedElement bounded = (BoundedElement) el;
    setLine(bounded.getLine());
    setColumn(bounded.getColumn());
    setStartLine(bounded.getStartLine());
    setEndLine(bounded.getEndLine());
    this.indexInParent = bounded.indexInParent();

    setContent(el.cloneContent());

    for(Attribute attribute : el.getAttributes()) {
        setAttribute(attribute.clone());
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:18,代码来源:ClonedElement.java

示例7: evaluateToAttributes

import org.jdom2.Attribute; //导入依赖的package包/类
/**
 * Evaluates the given XPath expression to a list of attributes.
 * 
 * @param expr XPath expression to evaluate.
 * @param parent If not null, the expression is evaluated relative to this element.
 * @return {@link ArrayList} or null
 * @throws FatalIndexerException 
 * @should return all values
 */
public List<Attribute> evaluateToAttributes(String expr, Object parent) throws FatalIndexerException {
    List<Attribute> retList = new ArrayList<>();
    if (parent == null) {
        parent = doc;
    }
    List<Object> list = evaluate(expr, parent, Filters.attribute());
    if (list == null) {
        return null;
    }
    for (Object object : list) {
        if (object instanceof Attribute) {
            Attribute attr = (Attribute) object;
            retList.add(attr);
        }
    }
    return retList;
}
 
开发者ID:intranda,项目名称:goobi-viewer-indexer,代码行数:27,代码来源:JDomXP.java

示例8: objectToString

import org.jdom2.Attribute; //导入依赖的package包/类
/**
 * Returns the string value of the given XML node object, depending on its type.
 * 
 * @param object
 * @return String
 */
public static String objectToString(Object object) {
    if (object instanceof Element) {
        return ((Element) object).getText();
    } else if (object instanceof Attribute) {
        return ((Attribute) object).getValue();
    } else if (object instanceof Text) {
        return ((Text) object).getText();
    } else if (object instanceof CDATA) {
        return ((CDATA) object).getText();
    } else if (object instanceof Comment) {
        return ((Comment) object).getText();
    } else if (object instanceof Double) {
        return String.valueOf(object);
    } else if (object instanceof Boolean) {
        return String.valueOf(object);
    } else if (object instanceof String) {
        return (String) object;
    } else if (object != null) {
        logger.error("Unknown object type: {}", object.getClass().getName());
        return null;
    } else {
        return null;
    }

}
 
开发者ID:intranda,项目名称:goobi-viewer-indexer,代码行数:32,代码来源:JDomXP.java

示例9: parseString

import org.jdom2.Attribute; //导入依赖的package包/类
/**
 * Parses a JDom2 Object into a string
 * @param e
 *            Object (Element, Text, Document or Attribute)
 * @return String
 * @author sholzer (11.05.2015)
 */
public String parseString(Object e) {
    XMLOutputter element2String = new XMLOutputter();
    if (e instanceof Element) {
        return element2String.outputString((Element) e);
    }
    if (e instanceof Text) {
        return element2String.outputString((Text) e);
    }
    if (e instanceof Document) {
        return element2String.outputString((Document) e);
    }
    if (e instanceof org.jdom2.Attribute) {
        Attribute a = (org.jdom2.Attribute) e;
        return a.getName() + "=\"" + a.getValue() + "\"";
    }
    return e.toString();
}
 
开发者ID:maybeec,项目名称:lexeme,代码行数:25,代码来源:JDom2Util.java

示例10: clean

import org.jdom2.Attribute; //导入依赖的package包/类
private boolean clean(Element element) {
    boolean changed = false;

    for (Iterator<Element> children = element.getChildren().iterator(); children.hasNext();) {
        Element child = children.next();
        if (clean(child))
            changed = true;
        if (!isRelevant(child)) {
            changed = true;
            children.remove();
        }
    }

    for (Iterator<Attribute> attributes = element.getAttributes().iterator(); attributes.hasNext();) {
        Attribute attribute = attributes.next();
        if (!isRelevant(attribute)) {
            changed = true;
            attributes.remove();
        }
    }

    return changed;
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:24,代码来源:MCRXMLCleaner.java

示例11: parseDuration

import org.jdom2.Attribute; //导入依赖的package包/类
private static int parseDuration(Element xml) {
    Attribute attribute = xml.getAttribute("duration");
    if (attribute != null) {
        Time time = XMLTime.parse(attribute, Time.SECOND);

        if (!time.isForever()) {
            try {
                return Math.toIntExact(time.toTicks());
            } catch (ArithmeticException ignored) {
            }
        }

        return Integer.MAX_VALUE;
    }

    return 20;
}
 
开发者ID:ShootGame,项目名称:Arcade2,代码行数:18,代码来源:XMLPotionEffect.java

示例12: process

import org.jdom2.Attribute; //导入依赖的package包/类
@Override
public void process(XMLPreProcessor xml, Entry entry, Element map) throws Throwable {
    Attribute typeAttribute = entry.getElement().getAttribute("type");
    Type type = Type.LOCAL; // default value
    if (typeAttribute != null) {
        Type parsedType = Type.valueOf(XMLParser.parseEnumValue(typeAttribute.getValue()));
        if (parsedType != null) {
            type = parsedType;
        }
    }

    String path = entry.getElement().getTextNormalize();
    if (path.isEmpty()) {
        return;
    }

    Element include = type.process(this.plugin, entry.getElement(), path);
    if (include == null) {
        return;
    }

    for (Element rootChild : include.getChildren()) {
        this.attachElement(map, rootChild);
    }
}
 
开发者ID:ShootGame,项目名称:Arcade2,代码行数:26,代码来源:XMLPreProcessor.java

示例13: testCompleteUndo

import org.jdom2.Attribute; //导入依赖的package包/类
@Test
public void testCompleteUndo() throws JaxenException, JDOMException {
    String template = "document[titles[title][title[2]]][authors/author[first='John'][last='Doe']]";
    Document doc = new Document(new MCRNodeBuilder().buildElement(template, null, null));
    Document before = doc.clone();

    MCRChangeTracker tracker = new MCRChangeTracker();

    Element titles = (Element) (new MCRBinding("document/titles", true, new MCRBinding(doc)).getBoundNode());
    Element title = new Element("title").setAttribute("type", "alternative");
    titles.addContent(2, title);
    tracker.track(MCRAddedElement.added(title));

    Attribute lang = new Attribute("lang", "de");
    doc.getRootElement().setAttribute(lang);
    tracker.track(MCRAddedAttribute.added(lang));

    Element author = (Element) (new MCRBinding("document/authors/author", true, new MCRBinding(doc))
        .getBoundNode());
    tracker.track(MCRRemoveElement.remove(author));

    tracker.undoChanges(doc);

    assertTrue(MCRXMLHelper.deepEqual(before, doc));
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:26,代码来源:MCRChangeTrackerTest.java

示例14: testRemoveChangeTracking

import org.jdom2.Attribute; //导入依赖的package包/类
@Test
public void testRemoveChangeTracking() throws JaxenException, JDOMException {
    String template = "document[titles[title][title[2]]][authors/author[first='John'][last='Doe']]";
    Document doc = new Document(new MCRNodeBuilder().buildElement(template, null, null));

    MCRChangeTracker tracker = new MCRChangeTracker();

    Element titles = (Element) (new MCRBinding("document/titles", true, new MCRBinding(doc)).getBoundNode());
    Element title = new Element("title").setAttribute("type", "alternative");
    titles.addContent(2, title);
    tracker.track(MCRAddedElement.added(title));

    Attribute lang = new Attribute("lang", "de");
    doc.getRootElement().setAttribute(lang);
    tracker.track(MCRAddedAttribute.added(lang));

    Element author = (Element) (new MCRBinding("document/authors/author", true, new MCRBinding(doc))
        .getBoundNode());
    tracker.track(MCRRemoveElement.remove(author));

    doc = MCRChangeTracker.removeChangeTracking(doc);
    assertFalse(doc.getDescendants(Filters.processinginstruction()).iterator().hasNext());
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:24,代码来源:MCRChangeTrackerTest.java

示例15: testNestedChanges

import org.jdom2.Attribute; //导入依赖的package包/类
@Test
public void testNestedChanges() {
    Element root = new Element("root");
    Document doc = new Document(root);
    MCRChangeTracker tracker = new MCRChangeTracker();

    Element title = new Element("title");
    root.addContent(title);
    tracker.track(MCRAddedElement.added(title));

    Attribute id = new Attribute("type", "main");
    title.setAttribute(id);
    tracker.track(MCRAddedAttribute.added(id));

    Element part = new Element("part");
    title.addContent(part);
    tracker.track(MCRAddedElement.added(part));

    tracker.track(MCRRemoveElement.remove(part));
    tracker.track(MCRRemoveAttribute.remove(id));
    tracker.track(MCRRemoveElement.remove(title));

    tracker.undoChanges(doc);
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:25,代码来源:MCRChangeTrackerTest.java


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