当前位置: 首页>>代码示例>>Java>>正文


Java XMLTranscoder类代码示例

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


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

示例1: testXMLEncodeSpecial

import org.azeckoski.reflectutils.transcoders.XMLTranscoder; //导入依赖的package包/类
public void testXMLEncodeSpecial() {
    Transcoder transcoder = new XMLTranscoder(false, true, false);
    String encoded = null;

    // test maps
    Map<String, Object> m = new ArrayOrderedMap<String, Object>();
    m.put("A_1", 111);
    m.put("B 2", 222);
    m.put("C&3", 333);
    m.put("D\"4", 444);
    m.put("E'5", 555);
    m.put("F<6", 666);
    m.put("G>7", 777);
    m.put("H=8", 888);
    encoded = transcoder.encode(m, null, null);
    assertNotNull(encoded);
    assertTrue(encoded.contains("111"));
    assertTrue(encoded.contains("222"));
    assertTrue(encoded.contains("333"));
    assertTrue(encoded.contains("444"));
    assertTrue(encoded.contains("555"));
    assertTrue(encoded.contains("666"));
    assertTrue(encoded.contains("777"));
    assertTrue(encoded.contains("888"));
}
 
开发者ID:azeckoski,项目名称:reflectutils,代码行数:26,代码来源:TranscodersTest.java

示例2: getTranscoder

import org.azeckoski.reflectutils.transcoders.XMLTranscoder; //导入依赖的package包/类
private Transcoder getTranscoder(String format) {
    if (transcoders == null) {
        transcoders = new HashMap<String, Transcoder>();
        JSONTranscoder jt = new JSONTranscoder(true, true, false);
        transcoders.put(jt.getHandledFormat(), 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,代码行数:17,代码来源:AbstractDeveloperHelperService.java

示例3: getTranscoder

import org.azeckoski.reflectutils.transcoders.XMLTranscoder; //导入依赖的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

示例4: callTurnitinReturnMap

import org.azeckoski.reflectutils.transcoders.XMLTranscoder; //导入依赖的package包/类
public static Map callTurnitinReturnMap(String apiURL, Map<String,Object> parameters, 
		String secretKey, int timeout, Proxy proxy) throws TransientSubmissionException, SubmissionException 
{
	InputStream inputStream = callTurnitinReturnInputStream(apiURL, parameters, secretKey, timeout, proxy, false);
	XMLTranscoder xmlt = new XMLTranscoder();

	try {
		Map togo = xmlt.decode(StreamCopyUtil.streamToString(inputStream));
		apiTraceLog.debug("Turnitin Result Payload: " + togo);
		return togo;
	} catch (Exception t) {
		// Could be 'java.lang.IllegalArgumentException: xml cannot be null or empty' from IO errors
		throw new TransientSubmissionException ("Cannot parse Turnitin response. Assuming call was unsuccessful", t);
	}
}
 
开发者ID:sakaicontrib,项目名称:turnitin,代码行数:16,代码来源:TurnitinAPIUtil.java

示例5: testLoopStoppingXML

import org.azeckoski.reflectutils.transcoders.XMLTranscoder; //导入依赖的package包/类
public void testLoopStoppingXML() {
    Transcoder transcoder = new XMLTranscoder(true, true, false);
    String encoded = null;

    TestBaseOne tbo = new TestBaseOne();
    encoded = transcoder.encode(tbo, null, null);
    int size = encoded.length();
    assertNotNull(encoded);
    assertTrue(size > 1000);
    assertTrue(size < 200000);
    
}
 
开发者ID:azeckoski,项目名称:reflectutils,代码行数:13,代码来源:TranscodersTest.java

示例6: testCrazyClassesXML

import org.azeckoski.reflectutils.transcoders.XMLTranscoder; //导入依赖的package包/类
public void testCrazyClassesXML() {
    TestHibernateLikeBean crazy = new TestHibernateLikeBean();

    Transcoder transcoder = new XMLTranscoder(true, true, false);
    String encoded = null;

    encoded = transcoder.encode(crazy, null, null);
    int size = encoded.length();
    assertNotNull(encoded);
    assertTrue(size > 100);
    assertTrue(size < 1000);
}
 
开发者ID:azeckoski,项目名称:reflectutils,代码行数:13,代码来源:TranscodersTest.java

示例7: callTurnitinReturnMap

import org.azeckoski.reflectutils.transcoders.XMLTranscoder; //导入依赖的package包/类
public static Map callTurnitinReturnMap(String apiURL, Map<String,Object> parameters, 
		String secretKey, int timeout, Proxy proxy) throws TransientSubmissionException, SubmissionException 
{
	XMLTranscoder xmlt = new XMLTranscoder();

	try (InputStream inputStream = callTurnitinReturnInputStream(apiURL, parameters, secretKey, timeout, proxy, false)) {
		Map togo = xmlt.decode(IOUtils.toString(inputStream));
		log.debug("Turnitin Result Payload: " + togo);
		return togo;
	} catch (Exception t) {
		// Could be 'java.lang.IllegalArgumentException: xml cannot be null or empty' from IO errors
		throw new TransientSubmissionException ("Cannot parse Turnitin response. Assuming call was unsuccessful", t);
	}
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:15,代码来源:TurnitinAPIUtil.java

示例8: testXMLDecodeWithoutTypes

import org.azeckoski.reflectutils.transcoders.XMLTranscoder; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void testXMLDecodeWithoutTypes() {
    Transcoder transcoder = new XMLTranscoder(true, true, false);
    Map<String, Object> decoded = null;

    // simple
    String xml = "<data><id>123</id><thing>AZ</thing></data>";
    decoded = transcoder.decode(xml);
    assertNotNull(decoded);
    assertEquals("123", decoded.get("id"));
    assertEquals("AZ", decoded.get("thing"));

    // nested
    xml = "<data><people><person><name>aaron</name><email>[email protected]</email></person><person><name>becky</name><email>[email protected]</email></person></people><country>USA</country></data>";
    decoded = transcoder.decode(xml);
    assertNotNull(decoded);
    assertEquals(2, decoded.size());
    assertEquals("USA", decoded.get("country"));
    List<Map<String,Object>> people = (List<Map<String, Object>>) decoded.get("people");
    assertEquals(2, people.size());
    assertEquals("aaron", people.get(0).get("name"));
    assertEquals("becky", people.get(1).get("name"));
    assertEquals("[email protected]", people.get(0).get("email"));
    assertEquals("[email protected]", people.get(1).get("email"));

    xml = "<data><people><person><name>aaron</name><emails><email>[email protected]</email><email>[email protected]</email><email>[email protected]</email></emails></person><person><name>becky</name><emails><email>[email protected]</email><email>[email protected]</email></emails></person></people><country>USA</country></data>";
    decoded = transcoder.decode(xml);
    assertNotNull(decoded);
    assertEquals(2, decoded.size());
    assertEquals("USA", decoded.get("country"));
    people = (List<Map<String, Object>>) decoded.get("people");
    assertEquals(2, people.size());
    assertEquals("aaron", people.get(0).get("name"));
    assertEquals("becky", people.get(1).get("name"));
    List<String> emails = (List<String>) people.get(0).get("emails");
    assertEquals(3, emails.size());
    assertEquals("[email protected]", emails.get(0));
    assertEquals("[email protected]", emails.get(1));
    assertEquals("[email protected]", emails.get(2));
    emails = (List<String>) people.get(1).get("emails");
    assertEquals("[email protected]", emails.get(0));
    assertEquals("[email protected]", emails.get(1));

    xml = "<data><people><person><name>aaron</name><emails><email>[email protected]</email><email>[email protected]</email></emails><pets><pet><name>minerva</name><type>cat</type></pet><pet><name>rocky</name><type>rock</type></pet><pet><name>puter</name><type>laptop</type></pet></pets></person><person><name>becky</name><emails><email>[email protected]</email><email>[email protected]</email></emails><pets/></person></people><country>USA</country></data>";
    decoded = transcoder.decode(xml);
    assertNotNull(decoded);
    assertEquals(2, decoded.size());
    assertEquals("USA", decoded.get("country"));
    people = (List<Map<String, Object>>) decoded.get("people");
    assertEquals(2, people.size());
    assertEquals("aaron", people.get(0).get("name"));
    assertEquals("becky", people.get(1).get("name"));
    emails = (List<String>) people.get(0).get("emails");
    assertEquals("[email protected]", emails.get(0));
    assertEquals("[email protected]", emails.get(1));
    emails = (List<String>) people.get(1).get("emails");
    assertEquals("[email protected]", emails.get(0));
    assertEquals("[email protected]", emails.get(1));
    List<Map<String,Object>> pets = (List<Map<String, Object>>) people.get(0).get("pets");
    assertNotNull(pets);
    assertEquals(3, pets.size());
    assertEquals("minerva", pets.get(0).get("name"));
    assertEquals("cat", pets.get(0).get("type"));
    assertEquals("rocky", pets.get(1).get("name"));
    assertEquals("rock", pets.get(1).get("type"));
    assertEquals("puter", pets.get(2).get("name"));
    assertEquals("laptop", pets.get(2).get("type"));
    assertNull( people.get(1).get("pets") );
}
 
开发者ID:azeckoski,项目名称:reflectutils,代码行数:70,代码来源:TranscodersTest.java

示例9: handleGradeItem

import org.azeckoski.reflectutils.transcoders.XMLTranscoder; //导入依赖的package包/类
@EntityCustomAction(action = "gradeitem", viewKey = "")
public GradebookItem handleGradeItem(EntityView view) {
    String courseId = view.getPathSegment(2);
    if (courseId == null) {
        throw new IllegalArgumentException(
                "valid courseId must be included in the URL /grades/gradeitem/{courseId}");
    }
    String userId = externalLogic.getCurrentUserId();
    if (userId == null) {
        throw new SecurityException(
                "Only logged in users can access instructor courses listings");
    }
    if (!externalLogic.isUserAdmin(userId) && !externalLogic.isUserInstructor(userId)) {
        throw new SecurityException("Only instructors can access course gradebook");
    }
    GradebookItem gbItemOut;
    if (Method.GET.toString().equalsIgnoreCase(view.getMethod())) {
        String gradeItemName = view.getPathSegment(3);
        if (gradeItemName == null) {
            throw new IllegalArgumentException(
                    "valid gbItemName must be included in the URL /grades/gradeitem/{courseId}/{gradeItemName}");
        }
        Gradebook gb = externalLogic.getCourseGradebook(courseId, gradeItemName);
        gbItemOut = gb.items.get(0);
    } else if (Method.POST.toString().equalsIgnoreCase(view.getMethod())
            || Method.PUT.toString().equalsIgnoreCase(view.getMethod())) {
        ServletRequest request = requestGetter.getRequest();
        if (request == null) {
            throw new IllegalStateException("Cannot get request to read data from");
        }
        String inputData;
        try {
            inputData = readerToString(request.getReader());
        } catch (IOException e) {
            throw new RuntimeException("Failed to read the data from the request: " + e);
        }
        if (inputData == null || "".equals(inputData)) {
            throw new IllegalStateException("Must include the grade item and grades data for input (sent nothing)");
        }
        Map<String, Object> input;
        if (Formats.JSON.equals(view.getFormat())) {
            input = new JSONTranscoder().decode(inputData);
        } else {
            input = new XMLTranscoder().decode(inputData);
        }
        // loop through and get the data out and put it into a gradeitem
        ConversionUtils cvu = ConversionUtils.getInstance();
        String gbItemName = (String) input.get("name");
        GradebookItem gbItemIn = new GradebookItem(courseId, gbItemName);
        gbItemIn.pointsPossible = cvu.convert(input.get("pointsPossible"), Double.class);
        gbItemIn.dueDate = cvu.convert(input.get("dueDate"), Date.class);
        gbItemIn.eid = cvu.convert(input.get("externalID"), String.class);
        @SuppressWarnings("unchecked")
        List<Object> scores = cvu.convert(input.get("scores"), List.class);
        if (scores != null) {
            for (Object o : scores) {
                GradebookItemScore score = cvu.convert(o, GradebookItemScore.class);
                gbItemIn.scores.add( score );
            }
        }
        gbItemOut = externalLogic.saveGradebookItem(gbItemIn);
    } else {
        throw new EntityException("Method ("+view.getMethod()+") not supported", "grades/gradeitem", HttpServletResponse.SC_METHOD_NOT_ALLOWED);
    }
    return gbItemOut;
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:67,代码来源:GradesEntityProvider.java


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