/** * Creates a {@link FsIndexCollection} from a descriptor file * * @param descriptorURIs * The descriptor file paths. * @return A {@link FsIndexCollection} that includes the indexes from all of the specified files. */ public static FsIndexCollection createTypeSystemDescriptionFromPath(String... descriptorURIs) { List<Import> imports = new ArrayList<Import>(); for (String descriptorURI : descriptorURIs) { Import imp = new Import_impl(); imp.setLocation(descriptorURI); imports.add(imp); } Import[] importArray = new Import[imports.size()]; FsIndexCollection fsIndexCollection = new FsIndexCollection_impl(); fsIndexCollection.setImports(imports.toArray(importArray)); return fsIndexCollection; }
/** * Creates a TypeSystemDescription from a descriptor file * * @param descriptorURIs * The descriptor file paths. * @return A TypeSystemDescription that includes the types from all of the specified files. */ public static TypeSystemDescription createTypeSystemDescriptionFromPath(String... descriptorURIs) { TypeSystemDescription typeSystem = new TypeSystemDescription_impl(); List<Import> imports = new ArrayList<Import>(); for (String descriptorURI : descriptorURIs) { Import imp = new Import_impl(); imp.setLocation(descriptorURI); imports.add(imp); } Import[] importArray = new Import[imports.size()]; typeSystem.setImports(imports.toArray(importArray)); return typeSystem; }
/** * Creates the location import. * * @param location the location * @return a location import * @throws MalformedURLException - */ public Import createLocationImport(String location) throws MalformedURLException { String sDescriptorRelativePath = editor.getDescriptorRelativePath(location); // If relative path is not "relative", on Windows might get back // an absolute path starting with C: or something like it. // If a path starts with "C:", it must be preceeded by // file:/ so the C: is not interpreted as a "scheme". if (sDescriptorRelativePath.indexOf("file:/") == -1 //$NON-NLS-1$ && sDescriptorRelativePath.indexOf(":/") > -1) { //$NON-NLS-1$ sDescriptorRelativePath = "file:/" + sDescriptorRelativePath; //$NON-NLS-1$ } Import imp = new Import_impl(); // fails on unix? URL url = new URL("file:/" + getDescriptorDirectory()); // Set relative Path Base // a version that might work on all platforms URL url = new File(editor.getDescriptorDirectory()).toURL(); ((Import_impl) imp).setSourceUrl(url); imp.setLocation(sDescriptorRelativePath); return imp; }
private static void setImportsByLocation(File dir, String descName) { FileOutputStream fos = null; try { File file = new File(dir, descName); AnalysisEngineDescription description = UIMAFramework.getXMLParser() .parseAnalysisEngineDescription(new XMLInputSource(file)); Import[] imports = description.getAnalysisEngineMetaData().getTypeSystem().getImports(); for (Import each : imports) { String name = each.getName(); String[] split = name.split("[.]"); String location = split[split.length - 1] + ".xml"; each.setName(null); each.setLocation(location); } fos = new FileOutputStream(file); description.toXML(fos); } catch (InvalidXMLException | IOException | SAXException e) { RutaIdeUIPlugin.error(e); } finally { IOUtils.closeQuietly(fos); } }
throw new RuntimeException(e); // this should never happen for files imp.setLocation(url.toString()); imports.add(imp);
/** * @param descriptor * @param cpeDescSaveFile */ private void updateImport(CpeComponentDescriptor descriptor, File cpeDescSaveFile) throws Exception { //don't touch import by name if (descriptor.getImport() != null && descriptor.getImport().getName() != null) return; //for include or import by location, get the absolute URL of the descriptor URL descUrl = descriptor.findAbsoluteUrl(defaultResourceManager); //don't touch URLs with protocol other than file: if ("file".equals(descUrl.getProtocol())) { File descFile = urlToFile(descUrl); //try to find relative path from cpeDescSaveFile to descFile String relPath = FileUtils.findRelativePath(descFile, cpeDescSaveFile.getParentFile()); if (relPath != null) { //update CPE descriptor descriptor.setInclude(null); Import newImport = UIMAFramework.getResourceSpecifierFactory().createImport(); newImport.setLocation(relPath); descriptor.setImport(newImport); } } }
/** * Update import. * * @param descriptor the descriptor * @param cpeDescSaveFile the cpe desc save file * @throws Exception the exception */ private void updateImport(CpeComponentDescriptor descriptor, File cpeDescSaveFile) throws Exception { //don't touch import by name if (descriptor.getImport() != null && descriptor.getImport().getName() != null) return; //for include or import by location, get the absolute URL of the descriptor URL descUrl = descriptor.findAbsoluteUrl(defaultResourceManager); //don't touch URLs with protocol other than file: if ("file".equals(descUrl.getProtocol())) { File descFile = urlToFile(descUrl); //try to find relative path from cpeDescSaveFile to descFile String relPath = FileUtils.findRelativePath(descFile, cpeDescSaveFile.getParentFile()); if (relPath != null) { //update CPE descriptor descriptor.setInclude(null); Import newImport = UIMAFramework.getResourceSpecifierFactory().createImport(); newImport.setLocation(relPath); descriptor.setImport(newImport); } } }
aeDescription = "file:" + aeDescription; descriptorImport.setLocation(aeDescription); } else {
dlgImport.setLocation(dlgDescRelPath);