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); } }
private static XMLInputSource resolveImportByName(String aFileResource, ResourceManager aResourceManager) throws InvalidXMLException, ResourceInitializationException, IOException { XMLInputSource input; if (aFileResource.startsWith(IMPORT_BY_NAME_PREFIX)) { Import theImport = new Import_impl(); theImport.setName(aFileResource.substring(IMPORT_BY_NAME_PREFIX.length())); input = new XMLInputSource(theImport.findAbsoluteUrl(aResourceManager)); } else { input = new XMLInputSource(aFileResource); } return input; }
String currentFileBeingEdited = editor.getFile().getLocation().toString(); currentFileBeingEdited = editor.getDescriptorRelativePath(currentFileBeingEdited); if (currentFileBeingEdited.equals(imp.getLocation())) { Utility .popMessage( .format( "The import {0} is the same as the current file being edited. A file can''t be imported into itself.", new Object[] { imp.getLocation() }), MessageDialog.ERROR); return true; if (currentImports[i].equals(imp)) { Utility.popMessage("Error - duplicate import", MessageFormat.format( "The import {0} is already present", new Object[] { null != imp.getName() ? imp .getName() : imp.getLocation() }), MessageDialog.ERROR); return true;
aeDescription = "file:" + aeDescription; descriptorImport.setLocation(aeDescription); } else { descriptorImport.setName(aeDescription); fcd.setImport(new Import_impl()); fcd.setKey(FlowControllerKey); fcd.getImport().setName(fcsn);
/** * 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; }
URL url = aeImport.findAbsoluteUrl(aResourceManager); } catch (IOException e) { throw new InvalidXMLException(InvalidXMLException.IMPORT_FAILED_COULD_NOT_READ_FROM_URL, new Object[] { url, aeImport.getSourceUrlString() }, e);
/** * @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); } } }
private String resolveToAbsolutePath(Import theImport) { ResourceManager resourceManager = UIMAFramework.newDefaultResourceManager(); try { return theImport.findAbsoluteUrl(resourceManager).toExternalForm(); } catch (Exception e) { if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.WARNING)) { UIMAFramework.getLogger(CLASS_NAME).logrb(Level.WARNING, WarmUpDataProvider.class.getName(), "resolveToAbsolutePath", UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE, "UIMAEE_exception__WARNING", e); } return "ERROR converting import by name to absolute path"; } }
/** * @return import instance. This is preferred way to include the AE into * pipeline, especially when a pipeline descriptor is expected to be * serialized into XML. * @see PipelineDescriptorUtils#createAggregateDescription(java.util.List, * java.util.List) */ public static Import getAEImport() { Import result = new Import_impl(); result.setName(AE_SENTENCE_SPLITTER); return result; }
CpeCollectionReader[] collRdrs = currentCpeDesc.getAllCollectionCollectionReaders(); for (CpeCollectionReader collReader : collRdrs) { File descFile = new File(rootFolder + System.getProperty("file.separator") + collReader.getDescriptor().getImport().getLocation()); CollectionReaderDescription crd = UIMAFramework.getXMLParser().parseCollectionReaderDescription(new XMLInputSource(descFile)); TypeSystemDescription typeSystem = crd.getCollectionReaderMetaData().getTypeSystem(); for (CpeCasProcessor casProcessor : cpeCasProcessors) { File descFile = new File(rootFolder + System.getProperty("file.separator") + casProcessor.getCpeComponentDescriptor().getImport().getLocation()); AnalysisEngineDescription aed = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(new XMLInputSource(descFile)); TypeSystemDescription typeSystem = aed.getAnalysisEngineMetaData().getTypeSystem();
/** * 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; }
URL url = imports[i].findAbsoluteUrl(aResourceManager); if (!aAlreadyImportedTypePrioritiesURLs.contains(url.toString())) { aAlreadyImportedTypePrioritiesURLs.add(url.toString()); } catch (IOException e) { throw new InvalidXMLException(InvalidXMLException.IMPORT_FAILED_COULD_NOT_READ_FROM_URL, new Object[] { url, imports[i].getSourceUrlString() }, e);
/** * 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); } } }
try { if (mImport != null) { return mImport.findAbsoluteUrl(aResourceManager);
/** * @return import instance. This is preferred way to include the AE into * pipeline, especially when a pipeline descriptor is expected to be * serialized into XML. * @see PipelineDescriptorUtils#createAggregateDescription(java.util.List, * java.util.List) */ public static Import getAEImport() { Import result = new Import_impl(); result.setName(AE_TOKENIZER); return result; }
CpeCollectionReader[] collRdrs = currentCpeDesc.getAllCollectionCollectionReaders(); for (CpeCollectionReader collReader : collRdrs) { File descFile = new File(rootFolder + System.getProperty("file.separator") + collReader.getDescriptor().getImport().getLocation()); CollectionReaderDescription crd = UIMAFramework.getXMLParser().parseCollectionReaderDescription(new XMLInputSource(descFile)); TypeSystemDescription typeSystem = crd.getCollectionReaderMetaData().getTypeSystem(); File descFile = new File(rootFolder + System.getProperty("file.separator") + casProcessor.getCpeComponentDescriptor().getImport().getLocation()); AnalysisEngineDescription aed = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(new XMLInputSource(descFile)); TypeSystemDescription typeSystem = aed.getAnalysisEngineMetaData().getTypeSystem();
imp.setName(fileName.substring(partStart)); try { imp.findAbsoluteUrl(rm); } catch (InvalidXMLException e) { partStart = fileName.indexOf('.', partStart) + 1;
/** * 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; }
((Import_impl) imports[i]).setSourceUrlIfNull(this.getSourceUrl()); URL url = imports[i].findAbsoluteUrl(aResourceManager); if (!aAlreadyImportedTypeSystemURLs.contains(url.toString())) { aAlreadyImportedTypeSystemURLs.add(url.toString()); } catch (IOException e) { throw new InvalidXMLException(InvalidXMLException.IMPORT_FAILED_COULD_NOT_READ_FROM_URL, new Object[] { url, imports[i].getSourceUrlString() }, e);
/** * Gets the absolute UR lfrom import. * * @param importItem the import item * @return the absolute UR lfrom import */ private URL getAbsoluteURLfromImport(Import importItem) { try { // if by location, it's relative to the descriptor. return Platform.asLocalURL(importItem.findAbsoluteUrl(createResourceManager())); } catch (InvalidXMLException ex) { ex.printStackTrace(); } catch (IOException e) { } return null; }