Package com.thoughtworks.xstream

Examples of com.thoughtworks.xstream.XStream


    }

    public Page loadPage(String pageUrl, boolean expanded) {
        String pattern = expanded ? EXPAND_PAGE : REGULAR_PAGE;
        String content = client.get(format(pattern, pageUrl));
        XStream parse = configureXStream();
        Page page = (Page) parse.fromXML(content);
        return page;
    }
View Full Code Here


    switch (type) {
    case JSON:
      Gson gson = new Gson();
      return gson.fromJson(entity, Page.class).content;
    case XML:
      XStream xstream = new XStream();
      xstream.alias("page", Page.class);
      xstream.ignoreUnknownElements();
      return ((Page) xstream.fromXML(entity)).content;
    default:
      return entity;
    }
  }
View Full Code Here

        Page page = (Page) parse.fromXML(content);
        return page;
    }

    protected XStream configureXStream() {
        XStream stream = new XStream();
        stream.addImplicitCollection(Page.class, "link");
        stream.alias("results", Results.class);
        stream.alias("result", Page.class);
        stream.alias("content", Page.class);
        stream.alias("link", Link.class);
        stream.useAttributeFor(Link.class, "rel");
        stream.useAttributeFor(Link.class, "href");
        stream.ignoreUnknownElements();
        return stream;
    }
View Full Code Here

      Gson gson = new Gson();
      String json = gson.toJson(page);
      return json;
    case XML:
      page.xmlns = "http://www.xwiki.org";
      XStream xstream = new XStream();
      xstream.alias("page", Page.class);
      xstream.useAttributeFor(Page.class, "xmlns");
            xstream.aliasField("xmlns", Page.class, "xmlns");
            xstream.ignoreUnknownElements();
      String xml = xstream.toXML(page);
      return xml;
    default:
      return resource.getContent();
    }
  }
View Full Code Here

    case JSON:
      Gson gson = new Gson();
      return gson.fromJson(jsonMember(entity, "wiki_page"),
          WikiPage.class).text;
    case XML:
      XStream xstream = new XStream();
      xstream.alias("wiki_page", WikiPage.class);
      xstream.ignoreUnknownElements();
      return ((WikiPage) xstream.fromXML(entity)).text;
    default:
      return entity;
    }
  }
View Full Code Here

    private static final Logger LOG = Logger.getLogger(XStreamEventSerializer.class);

    private XStream xstream;
   
    public XStreamEventSerializer() {
        xstream = new XStream();
        xstream.aliasPackage("event", LotteryEvent.class.getPackage().getName());
        xstream.addImmutableType(UUID.class);
    }
View Full Code Here

        String outXml = template.requestBody( "direct:exec",
                                              inXml,
                                              String.class );

        ClassLoader cl = ((InternalRuleBase) ((StatefulKnowledgeSessionImpl) ksession).getRuleBase()).getRootClassLoader();
        XStream xstream = BatchExecutionHelper.newXStreamMarshaller();
        xstream.setClassLoader( cl );
        FactHandle factHandle = (FactHandle) ((ExecutionResults) xstream.fromXML( outXml )).getFactHandle( "outStilton" );

        String expectedXml = "";
        expectedXml += "<execution-results>\n";
        expectedXml += "  <result identifier=\"outStilton\">\n";
        expectedXml += "    <org.foo.Whee>\n";
View Full Code Here

        steps.add(new ClassWithMethodsAandB());
        steps.add(new ClassWithMethodsCandD());
        String stepsAsString = steps.toString(); // includes object ID numbers
                                                 // from JVM

        XStream xs = new XStream();

        ScenarioType scenarioType = ScenarioType.NORMAL;
        List<Step> subset = foo.collectBeforeOrAfterScenarioSteps(steps, null, Stage.BEFORE, scenarioType);
        String subsetAsXML = xs.toXML(subset);
        assertThat(subsetAsXML.indexOf("<name>a</name>"), greaterThan(-1)); // there
        assertThat(subsetAsXML.indexOf("<name>b</name>"), equalTo(-1)); // not there
        assertThat(subsetAsXML.indexOf("<name>c</name>"), greaterThan(-1)); // there
        assertThat(subsetAsXML.indexOf("<name>d</name>"), equalTo(-1)); // not there
        assertThat(subsetAsXML.indexOf("<name>a</name>"), lessThan(subsetAsXML.indexOf("<name>c</name>"))); // there

        assertThat(stepsAsString, equalTo(steps.toString())); // steps have not been mutated.

        subset = foo.collectBeforeOrAfterScenarioSteps(steps, null, Stage.AFTER, scenarioType);
        subsetAsXML = xs.toXML(subset);
        assertThat(subsetAsXML.indexOf("<name>a</name>"), equalTo(-1)); // not there
        assertThat(subsetAsXML.indexOf("<name>b</name>"), greaterThan(-1)); // there
        assertThat(subsetAsXML.indexOf("<name>c</name>"), equalTo(-1)); // not there
        assertThat(subsetAsXML.indexOf("<name>d</name>"), greaterThan(-1)); // there
        assertThat(subsetAsXML.indexOf("<name>d</name>"), lessThan(subsetAsXML.indexOf("<name>b</name>"))); // reverse order
View Full Code Here

  /**
   * Constructor.
   */
  public XStreamSerializableFactory() {
    this.xstream = new XStream();
  }
View Full Code Here

  public void testEqualsNullComparison() {
    assertEqualsNullComparisonReturnsFalse(serializableFactory);
  }

  public void testGetOriginalValueWithArgumentBeingObjectWrapper() {
  XStream xstream = new XStream();
  ObjectWrapper wrapper = new ObjectWrapper(xstream.toXML(puppy));
    assertEquals(puppy, serializableFactory.getOriginalValue(wrapper));
  }
View Full Code Here

TOP

Related Classes of com.thoughtworks.xstream.XStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.