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


Java Element.getAttribute方法代码示例

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


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

示例1: getChildMap

import org.jdom.Element; //导入方法依赖的package包/类
public static <K, V> Map<K, V> getChildMap(Element element, String name, boolean optional) throws StudyUnrecognizedFormatException {
  Element mapParent = getChildWithName(element, name, optional);
  if (mapParent != null) {
    Element map = mapParent.getChild(MAP);
    if (map != null) {
      HashMap result = new HashMap();
      for (Element entry : map.getChildren()) {
        Object key = entry.getAttribute(KEY) == null ? entry.getChild(KEY).getChildren().get(0) : entry.getAttributeValue(KEY);
        Object value = entry.getAttribute(VALUE) == null ? entry.getChild(VALUE).getChildren().get(0) : entry.getAttributeValue(VALUE);
        result.put(key, value);
      }
      return result;
    }
  }
  return Collections.emptyMap();
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:17,代码来源:StudySerializationUtils.java

示例2: readFrom

import org.jdom.Element; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void readFrom(Element rootElement)
   /* Is passed an Element by TC, and is expected to load it into the in memory settings object.
    * Old settings should be overwritten.
    */
   {
   	Loggers.SERVER.debug("readFrom :: " + rootElement.toString());
   	CopyOnWriteArrayList<MsTeamsNotificationConfig> configs = new CopyOnWriteArrayList<MsTeamsNotificationConfig>();
   	
   	if (rootElement.getAttribute(ENABLED) != null){
   		this.msTeamsNotificationsEnabled = Boolean.parseBoolean(rootElement.getAttributeValue(ENABLED));
   	}
   	
	List<Element> namedChildren = rootElement.getChildren("msteamsNotification");
       if(namedChildren.isEmpty())
       {
           this.msteamsNotificationsConfigs = null;
       } else {
		for(Element e :  namedChildren)
        {
			MsTeamsNotificationConfig whConfig = new MsTeamsNotificationConfig(e);
			Loggers.SERVER.debug(e.toString());
			configs.add(whConfig);
			Loggers.SERVER.debug(NAME + ":readFrom :: enabled " + String.valueOf(whConfig.getEnabled()));
        }
		this.msteamsNotificationsConfigs = configs;
   	}
   }
 
开发者ID:spyder007,项目名称:teamcity-msteams-notifier,代码行数:30,代码来源:MsTeamsNotificationProjectSettings.java

示例3: test_WebookConfig

import org.jdom.Element; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void test_WebookConfig() throws JDOMException, IOException{
	SAXBuilder builder = new SAXBuilder();
	List<MsTeamsNotificationConfig> configs = new ArrayList<MsTeamsNotificationConfig>();
	builder.setIgnoringElementContentWhitespace(true);
		Document doc = builder.build("src/test/resources/testdoc2.xml");
		Element root = doc.getRootElement();
		if(root.getChild("msteamsNotifications") != null){
			Element child = root.getChild("msteamsNotifications");
			if ((child.getAttribute("enabled") != null) && (child.getAttribute("enabled").equals("true"))){
				List<Element> namedChildren = child.getChildren("msteamsNotification");
				for(Iterator<Element> i = namedChildren.iterator(); i.hasNext();)
	            {
					Element e = i.next();
					MsTeamsNotificationConfig whConfig = new MsTeamsNotificationConfig(e);
					configs.add(whConfig);
	            }
			}
		}

	
	for (MsTeamsNotificationConfig c : configs){
		MsTeamsNotification wh = new MsTeamsNotificationImpl();
		wh.setEnabled(c.getEnabled());
		//msteamsNotification.addParams(c.getParams());
		System.out.println(wh.isEnabled().toString());

	}
}
 
开发者ID:spyder007,项目名称:teamcity-msteams-notifier,代码行数:31,代码来源:MsTeamsNotificationSettingsTest.java

示例4: test_ReadXml

import org.jdom.Element; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void test_ReadXml() throws JDOMException, IOException {
	SAXBuilder builder = new SAXBuilder();
	//builder.setValidation(true);
	builder.setIgnoringElementContentWhitespace(true);
	
		Document doc = builder.build("src/test/resources/testdoc1.xml");
		Element root = doc.getRootElement();
		System.out.println(root.toString());
		if(root.getChild("msteamsNotifications") != null){
			Element child = root.getChild("msteamsNotifications");
			if ((child.getAttribute("enabled") != null) && (child.getAttribute("enabled").equals("true"))){
				List<Element> namedChildren = child.getChildren("msteamsNotification");
				for(Iterator<Element> i = namedChildren.iterator(); i.hasNext();)
	            {
					Element e = i.next();
					System.out.println(e.toString() + e.getAttributeValue("url"));
					//assertTrue(e.getAttributeValue("url").equals("http://something"));
					if(e.getChild("parameters") != null){
						Element eParams = e.getChild("parameters");
						List<Element> paramsList = eParams.getChildren("param");
						for(Iterator<Element> j = paramsList.iterator(); j.hasNext();)
						{
							Element eParam = j.next();
							System.out.println(eParam.toString() + eParam.getAttributeValue("name"));
							System.out.println(eParam.toString() + eParam.getAttributeValue("value"));
						}
					}
	            }
			}
		}

}
 
开发者ID:spyder007,项目名称:teamcity-msteams-notifier,代码行数:35,代码来源:MsTeamsNotificationSettingsTest.java

示例5: getChildWithName

import org.jdom.Element; //导入方法依赖的package包/类
public static Element getChildWithName(Element parent, String name, boolean optional) throws StudyUnrecognizedFormatException {
  for (Element child : parent.getChildren()) {
    Attribute attribute = child.getAttribute(NAME);
    if (attribute == null) {
      continue;
    }
    if (name.equals(attribute.getValue())) {
      return child;
    }
  }
  if (optional) {
    return null;
  }
  throw new StudyUnrecognizedFormatException();
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:16,代码来源:StudySerializationUtils.java

示例6: isMyType

import org.jdom.Element; //导入方法依赖的package包/类
public boolean isMyType(Document document) {
    boolean ok = false;
    Element rssRoot = document.getRootElement();
    ok = rssRoot.getName().equals("rss");
    if (ok) {
        ok = false;
        Attribute version = rssRoot.getAttribute("version");
        if (version!=null) {
            ok = version.getValue().equals(getRSSVersion());
        }
    }
    return ok;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:14,代码来源:RSS091UserlandParser.java

示例7: getTaxonomy

import org.jdom.Element; //导入方法依赖的package包/类
/**
 * Utility method to parse a taxonomy from an element.
 * <p>
 * @param desc the taxonomy description element.
 * @return the string contained in the resource of the element.
 */
protected final String getTaxonomy(Element desc) {
    String d = null;
    Element taxo = desc.getChild("topic", getTaxonomyNamespace());
    if (taxo!=null) {
        Attribute a = taxo.getAttribute("resource", getRDFNamespace());
        if (a!=null) {
            d = a.getValue();
        }
    }
    return d;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:18,代码来源:DCModuleParser.java

示例8: write

import org.jdom.Element; //导入方法依赖的package包/类
public static void write( Writer w, Model newModel, boolean namespaceDeclaration )
    throws IOException
{
    Element root = new Element( "project" );

    if ( namespaceDeclaration )
    {
        String modelVersion = newModel.getModelVersion();

        Namespace pomNamespace = Namespace.getNamespace( "", "http://maven.apache.org/POM/" + modelVersion );

        root.setNamespace( pomNamespace );

        Namespace xsiNamespace = Namespace.getNamespace( "xsi", "http://www.w3.org/2001/XMLSchema-instance" );

        root.addNamespaceDeclaration( xsiNamespace );

        if ( root.getAttribute( "schemaLocation", xsiNamespace ) == null )
        {
            root.setAttribute( "schemaLocation",
                               "http://maven.apache.org/POM/" + modelVersion + " http://maven.apache.org/maven-v"
                                   + modelVersion.replace( '.', '_' ) + ".xsd", xsiNamespace );
        }
    }

    Document doc = new Document( root );

    MavenJDOMWriter writer = new MavenJDOMWriter();

    String encoding = newModel.getModelEncoding() != null ? newModel.getModelEncoding() : "UTF-8";

    Format format = Format.getPrettyFormat().setEncoding( encoding );

    writer.write( newModel, doc, w, format );
}
 
开发者ID:javiersigler,项目名称:apache-maven-shade-plugin,代码行数:36,代码来源:PomWriter.java

示例9: NamedTextAttr

import org.jdom.Element; //导入方法依赖的package包/类
public NamedTextAttr(@NotNull Element element) {
    super(element);
    final Attribute attribute = element.getAttribute(ATTR_NAME);
    if (attribute != null) {
        name = attribute.getValue();
    }
    if (name == null) {
        name = "";
    }
}
 
开发者ID:huoguangjin,项目名称:MultiHighlight,代码行数:11,代码来源:NamedTextAttr.java

示例10: readConfigurationFromXmlElement

import org.jdom.Element; //导入方法依赖的package包/类
void readConfigurationFromXmlElement(Element msteamsNotificationsElement) {
    if(msteamsNotificationsElement != null){
        content.setEnabled(true);
        if(msteamsNotificationsElement.getAttribute(ENABLED) != null)
        {
            setEnabled(Boolean.parseBoolean(msteamsNotificationsElement.getAttributeValue(ENABLED)));
        }
        if(msteamsNotificationsElement.getAttribute(TOKEN) != null)
        {
            setToken(msteamsNotificationsElement.getAttributeValue(TOKEN));
        }
        if(msteamsNotificationsElement.getAttribute(ICON_URL) != null)
        {
            content.setIconUrl(msteamsNotificationsElement.getAttributeValue(ICON_URL));
        }
        if(msteamsNotificationsElement.getAttribute(BOT_NAME) != null)
        {
            content.setBotName(msteamsNotificationsElement.getAttributeValue(BOT_NAME));
        }
        if(msteamsNotificationsElement.getAttribute(SHOW_BUILD_AGENT) != null)
        {
            content.setShowBuildAgent(Boolean.parseBoolean(msteamsNotificationsElement.getAttributeValue(SHOW_BUILD_AGENT)));
        }
        if(msteamsNotificationsElement.getAttribute(SHOW_ELAPSED_BUILD_TIME) != null)
        {
            content.setShowElapsedBuildTime(Boolean.parseBoolean(msteamsNotificationsElement.getAttributeValue(SHOW_ELAPSED_BUILD_TIME)));
        }
        if(msteamsNotificationsElement.getAttribute(SHOW_COMMITS) != null)
        {
            content.setShowCommits(Boolean.parseBoolean(msteamsNotificationsElement.getAttributeValue(SHOW_COMMITS)));
        }
        if(msteamsNotificationsElement.getAttribute(SHOW_COMMITTERS) != null)
        {
            content.setShowCommitters(Boolean.parseBoolean(msteamsNotificationsElement.getAttributeValue(SHOW_COMMITTERS)));
        }
        if(msteamsNotificationsElement.getAttribute(MAX_COMMITS_TO_DISPLAY) != null)
        {
            content.setMaxCommitsToDisplay(Integer.parseInt(msteamsNotificationsElement.getAttributeValue(MAX_COMMITS_TO_DISPLAY)));
        }
        if(msteamsNotificationsElement.getAttribute(SHOW_FAILURE_REASON) != null)
        {
            content.setShowFailureReason(Boolean.parseBoolean(msteamsNotificationsElement.getAttributeValue(SHOW_FAILURE_REASON)));
        }

        Element proxyElement = msteamsNotificationsElement.getChild(PROXY);
        if(proxyElement != null)
        {
            if (proxyElement.getAttribute("proxyShortNames") != null){
                setProxyShortNames(Boolean.parseBoolean(proxyElement.getAttributeValue("proxyShortNames")));
            }

            if (proxyElement.getAttribute("host") != null){
                setProxyHost(proxyElement.getAttributeValue("host"));
            }

            if (proxyElement.getAttribute("port") != null){
                setProxyPort(Integer.parseInt(proxyElement.getAttributeValue("port")));
            }

            if (proxyElement.getAttribute(USERNAME) != null){
                setProxyUsername(proxyElement.getAttributeValue(USERNAME));
            }

            if (proxyElement.getAttribute(PASSWORD) != null){
                setProxyPassword(proxyElement.getAttributeValue(PASSWORD));
            }
        }
        else {
            setProxyHost(null);
            setProxyPort(null);
            setProxyUsername(null);
            setProxyPassword(null);
        }
    }
}
 
开发者ID:spyder007,项目名称:teamcity-msteams-notifier,代码行数:76,代码来源:MsTeamsNotificationMainConfig.java

示例11: convertToFifthVersion

import org.jdom.Element; //导入方法依赖的package包/类
public static Element convertToFifthVersion(Element state) throws StudyUnrecognizedFormatException {
  Element taskManagerElement = state.getChild(MAIN_ELEMENT);
  Element courseElement = getChildWithName(taskManagerElement, COURSE).getChild(COURSE_TITLED);
  final int courseId = getAsInt(courseElement, ID);
  if (courseElement != null && courseId > 0) {
    courseElement.setName(REMOTE_COURSE);
  }
  final Element adaptive = getChildWithName(courseElement, ADAPTIVE);
  for (Element lesson : getChildList(courseElement, LESSONS)) {
    for (Element task : getChildList(lesson, TASK_LIST)) {
      final Element lastSubtaskIndex = getChildWithName(task, LAST_SUBTASK_INDEX, true); //could be broken by 3->4 migration
      final Element adaptiveParams = getChildWithName(task, ADAPTIVE_TASK_PARAMETERS, true);
      Element theoryTask = getChildWithName(task, THEORY_TAG, true);
      if (theoryTask == null && adaptiveParams != null) {
        theoryTask = getChildWithName(adaptiveParams, THEORY_TAG, true);
      }
      final boolean hasAdaptiveParams = adaptiveParams != null && !adaptiveParams.getChildren().isEmpty();
      if (lastSubtaskIndex != null && Integer.valueOf(lastSubtaskIndex.getAttributeValue(VALUE)) != 0) {
        task.setName(TASK_WITH_SUBTASKS);
      }
      else if (theoryTask != null && Boolean.valueOf(theoryTask.getAttributeValue(VALUE))) {
        task.setName(THEORY_TASK);
      }
      else if (hasAdaptiveParams) {
        task.setName(CHOICE_TASK);
        final Element adaptiveParameters = adaptiveParams.getChildren().get(0);
        for (Element element : adaptiveParameters.getChildren()) {
          final Attribute name = element.getAttribute(NAME);
          if (name != null && !THEORY_TAG.equals(name.getValue())) {
            final Content elementCopy = element.clone();
            task.addContent(elementCopy);
          }
        }
      }
      else if (Boolean.valueOf(adaptive.getAttributeValue(VALUE))) {
        task.setName(CODE_TASK);
      }
      else {
        task.setName(PYCHARM_TASK);
      }
      task.removeContent(adaptiveParams);
      task.removeContent(theoryTask);
    }
  }
  return state;
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:47,代码来源:StudySerializationUtils.java

示例12: processResource

import org.jdom.Element; //导入方法依赖的package包/类
public void processResource( String resource, InputStream is, List<Relocator> relocators )
    throws IOException
{
    Document r;
    try
    {
        SAXBuilder builder = new SAXBuilder( false );
        builder.setExpandEntities( false );
        if ( ignoreDtd )
        {
            builder.setEntityResolver( new EntityResolver()
            {
                public InputSource resolveEntity( String publicId, String systemId )
                    throws SAXException, IOException
                {
                    return new InputSource( new StringReader( "" ) );
                }
            } );
        }
        r = builder.build( is );
    }
    catch ( JDOMException e )
    {
        throw new RuntimeException( "Error processing resource " + resource + ": " + e.getMessage(), e );
    }

    if ( doc == null )
    {
        doc = r;
    }
    else
    {
        Element root = r.getRootElement();

        for ( @SuppressWarnings( "unchecked" )
        Iterator<Attribute> itr = root.getAttributes().iterator(); itr.hasNext(); )
        {
            Attribute a = itr.next();
            itr.remove();

            Element mergedEl = doc.getRootElement();
            Attribute mergedAtt = mergedEl.getAttribute( a.getName(), a.getNamespace() );
            if ( mergedAtt == null )
            {
                mergedEl.setAttribute( a );
            }
        }

        for ( @SuppressWarnings( "unchecked" )
        Iterator<Content> itr = root.getChildren().iterator(); itr.hasNext(); )
        {
            Content n = itr.next();
            itr.remove();

            doc.getRootElement().addContent( n );
        }
    }
}
 
开发者ID:javiersigler,项目名称:apache-maven-shade-plugin,代码行数:59,代码来源:XmlAppendingTransformer.java

示例13: addAttribute

import org.jdom.Element; //导入方法依赖的package包/类
/**
 * Add an attribute with the given value to the given element, but only if the
 * element does not already have the attribute, and the value is not equal to
 * the given default value.
 * 
 * @param paramElt
 *          the element
 * @param value
 *          the attribute value (which will be converted to a string)
 * @param defaultValue
 *          if value.equals(defaultValue) we do not add the attribute.
 * @param attrName
 *          the name of the attribute to add.
 */
private void addAttribute(Element paramElt, Object value,
    Object defaultValue, String attrName) {
  if(!defaultValue.equals(value) && paramElt.getAttribute(attrName) == null) {
    paramElt.setAttribute(attrName, value.toString());
  }
}
 
开发者ID:GateNLP,项目名称:gate-core,代码行数:21,代码来源:CreoleAnnotationHandler.java


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