Search in sources :

Example 46 with Comment

use of org.jdom2.Comment in project JMRI by JMRI.

the class VariableTableModel method processDecVal.

protected VariableValue processDecVal(Element child, String name, String comment, boolean readOnly, boolean infoOnly, boolean writeOnly, boolean opsOnly, String CV, String mask, String item) throws NumberFormatException {
    VariableValue v;
    Attribute a;
    int minVal = 0;
    int maxVal = 255;
    if ((a = child.getAttribute("min")) != null) {
        minVal = Integer.valueOf(a.getValue()).intValue();
    }
    if ((a = child.getAttribute("max")) != null) {
        maxVal = Integer.valueOf(a.getValue()).intValue();
    }
    v = new DecVariableValue(name, comment, "", readOnly, infoOnly, writeOnly, opsOnly, CV, mask, minVal, maxVal, _cvModel.allCvMap(), _status, item);
    return v;
}
Also used : Attribute(org.jdom2.Attribute)

Example 47 with Comment

use of org.jdom2.Comment in project gocd by gocd.

the class CommandSnippetXmlParser method parse.

public CommandSnippet parse(String xmlContent, String fileName, String relativeFilePath) {
    try {
        Document document = buildXmlDocument(xmlContent, CommandSnippet.class.getResource("command-snippet.xsd"));
        CommandSnippetComment comment = getComment(document);
        Element execTag = document.getRootElement();
        String commandName = execTag.getAttributeValue("command");
        List<String> arguments = new ArrayList<>();
        for (Object child : execTag.getChildren()) {
            Element element = (Element) child;
            arguments.add(element.getValue());
        }
        return new CommandSnippet(commandName, arguments, comment, fileName, relativeFilePath);
    } catch (Exception e) {
        String errorMessage = String.format("Reason: %s", e.getMessage());
        LOGGER.info("Could not load command '{}'. {}", fileName, errorMessage);
        return CommandSnippet.invalid(fileName, errorMessage, new EmptySnippetComment());
    }
}
Also used : Element(org.jdom2.Element) ArrayList(java.util.ArrayList) XmlUtils.buildXmlDocument(com.thoughtworks.go.util.XmlUtils.buildXmlDocument) Document(org.jdom2.Document)

Example 48 with Comment

use of org.jdom2.Comment in project pwm by pwm-project.

the class StoredConfigurationImpl method writeSetting.

public void writeSetting(final PwmSetting setting, final String profileID, final StoredValue value, final UserIdentity userIdentity) throws PwmUnrecoverableException {
    if (profileID == null && setting.getCategory().hasProfiles()) {
        throw new IllegalArgumentException("reading of setting " + setting.getKey() + " requires a non-null profileID");
    }
    if (profileID != null && !setting.getCategory().hasProfiles()) {
        throw new IllegalArgumentException("cannot specify profile for non-profile setting");
    }
    preModifyActions();
    changeLog.updateChangeLog(setting, profileID, value);
    domModifyLock.writeLock().lock();
    try {
        final Element settingElement = createOrGetSettingElement(document, setting, profileID);
        settingElement.removeContent();
        settingElement.setAttribute(XML_ATTRIBUTE_SYNTAX, setting.getSyntax().toString());
        settingElement.setAttribute(XML_ATTRIBUTE_SYNTAX_VERSION, Integer.toString(value.currentSyntaxVersion()));
        if (setting_writeLabels) {
            final Element labelElement = new Element("label");
            labelElement.addContent(setting.getLabel(PwmConstants.DEFAULT_LOCALE));
            settingElement.addContent(labelElement);
        }
        if (setting.getSyntax() == PwmSettingSyntax.PASSWORD) {
            final List<Element> valueElements = ((PasswordValue) value).toXmlValues("value", getKey());
            settingElement.addContent(new Comment("Note: This value is encrypted and can not be edited directly."));
            settingElement.addContent(new Comment("Please use the Configuration Manager GUI to modify this value."));
            settingElement.addContent(valueElements);
        } else if (setting.getSyntax() == PwmSettingSyntax.PRIVATE_KEY) {
            final List<Element> valueElements = ((PrivateKeyValue) value).toXmlValues("value", getKey());
            settingElement.addContent(valueElements);
        } else if (setting.getSyntax() == PwmSettingSyntax.NAMED_SECRET) {
            final List<Element> valueElements = ((NamedSecretValue) value).toXmlValues("value", getKey());
            settingElement.addContent(valueElements);
        } else {
            settingElement.addContent(value.toXmlValues("value", getKey()));
        }
        updateMetaData(settingElement, userIdentity);
    } finally {
        domModifyLock.writeLock().unlock();
    }
}
Also used : Comment(org.jdom2.Comment) PasswordValue(password.pwm.config.value.PasswordValue) Element(org.jdom2.Element) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) NamedSecretValue(password.pwm.config.value.NamedSecretValue)

Example 49 with Comment

use of org.jdom2.Comment in project pwm by pwm-project.

the class StoredConfigurationImpl method resetAllPasswordValues.

public void resetAllPasswordValues(final String comment) {
    for (final Iterator<SettingValueRecord> settingValueRecordIterator = new StoredValueIterator(false); settingValueRecordIterator.hasNext(); ) {
        final SettingValueRecord settingValueRecord = settingValueRecordIterator.next();
        if (settingValueRecord.getSetting().getSyntax() == PwmSettingSyntax.PASSWORD) {
            this.resetSetting(settingValueRecord.getSetting(), settingValueRecord.getProfile(), null);
            if (comment != null && !comment.isEmpty()) {
                final XPathExpression xp = XPathBuilder.xpathForSetting(settingValueRecord.getSetting(), settingValueRecord.getProfile());
                final Element settingElement = (Element) xp.evaluateFirst(document);
                if (settingElement != null) {
                    settingElement.addContent(new Comment(comment));
                }
            }
        }
    }
    final String pwdHash = this.readConfigProperty(ConfigurationProperty.PASSWORD_HASH);
    if (pwdHash != null && !pwdHash.isEmpty()) {
        this.writeConfigProperty(ConfigurationProperty.PASSWORD_HASH, comment);
    }
}
Also used : XPathExpression(org.jdom2.xpath.XPathExpression) Comment(org.jdom2.Comment) Element(org.jdom2.Element)

Example 50 with Comment

use of org.jdom2.Comment in project jPOS by jpos.

the class TransactionManagerTest method testSnapshotThrowsNullPointerException1.

@Test
public void testSnapshotThrowsNullPointerException1() throws Throwable {
    try {
        transactionManager.snapshot(100L, new Comment("testTransactionManagerText"));
        fail("Expected NullPointerException to be thrown");
    } catch (NullPointerException ex) {
        if (isJavaVersionAtMost(JAVA_14)) {
            assertNull(ex.getMessage(), "ex.getMessage()");
        } else {
            assertEquals("Cannot invoke \"String.length()\" because \"str\" is null", ex.getMessage(), "ex.getMessage()");
        }
        assertNull(transactionManager.psp, "transactionManager.psp");
    }
}
Also used : Comment(org.jdom2.Comment) Test(org.junit.jupiter.api.Test)

Aggregations

Element (org.jdom2.Element)39 Attribute (org.jdom2.Attribute)10 Document (org.jdom2.Document)9 Comment (org.jdom2.Comment)8 ArrayList (java.util.ArrayList)4 File (java.io.File)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 List (java.util.List)3 JButton (javax.swing.JButton)3 JDOMException (org.jdom2.JDOMException)3 ProcessingInstruction (org.jdom2.ProcessingInstruction)3 Modification (com.thoughtworks.go.domain.materials.Modification)2 Date (java.util.Date)2 Block (jmri.Block)2 NamedBeanHandle (jmri.NamedBeanHandle)2 SignalGroup (jmri.SignalGroup)2 SignalGroupManager (jmri.SignalGroupManager)2 SignalMast (jmri.SignalMast)2 SignalMastLogic (jmri.SignalMastLogic)2