Java Code Examples for org.apache.olingo.commons.api.data.ContextURL#getServiceRoot()

The following examples show how to use org.apache.olingo.commons.api.data.ContextURL#getServiceRoot() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PropertyResponse.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private String buildOperationTarget(ContextURL contextURL) {
  StringBuilder result = new StringBuilder();
  if (contextURL.getServiceRoot() != null) {
    result.append(contextURL.getServiceRoot());
  }
  if (contextURL.getEntitySetOrSingletonOrType() != null) {
    if (result.length() != 0) {
      result.append("/");
    }
    result.append(Encoder.encode(contextURL.getEntitySetOrSingletonOrType()));
  }
  if (contextURL.getKeyPath() != null) {
    result.append('(').append(contextURL.getKeyPath()).append(')');
  }    
  if (contextURL.getNavOrPropertyPath() != null) {
    result.append('/').append(contextURL.getNavOrPropertyPath());
  }
  return result.toString();
}
 
Example 2
Source File: EntitySetResponse.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private String buildOperationTarget(ContextURL contextURL) {
  StringBuilder result = new StringBuilder();
  if (contextURL.getServiceRoot() != null) {
    result.append(contextURL.getServiceRoot());
  }
  if (contextURL.getEntitySetOrSingletonOrType() != null) {
    if (result.length() != 0) {
      result.append("/");
    }
    result.append(Encoder.encode(contextURL.getEntitySetOrSingletonOrType()));
  }
  if (contextURL.getKeyPath() != null) {
    result.append('(').append(contextURL.getKeyPath()).append(')');
  }    
  if (contextURL.getNavOrPropertyPath() != null) {
    result.append('/').append(contextURL.getNavOrPropertyPath());
  }
  return result.toString();
}
 
Example 3
Source File: AtomSerializer.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private <T> void addContextInfo(
    final XMLStreamWriter writer, final ResWrap<T> container) throws XMLStreamException {

  if (container.getContextURL() != null) {
    final ContextURL contextURL = ContextURLParser.parse(container.getContextURL());
    final URI base = contextURL.getServiceRoot();
    if (container.getPayload() instanceof EntityCollection) {
      ((EntityCollection) container.getPayload()).setBaseURI(base);
    }
    if (container.getPayload() instanceof Entity) {
      ((Entity) container.getPayload()).setBaseURI(base);
    }

    writer.writeAttribute(Constants.NS_METADATA, Constants.CONTEXT,
        container.getContextURL().toASCIIString());
  }

  if (container.getMetadataETag() != null) {
    writer.writeAttribute(Constants.NS_METADATA, Constants.ATOM_ATTR_METADATAETAG,
        container.getMetadataETag());
  }
}
 
Example 4
Source File: ContextURLBuilder.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
public static URI create(final ContextURL contextURL) {
  StringBuilder result = new StringBuilder();
  if (contextURL.getServiceRoot() != null) {
    result.append(contextURL.getServiceRoot());
  } else if (contextURL.getODataPath() != null) {
    String oDataPath = contextURL.getODataPath();
    char[] chars = oDataPath.toCharArray();
    for (int i = 1; i < chars.length - 1; i++) {
      if (chars[i] == '/' && chars[i - 1] != '/') {
        result.append("../");
      }
    }
  }

  result.append(Constants.METADATA);
  if (contextURL.getEntitySetOrSingletonOrType() != null) {
    result.append('#');
    if (contextURL.isCollection()) {
      result.append("Collection(")
          .append(Encoder.encode(contextURL.getEntitySetOrSingletonOrType()))
          .append(")");
    } else {
      result.append(Encoder.encode(contextURL.getEntitySetOrSingletonOrType()));
    }
  }
  if (contextURL.getDerivedEntity() != null) {
    if (contextURL.getEntitySetOrSingletonOrType() == null) {
      throw new IllegalArgumentException("ContextURL: Derived Type without anything to derive from!");
    }
    result.append('/').append(Encoder.encode(contextURL.getDerivedEntity()));
  }
  if (contextURL.getKeyPath() != null) {
    result.append('(').append(contextURL.getKeyPath()).append(')');
  }
  if (contextURL.getNavOrPropertyPath() != null) {
    if (contextURL.getServiceRoot() == null || 
        !contextURL.getServiceRoot().isAbsolute()) {
      String[] paths = contextURL.getNavOrPropertyPath().split("/");
      for (String path : paths) {
        result.insert(0, "../");
      }
    }
    result.append('/').append(contextURL.getNavOrPropertyPath());
  }
  if (contextURL.getSelectList() != null) {
    result.append('(').append(contextURL.getSelectList()).append(')');
  }
  if (contextURL.isReference()) {
    if (contextURL.getServiceRoot() == null ||
        !contextURL.getServiceRoot().isAbsolute()) {
      result.insert(0, "../");
    }
    if (contextURL.getEntitySetOrSingletonOrType() != null) {
      throw new IllegalArgumentException("ContextURL: $ref with Entity Set");
    }
    if (contextURL.isCollection()) {
      result.append('#')
          .append("Collection(")
          .append(ContextURL.Suffix.REFERENCE.getRepresentation())
          .append(")");
    } else {
      result.append('#').append(ContextURL.Suffix.REFERENCE.getRepresentation());
    }
  } else if (contextURL.getSuffix() != null) {
    if (contextURL.getEntitySetOrSingletonOrType() == null) {
      throw new IllegalArgumentException("ContextURL: Suffix without preceding Entity Set!");
    }
    result.append('/').append(contextURL.getSuffix().getRepresentation());
  }
  return URI.create(result.toString());
}