use of org.jdom.Attribute in project libresonic by Libresonic.
the class JAXBWriter method getRESTProtocolVersion.
private String getRESTProtocolVersion() throws Exception {
InputStream in = null;
try {
in = StringUtil.class.getResourceAsStream("/libresonic-rest-api.xsd");
Document document = new SAXBuilder().build(in);
Attribute version = document.getRootElement().getAttribute("version");
return version.getValue();
} finally {
IOUtils.closeQuietly(in);
}
}
use of org.jdom.Attribute in project OpenClinica by OpenClinica.
the class RepeatManager method addChildRepeatAttributes.
/*
* Add the attributes to an HTML tag that provide the template for other
* repeating form elements. This method adds the required attributes to the
* repeater parameter than returns the changed element.
*/
public Element addChildRepeatAttributes(Element repeater, String parentId, Integer itemId, String forcedInputNameIndex) {
// The code needs a input name prefix that is unique for every table
// to make sure that the input name is unique for every form field
StringBuilder nameVal = new StringBuilder(parentId);
if (forcedInputNameIndex == null || forcedInputNameIndex.length() < 1) {
nameVal.append("_[").append(parentId).append("]input");
} else {
nameVal.append("_[").append(forcedInputNameIndex).append("]input");
}
// so that the input elements will have unique IDs
if (itemId == 0) {
Random rand = new Random();
itemId = rand.nextInt(100000) + 1;
}
nameVal.append(itemId);
// if the element does not have an input "name" attribute, then create a
// new one; otherwise
// remove and edit the existing one to add this required repeat
// information.
// The child elements have names of input, select, or textarea
List<Element> inputs = repeater.getChildren("input");
if (inputs.isEmpty()) {
inputs = repeater.getChildren("select");
}
if (inputs.isEmpty()) {
inputs = repeater.getChildren("textarea");
}
for (Element input : inputs) {
// do not include input type="hidden"
boolean isHidden;
Attribute attribute = input.getAttribute("type");
if (attribute == null || attribute.getValue() == null || !attribute.getValue().equalsIgnoreCase("hidden")) {
if (input.getAttribute("name") != null) {
input.removeAttribute("name");
}
} else {
continue;
}
// the input Element has to use the id of its "repeat parent"
// element
input.setAttribute("name", nameVal.toString());
}
return repeater;
}
use of org.jdom.Attribute in project intellij-plugins by StepicOrg.
the class StudySerializationUtils method convertToXStreamStyle.
private static void convertToXStreamStyle(List<Element> elements) {
elements.forEach(element -> {
if (element.getName().equals(OPTION)) {
Attribute nameAttr = element.getAttribute(NAME);
if (nameAttr != null) {
String name = nameAttr.getValue();
element.setName(nameAttr.getValue());
element.removeAttribute(nameAttr);
if (name.equals(DATA)) {
Element parent = element.getParentElement();
String dataClass = null;
switch(parent.getName()) {
case COURSE_NODE_CLASS:
dataClass = COURSE_CLASS;
break;
case SECTION_NODE_CLASS:
dataClass = SECTION_CLASS;
break;
case LESSON_NODE_CLASS:
dataClass = COMPOUND_UNIT_LESSON_CLASS;
break;
case STEP_NODE_CLASS:
dataClass = STEP_CLASS;
break;
}
if (dataClass != null) {
element.setAttribute("class", dataClass);
}
}
}
Attribute valueAttr = element.getAttribute(VALUE);
if (valueAttr != null) {
element.setText(valueAttr.getValue());
element.removeAttribute(valueAttr);
if (nameAttr == null) {
element.setName("string");
}
} else {
List<Element> children = element.getChildren();
if (!children.isEmpty()) {
Element child = children.get(0);
removeChild(element, child);
element.addContent(child.cloneContent());
}
}
} else if (element.getName().equals(ENTRY)) {
Attribute keyAttr = element.getAttribute(KEY);
if (keyAttr == null) {
return;
}
addAttributeAsChild(element, keyAttr);
Attribute valueAttr = element.getAttribute(VALUE);
if (valueAttr != null) {
addAttributeAsChild(element, valueAttr);
} else {
Element value = element.getChild(VALUE);
if (value != null) {
element.removeChild(value.getName());
element.addContent(value.cloneContent());
}
}
}
convertToXStreamStyle(element.getChildren());
});
}
use of org.jdom.Attribute in project intellij-community by JetBrains.
the class MetaManager method loadProperties.
protected void loadProperties(MetaModel meta, Element properties) throws Exception {
Attribute inplace = properties.getAttribute("inplace");
if (inplace != null) {
meta.setInplaceProperties(StringUtil.split(inplace.getValue(), " "));
}
Attribute top = properties.getAttribute("top");
if (top != null) {
meta.setTopProperties(StringUtil.split(top.getValue(), " "));
}
Attribute normal = properties.getAttribute("normal");
if (normal != null) {
meta.setNormalProperties(StringUtil.split(normal.getValue(), " "));
}
Attribute important = properties.getAttribute("important");
if (important != null) {
meta.setImportantProperties(StringUtil.split(important.getValue(), " "));
}
Attribute expert = properties.getAttribute("expert");
if (expert != null) {
meta.setExpertProperties(StringUtil.split(expert.getValue(), " "));
}
Attribute deprecated = properties.getAttribute("deprecated");
if (deprecated != null) {
meta.setDeprecatedProperties(StringUtil.split(deprecated.getValue(), " "));
}
}
use of org.jdom.Attribute in project intellij-community by JetBrains.
the class SaveFormAsTemplateHandler method getTemplateText.
@Override
public String getTemplateText(final PsiFile file, final String fileText, final String nameWithoutExtension) {
if (StdFileTypes.GUI_DESIGNER_FORM.equals(file.getFileType())) {
LwRootContainer rootContainer = null;
try {
rootContainer = Utils.getRootContainer(fileText, null);
} catch (Exception ignored) {
}
if (rootContainer != null && rootContainer.getClassToBind() != null) {
try {
Element document = JdomKt.loadElement(fileText);
Attribute attribute = document.getAttribute(UIFormXmlConstants.ATTRIBUTE_BIND_TO_CLASS);
attribute.detach();
return JDOMUtil.write(document, CodeStyleSettingsManager.getSettings(file.getProject()).getLineSeparator());
} catch (Exception ignored) {
}
}
}
return null;
}
Aggregations