/** * Edits the container's configuration so that the file's XML element specified by the XPath * parameter contains the given XML attributes * * Uses {@link XmlReplacement} instances to add XML attributes to the specified XML node without * actively updating the original XML file. * * This function is used to edit the system properties that need to be placed in the server.xml * file. Adding these replacement XML pieces to the container's configuration allows the * configuration to modify the server.xml file only when creating the standalone container * configuration. This means that the server.xml file located in the installation's 'conf' folder * remains static, which resolves possible concurrency issues that might arise if more than one * container is modifying the server.xml file. * * @param file The path to the XML file that will be edited * @param XPath The path within XML file that leads to the node that should be changed * @param attributes The attributes to add to the node */ private void writePropertiesToConfig(StandaloneLocalConfiguration config, String file, String XPath, HashMap<String, String> attributes) { for (String key : attributes.keySet()) { XmlReplacement property = new XmlReplacement(); property.setFile(file); property.setXpathExpression(XPath); property.setAttributeName(key); property.setValue(attributes.get(key)); config.addXmlReplacement(property); } }
/** * Uses the {@link DefaultAntTaskFactory} class when creating Ant tasks. */ public AntUtils() { this.antTaskFactory = new DefaultAntTaskFactory(createProject()); }
/** * {@inheritDoc} */ @Override public String readScript() { FileHandler fileHandler = new DefaultFileHandler(); String customScript = fileHandler.readTextFile(resourcePath, "UTF-8"); return customScript; }
/** * @return url this server serves. */ @Override public URL getURL() { if (this.url == null) { throw new CargoException("Please call setListeningParameters first!"); } return url; }
/** * @param remoteLocation URL where the zipped container is located * @param downloadDir directory where the zipped container install will be downloaded. * @param extractDir directory where the zipped container install will be extracted. */ public ZipURLInstaller(URL remoteLocation, String downloadDir, String extractDir) { this.remoteLocation = remoteLocation; this.downloadDir = downloadDir; this.extractDir = extractDir; this.fileHandler = new DefaultFileHandler(); this.antUtils = new AntUtils(); }
/** * Nothing will be appended, document is already as expected. * @throws Exception if anything goes wrong */ public void testAppendNotNeeded() throws Exception { String xml = "<Root/>"; String xPath = "/Root"; MissingXmlElementAppender missingXmlElementAppender = new MissingXmlElementAppender(parse(xml), xPath); missingXmlElementAppender.append(); assertEquals("<Root/>", toString(missingXmlElementAppender.getDocument())); }
/** * Test the {@link FileHandler#getName(java.lang.String)} method. * @throws Exception If anything goes wrong. */ public void testGetName() throws Exception { assertEquals("file.txt", this.fileHandler.getName("ram:///some/file.txt")); }
/** * @return FileHandler. */ private FileHandler getFileHandler() { return new DefaultFileHandler(); }
/** * creates the instance, which will use the specified @{link FileHandler fileHandler} to read or * write the xml file. * * @param fileHandler used for file i/o. * @param namespaceAware true if builder should be namespace aware. */ public DefaultXmlFileBuilder(FileHandler fileHandler, boolean namespaceAware) { xmlUtil = new XmlUtils(fileHandler, namespaceAware); }
/** * Test Base64 encoding. */ public void testEncode() { assertEquals("SGVsbG8gV29ybGQ=", Base64.encode("Hello World")); }
/** * {@inheritDoc} */ @Override public Document loadFile() { this.document = xmlUtil.loadXmlFromFile(path); return this.document; }
/** * {@inheritDoc} */ @Override public void setNamespaces(Map<String, String> namespaces) { xmlUtil.setNamespaces(namespaces); }
/** * Base64 encodes the specified bytes. This method is provided for signature compatibility with * commons-codec. * * @param bytes the bytes to encode * @return the encoded bytes */ public static byte[] encodeBase64(byte[] bytes) { return encode(bytes); }
/** * Print the full stack trace, including the original exception. */ @Override public void printStackTrace() { printStackTrace(System.err); }
/** * {@inheritDoc}. The default buffer size if 1024. */ @Override public void copy(InputStream in, OutputStream out) { copy(in, out, 1024); }
/** * {@inheritDoc} */ @Override public String readScript() { FileHandler fileHandler = new DefaultFileHandler(); String customScript = fileHandler.readTextFile(resourcePath, "UTF-8"); return customScript; }
/** * Assert that one hierarchy level will be added. * @throws Exception if anything goes wrong */ public void testAppendBranch() throws Exception { String xml = "<Root/>"; String xPath = "/Root/Branch"; MissingXmlElementAppender missingXmlElementAppender = new MissingXmlElementAppender(parse(xml), xPath); missingXmlElementAppender.append(); assertEquals("<Root><Branch/></Root>", toString(missingXmlElementAppender.getDocument())); }
/** * Uses the {@link DefaultAntTaskFactory} class when creating Ant tasks. */ public AntUtils() { this.antTaskFactory = new DefaultAntTaskFactory(createProject()); }
/** * Assert that more hierarchy levels will be added * @throws Exception if anything goes wrong */ public void testAppendLeave() throws Exception { String xml = "<Root/>"; String xPath = "/Root/Branch/Leave"; MissingXmlElementAppender missingXmlElementAppender = new MissingXmlElementAppender(parse(xml), xPath); missingXmlElementAppender.append(); assertEquals("<Root><Branch><Leave/></Branch></Root>", toString(missingXmlElementAppender.getDocument())); }