org.eclipse.emf.common.util.URI.trimSegments()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(114)

本文整理了Java中org.eclipse.emf.common.util.URI.trimSegments()方法的一些代码示例,展示了URI.trimSegments()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。URI.trimSegments()方法的具体详情如下:
包路径:org.eclipse.emf.common.util.URI
类名称:URI
方法名:trimSegments

URI.trimSegments介绍

[英]Returns the URI formed by trimming the specified number of segments (including empty segments, such as one representing a trailing separator) from the end of the path of this URI, if hierarchical; otherwise, this URI is returned unchanged.

Note that if all segments are trimmed from an absolute path, the root absolute path remains.
[中]返回通过从该URI的路径末端修剪指定数量的段(包括空段,例如表示尾随分隔符的段)形成的URI(如果是分层的);否则,此URI将原封不动地返回。
请注意,如果从绝对路径修剪所有线段,则根绝对路径将保持不变。

代码示例

代码示例来源:origin: fr.inria.atlanmod.neoemf/neoemf-core

@Override
public URI trimSegments(int i) {
  return internalUri.trimSegments(i);
}

代码示例来源:origin: atlanmod/NeoEMF

@Override
public URI trimSegments(int i) {
  return base.trimSegments(i);
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.eclipse.emf.common

@Override
public URI trimSegments(int i)
{
 URI result = uri.trimSegments(i);
 return result == uri ? this : appendFragment(result);
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.eclipse.e4.ui.workbench

static public String EMFtoPlatform(org.eclipse.emf.common.util.URI uri) {
  if (!PLATFORM_SCHEMA_EMF.equals(uri.scheme()))
    return null;
  // remove all segments but first two - only need bundle/fragment name
  int segments = uri.segmentCount();
  // segments: { "plugin", "org.eclipse.platform", "myDir", "model.e4xmi" }
  if (segments > 2)
    uri = uri.trimSegments(segments - 2);
  return uri.toString();
}

代码示例来源:origin: org.eclipse.uml2.uml/resources

private static URI getBaseUMLResourceURI() {
  URI umlMetamodel = URI.createURI(UMLResource.UML_METAMODEL_URI);
  URL resultURL = UMLResourcesUtil.class.getClassLoader().getResource(
    String.format("metamodels/%s", umlMetamodel.lastSegment())); //$NON-NLS-1$
  URI result;
  if (resultURL != null) {
    // remove the /metamodel/UML.metamodel.uml segments of the resource
    // we found
    result = URI.createURI(resultURL.toExternalForm(), true)
      .trimSegments(2);
  } else {
    // probably, we're not running with JARs, so assume the source
    // project folder layout
    resultURL = UMLResourcesUtil.class
      .getResource("UMLResourcesUtil.class"); //$NON-NLS-1$
    String baseURL = resultURL.toExternalForm();
    baseURL = baseURL.substring(0, baseURL.lastIndexOf("/bin/")); //$NON-NLS-1$
    result = URI.createURI(baseURL, true);
  }
  return result;
}

代码示例来源:origin: org.eclipse.uml2/common

URI baseURI = uri.trimSegments(1);
String baseSegment = uri.trimFileExtension().lastSegment();

代码示例来源:origin: org.eclipse.emf/org.eclipse.emf.codegen.ecore

public String getRelativeGenModelLocation()
{
 URI genModelURI = eResource().getURI();
 String result = genModelURI.deresolve(genModelURI.trimSegments(genModelURI.segmentCount() - 2).appendSegment("")).toString();
 return result;
}

代码示例来源:origin: org.eclipse.uml2/org.eclipse.uml2.common

URI baseURI = uri.trimSegments(1);
String baseSegment = uri.trimFileExtension().lastSegment();

代码示例来源:origin: org.eclipse.emf/org.eclipse.emf.codegen.ecore

for (int i = 0, count = baseURI.segmentCount(); i <= count; ++i)
 URI uri = baseURI.trimSegments(i);
 if (targetPlatformPropertyEditorFactories.contains(uri))

代码示例来源:origin: org.jabylon/rest.api

private void putLocale(HttpServletRequest req, final URI uri, HttpServletResponse resp) throws IOException {
  URI truncated = uri.trimSegments(1);
  Resolvable object = getObject(truncated.path());
  if (object instanceof ProjectVersion) {
    ProjectVersion version = (ProjectVersion) object;
    if(!isAuthorized(req, true, version)) {
      resp.setHeader("WWW-Authenticate", BASIC_AUTH_REALM);  
      resp.sendError(HttpServletResponse.SC_UNAUTHORIZED);  
    }
    else if (version.getChild(uri.lastSegment()) == null) {
      try {
        TransactionUtil.commit(version, new Modification<ProjectVersion, ProjectVersion>() {
          @Override
          public ProjectVersion apply(ProjectVersion object) {
            ProjectLocale locale = PropertiesFactory.eINSTANCE.createProjectLocale();
            locale.setName(uri.lastSegment());
            locale.setLocale((Locale) PropertiesFactory.eINSTANCE.createFromString(PropertiesPackage.Literals.LOCALE,
                uri.lastSegment()));
            PropertyResourceUtil.addNewLocale(locale, object);
            return object;
          }
        });
      } catch (CommitException e) {
        logger.error("Commit failed", e);
      }
    }
  } else
    resp.sendError(HttpServletResponse.SC_NOT_FOUND, "Version " + truncated.path() + " does not exist");
}

代码示例来源:origin: org.jabylon/rest.api

private void putVersion(HttpServletRequest req, final URI uri, HttpServletResponse resp) throws IOException {
  URI truncated = uri.trimSegments(1);
  Resolvable object = getObject(truncated.path());
  if (object instanceof Project) {
    Project project = (Project) object;
    if(!isAuthorized(req, true, project)) {
      resp.setHeader("WWW-Authenticate", BASIC_AUTH_REALM);  
      resp.sendError(HttpServletResponse.SC_UNAUTHORIZED);  
    }
    else if (project.getChild(uri.lastSegment()) == null) {
      try {
        TransactionUtil.commit(project, new Modification<Project, Project>() {
          @Override
          public Project apply(Project object) {
            ProjectVersion child = PropertiesFactory.eINSTANCE.createProjectVersion();
            ProjectLocale locale = PropertiesFactory.eINSTANCE.createProjectLocale();
            child.getChildren().add(locale);
            child.setTemplate(locale);
            child.setName(uri.lastSegment());
            object.getChildren().add(child);
            return object;
          }
        });
      } catch (CommitException e) {
        logger.error("Commit failed", e);
      }
    }
  } else
    resp.sendError(HttpServletResponse.SC_NOT_FOUND, "Project " + truncated.path() + " does not exist");
}

代码示例来源:origin: org.eclipse.xtext/ui

if (data.uriPrefix != null && archivePath.equals(data.root.getPath())) {
  URI prefix = data.uriPrefix.lastSegment().length()==0 ? data.uriPrefix.trimSegments(1) : data.uriPrefix;
  URI expectedURI = prefix.appendSegments(uri.segments());
  IStorage storage = data.uri2Storage.get(expectedURI);

代码示例来源:origin: org.eclipse/org.eclipse.emf.codegen.ecore

public String getRelativeGenModelLocation()
{
 URI genModelURI = eResource().getURI();
 String result = genModelURI.deresolve(genModelURI.trimSegments(genModelURI.segmentCount() - 2).appendSegment("")).toString();
 return result;
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.eclipse.emf.ecore

if (platformResourceMap == null || !platformResourceMap.containsKey(pluginID))
 URI platformPluginURI = uri.trimSegments(uri.segmentCount() - 2).appendSegment("");
 URI platformResourceURI = URI.createPlatformResourceURI(platformPluginURI.segment(1), false).appendSegment("");
 result.put(platformResourceURI, platformPluginURI);

代码示例来源:origin: org.eclipse.emf/org.eclipse.emf.ecore

if (platformResourceMap == null || !platformResourceMap.containsKey(pluginID))
 URI platformPluginURI = uri.trimSegments(uri.segmentCount() - 2).appendSegment("");
 URI platformResourceURI = URI.createPlatformResourceURI(platformPluginURI.segment(1), false).appendSegment("");
 result.put(platformResourceURI, platformPluginURI);

代码示例来源:origin: org.eclipse.emf/org.eclipse.emf.codegen.ecore

Generator.EMF_MODEL_PROJECT_STYLE,
getGenModel().getEffectiveModelPluginVariables(),
outputURI.trimSegments(1),
false);

代码示例来源:origin: org.eclipse.xtext/ui

protected URI findResourceInWorkspace(IJavaProject javaProject, URI classpathUri) throws CoreException {
  if (javaProject.exists()) {
    String packagePath = classpathUri.trimSegments(1).path();
    String fullPath = classpathUri.path();
    String fileName = classpathUri.lastSegment();

代码示例来源:origin: org.jabylon/properties

@SuppressWarnings({ "unchecked", "rawtypes" })
public static void addNewLocalizedDescriptor(PropertyFileDescriptor descriptor, ProjectLocale locale) {
  if (!descriptor.eIsSet(PropertiesPackage.Literals.PROPERTY_FILE_DESCRIPTOR__LOCATION))
    throw new IllegalArgumentException("Property File Descriptor location is not set");
  ProjectVersion version = locale.getParent();
  ProjectLocale templateLocale = version.getTemplate();
  URI templateResourceLocation = computeTemplateResourceLocation(locale.getLocale(), descriptor.getLocation(),
      templateLocale.getLocale(),version);
  Resolvable<?, ?> resolved = templateLocale.resolveChild(templateResourceLocation);
  PropertyFileDescriptor template = null;
  if (resolved instanceof PropertyFileDescriptor) {
    template = (PropertyFileDescriptor) resolved;
  }
  if (template == null)
    throw new IllegalArgumentException("Template property " + templateResourceLocation + " doesn't exist");
  Resolvable container = getOrCreateFolder(locale, descriptor.getLocation().trimSegments(1).segments());
  if (container.getChild(descriptor.getLocation().lastSegment()) != null) {
    PropertyFileDescriptor child = (PropertyFileDescriptor) container.getChild(descriptor.getLocation().lastSegment());
    child.setMaster(null);
    container.getChildren().set(container.getChildren().indexOf(child), descriptor);
    locale.getDescriptors().remove(child);
  } else {
    container.getChildren().add(descriptor);
  }
  descriptor.setMaster(template);
  locale.getDescriptors().add(descriptor);
}

代码示例来源:origin: org.jabylon/properties

private static void createMissingChildren(ProjectLocale template, ProjectLocale other) {
  EList<PropertyFileDescriptor> descriptors = template.getDescriptors();
  for (PropertyFileDescriptor descriptor : descriptors) {
    URI derivedLocation = computeLocaleResourceLocation(other.getLocale(), other.getParent(), descriptor.getLocation());
    Resolvable<?, ?> child = other.resolveChild(derivedLocation);
    if(child==null){
      Resolvable<?, ?> folder = getOrCreateFolder(other, derivedLocation.trimSegments(1).segments());
      PropertyFileDescriptor localeDescriptor = PropertiesFactory.eINSTANCE.createPropertyFileDescriptor();
      localeDescriptor.setMaster(descriptor);
      localeDescriptor.setVariant(other.getLocale());
      localeDescriptor.setLocation(derivedLocation);
      localeDescriptor.setProjectLocale(other);
      localeDescriptor.setParent(folder);
      localeDescriptor.setName(URI.decode(derivedLocation.lastSegment()));
    }
  }
}

代码示例来源:origin: org.eclipse/org.eclipse.emf.exporter

if (genModel != null && genModel.eResource() != null)
 URI uri = genModel.eResource().getURI().trimSegments(1);
 getModelExporter().setDirectoryURI(uri.toString() + "/");

相关文章

微信公众号

最新文章

更多