@Test public void reference() { ContextURL contextURL = ContextURLParser.parse(URI.create("http: assertTrue(contextURL.isReference()); assertNull(contextURL.getSelectList()); assertNull(contextURL.getNavOrPropertyPath()); assertFalse(contextURL.isEntity()); assertFalse(contextURL.isDelta()); }
public static ContextURL parse(final URI contextURL) { if (contextURL == null) { return null; } final ContextURL.Builder contextUrl = ContextURL.with(); String contextURLasString = contextURL.toASCIIString(); boolean isEntity = false; if (contextURLasString.endsWith("/$entity") || contextURLasString.endsWith("/@Element")) { isEntity = true; contextUrl.suffix(Suffix.ENTITY); contextURLasString = contextURLasString.replace("/$entity", StringUtils.EMPTY). replace("/@Element", StringUtils.EMPTY); } else if (contextURLasString.endsWith("/$ref")) { contextUrl.suffix(Suffix.REFERENCE); contextURLasString = contextURLasString.replace("/$ref", StringUtils.EMPTY); } else if (contextURLasString.endsWith("/$delta")) { contextUrl.suffix(Suffix.DELTA); contextURLasString = contextURLasString.replace("/$delta", StringUtils.EMPTY); } else if (contextURLasString.endsWith("/$deletedEntity")) { contextUrl.suffix(Suffix.DELTA_DELETED_ENTITY); contextURLasString = contextURLasString.replace("/$deletedEntity", StringUtils.EMPTY); } else if (contextURLasString.endsWith("/$link")) { contextUrl.suffix(Suffix.DELTA_LINK); contextURLasString = contextURLasString.replace("/$link", StringUtils.EMPTY); } else if (contextURLasString.endsWith("/$deletedLink")) { contextUrl.suffix(Suffix.DELTA_DELETED_LINK); contextURLasString = contextURLasString.replace("/$deletedLink", StringUtils.EMPTY); } contextUrl.serviceRoot(URI.create(StringUtils.substringBefore(contextURLasString, Constants.METADATA))); final String rest = StringUtils.substringAfter(contextURLasString, Constants.METADATA + "#"); String firstToken; String entitySetOrSingletonOrType; if (rest.startsWith("Collection(")) { firstToken = rest.substring(0, rest.indexOf(')') + 1); entitySetOrSingletonOrType = firstToken; } else { final int openParIdx = rest.indexOf('('); if (openParIdx == -1) { firstToken = StringUtils.substringBeforeLast(rest, "/"); entitySetOrSingletonOrType = firstToken; } else { firstToken = isEntity ? rest : StringUtils.substringBeforeLast(rest, ")") + ")"; final List<String> parts = new ArrayList<>(); for (String split : firstToken.split("\\)/")) { parts.add(split.replaceAll("\\(.*", "")); } entitySetOrSingletonOrType = StringUtils.join(parts, '/'); final int commaIdx = firstToken.indexOf(','); if (commaIdx != -1) { contextUrl.selectList(firstToken.substring(openParIdx + 1, firstToken.length() - 1)); } } } contextUrl.entitySetOrSingletonOrType(entitySetOrSingletonOrType); final int slashIdx = entitySetOrSingletonOrType.lastIndexOf('/'); if (slashIdx != -1 && entitySetOrSingletonOrType.substring(slashIdx + 1).indexOf('.') != -1) { contextUrl.entitySetOrSingletonOrType(entitySetOrSingletonOrType.substring(0, slashIdx)); contextUrl.derivedEntity(entitySetOrSingletonOrType.substring(slashIdx + 1)); } if (!firstToken.equals(rest)) { final String[] pathElems = StringUtils.substringAfter(rest, "/").split("/"); if (pathElems.length > 0 && pathElems[0].length() > 0) { if (pathElems[0].indexOf('.') == -1) { contextUrl.navOrPropertyPath(pathElems[0]); } else { contextUrl.derivedEntity(pathElems[0]); } if (pathElems.length > 1) { contextUrl.navOrPropertyPath(pathElems[1]); } } } return contextUrl.build(); }
ContextURLParser { public static ContextURL parse(final URI contextURL) { if (contextURL == null) { return null; } final ContextURL.Builder contextUrl = ContextURL.with(); String contextURLasString = contextURL.toASCIIString(); boolean isEntity = false; if (contextURLasString.endsWith("/$entity") || contextURLasString.endsWith("/@Element")) { isEntity = true; contextUrl.suffix(Suffix.ENTITY); contextURLasString = contextURLasString.replace("/$entity", StringUtils.EMPTY). replace("/@Element", StringUtils.EMPTY); } else if (contextURLasString.endsWith("/$ref")) { contextUrl.suffix(Suffix.REFERENCE); contextURLasString = contextURLasString.replace("/$ref", StringUtils.EMPTY); } else if (contextURLasString.endsWith("/$delta")) { contextUrl.suffix(Suffix.DELTA); contextURLasString = contextURLasString.replace("/$delta", StringUtils.EMPTY); } else if (contextURLasString.endsWith("/$deletedEntity")) { contextUrl.suffix(Suffix.DELTA_DELETED_ENTITY); contextURLasString = contextURLasString.replace("/$deletedEntity", StringUtils.EMPTY); } else if (contextURLasString.endsWith("/$link")) { contextUrl.suffix(Suffix.DELTA_LINK); contextURLasString = contextURLasString.replace("/$link", StringUtils.EMPTY); } else if (contextURLasString.endsWith("/$deletedLink")) { contextUrl.suffix(Suffix.DELTA_DELETED_LINK); contextURLasString = contextURLasString.replace("/$deletedLink", StringUtils.EMPTY); } contextUrl.serviceRoot(URI.create(StringUtils.substringBefore(contextURLasString, Constants.METADATA))); final String rest = StringUtils.substringAfter(contextURLasString, Constants.METADATA + "#"); String firstToken; String entitySetOrSingletonOrType; if (rest.startsWith("Collection(")) { firstToken = rest.substring(0, rest.indexOf(')') + 1); entitySetOrSingletonOrType = firstToken; } else { final int openParIdx = rest.indexOf('('); if (openParIdx == -1) { firstToken = StringUtils.substringBeforeLast(rest, "/"); entitySetOrSingletonOrType = firstToken; } else { firstToken = isEntity ? rest : StringUtils.substringBeforeLast(rest, ")") + ")"; final List<String> parts = new ArrayList<>(); for (String split : firstToken.split("\\)/")) { parts.add(split.replaceAll("\\(.*", "")); } entitySetOrSingletonOrType = StringUtils.join(parts, '/'); final int commaIdx = firstToken.indexOf(','); if (commaIdx != -1) { contextUrl.selectList(firstToken.substring(openParIdx + 1, firstToken.length() - 1)); } } } contextUrl.entitySetOrSingletonOrType(entitySetOrSingletonOrType); final int slashIdx = entitySetOrSingletonOrType.lastIndexOf('/'); if (slashIdx != -1 && entitySetOrSingletonOrType.substring(slashIdx + 1).indexOf('.') != -1) { contextUrl.entitySetOrSingletonOrType(entitySetOrSingletonOrType.substring(0, slashIdx)); contextUrl.derivedEntity(entitySetOrSingletonOrType.substring(slashIdx + 1)); } if (!firstToken.equals(rest)) { final String[] pathElems = StringUtils.substringAfter(rest, "/").split("/"); if (pathElems.length > 0 && pathElems[0].length() > 0) { if (pathElems[0].indexOf('.') == -1) { contextUrl.navOrPropertyPath(pathElems[0]); } else { contextUrl.derivedEntity(pathElems[0]); } if (pathElems.length > 1) { contextUrl.navOrPropertyPath(pathElems[1]); } } } return contextUrl.build(); } }
ContextURLParser { public static ContextURL parse(final URI contextURL) { if (contextURL == null) { return null; } final ContextURL.Builder contextUrl = ContextURL.with(); String contextURLasString = contextURL.toASCIIString(); boolean isEntity = false; if (contextURLasString.endsWith("/$entity") || contextURLasString.endsWith("/@Element")) { isEntity = true; contextUrl.suffix(Suffix.ENTITY); contextURLasString = contextURLasString.replace("/$entity", StringUtils.EMPTY). replace("/@Element", StringUtils.EMPTY); } else if (contextURLasString.endsWith("/$ref")) { contextUrl.suffix(Suffix.REFERENCE); contextURLasString = contextURLasString.replace("/$ref", StringUtils.EMPTY); } else if (contextURLasString.endsWith("/$delta")) { contextUrl.suffix(Suffix.DELTA); contextURLasString = contextURLasString.replace("/$delta", StringUtils.EMPTY); } else if (contextURLasString.endsWith("/$deletedEntity")) { contextUrl.suffix(Suffix.DELTA_DELETED_ENTITY); contextURLasString = contextURLasString.replace("/$deletedEntity", StringUtils.EMPTY); } else if (contextURLasString.endsWith("/$link")) { contextUrl.suffix(Suffix.DELTA_LINK); contextURLasString = contextURLasString.replace("/$link", StringUtils.EMPTY); } else if (contextURLasString.endsWith("/$deletedLink")) { contextUrl.suffix(Suffix.DELTA_DELETED_LINK); contextURLasString = contextURLasString.replace("/$deletedLink", StringUtils.EMPTY); } contextUrl.serviceRoot(URI.create(StringUtils.substringBefore(contextURLasString, Constants.METADATA))); final String rest = StringUtils.substringAfter(contextURLasString, Constants.METADATA + "#"); String firstToken; String entitySetOrSingletonOrType; if (rest.startsWith("Collection(")) { firstToken = rest.substring(0, rest.indexOf(')') + 1); entitySetOrSingletonOrType = firstToken; } else { final int openParIdx = rest.indexOf('('); if (openParIdx == -1) { firstToken = StringUtils.substringBeforeLast(rest, "/"); entitySetOrSingletonOrType = firstToken; } else { firstToken = isEntity ? rest : StringUtils.substringBeforeLast(rest, ")") + ")"; final List<String> parts = new ArrayList<>(); for (String split : firstToken.split("\\)/")) { parts.add(split.replaceAll("\\(.*", "")); } entitySetOrSingletonOrType = StringUtils.join(parts, '/'); final int commaIdx = firstToken.indexOf(','); if (commaIdx != -1) { contextUrl.selectList(firstToken.substring(openParIdx + 1, firstToken.length() - 1)); } } } contextUrl.entitySetOrSingletonOrType(entitySetOrSingletonOrType); final int slashIdx = entitySetOrSingletonOrType.lastIndexOf('/'); if (slashIdx != -1 && entitySetOrSingletonOrType.substring(slashIdx + 1).indexOf('.') != -1) { contextUrl.entitySetOrSingletonOrType(entitySetOrSingletonOrType.substring(0, slashIdx)); contextUrl.derivedEntity(entitySetOrSingletonOrType.substring(slashIdx + 1)); } if (!firstToken.equals(rest)) { final String[] pathElems = StringUtils.substringAfter(rest, "/").split("/"); if (pathElems.length > 0 && pathElems[0].length() > 0) { if (pathElems[0].indexOf('.') == -1) { contextUrl.navOrPropertyPath(pathElems[0]); } else { contextUrl.derivedEntity(pathElems[0]); } if (pathElems.length > 1) { contextUrl.navOrPropertyPath(pathElems[1]); } } } return contextUrl.build(); }  }
ContextURLParser { public static ContextURL parse(final URI contextURL) { if (contextURL == null) { return null; } final ContextURL.Builder contextUrl = ContextURL.with(); String contextURLasString = contextURL.toASCIIString(); boolean isEntity = false; if (contextURLasString.endsWith("/$entity") || contextURLasString.endsWith("/@Element")) { isEntity = true; contextUrl.suffix(Suffix.ENTITY); contextURLasString = contextURLasString.replace("/$entity", StringUtils.EMPTY). replace("/@Element", StringUtils.EMPTY); } else if (contextURLasString.endsWith("/$ref")) { contextUrl.suffix(Suffix.REFERENCE); contextURLasString = contextURLasString.replace("/$ref", StringUtils.EMPTY); } else if (contextURLasString.endsWith("/$delta")) { contextUrl.suffix(Suffix.DELTA); contextURLasString = contextURLasString.replace("/$delta", StringUtils.EMPTY); } else if (contextURLasString.endsWith("/$deletedEntity")) { contextUrl.suffix(Suffix.DELTA_DELETED_ENTITY); contextURLasString = contextURLasString.replace("/$deletedEntity", StringUtils.EMPTY); } else if (contextURLasString.endsWith("/$link")) { contextUrl.suffix(Suffix.DELTA_LINK); contextURLasString = contextURLasString.replace("/$link", StringUtils.EMPTY); } else if (contextURLasString.endsWith("/$deletedLink")) { contextUrl.suffix(Suffix.DELTA_DELETED_LINK); contextURLasString = contextURLasString.replace("/$deletedLink", StringUtils.EMPTY); } contextUrl.serviceRoot(URI.create(StringUtils.substringBefore(contextURLasString, Constants.METADATA))); final String rest = StringUtils.substringAfter(contextURLasString, Constants.METADATA + "#"); String firstToken; String entitySetOrSingletonOrType; if (rest.startsWith("Collection(")) { firstToken = rest.substring(0, rest.indexOf(')') + 1); entitySetOrSingletonOrType = firstToken; } else { final int openParIdx = rest.indexOf('('); if (openParIdx == -1) { firstToken = StringUtils.substringBeforeLast(rest, "/"); entitySetOrSingletonOrType = firstToken; } else { firstToken = isEntity ? rest : StringUtils.substringBeforeLast(rest, ")") + ")"; final List<String> parts = new ArrayList<>(); for (String split : firstToken.split("\\)/")) { parts.add(split.replaceAll("\\(.*", "")); } entitySetOrSingletonOrType = StringUtils.join(parts, '/'); final int commaIdx = firstToken.indexOf(','); if (commaIdx != -1) { contextUrl.selectList(firstToken.substring(openParIdx + 1, firstToken.length() - 1)); } } } contextUrl.entitySetOrSingletonOrType(entitySetOrSingletonOrType); final int slashIdx = entitySetOrSingletonOrType.lastIndexOf('/'); if (slashIdx != -1 && entitySetOrSingletonOrType.substring(slashIdx + 1).indexOf('.') != -1) { contextUrl.entitySetOrSingletonOrType(entitySetOrSingletonOrType.substring(0, slashIdx)); contextUrl.derivedEntity(entitySetOrSingletonOrType.substring(slashIdx + 1)); } if (!firstToken.equals(rest)) { final String[] pathElems = StringUtils.substringAfter(rest, "/").split("/"); if (pathElems.length > 0 && pathElems[0].length() > 0) { if (pathElems[0].indexOf('.') == -1) { contextUrl.navOrPropertyPath(pathElems[0]); } else { contextUrl.derivedEntity(pathElems[0]); } if (pathElems.length > 1) { contextUrl.navOrPropertyPath(pathElems[1]); } } } return contextUrl.build(); }  static ContextURL parse(final URI contextURL); }
ContextURLParser { public static ContextURL parse(final URI contextURL) { if (contextURL == null) { return null; } final ContextURL.Builder contextUrl = ContextURL.with(); String contextURLasString = contextURL.toASCIIString(); boolean isEntity = false; if (contextURLasString.endsWith("/$entity") || contextURLasString.endsWith("/@Element")) { isEntity = true; contextUrl.suffix(Suffix.ENTITY); contextURLasString = contextURLasString.replace("/$entity", StringUtils.EMPTY). replace("/@Element", StringUtils.EMPTY); } else if (contextURLasString.endsWith("/$ref")) { contextUrl.suffix(Suffix.REFERENCE); contextURLasString = contextURLasString.replace("/$ref", StringUtils.EMPTY); } else if (contextURLasString.endsWith("/$delta")) { contextUrl.suffix(Suffix.DELTA); contextURLasString = contextURLasString.replace("/$delta", StringUtils.EMPTY); } else if (contextURLasString.endsWith("/$deletedEntity")) { contextUrl.suffix(Suffix.DELTA_DELETED_ENTITY); contextURLasString = contextURLasString.replace("/$deletedEntity", StringUtils.EMPTY); } else if (contextURLasString.endsWith("/$link")) { contextUrl.suffix(Suffix.DELTA_LINK); contextURLasString = contextURLasString.replace("/$link", StringUtils.EMPTY); } else if (contextURLasString.endsWith("/$deletedLink")) { contextUrl.suffix(Suffix.DELTA_DELETED_LINK); contextURLasString = contextURLasString.replace("/$deletedLink", StringUtils.EMPTY); } contextUrl.serviceRoot(URI.create(StringUtils.substringBefore(contextURLasString, Constants.METADATA))); final String rest = StringUtils.substringAfter(contextURLasString, Constants.METADATA + "#"); String firstToken; String entitySetOrSingletonOrType; if (rest.startsWith("Collection(")) { firstToken = rest.substring(0, rest.indexOf(')') + 1); entitySetOrSingletonOrType = firstToken; } else { final int openParIdx = rest.indexOf('('); if (openParIdx == -1) { firstToken = StringUtils.substringBeforeLast(rest, "/"); entitySetOrSingletonOrType = firstToken; } else { firstToken = isEntity ? rest : StringUtils.substringBeforeLast(rest, ")") + ")"; final List<String> parts = new ArrayList<>(); for (String split : firstToken.split("\\)/")) { parts.add(split.replaceAll("\\(.*", "")); } entitySetOrSingletonOrType = StringUtils.join(parts, '/'); final int commaIdx = firstToken.indexOf(','); if (commaIdx != -1) { contextUrl.selectList(firstToken.substring(openParIdx + 1, firstToken.length() - 1)); } } } contextUrl.entitySetOrSingletonOrType(entitySetOrSingletonOrType); final int slashIdx = entitySetOrSingletonOrType.lastIndexOf('/'); if (slashIdx != -1 && entitySetOrSingletonOrType.substring(slashIdx + 1).indexOf('.') != -1) { contextUrl.entitySetOrSingletonOrType(entitySetOrSingletonOrType.substring(0, slashIdx)); contextUrl.derivedEntity(entitySetOrSingletonOrType.substring(slashIdx + 1)); } if (!firstToken.equals(rest)) { final String[] pathElems = StringUtils.substringAfter(rest, "/").split("/"); if (pathElems.length > 0 && pathElems[0].length() > 0) { if (pathElems[0].indexOf('.') == -1) { contextUrl.navOrPropertyPath(pathElems[0]); } else { contextUrl.derivedEntity(pathElems[0]); } if (pathElems.length > 1) { contextUrl.navOrPropertyPath(pathElems[1]); } } } return contextUrl.build(); }  static ContextURL parse(final URI contextURL);  }