/** * Reads a type definition from a JSON stream. * * The stream must be UTF-8 encoded. */ @SuppressWarnings("unchecked") public static TypeDefinition readFromJSON(InputStream stream) throws IOException, JSONParseException { if (stream == null) { throw new IllegalArgumentException("Input stream must be set!"); } JSONParser parser = new JSONParser(); Object json = parser.parse(new InputStreamReader(stream, IOUtils.UTF8)); if (!(json instanceof Map)) { throw new CmisRuntimeException("Invalid stream! Not a type definition!"); } return JSONConverter.convertTypeDefinition((Map<String, Object>) json); }
/** * Converts a type definition list. */ @SuppressWarnings({ "unchecked" }) public static List<TypeDefinitionContainer> convertTypeDescendants(final List<Object> json) { if (json == null) { return null; } if (json.isEmpty()) { return Collections.emptyList(); } List<TypeDefinitionContainer> result = new ArrayList<TypeDefinitionContainer>(); for (Object obj : json) { if (obj instanceof Map) { Map<String, Object> jsonContainer = (Map<String, Object>) obj; TypeDefinitionContainerImpl container = new TypeDefinitionContainerImpl(); container.setTypeDefinition(convertTypeDefinition(getMap(jsonContainer.get(JSON_TYPESCONTAINER_TYPE)))); Object children = jsonContainer.get(JSON_TYPESCONTAINER_CHILDREN); if (children instanceof List) { container.setChildren(convertTypeDescendants((List<Object>) children)); } else { container.setChildren(Collections.<TypeDefinitionContainer> emptyList()); } convertExtension(jsonContainer, container, TYPESCONTAINER_KEYS); result.add(container); } } return result; }
/** * Converts a type definition list. */ @SuppressWarnings({ "unchecked" }) public static List<TypeDefinitionContainer> convertTypeDescendants(final List<Object> json) { if (json == null) { return null; } if (json.isEmpty()) { return Collections.emptyList(); } List<TypeDefinitionContainer> result = new ArrayList<TypeDefinitionContainer>(); for (Object obj : json) { if (obj instanceof Map) { Map<String, Object> jsonContainer = (Map<String, Object>) obj; TypeDefinitionContainerImpl container = new TypeDefinitionContainerImpl(); container.setTypeDefinition(convertTypeDefinition(getMap(jsonContainer.get(JSON_TYPESCONTAINER_TYPE)))); Object children = jsonContainer.get(JSON_TYPESCONTAINER_CHILDREN); if (children instanceof List) { container.setChildren(convertTypeDescendants((List<Object>) children)); } else { container.setChildren(Collections.<TypeDefinitionContainer> emptyList()); } convertExtension(jsonContainer, container, TYPESCONTAINER_KEYS); result.add(container); } } return result; }
/** * Converts a type definition list. */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static TypeDefinitionList convertTypeChildren(final Map<String, Object> json) { if (json == null) { return null; } TypeDefinitionListImpl result = new TypeDefinitionListImpl(); Object typesList = json.get(JSON_TYPESLIST_TYPES); List<TypeDefinition> types = new ArrayList<TypeDefinition>(); if (typesList instanceof List) { for (Object type : (List) typesList) { if (type instanceof Map) { types.add(convertTypeDefinition((Map<String, Object>) type)); } } } result.setList(types); result.setHasMoreItems(getBoolean(json, JSON_TYPESLIST_HAS_MORE_ITEMS)); result.setNumItems(getInteger(json, JSON_TYPESLIST_NUM_ITEMS)); convertExtension(json, result, TYPESLIST_KEYS); return result; }
/** * Converts a type definition list. */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static TypeDefinitionList convertTypeChildren(final Map<String, Object> json) { if (json == null) { return null; } TypeDefinitionListImpl result = new TypeDefinitionListImpl(); Object typesList = json.get(JSON_TYPESLIST_TYPES); List<TypeDefinition> types = new ArrayList<TypeDefinition>(); if (typesList instanceof List) { for (Object type : (List) typesList) { if (type instanceof Map) { types.add(convertTypeDefinition((Map<String, Object>) type)); } } } result.setList(types); result.setHasMoreItems(getBoolean(json, JSON_TYPESLIST_HAS_MORE_ITEMS)); result.setNumItems(getInteger(json, JSON_TYPESLIST_NUM_ITEMS)); convertExtension(json, result, TYPESLIST_KEYS); return result; }
/** * Retrieves a type definition. */ protected TypeDefinition getTypeDefinitionInternal(String repositoryId, String typeId) { // build URL UrlBuilder url = getRepositoryUrl(repositoryId, Constants.SELECTOR_TYPE_DEFINITION); url.addParameter(Constants.PARAM_TYPE_ID, typeId); // read and parse Response resp = read(url); Map<String, Object> json = parseObject(resp.getStream(), resp.getCharset()); return JSONConverter.convertTypeDefinition(json); }
/** * Retrieves a type definition. */ protected TypeDefinition getTypeDefinitionInternal(String repositoryId, String typeId) { // build URL UrlBuilder url = getRepositoryUrl(repositoryId, Constants.SELECTOR_TYPE_DEFINITION); url.addParameter(Constants.PARAM_TYPE_ID, typeId); // read and parse Response resp = read(url); Map<String, Object> json = parseObject(resp.getStream(), resp.getCharset()); return JSONConverter.convertTypeDefinition(json); }
TypeDefinition typeIn = JSONConverter.convertTypeDefinition((Map<String, Object>) typeJson);
TypeDefinition typeIn = JSONConverter.convertTypeDefinition((Map<String, Object>) typeJson);
@Override public TypeDefinition updateType(String repositoryId, TypeDefinition type, ExtensionsData extension) { // build URL UrlBuilder url = getRepositoryUrl(repositoryId); // prepare form data final FormDataWriter formData = new FormDataWriter(Constants.CMISACTION_UPDATE_TYPE); if (type != null) { formData.addParameter(Constants.CONTROL_TYPE, JSONConverter.convert(type, getDateTimeFormat()) .toJSONString()); } // send Response resp = post(url, formData.getContentType(), new Output() { @Override public void write(OutputStream out) throws IOException { formData.write(out); } }); Map<String, Object> json = parseObject(resp.getStream(), resp.getCharset()); return JSONConverter.convertTypeDefinition(json); }
@Override public TypeDefinition createType(String repositoryId, TypeDefinition type, ExtensionsData extension) { // build URL UrlBuilder url = getRepositoryUrl(repositoryId); // prepare form data final FormDataWriter formData = new FormDataWriter(Constants.CMISACTION_CREATE_TYPE); if (type != null) { formData.addParameter(Constants.CONTROL_TYPE, JSONConverter.convert(type, getDateTimeFormat()) .toJSONString()); } // send Response resp = post(url, formData.getContentType(), new Output() { @Override public void write(OutputStream out) throws IOException { formData.write(out); } }); Map<String, Object> json = parseObject(resp.getStream(), resp.getCharset()); return JSONConverter.convertTypeDefinition(json); }
@Override public TypeDefinition createType(String repositoryId, TypeDefinition type, ExtensionsData extension) { // build URL UrlBuilder url = getRepositoryUrl(repositoryId); // prepare form data final FormDataWriter formData = new FormDataWriter(Constants.CMISACTION_CREATE_TYPE); if (type != null) { formData.addParameter(Constants.CONTROL_TYPE, JSONConverter.convert(type, getDateTimeFormat()) .toJSONString()); } // send Response resp = post(url, formData.getContentType(), new Output() { @Override public void write(OutputStream out) throws IOException { formData.write(out); } }); Map<String, Object> json = parseObject(resp.getStream(), resp.getCharset()); return JSONConverter.convertTypeDefinition(json); }
@Override public TypeDefinition updateType(String repositoryId, TypeDefinition type, ExtensionsData extension) { // build URL UrlBuilder url = getRepositoryUrl(repositoryId); // prepare form data final FormDataWriter formData = new FormDataWriter(Constants.CMISACTION_UPDATE_TYPE); if (type != null) { formData.addParameter(Constants.CONTROL_TYPE, JSONConverter.convert(type, getDateTimeFormat()) .toJSONString()); } // send Response resp = post(url, formData.getContentType(), new Output() { @Override public void write(OutputStream out) throws IOException { formData.write(out); } }); Map<String, Object> json = parseObject(resp.getStream(), resp.getCharset()); return JSONConverter.convertTypeDefinition(json); }