• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Formats类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.sakaiproject.entitybroker.entityprovider.extension.Formats的典型用法代码示例。如果您正苦于以下问题:Java Formats类的具体用法?Java Formats怎么用?Java Formats使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Formats类属于org.sakaiproject.entitybroker.entityprovider.extension包,在下文中一共展示了Formats类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getTranscoder

import org.sakaiproject.entitybroker.entityprovider.extension.Formats; //导入依赖的package包/类
public Transcoder getTranscoder(String format) {
     if (transcoders == null) {
         transcoders = new HashMap<String, Transcoder>();
         JSONTranscoder jt = new JSONTranscoder(true, true, false);
jt.setMaxLevel(entityBrokerManager.getMaxJSONLevel());
         transcoders.put(jt.getHandledFormat(), jt);
         transcoders.put(Formats.JSONP, jt);
         XMLTranscoder xt = new XMLTranscoder(true, true, false, false);
         transcoders.put(xt.getHandledFormat(), xt);
         HTMLTranscoder ht = new HTMLTranscoder();
         transcoders.put(ht.getHandledFormat(), ht);
     }
     Transcoder transcoder = transcoders.get(format);
     if (transcoder == null) {
         throw new IllegalArgumentException("Failed to find a transcoder for format, none exists, cannot encode or decode data for format: " + format);
     }
     return transcoder;
 }
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:19,代码来源:EntityEncodingManager.java


示例2: testJSONDecode

import org.sakaiproject.entitybroker.entityprovider.extension.Formats; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void testJSONDecode() {
    Map<String, Object> decoded = null;

    String json = "{\"id\":123,\"thing\":\"AZ\"}";
    decoded = entityEncodingManager.decodeData(json, Formats.JSON);
    assertNotNull(decoded);
    assertEquals(123, decoded.get("id"));
    assertEquals("AZ", decoded.get("thing"));

    json = "{\"id\":123,\"thing\":\"AZ\",\"map\":{\"name\":\"aaron\",\"date\":1221493247004,\"num\":456,\"array\":[\"A\",\"B\",\"C\"]}}";
    decoded = entityEncodingManager.decodeData(json, Formats.JSON);
    assertNotNull(decoded);
    assertEquals(3, decoded.size());
    assertEquals(123, decoded.get("id"));
    assertEquals("AZ", decoded.get("thing"));
    Map<String, Object> m2d = (Map<String, Object>) decoded.get("map");
    assertEquals(4, m2d.size());
    assertEquals("aaron", m2d.get("name"));
    assertEquals(456, m2d.get("num"));

}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:23,代码来源:EntityEncodingManagerTest.java


示例3: testTranslateInputToEntity

import org.sakaiproject.entitybroker.entityprovider.extension.Formats; //导入依赖的package包/类
@Test
public void testTranslateInputToEntity() {
    InputStream input = null;
    MyEntity me = null;

    // test creating an entity
    String reference = TestData.SPACE6;
    String format = Formats.XML;
    input = new ByteArrayInputStream( makeUTF8Bytes("<"+TestData.PREFIX6+"><stuff>TEST</stuff><number>5</number></"+TestData.PREFIX6+">") );
    me = (MyEntity) entityBroker.translateInputToEntity(reference, format, input, null);
    assertNotNull(me);
    assertNull(me.getId());
    assertEquals("TEST", me.getStuff());
    assertEquals(5, me.getNumber());

    // test modifying an entity
    reference = TestData.REF6_2;
    input = new ByteArrayInputStream( makeUTF8Bytes("<"+TestData.PREFIX6+"><id>"+TestData.IDS6[1]+"</id><stuff>TEST-PUT</stuff><number>8</number></"+TestData.PREFIX6+">") );
    me = (MyEntity) entityBroker.translateInputToEntity(reference, format, input, null);
    assertNotNull(me);
    assertNotNull(me.getId());
    assertEquals(TestData.IDS6[1], me.getId());
    assertEquals("TEST-PUT", me.getStuff());
    assertEquals(8, me.getNumber());
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:26,代码来源:EntityBrokerImplTest.java


示例4: decodeData

import org.sakaiproject.entitybroker.entityprovider.extension.Formats; //导入依赖的package包/类
/**
 * Decode a string of a specified format into a java map <br/> 
 * Returned map can be fed into the {@link ReflectUtils#populate(Object, Map)} if you want to convert it
 * into a known object type <br/> 
 * Types are likely to require conversion as guesses are made about the right formats,
 * use of the {@link ReflectUtils#convert(Object, Class)} method is recommended
 * 
 * @param data encoded data
 * @param format the format of the encoded data (from {@link Formats})
 * @return a map containing all the data derived from the encoded data
 * @throws UnsupportedOperationException if the data cannot be decoded
 */
@SuppressWarnings("unchecked")
public Map<String, Object> decodeData(String data, String format) {
    if (format == null) {
        format = Formats.XML;
    }
    Map<String, Object> decoded = new ArrayOrderedMap<String, Object>();
    if (data != null && ! "".equals(data)) {
        Object decode = null;
        Transcoder transcoder = getTranscoder(format);
        try {
            decode = transcoder.decode(data);
            if (decode instanceof Map) {
                decoded = (Map<String, Object>) decode;
            } else {
                decoded.put(DATA_KEY, decode);
            }
        } catch (RuntimeException e) {
            // convert failure to UOE
            throw new UnsupportedOperationException("Failure decoding data ("+data+") for format ("+format+"): " + e.getMessage(), e);
        }
    }
    return decoded;
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:36,代码来源:EntityEncodingManager.java


示例5: testMakeEntityView

import org.sakaiproject.entitybroker.entityprovider.extension.Formats; //导入依赖的package包/类
/**
 * Test method for
 * {@link org.sakaiproject.entitybroker.impl.EntityBrokerManagerImpl#makeEntityView(org.sakaiproject.entitybroker.EntityReference, java.lang.String, java.lang.String)}.
 */
@Test
public void testMakeEntityView() {
   EntityView ev = entityBrokerManager.makeEntityView(new EntityReference("azprefix", "azid"), EntityView.VIEW_SHOW, Formats.XML);
   Assert.assertNotNull(ev);
   Assert.assertEquals("azprefix", ev.getEntityReference().getPrefix());
   Assert.assertEquals("azid", ev.getEntityReference().getId());
   Assert.assertEquals(EntityView.VIEW_SHOW, ev.getViewKey());
   Assert.assertEquals(Formats.XML, ev.getExtension());

   ev = entityBrokerManager.makeEntityView(new EntityReference("azprefix", "azid"), null, null);
   Assert.assertNotNull(ev);
   Assert.assertEquals("azprefix", ev.getEntityReference().getPrefix());
   Assert.assertEquals("azid", ev.getEntityReference().getId());
   Assert.assertEquals(EntityView.VIEW_SHOW, ev.getViewKey());
   Assert.assertEquals(null, ev.getExtension());

   try {
      ev = entityBrokerManager.makeEntityView(null, null, null);
      Assert.fail("Should have thrown exception");
   } catch (IllegalArgumentException e) {
      Assert.assertNotNull(e.getMessage());
   }
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:28,代码来源:EntityBrokerManagerTest.java


示例6: testSpaceEncoding

import org.sakaiproject.entitybroker.entityprovider.extension.Formats; //导入依赖的package包/类
/**
 * Testing for http://jira.sakaiproject.org/browse/SAK-19197 (xml encoding)
 * Items with spaces will not encode correctly and will cause an exception, they 
 * have to be fixed at the provider level
 */
public void testSpaceEncoding() {
    EntityData ed = null;

    // test encoding weird stuff
    Map<String, Object> map = new ArrayOrderedMap<String, Object>();
    map.put("A1", "aaron one");
    map.put("C&3", "minerva three");
    map.put("B 2", "becky two");
    ed = new EntityData(map);
    /* fixed in 0.9.15 reflectutils
    try {
        entityEncodingManager.encodeEntity(TestData.PREFIX4, Formats.XML, ed, null);
        fail("Could not encode spaces");
    } catch (UnsupportedOperationException e) {
        assertNotNull(e.getMessage());
    }*/
    String encoded = entityEncodingManager.encodeEntity(TestData.PREFIX4, Formats.XML, ed, null);
    assertNotNull(encoded);
    assertTrue(encoded.contains("aaron one"));
    assertTrue(encoded.contains("becky two"));
    assertTrue(encoded.contains("minerva three"));
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:28,代码来源:EntityEncodingManagerTest.java


示例7: testXMLDecode

import org.sakaiproject.entitybroker.entityprovider.extension.Formats; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void testXMLDecode() {
    Map<String, Object> decoded = null;

    String xml = "<data><id type='number'>123</id><thing>AZ</thing></data>";
    decoded = entityEncodingManager.decodeData(xml, Formats.XML);
    assertNotNull(decoded);
    assertEquals(123, decoded.get("id"));
    assertEquals("AZ", decoded.get("thing"));

    xml = "<data type='map' size='3' class='org.sakaiproject.genericdao.util.map.ArrayOrderedMap'><id type='number' class='java.lang.Integer'>123</id><thing>AZ</thing><map type='map' size='4' class='org.sakaiproject.genericdao.util.map.ArrayOrderedMap'><name>aaron</name><date type='date' date='2008-09-17T14:47:18+01:00'>1221659238015</date><num type='number' class='java.lang.Integer'>456</num><array type='array' length='3' component='java.lang.String'><string>A</string><string>B</string><string>C</string></array></map></data>";
    decoded = entityEncodingManager.decodeData(xml, Formats.XML);
    assertNotNull(decoded);
    assertEquals(3, decoded.size());
    assertEquals(123, decoded.get("id"));
    assertEquals("AZ", decoded.get("thing"));
    Map<String, Object> m2d = (Map<String, Object>) decoded.get("map");
    assertEquals(4, m2d.size());
    assertEquals("aaron", m2d.get("name"));
    assertEquals(456, m2d.get("num"));

}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:23,代码来源:EntityEncodingManagerTest.java


示例8: decodeData

import org.sakaiproject.entitybroker.entityprovider.extension.Formats; //导入依赖的package包/类
public Map<String, Object> decodeData(String data, String format) {
    if (format == null) {
        format = Formats.XML;
    }
    Map<String, Object> decoded = new HashMap<String, Object>(0);
    if (getEntityRESTProvider() == null) {
        log.warn("No entityRESTProvider available for decoding, using basic internal decoder");
        if (data != null) {
            Transcoder transcoder = getTranscoder(format);
            try {
                decoded = transcoder.decode(data);
            } catch (RuntimeException e) {
                // convert failure to UOE
                throw new UnsupportedOperationException("Failure encoding data ("+data+") of type ("+data.getClass()+"): " + e.getMessage(), e);
            }
        }
    } else {
        decoded = getEntityRESTProvider().decodeData(data, format);
    }
    return decoded;
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:22,代码来源:AbstractDeveloperHelperService.java


示例9: testFormatAndOutputEntity

import org.sakaiproject.entitybroker.entityprovider.extension.Formats; //导入依赖的package包/类
@Test
public void testFormatAndOutputEntity() {

    String fo = null;
    String reference = null;
    OutputStream output = null;
    String format = Formats.XML;

    // XML test valid resolveable entity
    reference = TestData.REF4;
    output = new ByteArrayOutputStream();
    entityBroker.formatAndOutputEntity(reference, format, null, output, null);
    fo = output.toString();
    assertNotNull(fo);
    assertTrue(fo.length() > 20);
    assertTrue(fo.contains(TestData.PREFIX4));
    assertTrue(fo.contains("<id>4-one</id>"));
    assertTrue(fo.contains(EntityEncodingManager.ENTITY_REFERENCE));

    // test list of entities
    ArrayList<EntityData> testEntities = new ArrayList<EntityData>();
    testEntities.add( new EntityData(TestData.REF4, null, TestData.entity4) );
    testEntities.add( new EntityData(TestData.REF4_two, null, TestData.entity4_two) );
    reference = TestData.SPACE4;
    output = new ByteArrayOutputStream();
    entityBroker.formatAndOutputEntity(reference, format, testEntities, output, null);
    fo = output.toString();
    assertNotNull(fo);
    assertTrue(fo.length() > 20);
    assertTrue(fo.contains(TestData.PREFIX4));
    assertTrue(fo.contains("<id>4-one</id>"));
    assertTrue(fo.contains("<id>4-two</id>"));
    assertFalse(fo.contains("<id>4-three</id>"));
    assertTrue(fo.contains(EntityEncodingManager.ENTITY_REFERENCE));

}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:37,代码来源:EntityBrokerImplTest.java


示例10: testTranslateInputToEntity

import org.sakaiproject.entitybroker.entityprovider.extension.Formats; //导入依赖的package包/类
@Test
public void testTranslateInputToEntity() {
    // test no provider
    String reference = TestData.SPACE6;
    String format = Formats.XML;
    InputStream input = new ByteArrayInputStream( makeUTF8Bytes("<"+TestData.PREFIX6+"><stuff>TEST</stuff><number>5</number></"+TestData.PREFIX6+">") );
    try {
        entityBroker.translateInputToEntity(reference, format, input, null);
        Assert.fail("Should have died");
    } catch (UnsupportedOperationException e) {
        Assert.assertNotNull(e.getMessage());
    }
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:14,代码来源:EntityBrokerTransactionalTest.java


示例11: testFormatAndOutputEntity

import org.sakaiproject.entitybroker.entityprovider.extension.Formats; //导入依赖的package包/类
@Test
public void testFormatAndOutputEntity() {
    // test no provider
    String reference = TestData.REF4;
    OutputStream output = new ByteArrayOutputStream();
    String format = Formats.XML;

    try {
        entityBroker.formatAndOutputEntity(reference, format, null, output, null);
        Assert.fail("Should have died");
    } catch (UnsupportedOperationException e) {
        Assert.assertNotNull(e.getMessage());
    }
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:15,代码来源:EntityBrokerTransactionalTest.java


示例12: makeUTF8Bytes

import org.sakaiproject.entitybroker.entityprovider.extension.Formats; //导入依赖的package包/类
/**
 * Convenience method for making byte content encoded into UTF-8
 */
private byte[] makeUTF8Bytes(String string) {
    byte[] bytes;
    try {
        bytes = string.getBytes(Formats.UTF_8);
    } catch (UnsupportedEncodingException e) {
        bytes = string.getBytes();
    }
    return bytes;
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:13,代码来源:EntityBrokerImplTest.java


示例13: testJSONEncode

import org.sakaiproject.entitybroker.entityprovider.extension.Formats; //导入依赖的package包/类
public void testJSONEncode() {
    String encoded = null;

    encoded = entityEncodingManager.encodeData(null, Formats.JSON, null, null);
    assertNotNull(encoded);
    assertEquals("", encoded);

    Map<String, Object> m = new ArrayOrderedMap<String, Object>();
    m.put("id", 123);
    m.put("thing", "AZ");
    encoded = entityEncodingManager.encodeData(m, Formats.JSON, null, null);
    assertNotNull(encoded);
    assertTrue(encoded.contains("123"));
    assertTrue(encoded.contains("AZ"));

    Map<String, Object> m2 = new ArrayOrderedMap<String, Object>();
    m2.put("name", "aaron");
    m2.put("date", new Date());
    m2.put("num", 456);
    m2.put("array", new String[] {"A","B","C"});
    m.put("map", m2);

    encoded = entityEncodingManager.encodeData(m, Formats.JSON, null, null);
    assertNotNull(encoded);
    assertTrue(encoded.contains("123"));
    assertTrue(encoded.contains("AZ"));
    assertTrue(encoded.contains("aaron"));
    assertTrue(encoded.contains("456"));

}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:31,代码来源:EntityEncodingManagerTest.java


示例14: makeFormUrlHtml

import org.sakaiproject.entitybroker.entityprovider.extension.Formats; //导入依赖的package包/类
protected String makeFormUrlHtml(String url, String[] formats) {
    String form = "";
    if (formats != null) {
        if (ArrayUtils.contains(formats, Formats.FORM)) {
            form = makeFormatUrlHtml(url, Formats.FORM);
        }
    }
    return form;
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:10,代码来源:EntityDescriptionManager.java


示例15: setTranscoder

import org.sakaiproject.entitybroker.entityprovider.extension.Formats; //导入依赖的package包/类
/**
 * Override the transcoder used for a specific format
 * @param transcoder a transcoder implementation
 */
public void setTranscoder(Transcoder transcoder) {
    if (transcoder == null) {
        throw new IllegalArgumentException("transcoder cannot be null");
    }
    if (transcoders == null) {
        getTranscoder(Formats.XML);
    }
    String format = transcoder.getHandledFormat();
    if (format != null && transcoder != null) {
        transcoders.put(format, transcoder);
    }
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:17,代码来源:EntityEncodingManager.java


示例16: handleRedirects

import org.sakaiproject.entitybroker.entityprovider.extension.Formats; //导入依赖的package包/类
public String handleRedirects(String matchedTemplate, String incomingURL,
      String[] incomingSegments, Map<String, String> values) {
   String redirectURL = null;
   if (matchedTemplate.equals(templates[0])) {
      redirectURL = values.get(EntityView.PREFIX) + EntityView.SEPARATOR 
         + "siteuser?site=" + values.get("siteId") + "&user=" + values.get("userId");
   } else if (matchedTemplate.equals(templates[1])) {
      redirectURL = "http://caret.cam.ac.uk/?prefix=" + values.get(EntityView.PREFIX) + "&thing=" + values.get("thing");
   } else if (matchedTemplate.equals(templates[2])) {
      redirectURL = values.get(EntityView.PREFIX) + EntityView.SEPARATOR 
         + values.get(EntityView.ID) + EntityView.PERIOD + Formats.XML;
   }
   return redirectURL;
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:15,代码来源:RedirectControllableEntityProviderMock.java


示例17: testXMLEncode

import org.sakaiproject.entitybroker.entityprovider.extension.Formats; //导入依赖的package包/类
public void testXMLEncode() {
    String encoded = null;

    encoded = entityEncodingManager.encodeData(null, Formats.XML, null, null);
    assertNotNull(encoded);
    assertEquals("", encoded);

    Map<String, Object> m = new ArrayOrderedMap<String, Object>();
    m.put("id", 123);
    m.put("thing", "AZ");
    encoded = entityEncodingManager.encodeData(m, Formats.XML, null, null);
    assertNotNull(encoded);
    assertTrue(encoded.contains("123"));
    assertTrue(encoded.contains("AZ"));

    Map<String, Object> m2 = new ArrayOrderedMap<String, Object>();
    m2.put("name", "aaron");
    m2.put("date", new Date());
    m2.put("num", 456);
    m2.put("array", new String[] {"A","B","C"});
    m.put("map", m2);

    encoded = entityEncodingManager.encodeData(m, Formats.XML, null, null);
    assertNotNull(encoded);
    assertTrue(encoded.contains("123"));
    assertTrue(encoded.contains("AZ"));
    assertTrue(encoded.contains("aaron"));
    assertTrue(encoded.contains("456"));

}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:31,代码来源:EntityEncodingManagerTest.java


示例18: getFormat

import org.sakaiproject.entitybroker.entityprovider.extension.Formats; //导入依赖的package包/类
/**
 * @return the format (from {@link Formats}) that is being used for this view,
 * will return {@link Formats#HTML} if none set
 */
public String getFormat() {
    String format = extension;
    if (format == null) {
        format = Formats.HTML;
    }
    return format;
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:12,代码来源:EntityView.java


示例19: setResponseEncoding

import org.sakaiproject.entitybroker.entityprovider.extension.Formats; //导入依赖的package包/类
/**
 * This will set the response mime type correctly based on the format constant,
 * also sets the response encoding to UTF_8
 * @param format the format constant, example {@link Formats#XML}
 * @param res the current outgoing response
 */
public static void setResponseEncoding(String format, HttpServletResponse res) {
    String encoding = Formats.TXT_MIME_TYPE;
    if (format != null) {
        String mimeType = formatToMimeType.get(format);
        if (mimeType != null) {
            encoding = mimeType;
        }
    }
    res.setContentType(encoding);
    res.setCharacterEncoding(Formats.UTF_8);
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:18,代码来源:RequestUtils.java


示例20: reintegrateDataContent

import org.sakaiproject.entitybroker.entityprovider.extension.Formats; //导入依赖的package包/类
/**
 * Takes the overall data and reintegrates any content data that is waiting to be merged,
 * this may do nothing if there is no content to merge
 * @return the integrated data content
 */
private String reintegrateDataContent(String format, HashMap<String, String> dataMap,
        String overallData) {
    StringBuilder sb = new StringBuilder();
    int curLoc = 0;
    for (Entry<String, String> entry : dataMap.entrySet()) {
        // looping order is critical here, it must be in the same order it was added
        if (entry.getKey() != null && ! "".equals(entry.getKey())) {
            String key = entry.getKey();
            String value = entry.getValue();
            if (Formats.XML.equals(format)) {
                value = "\n" + value; // add in a break
            } else if (Formats.JSON.equals(format)) {
                key = '"' + key + '"'; // have to also replace the quotes
            }
            int keyLoc = overallData.indexOf(key);
            if (keyLoc > -1) {
                sb.append( overallData.subSequence(curLoc, keyLoc) );
                sb.append( value );
                curLoc = keyLoc + key.length();
            }
            //overallData = overallData.replace(key, value);
        }
    }
    // add in the remainder of the overall data string
    sb.append( overallData.subSequence(curLoc, overallData.length()) );
    return sb.toString();
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:33,代码来源:EntityBatchHandler.java



注:本文中的org.sakaiproject.entitybroker.entityprovider.extension.Formats类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DateTimeField类代码示例发布时间:2022-05-22
下一篇:
Java TestEvent类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap