Search in sources :

Example 1 with Style

use of com.aliyun.oss.model.Style in project aliyun-oss-java-sdk by aliyun.

the class TestForImg method testListImageStyle.

public void testListImageStyle() {
    // Clear all image style
    clientImg.deleteBucketImage(bucketName);
    sleepSecond(10);
    PutBucketImageRequest request = new PutBucketImageRequest(bucketName);
    clientImg.putBucketImage(request);
    sleepSecond(10);
    PutImageStyleRequest requestStyle = new PutImageStyleRequest();
    requestStyle.SetBucketName(bucketName);
    // Same length with style
    String[] styleName = { "myStyle", "myStyle1", "myStyle2", "myStyle3", "myStyle4" };
    String[] style = { "200w", "300w", "400w", "500w", "600w" };
    for (int i = 0; i < styleName.length; ++i) {
        requestStyle.SetStyle(style[i]);
        requestStyle.SetStyleName(styleName[i]);
        clientImg.putImageStyle(requestStyle);
    }
    sleepSecond(10);
    List<Style> styleList = clientImg.listImageStyle(bucketName);
    Assert.assertEquals(styleList.size(), styleName.length);
    int i;
    for (Style s : styleList) {
        for (i = 0; i < style.length; i++) {
            if (s.GetStyle().equals(style[i]))
                break;
        }
        Assert.assertTrue(i != style.length);
        for (i = 0; i < styleName.length; i++) {
            if (s.GetStyleName().equals(styleName[i]))
                break;
        }
        Assert.assertTrue(i != styleName.length);
    }
}
Also used : Style(com.aliyun.oss.model.Style) PutBucketImageRequest(com.aliyun.oss.model.PutBucketImageRequest) PutImageStyleRequest(com.aliyun.oss.model.PutImageStyleRequest)

Example 2 with Style

use of com.aliyun.oss.model.Style in project aliyun-oss-java-sdk by aliyun.

the class ResponseParsers method parseListImageStyle.

/**
 * Unmarshall list image style response body to style list.
 */
@SuppressWarnings("unchecked")
public static List<Style> parseListImageStyle(InputStream responseBody) throws ResponseParseException {
    try {
        Element root = getXmlRootElement(responseBody);
        List<Style> styleList = new ArrayList<Style>();
        List<Element> styleElems = root.getChildren("Style");
        for (Element e : styleElems) {
            Style style = new Style();
            style.SetStyleName(e.getChildText("Name"));
            style.SetStyle(e.getChildText("Content"));
            style.SetLastModifyTime(DateUtil.parseRfc822Date(e.getChildText("LastModifyTime")));
            style.SetCreationDate(DateUtil.parseRfc822Date(e.getChildText("CreateTime")));
            styleList.add(style);
        }
        return styleList;
    } catch (JDOMParseException e) {
        throw new ResponseParseException(e.getPartialDocument() + ": " + e.getMessage(), e);
    } catch (Exception e) {
        throw new ResponseParseException(e.getMessage(), e);
    }
}
Also used : JDOMParseException(org.jdom.input.JDOMParseException) Element(org.jdom.Element) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException) ArrayList(java.util.ArrayList) Style(com.aliyun.oss.model.Style) ParseException(java.text.ParseException) JDOMParseException(org.jdom.input.JDOMParseException) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException)

Aggregations

Style (com.aliyun.oss.model.Style)2 ResponseParseException (com.aliyun.oss.common.parser.ResponseParseException)1 PutBucketImageRequest (com.aliyun.oss.model.PutBucketImageRequest)1 PutImageStyleRequest (com.aliyun.oss.model.PutImageStyleRequest)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Element (org.jdom.Element)1 JDOMParseException (org.jdom.input.JDOMParseException)1