use of org.dom4j.Attribute in project siena by mandubian.
the class JsonSerializer method toJson.
@SuppressWarnings("unchecked")
private static void toJson(Element element, Json e) {
List<Element> elements = element.elements();
if (elements.isEmpty()) {
if (element.hasContent()) {
e.put("@", element.getText());
// } else {
// e.put("@", null);
}
} else {
Json map = Json.map();
e.put("@", map);
for (Element elem : elements) {
Json j = Json.map();
map.put(elem.getName(), j);
toJson(elem, j);
}
}
List<Attribute> attributes = element.attributes();
for (Attribute attr : attributes) {
e.put(attr.getName(), attr.getValue());
}
}
use of org.dom4j.Attribute in project tesb-studio-se by Talend.
the class RouteJavaScriptOSGIForESBManager method formatSchemaLocation.
private static void formatSchemaLocation(Element root, boolean addBlueprint, boolean addCamel) {
Attribute schemaLocation = root.attribute("schemaLocation");
if (schemaLocation == null) {
return;
}
String value = schemaLocation.getValue().replaceAll("(\\A|\\b)\\s\\s+\\b", "\n ");
if (addBlueprint) {
// see targetNamespace in:
// http://cxf.apache.org/schemas/blueprint/core.xsd
// http://cxf.apache.org/schemas/blueprint/policy.xsd
value = value.replace("http://cxf.apache.org/core", "http://cxf.apache.org/blueprint/core").replace("http://cxf.apache.org/schemas/core.xsd", "http://cxf.apache.org/schemas/blueprint/core.xsd").replace("http://cxf.apache.org/schemas/policy.xsd", "http://cxf.apache.org/schemas/blueprint/policy.xsd");
value += "\n http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd";
}
if (addCamel) {
value += "\n http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd";
}
schemaLocation.setValue(value);
}
use of org.dom4j.Attribute in project tesb-studio-se by Talend.
the class RouteJavaScriptOSGIForESBManager method handleSpringXml.
private void handleSpringXml(String targetFilePath, ProcessItem processItem, InputStream springInput, ExportFileResource osgiResource, boolean convertToBP, boolean convertImports, Map<String, Element> needHandleElements) {
File targetFile = new File(getTmpFolder() + PATH_SEPARATOR + targetFilePath);
try {
SAXReader saxReader = new SAXReader();
saxReader.setStripWhitespaceText(false);
Document document = saxReader.read(springInput);
Element root = document.getRootElement();
if (convertToBP) {
if ("blueprint".equals(root.getName())) {
formatSchemaLocation(root, false, false);
InputStream inputStream = new ByteArrayInputStream(root.asXML().getBytes());
FilesUtils.copyFile(inputStream, targetFile);
osgiResource.addResource(FileConstants.BLUEPRINT_FOLDER_NAME, targetFile.toURI().toURL());
return;
}
// replace spring cxf core to blueprint cxf core.
Namespace springCxfCoreNs = root.getNamespaceForURI("http://cxf.apache.org/core");
if (null != springCxfCoreNs) {
Namespace blueprintCxfCoreNs = Namespace.get("cxf", "http://cxf.apache.org/blueprint/core");
moveNamespace(root, springCxfCoreNs, blueprintCxfCoreNs);
root.remove(springCxfCoreNs);
root.add(blueprintCxfCoreNs);
}
String bpPrefix = "bp";
int cnt = 0;
while (root.getNamespaceForPrefix(bpPrefix) != null) {
bpPrefix = "bp" + (++cnt);
}
root.setQName(QName.get("blueprint", bpPrefix, BLUEPRINT_NSURI));
}
Namespace springCamelNsp = Namespace.get("camel", CAMEL_SPRING_NSURI);
Namespace springCamelCxfNsp = Namespace.get("cxf", CAMEL_CXF_NSURI);
boolean addCamel = springCamelNsp.equals(root.getNamespaceForPrefix("camel"));
formatSchemaLocation(root, convertToBP, addCamel);
for (Iterator<?> i = root.elementIterator("import"); i.hasNext(); ) {
Element ip = (Element) i.next();
Attribute resource = ip.attribute("resource");
URL path = dummyURL(resource.getValue());
for (ResourceDependencyModel resourceModel : RouteResourceUtil.getResourceDependencies(processItem)) {
if (matches(path, resourceModel)) {
IFile resourceFile = RouteResourceUtil.getSourceFile(resourceModel.getItem());
String cpUrl = adaptedClassPathUrl(resourceModel, convertImports);
handleSpringXml(cpUrl, processItem, resourceFile.getContents(), osgiResource, convertImports, convertImports, needHandleElements);
resource.setValue(IMPORT_RESOURCE_PREFIX + cpUrl);
}
}
if (convertImports) {
i.remove();
}
}
for (Iterator<?> i = root.elementIterator("bean"); i.hasNext(); ) {
Element ip = (Element) i.next();
Attribute resource = ip.attribute("class");
if ("org.apache.camel.component.properties.PropertiesComponent".equals(resource.getStringValue())) {
// <propertyPlaceholder id="properties" location="classpath:RouteWithSpring.properties"/>
Element propertyPlaceholderElement = DocumentHelper.createElement("propertyPlaceholder");
propertyPlaceholderElement.addAttribute("id", ip.attribute("id").getStringValue());
for (Iterator<?> ii = ip.elementIterator("property"); ii.hasNext(); ) {
Element property = (Element) ii.next();
if ("location".equals(property.attribute("name").getStringValue())) {
propertyPlaceholderElement.addAttribute("location", property.attribute("value").getStringValue());
needHandleElements.put("propertyPlaceholder", propertyPlaceholderElement);
}
}
root.remove(ip);
}
}
if (CONVERT_CAMEL_CONTEXT) {
if (CONVERT_CAMEL_CONTEXT_ALL) {
moveNamespace(root, CAMEL_SPRING_NSURI, CAMEL_BLUEPRINT_NSURI);
} else {
Namespace blueprintCamelNsp = Namespace.get("camel", CAMEL_BLUEPRINT_NSURI);
moveNamespace(root, springCamelNsp, blueprintCamelNsp);
if (springCamelNsp.equals(root.getNamespaceForPrefix("camel"))) {
root.remove(springCamelNsp);
root.add(blueprintCamelNsp);
}
Namespace blueprintCamelCxfNsp = Namespace.get("cxf", CAMEL_BLUEPRINT_CXF_NSURI);
moveNamespace(root, springCamelCxfNsp, blueprintCamelCxfNsp);
if (springCamelCxfNsp.equals(root.getNamespaceForPrefix("cxf"))) {
root.remove(springCamelCxfNsp);
root.add(blueprintCamelCxfNsp);
}
Namespace springCamelDefNsp = Namespace.get(CAMEL_SPRING_NSURI);
Namespace blueprintCamelDefNsp = Namespace.get(CAMEL_BLUEPRINT_NSURI);
for (Iterator<?> i = root.elementIterator("camelContext"); i.hasNext(); ) {
Element cc = (Element) i.next();
if (springCamelDefNsp.equals(cc.getNamespace())) {
moveNamespace(cc, springCamelDefNsp, blueprintCamelDefNsp);
}
}
Namespace springBeansNsp = Namespace.get(SPRING_BEANS_NSURI);
for (Iterator<?> iter = root.selectNodes("//*[name() = 'ref']").iterator(); iter.hasNext(); ) {
Element ref = (Element) iter.next();
if (springBeansNsp.equals(ref.getNamespace())) {
Attribute refBean = ref.attribute("bean");
if (refBean != null) {
// as it is not supported by blueprint
if (hasParentElement(refBean.getParent(), "constructor-arg")) {
continue;
}
if (hasParentElementWithProperty(refBean.getParent(), "name", "constraintMappings")) {
continue;
}
ref.setQName(QName.get(ref.getName(), "bp", BLUEPRINT_NSURI));
ref.addAttribute("component-id", refBean.getValue());
ref.remove(refBean);
}
}
}
}
}
InputStream inputStream = new ByteArrayInputStream(root.asXML().getBytes());
FilesUtils.copyFile(inputStream, targetFile);
osgiResource.addResource(adaptedResourceFolderName(targetFilePath, convertToBP), targetFile.toURI().toURL());
} catch (Exception e) {
Logger.getAnonymousLogger().log(Level.WARNING, "Custom Spring to OSGi conversion failed. ", e);
} finally {
try {
springInput.close();
} catch (IOException e) {
Logger.getAnonymousLogger().log(Level.WARNING, "Unexpected File closing failure. ", e);
}
}
}
use of org.dom4j.Attribute in project tesb-studio-se by Talend.
the class AddSpringConfigurationPropertyMigrationTask method addIgnoreExchangeEventProperty.
private void addIgnoreExchangeEventProperty(CamelProcessItem item) throws PersistenceException, DocumentException {
String springContent = item.getSpringContent();
if (null != springContent && !springContent.isEmpty()) {
Document document = DocumentHelper.parseText(springContent);
QName qname = QName.get("bean", SPRING_BEANS_NAMESPACE);
List<Element> beans = document.getRootElement().elements(qname);
for (Element bean : beans) {
if ("jmxEventNotifier".equals(bean.attributeValue("id")) && "org.apache.camel.management.JmxNotificationEventNotifier".equals(bean.attributeValue("class"))) {
List<Element> properties = bean.elements(QName.get("property", SPRING_BEANS_NAMESPACE));
boolean hasIgnore = false;
for (Element property : properties) {
List<Attribute> propertyAttributes = property.attributes();
for (Attribute propertyAttribute : propertyAttributes) {
if (propertyAttribute.getValue().equals(IGNORE_EXCHANGE_EVENTS)) {
hasIgnore = true;
break;
}
}
}
if (!hasIgnore) {
DefaultElement ignoreExchangeElement = new DefaultElement("property", bean.getNamespace());
ignoreExchangeElement.add(DocumentHelper.createAttribute(ignoreExchangeElement, "name", IGNORE_EXCHANGE_EVENTS));
ignoreExchangeElement.add(DocumentHelper.createAttribute(ignoreExchangeElement, "value", "true"));
bean.add(ignoreExchangeElement);
item.setSpringContent(document.asXML());
saveItem(item);
}
break;
}
}
}
}
use of org.dom4j.Attribute in project atlas by alibaba.
the class StandardizeLibManifestTask method getManifestFileObject.
/**
* Get the contents of the mainifest file
*
* @param manifestFile
* @return
*/
public static ManifestInfo getManifestFileObject(File manifestFile) throws DocumentException {
ManifestInfo manifestFileObject = new ManifestInfo();
manifestFileObject.setManifestFile(manifestFile);
if (manifestFile.exists()) {
// Read the XML file
Document document = XmlHelper.readXml(manifestFile);
// Get the root node
Element root = document.getRootElement();
for (Attribute attribute : root.attributes()) {
if (StringUtils.isNotBlank(attribute.getNamespacePrefix())) {
manifestFileObject.addManifestProperty(attribute.getNamespacePrefix() + ":" + attribute.getName(), attribute.getValue());
} else {
manifestFileObject.addManifestProperty(attribute.getName(), attribute.getValue());
}
}
Element useSdkElement = root.element("uses-sdk");
Element applicationElement = root.element("application");
if (null != useSdkElement) {
for (Attribute attribute : useSdkElement.attributes()) {
if (StringUtils.isNotBlank(attribute.getNamespacePrefix())) {
manifestFileObject.addUseSdkProperty(attribute.getNamespacePrefix() + ":" + attribute.getName(), attribute.getValue());
} else {
manifestFileObject.addUseSdkProperty(attribute.getName(), attribute.getValue());
}
}
}
if (null != applicationElement) {
for (Attribute attribute : applicationElement.attributes()) {
if (StringUtils.isNotBlank(attribute.getNamespacePrefix())) {
manifestFileObject.addApplicationProperty(attribute.getNamespacePrefix() + ":" + attribute.getName(), attribute.getValue());
} else {
manifestFileObject.addApplicationProperty(attribute.getName(), attribute.getValue());
}
}
}
}
manifestFileObject.init();
return manifestFileObject;
}
Aggregations