本文整理汇总了Java中org.sakaiproject.entitybroker.entityprovider.extension.Formats类的典型用法代码示例。如果您正苦于以下问题:Java Formats类的具体用法?Java Formats怎么用?Java Formats使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Formats类属于org.sakaiproject.entitybroker.entityprovider.extension包,在下文中一共展示了Formats类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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"));
}
示例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());
}
示例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;
}
示例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());
}
}
示例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"));
}
示例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"));
}
示例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;
}
示例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));
}
示例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());
}
}
示例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());
}
}
示例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;
}
示例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"));
}
示例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;
}
示例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);
}
}