List of usage examples for org.dom4j Element attribute
Attribute attribute(QName qName);
From source file:com.sun.xml.ws.test.container.AbstractApplicationContainer.java
License:Open Source License
protected void updateWsitClient(WAR war, DeployedService deployedService, String id) throws Exception { File wsitClientFile = new File(deployedService.getResources(), "wsit-client.xml"); if (wsitClientFile.exists()) { SAXReader reader = new SAXReader(); Document document = reader.read(wsitClientFile); Element root = document.getRootElement(); Element policy = root.element("Policy"); Element sts = policy.element("ExactlyOne").element("All").element("PreconfiguredSTS"); Attribute endpoint = sts.attribute("endpoint"); endpoint.setValue(id);/*w w w .j a v a 2s .c o m*/ Attribute wsdlLoc = sts.attribute("wsdlLocation"); String x = deployedService.service.wsdl.get(0).wsdlFile.toURI().toString(); wsdlLoc.setValue(x); XMLWriter writer = new XMLWriter(new FileWriter(wsitClientFile)); writer.write(document); writer.close(); war.copyWsit(wsitClientFile); } else { throw new RuntimeException("wsit-client.xml is absent. It is required. \n" + "Please check " + deployedService.getResources()); } }
From source file:com.sun.xml.ws.test.container.invm.InVmContainer.java
License:Open Source License
/** * Fix the address in the WSDL. to the local address. *///from www.j av a2s .c om private void patchWsdl(DeployedService service, File wsdl, String id) throws Exception { Document doc = new SAXReader().read(wsdl); List<Element> ports = doc.getRootElement().element("service").elements("port"); for (Element port : ports) { String portName = port.attributeValue("name"); Element address = getSoapAddress(port); //Looks like invalid wsdl:port, MUST have a soap:address //TODO: give some error message if (address == null) continue; if (!"wsdl".equalsIgnoreCase(wsdl.getParentFile().getName())) { portName = wsdl.getParentFile().getName() + portName; } Attribute locationAttr = address.attribute("location"); String newLocation = "in-vm://" + id + "/?" + portName; newLocation = newLocation.replace('\\', '/'); locationAttr.setValue(newLocation); //Patch wsa:Address in wsa:EndpointReference as well Element wsaEprEl = port .element(QName.get("EndpointReference", "wsa", "http://www.w3.org/2005/08/addressing")); if (wsaEprEl != null) { Element wsaAddrEl = wsaEprEl .element(QName.get("Address", "wsa", "http://www.w3.org/2005/08/addressing")); wsaAddrEl.setText(newLocation); } } // save file FileOutputStream os = new FileOutputStream(wsdl); new XMLWriter(os).write(doc); os.close(); }
From source file:com.sun.xml.ws.test.container.local.LocalApplicationContainer.java
License:Open Source License
/** * Fix the address in the WSDL. to the local address. *///from w ww . java 2 s .c o m private void patchWsdl(DeployedService service, File wsdl) throws Exception { Document doc = new SAXReader().read(wsdl); List<Element> ports = doc.getRootElement().element("service").elements("port"); for (Element port : ports) { String portName = port.attributeValue("name"); Element address = (Element) port.elements().get(0); Attribute locationAttr = address.attribute("location"); String newLocation = "local://" + service.warDir.getAbsolutePath() + "?" + portName; newLocation = newLocation.replace('\\', '/'); locationAttr.setValue(newLocation); //Patch wsa:Address in wsa:EndpointReference as well Element wsaEprEl = port .element(QName.get("EndpointReference", "wsa", "http://www.w3.org/2005/08/addressing")); if (wsaEprEl != null) { Element wsaAddrEl = wsaEprEl .element(QName.get("Address", "wsa", "http://www.w3.org/2005/08/addressing")); wsaAddrEl.setText(newLocation); } } // save file FileOutputStream os = new FileOutputStream(wsdl); new XMLWriter(os).write(doc); os.close(); }
From source file:com.taobao.android.builder.tasks.tpatch.DiffBundleInfoTask.java
License:Apache License
private static ArtifactBundleInfo getMainArtifactBundInfo(File manifestFile) { ArtifactBundleInfo mainBundleInfo = new ArtifactBundleInfo(); SAXReader reader = new SAXReader(); Document document = null;// ?XML try {//from w ww . j a v a 2 s .c om document = reader.read(manifestFile); } catch (DocumentException e) { throw new GradleException(e.getMessage(), e); } Element root = document.getRootElement();// List<? extends Node> metadataNodes = root.selectNodes("//meta-data"); for (Node node : metadataNodes) { Element element = (Element) node; Attribute attribute = element.attribute("name"); if (attribute.getValue().equals("label")) { Attribute labelAttribute = element.attribute("value"); mainBundleInfo.setName(labelAttribute.getValue()); } } List<? extends Node> applicatNodes = root.selectNodes("//application"); for (Node node : applicatNodes) { Element element = (Element) node; Attribute attribute = element.attribute("name"); if (attribute != null) { mainBundleInfo.setApplicationName(attribute.getValue()); } } if ("manifest".equalsIgnoreCase(root.getName())) { List<Attribute> attributes = root.attributes(); for (Attribute attr : attributes) { if (StringUtils.equalsIgnoreCase(attr.getName(), "versionName")) { String versionName = attr.getValue(); mainBundleInfo.setVersion(versionName); } } } String pkgName = root.attributeValue("package"); mainBundleInfo.setPkgName(pkgName); return mainBundleInfo; }
From source file:com.taobao.android.builder.tools.bundleinfo.BundleInfoUtils.java
License:Apache License
/** * ?manifestBundleInfo/*w w w.j a v a 2 s . c o m*/ * * @return */ private static void update(AwbBundle awbBundle, Map<String, BundleInfo> bundleInfoMap, AppVariantContext appVariantContext, String apkVersion) throws DocumentException { String artifactId = awbBundle.getResolvedCoordinates().getArtifactId(); BundleInfo bundleInfo = bundleInfoMap.get(artifactId); if (null != bundleInfo) { awbBundle.bundleInfo = bundleInfo; } else { bundleInfo = awbBundle.bundleInfo; } awbBundle.isRemote = appVariantContext.getAtlasExtension().getTBuildConfig().getOutOfApkBundles() .contains(artifactId); bundleInfo.setIsInternal(!awbBundle.isRemote); bundleInfo.setVersion(apkVersion + "@" + awbBundle.getResolvedCoordinates().getVersion()); bundleInfo.setPkgName(awbBundle.getPackageName()); String applicationName = ManifestFileUtils.getApplicationName(awbBundle.getOrgManifestFile()); if (StringUtils.isNotEmpty(applicationName)) { bundleInfo.setApplicationName(applicationName); } SAXReader reader = new SAXReader(); Document document = reader.read(awbBundle.getManifest());// ?XML Element root = document.getRootElement();// List<? extends Node> metadataNodes = root.selectNodes("//meta-data"); for (Node node : metadataNodes) { Element element = (Element) node; Attribute attribute = element.attribute("name"); if (attribute.getValue().equals("label")) { Attribute labelAttribute = element.attribute("value"); bundleInfo.setName(labelAttribute.getValue()); } else if (attribute.getValue().equals("description")) { Attribute descAttribute = element.attribute("value"); bundleInfo.setDesc(descAttribute.getValue()); } } addComponents(bundleInfo, root); for (AndroidLibrary depLib : awbBundle.getLibraryDependencies()) { SAXReader reader2 = new SAXReader(); Document document2 = reader2.read(depLib.getManifest());// ?XML Element root2 = document2.getRootElement();// addComponents(bundleInfo, root2); } }
From source file:com.taobao.android.builder.tools.bundleinfo.BundleInfoUtils.java
License:Apache License
private static void addComponents(BundleInfo bundleInfo, Element root) { List<? extends Node> serviceNodes = root.selectNodes("//service"); for (Node node : serviceNodes) { Element element = (Element) node; Attribute attribute = element.attribute("name"); bundleInfo.getServices().add(attribute.getValue()); }/* w w w .j a v a 2 s. c o m*/ List<? extends Node> receiverNodes = root.selectNodes("//receiver"); for (Node node : receiverNodes) { Element element = (Element) node; Attribute attribute = element.attribute("name"); bundleInfo.getReceivers().add(attribute.getValue()); } List<? extends Node> providerNodes = root.selectNodes("//provider"); for (Node node : providerNodes) { Element element = (Element) node; Attribute attribute = element.attribute("name"); bundleInfo.getContentProviders().add(attribute.getValue()); } List<? extends Node> activityNodes = root.selectNodes("//activity"); for (Node node : activityNodes) { Element element = (Element) node; Attribute attribute = element.attribute("name"); bundleInfo.getActivities().add(attribute.getValue()); } }
From source file:com.taobao.android.builder.tools.manifest.AtlasProxy.java
License:Apache License
public static void addAtlasProxyClazz(Document document, Set<String> nonProxyChannels, Result result) { Element root = document.getRootElement();// List<? extends Node> serviceNodes = root.selectNodes("//@android:process"); String packageName = root.attribute("package").getStringValue(); Set<String> processNames = new HashSet<>(); processNames.add(packageName);/*w ww . j a v a2 s . c om*/ for (Node node : serviceNodes) { if (null != node && StringUtils.isNotEmpty(node.getStringValue())) { String value = node.getStringValue(); processNames.add(value); } } processNames.removeAll(nonProxyChannels); List<String> elementNames = Lists.newArrayList("activity", "service", "provider"); Element applicationElement = root.element("application"); for (String processName : processNames) { boolean isMainPkg = packageName.equals(processName); //boolean isMainPkg = true; String processClazzName = processName.replace(":", "").replace(".", "_"); for (String elementName : elementNames) { String fullClazzName = "ATLASPROXY_" + (isMainPkg ? "" : (packageName.replace(".", "_") + "_")) + processClazzName + "_" + StringUtils.capitalize(elementName); if ("activity".equals(elementName)) { result.proxyActivities.add(fullClazzName); } else if ("service".equals(elementName)) { result.proxyServices.add(fullClazzName); } else { result.proxyProviders.add(fullClazzName); } Element newElement = applicationElement.addElement(elementName); newElement.addAttribute("android:name", ATLAS_PROXY_PACKAGE + "." + fullClazzName); if (!packageName.equals(processName)) { newElement.addAttribute("android:process", processName); } boolean isProvider = "provider".equals(elementName); if (isProvider) { newElement.addAttribute("android:authorities", ATLAS_PROXY_PACKAGE + "." + fullClazzName); } } } }
From source file:com.taobao.android.builder.tools.manifest.ManifestFileUtils.java
License:Apache License
/** * libManifest/*from w ww. j a v a 2 s. c om*/ * * @param libManifestFile * @param mainManifestFileObject param updateSdkVersion */ public static void updatePreProcessManifestFile(File libManifestFile, ManifestFileObject mainManifestFileObject, boolean updateSdkVersion) throws IOException, DocumentException { if (!libManifestFile.exists()) { return; } File orgManifestFile = new File(libManifestFile.getParentFile(), "AndroidManifest-org.xml"); if (orgManifestFile.exists()) { return; } libManifestFile.renameTo(orgManifestFile); SAXReader reader = new SAXReader(); OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("UTF-8");// XML?? Document document = reader.read(orgManifestFile);// ?XML Element root = document.getRootElement();// if (updateSdkVersion) { Element useSdkElement = root.element("uses-sdk"); if (null == useSdkElement) { useSdkElement = root.addElement("uses-sdk"); } if (null != useSdkElement) { updateElement(useSdkElement, mainManifestFileObject.getUseSdkProperties()); } } // ?tools:removetools:replace?ManifestMerge?? Element applicationElement = root.element("application"); Map<String, String> replaceAttrs = mainManifestFileObject.getReplaceApplicationAttribute(); List<String> removeAttrs = mainManifestFileObject.getRemoveApplicationAttribute(); if (null != applicationElement) { // libtools List<Attribute> toRomoved = new ArrayList<Attribute>(); for (Attribute attribute : applicationElement.attributes()) { if (attribute.getName().equals("replace") || attribute.getName().equals("remove")) { // applicationElement.remove(attribute); // applicationElement.attributes().remove(attribute); toRomoved.add(attribute); } } if (toRomoved.size() > 0) { for (Attribute attribute : toRomoved) { applicationElement.remove(attribute); } } updateApplicationElement(applicationElement, replaceAttrs, removeAttrs); } //?packageName TODO String packageName = root.attributeValue("package"); if (StringUtils.isEmpty(packageName)) { packageName = ManifestFileUtils.getPackage(orgManifestFile); } List<? extends Node> applicatNodes = root.selectNodes("//application"); for (Node node : applicatNodes) { Element element = (Element) node; Attribute attribute = element.attribute("name"); if (attribute != null) { if (!attribute.getValue().startsWith(packageName)) { attribute.setValue(packageName + attribute.getValue()); } } } fillFullClazzName(root, packageName, "activity"); fillFullClazzName(root, packageName, "provider"); fillFullClazzName(root, packageName, "receiver"); fillFullClazzName(root, packageName, "service"); saveFile(document, format, libManifestFile); }
From source file:com.taobao.android.builder.tools.manifest.ManifestFileUtils.java
License:Apache License
private static void fillFullClazzName(Element root, String packageName, String type) { List<? extends Node> applicatNodes = root.selectNodes("//" + type); for (Node node : applicatNodes) { Element element = (Element) node; Attribute attribute = element.attribute("name"); if (attribute != null) { if (attribute.getValue().startsWith(".")) { attribute.setValue(packageName + attribute.getValue()); }/*from ww w. j a v a 2 s.c om*/ } } }
From source file:com.taobao.android.builder.tools.manifest.ManifestFileUtils.java
License:Apache License
/** * Application?//from ww w. jav a 2s . co m * * @param element * @param replaceAttrs * @param removeAttrs */ private static void updateApplicationElement(Element element, Map<String, String> replaceAttrs, List<String> removeAttrs) { for (Map.Entry<String, String> entry : replaceAttrs.entrySet()) { String key = entry.getKey(); key = StringUtils.substringAfter(key, ":"); Attribute attribute = element.attribute(key); if (null != attribute) { element.remove(attribute); } } for (String key : removeAttrs) { key = StringUtils.substringAfter(key, ":"); Attribute attribute = element.attribute(key); if (null != attribute) { element.remove(attribute); } } }