當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。