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

The following examples show how to use org.jdom.Element#getAttributeValue() . 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: ActionMacro.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void readExternal(Element macro) throws InvalidDataException {
  setName(macro.getAttributeValue(ATTRIBUTE_NAME));
  List actions = macro.getChildren();
  for (final Object o : actions) {
    Element action = (Element)o;
    if (ELEMENT_TYPING.equals(action.getName())) {
      Pair<List<Integer>, List<Integer>> codes = parseKeyCodes(action.getAttributeValue(ATTRIBUTE_KEY_CODES));

      String text = action.getText();
      if (text == null || text.length() == 0) {
        text = action.getAttributeValue(ATTRIBUTE_TEXT);
      }
      text = text.replaceAll("&#x20;", " ");

      if (!StringUtil.isEmpty(text)) {
        myActions.add(new TypedDescriptor(text, codes.getFirst(), codes.getSecond()));
      }
    }
    else if (ELEMENT_ACTION.equals(action.getName())) {
      myActions.add(new IdActionDescriptor(action.getAttributeValue(ATTRIBUTE_ID)));
    }
    else if (ELEMENT_SHORTCUT.equals(action.getName())) {
      myActions.add(new ShortcutActionDesciption(action.getAttributeValue(ATTRIBUTE_TEXT)));
    }
  }
}
 
Example 2
Source File: AbstractCollectionBinding.java    From consulo with Apache License 2.0 6 votes vote down vote up
private Object deserializeItem(@Nonnull Element node, Object context) {
  Binding binding = getElementBinding(node);
  if (binding == null) {
    String attributeName = annotation == null ? Constants.VALUE : annotation.elementValueAttribute();
    String value;
    if (attributeName.isEmpty()) {
      value = XmlSerializerImpl.getTextValue(node, "");
    }
    else {
      value = node.getAttributeValue(attributeName);
    }
    return XmlSerializerImpl.convert(value, itemType);
  }
  else {
    return binding.deserialize(context, node);
  }
}
 
Example 3
Source File: CompilerConfigurationImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void loadState(Element element) {
  String url = element.getAttributeValue(URL);
  if (url != null) {
    setCompilerOutputUrl(url);
  }

  for (Element moduleElement : element.getChildren("module")) {
    String name = moduleElement.getAttributeValue("name");
    if (name == null) {
      continue;
    }
    Module module = AccessRule.read(() -> myModuleManager.findModuleByName(name));
    if (module != null) {
      ModuleCompilerPathsManagerImpl moduleCompilerPathsManager = (ModuleCompilerPathsManagerImpl)ModuleCompilerPathsManager.getInstance(module);
      moduleCompilerPathsManager.loadState(moduleElement);
    }
  }
}
 
Example 4
Source File: ValueElementReader.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Reads a value of the specified type
 * from the specified attribute of the given element.
 *
 * @param type      the class that defines the result type
 * @param element   the value element
 * @param attribute the attribute that contains a value
 * @param <T>       the result type
 * @return a value or {@code null} if it cannot be read
 */
private <T> T read(Class<T> type, Element element, String attribute) {
  String value = element.getAttributeValue(attribute);
  if (value != null) {
    value = value.trim();
    if (value.isEmpty()) {
      if (LOG.isDebugEnabled()) LOG.debug("empty attribute: " + attribute);
    }
    else {
      try {
        return convert(type, value);
      }
      catch (Exception exception) {
        if (LOG.isDebugEnabled()) LOG.debug("wrong attribute: " + attribute, exception);
      }
    }
  }
  return null;
}
 
Example 5
Source File: RemovedMappingTracker.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
static List<RemovedMapping> readRemovedMappings(@Nonnull Element e) {
  List<Element> children = e.getChildren(ELEMENT_REMOVED_MAPPING);
  if (children.isEmpty()) {
    return Collections.emptyList();
  }

  List<RemovedMapping> result = new ArrayList<>();
  for (Element mapping : children) {
    String ext = mapping.getAttributeValue(AbstractFileType.ATTRIBUTE_EXT);
    FileNameMatcher matcher = ext == null ? FileTypeManager.parseFromString(mapping.getAttributeValue(AbstractFileType.ATTRIBUTE_PATTERN)) : new ExtensionFileNameMatcher(ext);
    boolean approved = Boolean.parseBoolean(mapping.getAttributeValue(ATTRIBUTE_APPROVED));
    String fileTypeName = mapping.getAttributeValue(ATTRIBUTE_TYPE);
    if (fileTypeName == null) continue;

    RemovedMapping removedMapping = new RemovedMapping(matcher, fileTypeName, approved);
    result.add(removedMapping);
  }
  return result;
}
 
Example 6
Source File: TextEditorProvider.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
@Nonnull
public FileEditorState readState(@Nonnull Element element, @Nonnull Project project, @Nonnull VirtualFile file) {
  TextEditorState state = new TextEditorState();

  try {
    List<Element> caretElements = element.getChildren(CARET_ELEMENT);
    if (caretElements.isEmpty()) {
      state.CARETS = new TextEditorState.CaretState[]{readCaretInfo(element)};
    }
    else {
      state.CARETS = new TextEditorState.CaretState[caretElements.size()];
      for (int i = 0; i < caretElements.size(); i++) {
        state.CARETS[i] = readCaretInfo(caretElements.get(i));
      }
    }

    String verticalScrollProportion = element.getAttributeValue(RELATIVE_CARET_POSITION_ATTR);
    state.RELATIVE_CARET_POSITION = verticalScrollProportion == null ? 0 : Integer.parseInt(verticalScrollProportion);
  }
  catch (NumberFormatException ignored) {
  }

  return state;
}
 
Example 7
Source File: WorkflowNotifierDOM.java    From entando-components with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void extractMailConfig(NotifierConfig notifierConfig, Element mailElement) {
	notifierConfig.setSenderCode(mailElement.getAttributeValue(MAIL_SENDERCODE_ATTR));
	//notifierConfig.setMailAttrName(mailElement.getAttributeValue(MAIL_MAILATTRNAME_ATTR));
	String html = mailElement.getAttributeValue(MAIL_HTML_ATTR);
	notifierConfig.setHtml(html!=null && "true".equalsIgnoreCase(html));
	notifierConfig.setSubject(mailElement.getChild(MAIL_SUBJECT_CHILD).getText());
	notifierConfig.setHeader(mailElement.getChild(MAIL_HEADER_CHILD).getText());
	notifierConfig.setTemplate(mailElement.getChild(MAIL_TEMPLATE_CHILD).getText());
	notifierConfig.setFooter(mailElement.getChild(MAIL_FOOTER_CHILD).getText());
}
 
Example 8
Source File: ModuleOrderEntryType.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public ModuleOrderEntryImpl loadOrderEntry(@Nonnull Element element, @Nonnull ModuleRootLayer moduleRootLayer) throws InvalidDataException {
  String moduleName = element.getAttributeValue(MODULE_NAME_ATTR);
  if (moduleName == null) {
    throw new InvalidDataException();
  }
  DependencyScope dependencyScope = DependencyScope.readExternal(element);
  boolean exported = element.getAttributeValue(EXPORTED_ATTR) != null;
  boolean productionOnTestDependency = element.getAttributeValue(PRODUCTION_ON_TEST_ATTRIBUTE) != null;
  return new ModuleOrderEntryImpl(moduleName, (ModuleRootLayerImpl)moduleRootLayer, dependencyScope, exported, productionOnTestDependency);
}
 
Example 9
Source File: FileColorConfiguration.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static FileColorConfiguration load(@Nonnull final Element e) {
  final String path = e.getAttributeValue(SCOPE_NAME);
  if (path == null) {
    return null;
  }

  final String colorName = e.getAttributeValue(COLOR);
  if (colorName == null) {
    return null;
  }

  return new FileColorConfiguration(path, colorName);
}
 
Example 10
Source File: ContextRegisterInfo.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a {@link ContextRegisterInfo} object using data in the supplied XML node.
 * 
 * @param ele xml Element
 * @return new {@link ContextRegisterInfo} object, never null
 */
public static ContextRegisterInfo fromXml(Element ele) {

	String contextRegister = ele.getAttributeValue("contextRegister");
	String value = ele.getAttributeValue("value");

	ContextRegisterInfo result = new ContextRegisterInfo();
	result.setContextRegister(contextRegister);
	result.setValue(value != null ? new BigInteger(value) : null);

	return result;
}
 
Example 11
Source File: WebAppGuesser.java    From zap-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * this function return a list of possible version according to the presence or not of indicator
 * files
 *
 * <p>TODO : implement analyze of HTTP response and compare with 404 model file
 *
 * @param urlToGuess
 * @return
 * @throws MalformedURLException
 * @throws IOException
 * @throws NoSuchAlgorithmException
 * @throws DecoderException
 */
public static ArrayList<String> guessApps(URL urlToGuess)
        throws MalformedURLException, IOException, NoSuchAlgorithmException, DecoderException {
    ArrayList<String> guessedApps = new ArrayList<String>();
    Document doc = getFastGuessBDD(fastAppGuessBD);
    Element racine = doc.getRootElement();
    for (int i = 0; i < racine.getChildren().size(); i++) {
        Element app = (Element) racine.getChildren().get(i);
        String appName = app.getAttributeValue("name");
        // System.out.println(appName);
        for (int j = 0; j < app.getChildren().size(); j++) {
            String indicFilePath = ((Element) app.getChildren().get(j)).getValue();
            // System.out.println(indicFilePath);
            if (checkIfExist(urlToGuess, indicFilePath)) {

                // ici soit on retourne le resultat ou on passe au fingerprinting
                System.out.println(appName);

                // ********************************************

                // here we can change this to : pass urlToGuess
                // to fingerprintFile as an argument or ...
                setUrlToGuess(urlToGuess);
                // TODO the following call must return a set of versions
                // fingerPrintFile(appName);
                guessedApps.add(appName.toLowerCase());
                break;
            }
        }
    }
    return guessedApps;
}
 
Example 12
Source File: TodoPattern.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void readExternal(Element element, @Nonnull TextAttributes defaultTodoAttributes) throws InvalidDataException {
  myAttributes = new TodoAttributes(element,defaultTodoAttributes);
  myIndexPattern.setCaseSensitive(Boolean.valueOf(element.getAttributeValue(CASE_SENS_ATT)).booleanValue());
  String attributeValue = element.getAttributeValue(PATTERN_ATT);
  if (attributeValue != null){
    myIndexPattern.setPatternString(attributeValue.trim());
  }
}
 
Example 13
Source File: CodeStyleSettings.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static int getVersion(@Nonnull Element element) {
  String versionStr = element.getAttributeValue(VERSION_ATTR);
  if (versionStr == null) {
    return 0;
  }
  else {
    try {
      return Integer.parseInt(versionStr);
    }
    catch (NumberFormatException nfe) {
      return CURR_VERSION;
    }
  }
}
 
Example 14
Source File: AbbreviationManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void loadState(Element state) {
  final List<Element> abbreviations = state.getChildren("abbreviations");
  if (abbreviations != null && abbreviations.size() == 1) {
    final List<Element> actions = abbreviations.get(0).getChildren("action");
    if (actions != null && actions.size() > 0) {
      for (Element action : actions) {
        final String actionId = action.getAttributeValue("id");
        LinkedHashSet<String> values = myActionId2Abbreviations.get(actionId);
        if (values == null) {
          values = new LinkedHashSet<>(1);
          myActionId2Abbreviations.put(actionId, values);
        }

        final List<Element> abbreviation = action.getChildren("abbreviation");
        if (abbreviation != null) {
          for (Element abbr : abbreviation) {
            final String abbrValue = abbr.getAttributeValue("name");
            if (abbrValue != null) {
              values.add(abbrValue);
            }
          }
        }
      }
    }
  }
}
 
Example 15
Source File: NodesLoader.java    From jbt with Apache License 2.0 5 votes vote down vote up
private static void parseElement(String currentPath, Element e) {
	String nodeType = e.getName();

	if (nodeType.equals("Category")) {
		String categoryName = e.getAttributeValue("name");
		List<Element> children = e.getChildren();

		for (Element child : children) {
			String nextPath = currentPath == null ? categoryName : currentPath
					+ ConceptualNodesTree.CATEGORY_SEPARATOR + categoryName;
			parseElement(nextPath, child);
		}
	} else if (nodeType.equals("Node")) {
		ConceptualBTNode xmlNode = new ConceptualBTNode();
		xmlNode.setType(e.getChild("Type").getValue());
		String numChildren = e.getChild("Children").getValue();
		xmlNode.setNumChildren(numChildren.equals("I") ? -1 : Integer.parseInt(numChildren));
		xmlNode.setIcon(e.getChild("Icon").getValue());
		xmlNode.setReadableType(e.getChild("ReadableType").getValue());
		xmlNode.setHasName(false);
		parseParameters(xmlNode, e);
		
		ConceptualBTNodeItem nodeToInsert = new ConceptualBTNodeItem(xmlNode);
		standardNodesTree.insertNode(currentPath, nodeToInsert);
		standardNodes.put(xmlNode.getType(), xmlNode);
		nodesByCategory.put(xmlNode.getType(), currentPath);
	}
}
 
Example 16
Source File: UserRegConfigDOM.java    From entando-components with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void extractUserAuthDefaults(Element root, IUserRegConfig config) {
	Element userAuths = root.getChild(USER_DEFAULT_AUTHS);
	if (null != userAuths) {
		List<Element> auths = userAuths.getChildren(USER_DEFAULT_AUTH_ELEM);
		Iterator<Element> it = auths.iterator();
		while (it.hasNext()) {
			Element current = (Element) it.next();
			String groupName = current.getAttributeValue(USER_AUTH_GROUP_ATTR);
			String roleName = current.getAttributeValue(USER_AUTH_ROLE_ATTR);
			if (null == roleName) roleName = "";
			String csv = groupName + "," + roleName;
			config.addDefaultCsvAuthorization(csv);
		}
	}
}
 
Example 17
Source File: PredefinedLogFile.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void readExternal(Element element) throws InvalidDataException {
  myId = element.getAttributeValue(ID_ATTRIBUTE);
  myEnabled = Boolean.parseBoolean(element.getAttributeValue(ENABLED_ATTRIBUTE));
}
 
Example 18
Source File: FunctionBitPatternInfo.java    From ghidra with Apache License 2.0 4 votes vote down vote up
/**
 * Converts a XML element into a FunctionBitPatternInfo object.
 * 
 * @param e xml {@link Element} to convert
 * @return new {@link FunctionBitPatternInfo} object, never null
 */
public static FunctionBitPatternInfo fromXml(Element e) {
	String preBytes = e.getAttributeValue("preBytes");
	String firstBytes = e.getAttributeValue("firstBytes");
	String address = e.getAttributeValue("address");

	List<String> returnBytes = new ArrayList<>();
	Element returnBytesListEle = e.getChild("returnBytesList");
	if (returnBytesListEle != null) {
		for (Element rbEle : XmlUtilities.getChildren(returnBytesListEle, "returnBytes")) {
			returnBytes.add(rbEle.getAttributeValue("value"));
		}
	}

	InstructionSequence firstInst = InstructionSequence.fromXml(e.getChild("firstInst"));
	InstructionSequence preInst = InstructionSequence.fromXml(e.getChild("preInst"));

	List<InstructionSequence> returnInst = new ArrayList<>();
	Element returnInstListEle = e.getChild("returnInstList");
	if (returnInstListEle != null) {
		for (Element isEle : XmlUtilities.getChildren(returnInstListEle,
			InstructionSequence.XML_ELEMENT_NAME)) {
			returnInst.add(InstructionSequence.fromXml(isEle));
		}
	}

	List<ContextRegisterInfo> contextRegisters = new ArrayList<>();
	Element contextRegistersListEle = e.getChild("contextRegistersList");
	if ( contextRegistersListEle != null ) {
		for (Element criElement : XmlUtilities.getChildren(contextRegistersListEle,
			ContextRegisterInfo.XML_ELEMENT_NAME)) {
			contextRegisters.add(ContextRegisterInfo.fromXml(criElement));
		}
	}
	
	FunctionBitPatternInfo result = new FunctionBitPatternInfo();
	result.setPreBytes(preBytes);
	result.setFirstBytes(firstBytes);
	result.setAddress(address);
	result.setReturnBytes(returnBytes);
	result.setFirstInst(firstInst);
	result.setPreInst(preInst);
	result.setReturnInst(returnInst);
	result.setContextRegisters(contextRegisters);

	return result;
}
 
Example 19
Source File: HaxeProjectSettings.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
@Override
public void loadState(Element state) {
  userCompilerDefinitions = state.getAttributeValue(DEFINES, "");
  tracker.notifyUpdated();
}
 
Example 20
Source File: RuleXmlParser.java    From rice with Educational Community License v2.0 4 votes vote down vote up
/**
 * Parses, and only parses, a rule definition (be it a top-level rule, or a rule delegation).  This method will
 * NOT dirty or save any existing data, it is side-effect-free.
 * @param element the rule element
 * @return a new RuleBaseValues object which is not yet saved
 * @throws XmlException
 */
private RuleBaseValues parseRule(Element element) throws XmlException {
    String name = element.getChildText(NAME, element.getNamespace());
    RuleBaseValues rule = createRule(name);
    
    setDefaultRuleValues(rule);
    rule.setName(name);
    
    String toDatestr = element.getChildText( TO_DATE, element.getNamespace());
    String fromDatestr = element.getChildText( FROM_DATE, element.getNamespace());
    rule.setToDateValue(formatDate("toDate", toDatestr));
    rule.setFromDateValue(formatDate("fromDate", fromDatestr));

    String description = element.getChildText(DESCRIPTION, element.getNamespace());
    if (StringUtils.isBlank(description)) {
        throw new XmlException("Rule must have a description.");
    }
            
    String documentTypeName = element.getChildText(DOCUMENT_TYPE, element.getNamespace());
    if (StringUtils.isBlank(documentTypeName)) {
    	throw new XmlException("Rule must have a document type.");
    }
    DocumentType documentType = KEWServiceLocator.getDocumentTypeService().findByName(documentTypeName);
    if (documentType == null) {
    	throw new XmlException("Could not locate document type '" + documentTypeName + "'");
    }

    RuleTemplateBo ruleTemplate = null;
    String ruleTemplateName = element.getChildText(RULE_TEMPLATE, element.getNamespace());        
    Element ruleExtensionsElement = element.getChild(RULE_EXTENSIONS, element.getNamespace());
    if (!StringUtils.isBlank(ruleTemplateName)) {
    	ruleTemplate = KEWServiceLocator.getRuleTemplateService().findByRuleTemplateName(ruleTemplateName);
    	if (ruleTemplate == null) {
    		throw new XmlException("Could not locate rule template '" + ruleTemplateName + "'");
    	}
    } else {
    	if (ruleExtensionsElement != null) {
    		throw new XmlException("Templateless rules may not have rule extensions");
    	}
    }

    RuleExpressionDef ruleExpressionDef = null;
    Element exprElement = element.getChild(RULE_EXPRESSION, element.getNamespace());
    if (exprElement != null) {
    	String exprType = exprElement.getAttributeValue("type");
    	if (StringUtils.isEmpty(exprType)) {
    		throw new XmlException("Expression type must be specified");
    	}
    	String expression = exprElement.getTextTrim();
    	ruleExpressionDef = new RuleExpressionDef();
    	ruleExpressionDef.setType(exprType);
    	ruleExpressionDef.setExpression(expression);
    }
    
    String forceActionValue = element.getChildText(FORCE_ACTION, element.getNamespace());
    Boolean forceAction = Boolean.valueOf(DEFAULT_FORCE_ACTION);
    if (!StringUtils.isBlank(forceActionValue)) {
        forceAction = Boolean.valueOf(forceActionValue);
    }

    rule.setDocTypeName(documentType.getName());
    if (ruleTemplate != null) {
        rule.setRuleTemplateId(ruleTemplate.getId());
        rule.setRuleTemplate(ruleTemplate);
    }
    if (ruleExpressionDef != null) {
        rule.setRuleExpressionDef(ruleExpressionDef);
    }
    rule.setDescription(description);
    rule.setForceAction(forceAction);

    Element responsibilitiesElement = element.getChild(RESPONSIBILITIES, element.getNamespace());
    rule.setRuleResponsibilities(parseResponsibilities(responsibilitiesElement, rule));
    rule.setRuleExtensions(parseRuleExtensions(ruleExtensionsElement, rule));

    return rule;
}