diff options
author | 2023-12-19 17:13:25 +0530 | |
---|---|---|
committer | 2023-12-19 17:13:25 +0530 | |
commit | c5b8756512cb6dfbb0093514af7924cb3e78699b (patch) | |
tree | 7202621ea816d666bbce482b420ef574280a1c0a /sdnr/wt/helpserver/provider/src/main/java | |
parent | dfd91573b7567e1dab482f17111ab8f809553d99 (diff) |
Delete wt/odlux directory
New directory for odlux is sdnr/wt-odlux
Issue-ID: CCSDK-3971
Change-Id: Ia0f8ba38d913a3d3bcde999b871794c65d5e575e
Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/helpserver/provider/src/main/java')
3 files changed, 0 insertions, 471 deletions
diff --git a/sdnr/wt/helpserver/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/helpserver/HelpServlet.java b/sdnr/wt/helpserver/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/helpserver/HelpServlet.java deleted file mode 100644 index ddd684019..000000000 --- a/sdnr/wt/helpserver/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/helpserver/HelpServlet.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * ================================================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * ============LICENSE_END========================================================================== - */ -package org.onap.ccsdk.features.sdnr.wt.helpserver; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileReader; -import java.io.IOException; -import java.io.OutputStream; -import java.net.URISyntaxException; -import java.net.URLDecoder; -import java.nio.file.Path; -import javax.servlet.Servlet; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import org.onap.ccsdk.features.sdnr.wt.helpserver.data.HelpInfrastructureObject; -import org.osgi.service.component.annotations.Component; -import org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardServletName; -import org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardServletPattern; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@HttpWhiteboardServletPattern("/help/*") -@HttpWhiteboardServletName("HelpServlet") -@Component(service = Servlet.class) -public class HelpServlet extends HttpServlet implements AutoCloseable { - - private static Logger LOG = LoggerFactory.getLogger(HelpServlet.class); - private static final long serialVersionUID = -4285072760648493461L; - - private static final String BASEURI = "/help"; - - private final Path basePath; - - public HelpServlet() { - LOG.info("Starting HelpServlet instance {}", this.hashCode()); - HelpInfrastructureObject.createFilesFromResources(); - this.basePath = HelpInfrastructureObject.getHelpDirectoryBase(); - } - - @Override - public void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - resp.addHeader("Access-Control-Allow-Origin", "*"); - resp.addHeader("Access-Control-Allow-Methods", "OPTIONS, HEAD, GET, POST, PUT, DELETE"); - resp.addHeader("Access-Control-Allow-Headers", "X-Requested-With, Content-Type, Content-Length"); - } - - @Override - public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - String query = req.getQueryString(); - resp.addHeader("Access-Control-Allow-Origin", "*"); - resp.addHeader("Access-Control-Allow-Methods", "OPTIONS, HEAD, GET, POST, PUT, DELETE"); - resp.addHeader("Access-Control-Allow-Headers", "X-Requested-With, Content-Type, Content-Length"); - if (query != null && query.contains("meta")) { - - File f = new File(HelpInfrastructureObject.KARAFHELPDIRECTORY, "meta.json"); - if (f.exists()) { - LOG.debug("found local meta file"); - try (BufferedReader rd = new BufferedReader(new FileReader(f));) { - String line = rd.readLine(); - while (line != null) { - resp.getOutputStream().println(line); - line = rd.readLine(); - } - rd.close(); - } catch (IOException e) { - LOG.debug("Can not read meta file", e); - } - } else { - LOG.debug("start walking from path=" + basePath.toAbsolutePath().toString()); - HelpInfrastructureObject o = null; - try { - o = new HelpInfrastructureObject(this.basePath); - } catch (URISyntaxException e) { - LOG.debug("Can not relsolve URI. ", e); - } - resp.getOutputStream().println(o != null ? o.toString() : ""); - } - resp.setHeader("Content-Type", "application/json"); - } else { - LOG.debug("received get with uri=" + req.getRequestURI()); - String uri = URLDecoder.decode(req.getRequestURI().substring(BASEURI.length()), "UTF-8"); - if (uri.startsWith("/")) { - uri = uri.substring(1); - } - Path p = basePath.resolve(uri); - File f = p.toFile(); - if (f.isFile() && f.exists()) { - LOG.debug("found file for request"); - if (this.isTextFile(f)) { - resp.setHeader("Content-Type", "application/text"); - resp.setHeader("charset", "utf-8"); - } else if (this.isImageFile(f)) { - resp.setHeader("Content-Type", "image/*"); - } else if (this.ispdf(f)) { - resp.setHeader("Content-Type", "application/pdf"); - } else { - LOG.debug("file is not allowed to deliver"); - resp.setStatus(404); - return; - } - LOG.debug("delivering file"); - try (OutputStream out = resp.getOutputStream()) { - try (FileInputStream in = new FileInputStream(f)) { - - byte[] buffer = new byte[1024]; - int len; - while ((len = in.read(buffer)) != -1) { - out.write(buffer, 0, len); - } - in.close(); - out.flush(); - out.close(); - } - } catch (IOException e) { - LOG.warn("Can not write meta file", e); - resp.setStatus(500); - } - } else { - LOG.debug("found not file for request"); - resp.setStatus(404); - } - } - } - - private boolean ispdf(File f) { - return f != null && this.ispdf(f.getName()); - } - - private boolean ispdf(String name) { - return name != null && name.toLowerCase().endsWith("pdf"); - } - - private boolean isImageFile(File f) { - return f != null && this.isImageFile(f.getName()); - } - - private boolean isImageFile(String name) { - - return name != null - ? name.toLowerCase().endsWith("png") || name.toLowerCase().endsWith("jpg") - || name.toLowerCase().endsWith("jpeg") || name.toLowerCase().endsWith("svg") - || name.toLowerCase().endsWith("eps") - : false; - } - - private boolean isTextFile(File f) { - return f != null && this.isTextFile(f.getName()); - - } - - private boolean isTextFile(String name) { - return name != null - ? name.toLowerCase().endsWith("md") || name.toLowerCase().endsWith("txt") - || name.toLowerCase().endsWith("html") || name.toLowerCase().endsWith("htm") - || name.toLowerCase().endsWith("js") || name.toLowerCase().endsWith("css") - : false; - } - - @Override - public void close() throws Exception {} -} diff --git a/sdnr/wt/helpserver/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/helpserver/data/ExtactBundleResource.java b/sdnr/wt/helpserver/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/helpserver/data/ExtactBundleResource.java deleted file mode 100644 index ca3a40043..000000000 --- a/sdnr/wt/helpserver/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/helpserver/data/ExtactBundleResource.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * ================================================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * ============LICENSE_END========================================================================== - */ -package org.onap.ccsdk.features.sdnr.wt.helpserver.data; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Enumeration; -import org.osgi.framework.Bundle; - -/** - * Extract subtree with resources from Opendaylight/Karaf/OSGi bundle into Karaf directory<br> - * - * Reference: Eclipsezone @see - * <a href="https://www.eclipsezone.com/eclipse/forums/t101557.html">https://www.eclipszone.com</a> <br> - * <br> - * Example for resource and directory path from karaf log. write resource: help/FAQ/0.4.0/README.md Create directories - * for: data/cache/com.highstreet.technologies.help/help/FAQ/0.4.0/README.md Open the file: - * data/cache/com.highstreet.technologies.help/help/FAQ/0.4.0/README.md Problem: Binary, JPG files => do not use buffer - * related functions - * - * Hint: Verify with file manager the content of the bundle.jar file to see the location of the resources. There is no - * need to mark them via the classpath. - */ - -public class ExtactBundleResource { - - /** - * Extract resources from Karaf/OSGi bundle into karaf directory structure. - * - * @param bundle Karaf/OSGi bundle with resources - * @param filePrefix prefix in karaf file system for destination e.g. "data/cache/com.highstreet.technologies." - * @param ressoureRoot root name of ressources, with leading "/". e.g. "/help" - * @throws IOException In case of problems. - */ - public static void copyBundleResoucesRecursively(Bundle bundle, String filePrefix, String ressoureRoot) - throws IOException { - copyResourceTreeRecurse(bundle, filePrefix, bundle.getEntryPaths(ressoureRoot)); - } - - /** - * Delete a file or a directory and its children. - * - * @param file The directory to delete. - * @throws IOException Exception when problem occurs during deleting the directory. - */ - public static void deleteRecursively(File file) throws IOException { - - if (file.isDirectory()) { - for (File childFile : file.listFiles()) { - deleteRecursively(childFile); - } - } - if (file.exists()) { - if (!file.delete()) { - throw new IOException("No file " + file.getName()); - } - } - } - - // ------------- Private functions - - /** - * Recurse function to steps through the resource element tree - * - * @param b Bundle index for bundle with resourcs - * @param filePrefix - * @param resource - * @throws IOException - */ - private static void copyResourceTreeRecurse(Bundle b, String filePrefix, Enumeration<String> resource) - throws IOException { - while (resource.hasMoreElements()) { - String name = resource.nextElement(); - Enumeration<String> list = b.getEntryPaths(name); - if (list != null) { - copyResourceTreeRecurse(b, filePrefix, list); - } else { - // Read - File targetFile = new File(filePrefix + name); - targetFile.getParentFile().mkdirs(); - - try (InputStream in = b.getEntry(name).openStream(); - OutputStream outStream = new FileOutputStream(targetFile);) { - - int theInt; - while ((theInt = in.read()) >= 0) { - outStream.write(theInt); - } - in.close(); - outStream.flush(); - outStream.close(); - } - } - } - } -} diff --git a/sdnr/wt/helpserver/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/helpserver/data/HelpInfrastructureObject.java b/sdnr/wt/helpserver/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/helpserver/data/HelpInfrastructureObject.java deleted file mode 100644 index 4adb54dea..000000000 --- a/sdnr/wt/helpserver/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/helpserver/data/HelpInfrastructureObject.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * ================================================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * ============LICENSE_END========================================================================== - */ -package org.onap.ccsdk.features.sdnr.wt.helpserver.data; - -import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import org.json.JSONObject; -import org.osgi.framework.Bundle; -import org.osgi.framework.FrameworkUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class HelpInfrastructureObject extends JSONObject { - - private static final Logger LOG = LoggerFactory.getLogger(HelpInfrastructureObject.class); - private static String HELPBASE = "help"; - private static String KARAFBUNDLERESOURCEHELPROOT = "/" + HELPBASE; - private static String KARAFHELPDIRPREFIX = "data/cache/com.highstreet.technologies."; - public static File KARAFHELPDIRECTORY = new File(KARAFHELPDIRPREFIX + HELPBASE); - - public static class VersionObject extends JSONObject { - private static Comparator<VersionObject> comp; - private final String mVersion; - - public String getVersion() { - return this.mVersion; - } - - public VersionObject(String path, String date, String label, String version) { - this.mVersion = version; - this.put("path", path); - this.put("date", date); - this.put("label", label); - } - - public static Comparator<VersionObject> getComparer() { - if (comp == null) { - comp = (o1, o2) -> o1.getVersion().compareTo(o2.getVersion()); - } - return comp; - } - - public VersionObject cloneAsLatest() { - return new VersionObject(this.getString("path"), this.getString("date"), this.getString("label"), "latest"); - } - - public VersionObject cloneAsCurrent() { - return new VersionObject(this.getString("path"), this.getString("date"), this.getString("label"), - "current"); - } - } - public static class NodeObject extends JSONObject { - public NodeObject(Path base, File dir, String label, ArrayList<VersionObject> versions) { - this.put("label", label); - if (versions != null && !versions.isEmpty()) { - JSONObject o = new JSONObject(); - this.put("versions", o); - for (VersionObject version : versions) { - o.put(version.getVersion(), version); - } - - } - File[] list = dir.listFiles(); - if (list == null) { - return; - } - for (File f : list) { - if (f.isDirectory()) { - ArrayList<VersionObject> versions2 = findReadmeVersionFolders(base, f.toPath(), true); - if (versions2 != null && !versions2.isEmpty()) { - JSONObject nodes; - if (!this.has("nodes")) { - this.put("nodes", new JSONObject()); - } - nodes = this.getJSONObject("nodes"); - - NodeObject o = new NodeObject(base, f, f.getName(), versions2); - nodes.put(o.getString("label").toLowerCase(), o); - } - } - } - } - - } - - public HelpInfrastructureObject(Path pRoot) throws URISyntaxException { - File root = pRoot.toFile(); - File[] list = root.listFiles(); - if (list == null) { - return; - } - for (File f : list) { - if (f.isDirectory()) { - ArrayList<VersionObject> versions = findReadmeVersionFolders(root.toPath(), f.toPath(), true); - if (versions != null && !versions.isEmpty()) { - NodeObject o = new NodeObject(pRoot, f, f.getName(), versions); - this.put(o.getString("label").toLowerCase(), o); - } - } - } - } - - private static ArrayList<VersionObject> findReadmeVersionFolders(Path base, Path root, boolean appendCurrent) { - ArrayList<VersionObject> list = new ArrayList<>(); - File[] files = root.toFile().listFiles(); - int baselen = base.toFile().getAbsolutePath().length(); - if (files != null) { - for (File f : files) { - if (f.isDirectory() && new File(f.getAbsolutePath() + "/README.md").exists()) { - list.add(new VersionObject(f.getAbsolutePath().substring(baselen + 1) + "/README.md", "", "", - f.getName())); - } - } - } - Collections.sort(list, VersionObject.getComparer()); - Collections.reverse(list); - if (!list.isEmpty() && appendCurrent) { - list.add(list.get(0).cloneAsCurrent()); - } - return list; - } - - - public static void createFilesFromResources() { - - if (KARAFHELPDIRECTORY.exists()) { - LOG.debug("Delete existing directory"); - try { - ExtactBundleResource.deleteRecursively(KARAFHELPDIRECTORY); - } catch (IOException e1) { - LOG.warn(e1.toString()); - } - } - - LOG.debug("Extract"); - try { - Bundle b = FrameworkUtil.getBundle(HelpInfrastructureObject.class); - if (b == null) { - LOG.debug("No bundlereference: Use target in filesystem."); - // URL helpRessource = - // JarFileUtils.stringToJarURL("target/helpserver-impl-0.4.0-SNAPSHOT.jar",KARAFBUNDLERESOURCEHELPROOT); - - } else { - LOG.debug("Bundle location:{} State:{}", b.getLocation(), b.getState()); - LOG.debug("Write files from Resource"); - ExtactBundleResource.copyBundleResoucesRecursively(b, "data/cache/com.highstreet.technologies.", - KARAFBUNDLERESOURCEHELPROOT); - } - } catch (IOException e) { - LOG.warn("No help files available. Exception: " + e.toString()); - } - } - - public static Path getHelpDirectoryBase() { - return KARAFHELPDIRECTORY.toPath(); - } -} |