Java Code Examples for org.jdom.Element#getChildren()

The following examples show how to use org.jdom.Element#getChildren() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AboutCommands.java    From geoserver-shell with MIT License 6 votes vote down vote up
@CliCommand(value = "manifest get", help = "Get a manifest.")
public String manifestGet(
        @CliOption(key = "name", mandatory = true, help = "The name") String name
) throws Exception {
    String TAB = "   ";
    String xml = HTTPUtils.get(geoserver.getUrl() + "/rest/about/manifests.xml", geoserver.getUser(), geoserver.getPassword());
    StringBuilder builder = new StringBuilder();
    Element root = JDOMBuilder.buildElement(xml);
    List<Element> resources = root.getChildren("resource");
    for (Element resource : resources) {
        String n = resource.getAttributeValue("name");
        if (name.equalsIgnoreCase(n)) {
            builder.append(name).append(OsUtils.LINE_SEPARATOR);
            List<Element> children = resource.getChildren();
            for (Element child : children) {
                builder.append(TAB).append(child.getName()).append(": ").append(child.getTextTrim()).append(OsUtils.LINE_SEPARATOR);
            }
        }
    }
    return builder.toString();
}
 
Example 2
Source File: GroupedVertexInfo.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
GroupedVertexInfo(Element element) {
	super(element);

	List<Element> children = element.getChildren(VERTEX_INFO_ELEMENT_NAME);
	for (Element vertexInfoElement : children) {
		vertexInfos.add(new VertexInfo(vertexInfoElement));
	}

	children = element.getChildren(GROUPED_VERTEX_INFO_ELEMENT_NAME);
	for (Element groupedVertexInfoElement : children) {
		vertexInfos.add(new GroupedVertexInfo(groupedVertexInfoElement));
	}

	if (vertexInfos.isEmpty()) {
		throw new IllegalArgumentException(
			"Saved GroupedVertexInfo XML does not have child vertices");
	}

	userText =
		XmlUtilities.unEscapeElementEntities(element.getAttributeValue(USER_TEXT_ATTRIBUTE));
	backgroundColor = decodeColor(element.getAttributeValue(BACKGROUND_COLOR_ATTRIBUTE));
}
 
Example 3
Source File: FontCommands.java    From geoserver-shell with MIT License 6 votes vote down vote up
private List<String> getFontNames(String xml) {
	List<String> fonts = new ArrayList<String>();

	Element root = JDOMBuilder.buildElement(xml);
    Element fontElement = root.getChild("fonts");
    if (fontElement != null) {
        List<Element> children = fontElement.getChildren("entry");
        for (Element elem : children) {
    	    fonts.add(elem.getTextTrim());
    	}

        Collections.sort(fonts);
    }

    return fonts;
}
 
Example 4
Source File: AddressCorrelatorManager.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
// we know what the type is correct
public void readConfigState(SaveState saveState) {
	Element correlatorsRootElement = saveState.getXmlElement(ADDRESS_CORRELATORS_ELEMENT_NAME);
	if (correlatorsRootElement == null) {
		return; // nothing saved yet
	}

	List<Element> correlatorElements =
		correlatorsRootElement.getChildren(ADDRESS_CORRELATOR_SUB_ELEMENT_NAME);
	for (Element correlatorElement : correlatorElements) {
		String className = correlatorElement.getAttributeValue(ADDRESS_CORRELATOR_NAME_KEY);
		List<Element> optionsList =
			correlatorElement.getChildren(ADDRESS_CORRELATOR_OPTIONS_SUB_ELEMENT);
		Element optionsElement = optionsList.get(0);
		List<Element> optionsContentList =
			optionsElement.getChildren(ToolOptions.XML_ELEMENT_NAME);
		Element optionsContent = optionsContentList.get(0);
		Options options = new ToolOptions(optionsContent);
		updateCorrelatorOptions(className, options);
	}
}
 
Example 5
Source File: S3PreSignUrlHelper.java    From teamcity-s3-artifact-storage-plugin with Apache License 2.0 6 votes vote down vote up
@NotNull
public static Map<String, URL> readPreSignUrlMapping(String data) throws IOException {
  Document document;
  try {
    document = JDOMUtil.loadDocument(data);
  } catch (JDOMException e) {
    return Collections.emptyMap();
  }
  final Element rootElement = document.getRootElement();
  if (!rootElement.getName().equals(S3_PRESIGN_URL_MAPPING)) return Collections.emptyMap();
  final Map<String, URL> result = new HashMap<String, URL>();
  for (Object mapEntryElement : rootElement.getChildren(S3_PRESIGN_URL_MAP_ENTRY)) {
    final Element mapEntryElementCasted = (Element)mapEntryElement;
    final String s3ObjectKey = mapEntryElementCasted.getChild(S3_OBJECT_KEY).getValue();
    final String preSignUrlString = mapEntryElementCasted.getChild(PRE_SIGN_URL).getValue();
    result.put(s3ObjectKey, new URL(preSignUrlString));
  }
  return result;
}
 
Example 6
Source File: ContentEntryImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ContentEntryImpl(@Nonnull Element e, @Nonnull ModuleRootLayerImpl m) {
  this(getUrlFrom(e), m);

  for (Element child : e.getChildren(ContentFolderImpl.ELEMENT_NAME)) {
    myContentFolders.add(new ContentFolderImpl(child, this));
  }
}
 
Example 7
Source File: ContextConfigurator.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void setProperty(String id, String propertyName, String value) {
	Element element = xml.getChild("bean", "id", id);
	List poperties = element.getChildren("property", element.getNamespace());
	for (Iterator iter = poperties.iterator(); iter.hasNext();) {
		Element property = (Element) iter.next();
		if (propertyName.equals(property.getAttribute("name").getValue())) {
			property.getChild("value").setText(value);
			break;
		}
	}
}
 
Example 8
Source File: JPlistBuilder.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private static DictionaryElement parseDictionary(Element edict) {
List<Element> children = edict.getChildren();
    DictionaryElement dict = new DictionaryElement();
    for (Iterator iter = children.iterator(); iter.hasNext(); ) {
      Element keyElement = (Element)iter.next();
      PElementType keyType = PElementType.getType(keyElement.getName());
      if (keyType != PElementType.KEY)
        throw new IllegalArgumentException("Missing KEY!");
      String key = keyElement.getValue();
      Element pelement = (Element)iter.next();
      PElement value = parseGeneric(pelement);
      dict.put(key, value);
    }
    return dict;
  }
 
Example 9
Source File: IntentionManagerSettings.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void loadState(Element element) {
  myIgnoredActions.clear();
  List<Element> children = element.getChildren(IGNORE_ACTION_TAG);
  for (Element e : children) {
    myIgnoredActions.add(e.getAttributeValue(NAME_ATT));
  }
}
 
Example 10
Source File: SoapConverter.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
public Element getParameter(String name){
	if (bValid) {
		Element body = eRoot.getChild("Body", ns);
		List<Element> params = body.getChildren("parameter", ns);
		for (Element el : params) {
			if (el.getAttributeValue("name").equalsIgnoreCase(name)) {
				return el;
			}
		}
	}
	return null;
}
 
Example 11
Source File: NewsletterConfigDOM.java    From entando-components with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void extractContentTypes(Element root, NewsletterConfig config) {
	Element contentTypesElem = root.getChild(CONTENTTYPES_ELEM);
	if (null != contentTypesElem) {
		List<Element> contentTypeElements = contentTypesElem.getChildren(CONTENTTYPE_CHILD);
		if (null != contentTypeElements) {
			for (int i=0; i<contentTypeElements.size(); i++) {
				Element contentTypeElem = contentTypeElements.get(i);
				config.addContentType(this.extractContentType(contentTypeElem));
			}
		}
	}
}
 
Example 12
Source File: PathMacrosImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void loadState(Element state) {
  try {
    myLock.writeLock().lock();

    final List<Element> children = state.getChildren(MACRO_ELEMENT);
    for (Element aChildren : children) {
      final String name = aChildren.getAttributeValue(NAME_ATTR);
      String value = aChildren.getAttributeValue(VALUE_ATTR);
      if (name == null || value == null) {
        throw new InvalidDataException();
      }

      if (SYSTEM_MACROS.contains(name)) {
        continue;
      }

      if (value.length() > 1 && value.charAt(value.length() - 1) == '/') {
        value = value.substring(0, value.length() - 1);
      }

      myMacros.put(name, value);
    }

    final List<Element> ignoredChildren = state.getChildren(IGNORED_MACRO_ELEMENT);
    for (final Element child : ignoredChildren) {
      final String ignoredName = child.getAttributeValue(NAME_ATTR);
      if (ignoredName != null && !ignoredName.isEmpty() && !myIgnoredMacros.contains(ignoredName)) {
        myIgnoredMacros.add(ignoredName);
      }
    }
  }
  finally {
    myModificationStamp++;
    myLock.writeLock().unlock();
  }
}
 
Example 13
Source File: WindowStateServiceImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public final void loadState(@Nonnull Element element) {
  synchronized (myStateMap) {
    myStateMap.clear();
    for (Element child : element.getChildren()) {
      if (!STATE.equals(child.getName())) continue; // ignore unexpected element

      long current = System.currentTimeMillis();
      long timestamp = StringUtilRt.parseLong(child.getAttributeValue(TIMESTAMP), current);
      if (TimeUnit.DAYS.toMillis(100) <= (current - timestamp)) continue; // ignore old elements

      String key = child.getAttributeValue(KEY);
      if (StringUtilRt.isEmpty(key)) continue; // unexpected key

      Point location = JDOMUtil.getLocation(child);
      Dimension size = JDOMUtil.getSize(child);
      if (location == null && size == null) continue; // unexpected value

      CachedState state = new CachedState();
      state.myLocation = location;
      state.mySize = size;
      state.myMaximized = Boolean.parseBoolean(child.getAttributeValue(MAXIMIZED));
      state.myFullScreen = Boolean.parseBoolean(child.getAttributeValue(FULL_SCREEN));
      state.myScreen = apply(JDOMUtil::getBounds, child.getChild(SCREEN));
      state.myTimeStamp = timestamp;
      myStateMap.put(key, state);
    }
  }
}
 
Example 14
Source File: ModuleCompilerPathsManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void loadState(Element element) {
  myInheritOutput = false;
  myExcludeOutput = Boolean.valueOf(element.getAttributeValue(EXCLUDE, "true"));
  for (Element child2 : element.getChildren()) {
    final String moduleUrl = child2.getAttributeValue(URL);
    final String type = child2.getAttributeValue(TYPE);

    myVirtualFilePointers.put(type, VirtualFilePointerManager.getInstance().create(moduleUrl, this, null));
  }
}
 
Example 15
Source File: PageModelDOM.java    From entando-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
private ApsProperties buildProperties(Element propertiesElement) {
	List<Element> propertyElements = propertiesElement.getChildren(TAB_PROPERTY);
	if (null == propertyElements || propertyElements.isEmpty()) {
		return null;
	}
	ApsProperties prop = new ApsProperties();
	Iterator<Element> propertyElementsIter = propertyElements.iterator();
	while (propertyElementsIter.hasNext()) {
		Element property = (Element) propertyElementsIter.next();
		prop.put(property.getAttributeValue(ATTRIBUTE_KEY), property.getText().trim());
	}
	return prop;
}
 
Example 16
Source File: BeastImporter.java    From beast-mcmc with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Taxon readTaxon(TaxonList primaryTaxa, Element e) throws Importer.ImportException {

        String id = e.getAttributeValue(XMLParser.ID);

        Taxon taxon = null;

        if (id != null) {
            taxon = new Taxon(id);

            List children = e.getChildren();
            for(Object aChildren : children) {
                Element child = (Element) aChildren;

                if( child.getName().equalsIgnoreCase(dr.evolution.util.Date.DATE) ) {
                    Date date = readDate(child);
                    taxon.setAttribute(dr.evolution.util.Date.DATE, date);
                } else if( child.getName().equalsIgnoreCase(AttributeParser.ATTRIBUTE) ) {
                    String name = child.getAttributeValue(AttributeParser.NAME);
                    String value = child.getAttributeValue(AttributeParser.VALUE);
                    if (value == null) {
                        value = child.getTextTrim();
                    }
                    taxon.setAttribute(name, value);
                }
            }
        } else {
            String idref = e.getAttributeValue(XMLParser.IDREF);
            int index = primaryTaxa.getTaxonIndex(idref);
            if (index >= 0) {
                taxon = primaryTaxa.getTaxon(index);
            }
        }

        return taxon;
    }
 
Example 17
Source File: Polygon2D.java    From beast-mcmc with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Polygon2D(Element e) {
    List<Element> children = e.getChildren();
    id = e.getAttributeValue(XMLParser.ID);

    parseCoordinates(e);
}
 
Example 18
Source File: PCodeTestResults.java    From ghidra with Apache License 2.0 4 votes vote down vote up
public PCodeTestResults(Element root) {

		if (!TAG_NAME.equals(root.getName())) {
			throw new IllegalArgumentException("Unsupported root element: " + root.getName());
		}
		String ver = root.getAttributeValue("VERSION");
		if (!XML_VERSION.equals(ver)) {
			throw new IllegalArgumentException(
				"Unsupported XML format version " + ver + ", required format is " + XML_VERSION);
		}

		jUnitName = root.getAttributeValue("JUNIT");

		time = 0;
		String timeStr = root.getAttributeValue("TIME");
		if (timeStr != null) {
			try {
				time = Long.parseLong(timeStr);
			}
			catch (NumberFormatException e) {
				// ignore
			}
		}

		summaryHasIngestErrors = getAttributeValue(root, "INGEST_ERR", false);
		summaryHasRelocationErrors = getAttributeValue(root, "RELOC_ERR", false);
		summaryHasDisassemblyErrors = getAttributeValue(root, "DIS_ERR", false);

		@SuppressWarnings("unchecked")
		List<Element> elementList = root.getChildren("TestResults");
		for (Element element : elementList) {

			String testName = element.getAttributeValue("NAME");
			if (testName == null) {
				throw new IllegalArgumentException("Invalid TestResults element in XML");
			}
			TestResults testResults = new TestResults();
			testResults.totalAsserts = getAttributeValue(element, "TOTAL_ASSERTS", 0);
			testResults.passCount = getAttributeValue(element, "PASS", 0);
			testResults.failCount = getAttributeValue(element, "FAIL", 0);
			testResults.callOtherCount = getAttributeValue(element, "CALLOTHER", 0);
			testResults.severeFailure = getAttributeValue(element, "SEVERE_FAILURE", false);

			summaryTotalAsserts += testResults.totalAsserts;
			summaryPassCount += testResults.passCount;
			summaryFailCount += testResults.failCount;
			summaryCallOtherCount += testResults.callOtherCount;
			if (testResults.severeFailure) {
				++summarySevereFailures;
			}

			results.put(testName, testResults);
		}
	}
 
Example 19
Source File: BlazeCommandRunConfiguration.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Override
public void readExternal(Element element) throws InvalidDataException {
  super.readExternal(element);

  element = getBlazeSettingsCopy(element);

  String keepInSyncString = element.getAttributeValue(KEEP_IN_SYNC_TAG);
  keepInSync = keepInSyncString != null ? Boolean.parseBoolean(keepInSyncString) : null;
  contextElementString = element.getAttributeValue(CONTEXT_ELEMENT_ATTR);

  ImmutableList.Builder<String> targets = ImmutableList.builder();
  List<Element> targetElements = element.getChildren(TARGET_TAG);
  for (Element targetElement : targetElements) {
    if (targetElement != null && !Strings.isNullOrEmpty(targetElement.getTextTrim())) {
      targets.add(targetElement.getTextTrim());
      // backwards-compatibility with prior per-target kind serialization
      String kind = targetElement.getAttributeValue(KIND_ATTR);
      if (kind != null) {
        targetKindString = kind;
      }
    }
  }
  targetPatterns = targets.build();
  String singleKind = element.getAttributeValue(KIND_ATTR);
  if (singleKind != null) {
    targetKindString = element.getAttributeValue(KIND_ATTR);
  }

  // Because BlazeProjectData is not available when configurations are loading,
  // we can't call setTarget and have it find the appropriate handler provider.
  // So instead, we use the stored provider ID.
  String providerId = element.getAttributeValue(HANDLER_ATTR);
  BlazeCommandRunConfigurationHandlerProvider handlerProvider =
      BlazeCommandRunConfigurationHandlerProvider.getHandlerProvider(providerId);
  if (handlerProvider != null) {
    updateHandlerIfDifferentProvider(handlerProvider);
  }

  blazeElementState = element;
  handler.getState().readExternal(blazeElementState);
}
 
Example 20
Source File: DataSourceDumpReport.java    From entando-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
public DataSourceDumpReport(String xmlText) {
	if (null == xmlText || xmlText.trim().length() == 0) {
		return;
	}
	SAXBuilder builder = new SAXBuilder();
	builder.setValidation(false);
	StringReader reader = new StringReader(xmlText);
	try {
		Document doc = builder.build(reader);
		Element rootElement = doc.getRootElement();
		Element dateElement = rootElement.getChild(DATE_ELEMENT);
		if (null != dateElement) {
			Date date = DateConverter.parseDate(dateElement.getText(), DATE_FORMAT);
			this.setDate(date);
		}
		Element subfolderElement = rootElement.getChild(SUBFOLDER_NAME_ELEMENT);
		if (null != subfolderElement) {
			this.setSubFolderName(subfolderElement.getText());
		}
		
		Element requiredTimeElement = rootElement.getChild(REQUIRED_TIME_ELEMENT);
		if (null != requiredTimeElement) {
			this.setRequiredTime(Long.valueOf(requiredTimeElement.getText()));
		}
		
		Element componentsElement = rootElement.getChild(COMPONENTS_HISTORY_ELEMENT);
		if (null != componentsElement) {
			List<Element> componentElements = componentsElement.getChildren();
			for (int i = 0; i < componentElements.size(); i++) {
				Element componentElement = componentElements.get(i);
				ComponentInstallationReport componentHistory = new ComponentInstallationReport(componentElement);
				this.addComponentHistory(componentHistory);
			}
		}
		List<Element> elements = rootElement.getChildren(DATASOURCE_ELEMENT);
		for (int i = 0; i < elements.size(); i++) {
			Element dataSourceElement = elements.get(i);
			String dataSourceName = dataSourceElement.getAttributeValue(NAME_ATTRIBUTE);
			List<Element> tableElements = dataSourceElement.getChildren();
			for (int j = 0; j < tableElements.size(); j++) {
				Element tableElement = tableElements.get(j);
				TableDumpReport tableDumpReport = new TableDumpReport(tableElement);
				this.addTableReport(dataSourceName, tableDumpReport);
			}
		}
	} catch (Throwable t) {
		_logger.error("Error parsing Report. xml:{} ", xmlText, t);
		throw new RuntimeException("Error detected while parsing the XML", t);
	}
}