protected ServletContext getContext() { return container.get().getPortalContext(); } }
public LocalGadgetImporter(String name, GadgetRegistryService registryService, String gadgetPath, ConfigurationManager configurationManager, PortalContainer container) { super(name, gadgetPath); this.configurationManager = configurationManager; this.container = container; this.gadgetPath = gadgetPath; this.gadgetService = registryService; if (gadgetPath.startsWith("war:")) { gadgetPath = gadgetPath.replace("war:", ""); this.gadgetRootAbsolutePath = container.getPortalContext().getRealPath(gadgetPath); this.gadgetRootAbsolutePath = this.gadgetRootAbsolutePath.replace("\\", "/"); int gadgetRootPathIndex = this.gadgetRootAbsolutePath.lastIndexOf(gadgetPath); this.gadgetRootAbsolutePath = this.gadgetRootAbsolutePath.substring(0, gadgetRootPathIndex); } }
private String getMimeType(String fileName) { String mimeType = URLConnection.guessContentTypeFromName(fileName); if (mimeType == null) { mimeType = container.getPortalContext().getMimeType(fileName); } return mimeType; }
private String getRealPath(String resourcePath) throws Exception { if (!resourcePath.startsWith("war:") && !resourcePath.startsWith("classpath:") && !resourcePath.startsWith("jar:")) { File file = new File(resourcePath); return file.getAbsolutePath(); } else if (resourcePath.startsWith("war:")) { if (!resourcePath.equals(gadgetPath)) { resourcePath = resourcePath.replace("war:", ""); return gadgetRootAbsolutePath + resourcePath; } File file = new File(container.getPortalContext().getRealPath(resourcePath)); return file.getAbsolutePath(); } else { File file = new File(configurationManager.getURL(resourcePath).getPath()); return file.getAbsolutePath(); } }
private byte[] getContent(String filePath) throws IOException { InputStream in; try { if (!filePath.startsWith("classpath:") && !filePath.startsWith("jar:") && !filePath.startsWith("war:") && !filePath.startsWith("system:")) { if (filePath.startsWith("")) { filePath = "file:" + filePath; } else { filePath = "file:/" + filePath; } } if (filePath.startsWith("war:")) { filePath = filePath.replace("war:", ""); in = container.getPortalContext().getResourceAsStream(filePath); } else { in = configurationManager.getInputStream(filePath); } } catch (Exception exception) { return null; } if (in == null) { return null; } else { return IOTools.getBytes(in); } }
/** * {@inheritDoc} */ @Override public void processUpgrade(final String oldVersion, final String newVersion) { storeValueForPlugin(MIGRATION_STATUS, "0"); PortalContainer.addInitTask(portalContainer.getPortalContext(), new PortalContainerPostInitTask() { @Override public void execute(ServletContext context, PortalContainer portalContainer) { // Execute the task in an asynchrounous way new Thread(new Runnable() { @Override public void run() { doMigration(); } }, getName()).start(); } }); }
GadgetImporter importer = new ServletLocalImporter(gadgetUpgrade.getName(), gadgetURI, container.getPortalContext(), gadgetRegistryService);