List of usage examples for org.eclipse.jdt.internal.core JarEntryFile getContents
@Override
public InputStream getContents() throws CoreException
From source file:org.eclipse.che.plugin.java.server.JavaNavigation.java
License:Open Source License
private ClassContent readFileContent(JarEntryFile file) { try (InputStream stream = (file.getContents())) { return createContent(IoUtil.readStream(stream), false); } catch (IOException | CoreException e) { LOG.error("Can't read file content: " + file.getFullPath(), e); }// www . j a v a 2 s .co m return null; }
From source file:org.jboss.tools.jsf.jsf2.model.JSF2ComponentModelManager.java
License:Open Source License
public static IDOMDocument getReadableDOMDocument(JarEntryFile file) { IDOMDocument document = null;// ww w . j a v a 2 s .com IStructuredModel model = null; InputStream inputStream = null; try { inputStream = file.getContents(); if (inputStream != null) { StringBuilder buffer = new StringBuilder(); //$NON-NLS-1$ Scanner in = new Scanner(inputStream); while (in.hasNextLine()) { buffer.append(in.nextLine()); } model = new HTMLModelLoader().newModel(); model.setStructuredDocument(new JobSafeStructuredDocument(new XMLSourceParser())); model.getStructuredDocument().set(buffer.toString()); if (model instanceof IDOMModel) { document = ((IDOMModel) model).getDocument(); } } } catch (CoreException e) { JSFModelPlugin.getPluginLog().logError(e); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { // Ignore } } model = null; } return document; }
From source file:org.jboss.tools.vpe.editor.util.DocTypeUtil.java
License:Open Source License
/** * get doctype by {@link IEditorInput}//from w w w .j av a2s. c om * * @param editorInput * @return */ public static String getDoctype(IEditorInput editorInput) { /* * https://jira.jboss.org/jira/browse/JBIDE-4510 * Doctype string should always have some value: * empty value or doctype value, but not 'null' * because this string is displayed on VPE page. */ String doctype = Constants.EMPTY; /* * if opened file is located in eclipse workspace */ if (editorInput instanceof IFileEditorInput) { IFile f = ((IFileEditorInput) editorInput).getFile(); if ((f != null) && f.exists()) { doctype = getDoctype(f, null); } } /* * if opened file is not located in eclipse workspace */ else if (editorInput instanceof ILocationProvider) { IPath path = ((ILocationProvider) editorInput).getPath(editorInput); if (path != null && path.segmentCount() > 0) { //TODO SDzmitrovich Fix This Method, convert to IPath to IFile, //or smht. else, should be only one getDoctype(IFile, List<IFile>); doctype = getDoctype(path.toFile()); } } /* * https://jira.jboss.org/jira/browse/JBIDE-4510 * When file is opened from jar archive. */ else if (editorInput instanceof IStorageEditorInput) { /* * To determine the doctype of a file from jar archive * by means of eclipse's StructuredModelManager * file should be an IFile type and should exists in the workspace. * To achieve that conditions temporally IFile will be created * in the root project folder. * After doctype processing temporally file will be deleted. */ IStorageEditorInput input = ((IStorageEditorInput) editorInput); IStorage storage = null; try { storage = input.getStorage(); } catch (CoreException ex) { VpePlugin.getPluginLog().logError(ex); } JarEntryFile jarFile = null; IFile iFile = null; if (storage instanceof JarEntryFile) { jarFile = (JarEntryFile) storage; try { /* * Get the content of a file from jar archive. */ InputStream is = jarFile.getContents(); /* * Find the eclipse project that contains selected jar archive. */ IJavaProject javaProject = jarFile.getPackageFragmentRoot().getJavaProject(); if (javaProject != null) { IProject project = javaProject.getProject(); /* * Create temporally IFile. */ iFile = project.getFile(TEMP_FILE_NAME + jarFile.getFullPath().lastSegment()); /* * Delete any previously saved file. */ if ((iFile != null) && (iFile.exists())) { iFile.delete(true, false, null); } /* * Create new file with a content of the file from jar library. */ iFile.create(is, true, null); /* * Get doctype for this file, store it. */ doctype = getDoctype(iFile, null); /* * Delete temporally file. */ if (iFile != null) { iFile.delete(true, false, null); } } } catch (CoreException e) { /* * Log any possible errors. */ VpePlugin.getPluginLog().logError(e); } } } return doctype; }