/** This method provides a dataGroup list for user to select data source on the GUI */
  public static DataGroup getDataGroup() {
    try {
      if (dg == null) {
        XStream xstream = new XStream(new DomDriver());
        xstream.alias("dataGroup", DataGroup.class);
        xstream.alias("dataSource", DataSource.class);
        xstream.alias("sourceItem", SourceItem.class);
        xstream.addImplicitCollection(DataGroup.class, "dataSource", DataSource.class);
        xstream.addImplicitCollection(DataSource.class, "sourceItem", SourceItem.class);
        // move this file into Jboss directory, so users can modify it.

        // pass this in instead?
        File dataSourceItemConfigFile = DynamicSearchConfig.getDataSourceItemConfigFile();
        InputStream in = new FileInputStream(dataSourceItemConfigFile);

        dg = (DataGroup) xstream.fromXML(new InputStreamReader(in));

        in.close();
      }
    } catch (Exception e) {
      logger.error("Cannot open DataSourceItem file....");
      e.printStackTrace();
      throw new RuntimeException(e);
    }
    return dg;
  }
  public void testBeanSerialize() {

    Id id = new Id("id_123");
    ClassName className = new ClassName("ciaociaosonouna classe");
    BeanContext beanContext = new BeanContext(id, className);

    Context context = new Context();
    context.add(beanContext);

    XStream xstream = new XStream();
    xstream.alias("context", Context.class);
    xstream.alias("beancontext", BeanContext.class);

    xstream.alias("id", Id.class);
    xstream.alias("classname", ClassName.class);

    xstream.useAttributeFor(BeanContext.class, "id");
    xstream.registerConverter(new IdConverter());

    xstream.useAttributeFor(BeanContext.class, "classname");
    xstream.registerConverter(new ClassNameConverter());

    xstream.addImplicitCollection(Context.class, "beanscontext");

    // String expected = "<context>\r\n  <beancontext id=\"id_123\" classname=\"ciaociaosonouna
    // classe\"/>\r\n</context>\r\n";

    System.out.println(xstream.toXML(context));
    System.out.println("\r\n");
    System.out.println("\r\n");
    // assertEquals(expected, xstream.toXML(context));

  }
  /**
   * Retrieves representation of an instance of org.azrul.epice.rest.service.RetrivePasswordResource
   *
   * @return an instance of java.lang.String
   */
  @POST
  @Produces("application/xml")
  public String getXml() {
    // TODO return proper representation object
    XStream writer = new XStream();
    writer.setMode(XStream.XPATH_ABSOLUTE_REFERENCES);
    writer.alias("RetrievePasswordResponse", RetrievePasswordResponse.class);

    XStream reader = new XStream();
    reader.setMode(XStream.XPATH_ABSOLUTE_REFERENCES);
    reader.alias("RetrievePasswordRequest", RetrievePasswordRequest.class);

    RetrievePasswordResponse errorResponse = new RetrievePasswordResponse();
    List<String> errors = new ArrayList<String>();
    errors.add("MODIFY PASSWORD ERROR");
    errorResponse.setErrors(errors);

    MultivaluedMap<String, String> params = context.getQueryParameters();

    try {
      String request = URLDecoder.decode(params.getFirst("REQUEST"), "UTF-8");
      RetrievePasswordRequest oRequest = (RetrievePasswordRequest) reader.fromXML(request);
      RetrievePasswordResponse oResponse = doService(oRequest);
      return URLEncoder.encode(writer.toXML(oResponse), "UTF-8");
    } catch (UnsupportedEncodingException ex) {
      Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
      return writer.toXML(errorResponse);
    }
  }
 @Override
 public String toXML() {
   XStream xstream = getXstream();
   xstream.alias("xml", this.getClass()); // 将生成的XML文件的根节点替换成XML,默认为类的全路径类名
   xstream.alias("item", News.class);
   return xstream.toXML(this);
 }
  /**
   * Load in the configuration files
   *
   * @throws SimulatorException
   */
  public void loadConfigFiles(JSAPResult parserConfig) throws SimulatorException {
    // load in the simulator config file
    String configFile =
        parserConfig.getString("configPath") + parserConfig.getString("simulatorConfigFile");

    XStream xstream = new XStream();
    xstream.alias("SpaceSettlersConfig", SpaceSettlersConfig.class);
    xstream.alias("HighLevelTeamConfig", HighLevelTeamConfig.class);
    xstream.alias("BaseConfig", BaseConfig.class);
    xstream.alias("AsteroidConfig", AsteroidConfig.class);

    try {
      simConfig = (SpaceSettlersConfig) xstream.fromXML(new File(configFile));
    } catch (Exception e) {
      throw new SimulatorException("Error parsing config file at string " + e.getMessage());
    }

    // load in the ladder config file
    configFile = parserConfig.getString("configPath") + parserConfig.getString("ladderConfigFile");

    xstream = new XStream();
    xstream.alias("LadderConfig", LadderConfig.class);
    xstream.alias("HighLevelTeamConfig", HighLevelTeamConfig.class);

    try {
      ladderConfig = (LadderConfig) xstream.fromXML(new File(configFile));

      ladderConfig.makePlayerNamesUnique();

    } catch (Exception e) {
      throw new SimulatorException("Error parsing config file at string " + e.getMessage());
    }
  }
 static {
   xs = new XStream(new DomDriver());
   xs.alias("pipe", FilterPipeInfo.class);
   xs.alias("svr", String.class);
   // xs.alias("dfas", (new String[0]).getClass());
   // xs.alias("name", null);
 }
Exemple #7
0
 /** 把xml转化为java对象 */
 public static void xmlToJavaBean() {
   XStream stream = new XStream(new DomDriver());
   String xml = "book.xml";
   try {
     // 设置节点对应的实体类
     stream.alias("book", Book.class);
     stream.alias("books", Books.class);
     // 设置XML解析出来的对象是Books对象,根节点books对应Books类,book节点对应Book类,有多个book节点,这里需转换到集合中
     stream.addImplicitCollection(Books.class, "books");
     // 从XML解析出Books对象
     Books books = (Books) stream.fromXML(new FileReader(new File(xml)));
     ArrayList<Book> bookList = books.getBooks();
     for (int i = 0; i < bookList.size(); i++) {
       Book book = (Book) bookList.get(i);
       // 打印实体类
       System.out.println(
           "name:"
               + book.getName()
               + ","
               + "author:"
               + book.getAuthor()
               + ","
               + "date:"
               + book.getDate());
     }
   } catch (FileNotFoundException e) {
     e.printStackTrace();
   }
 }
 private String employeeToXml(EmployeeList list) {
   XStream xstream = new XStream();
   xstream.alias("employee", Employee.class);
   xstream.alias("employees", EmployeeList.class);
   xstream.addImplicitCollection(EmployeeList.class, "list");
   return xstream.toXML(list);
 }
 public CswRecordConverter() {
   xstream = new XStream(new Xpp3Driver());
   xstream.setClassLoader(this.getClass().getClassLoader());
   xstream.registerConverter(this);
   xstream.alias(CswConstants.CSW_RECORD_LOCAL_NAME, Metacard.class);
   xstream.alias(CswConstants.CSW_RECORD, Metacard.class);
 }
 public static XStream getXStream() {
   if (xStream == null) {
     synchronized (DashboardModelUtils.class) {
       if (xStream == null) {
         xStream = new XStream();
         xStream.alias("dashboard", Dashboard.class);
         xStream.alias("widget", Widget.class);
         xStream.alias("parameters", IParameters.class, Parameters.class);
         xStream.aliasAttribute(Dashboard.class, "title", "title");
         xStream.aliasAttribute(Dashboard.class, "layoutConstraints", "layoutConstraints");
         xStream.aliasAttribute(Dashboard.class, "rowConstraints", "rowConstraints");
         xStream.aliasAttribute(Dashboard.class, "colConstraints", "colConstraints");
         xStream.aliasAttribute(Widget.class, "classname", "classname");
         xStream.aliasAttribute(Widget.class, "id", "id");
         xStream.aliasAttribute(Widget.class, "style", "style");
         xStream.aliasAttribute(Widget.class, "title", "title");
         xStream.aliasAttribute(Widget.class, "collapsible", "collapsible");
         xStream.aliasAttribute(Widget.class, "collapsed", "collapsed");
         xStream.aliasAttribute(Widget.class, "hideTitleBar", "hideTitleBar");
         xStream.aliasAttribute(Widget.class, "layoutData", "layoutData");
         xStream.aliasAttribute(Widget.class, "listenToWidgets", "listenToWidgets");
         xStream.addImplicitCollection(Dashboard.class, "widgets", Widget.class);
         xStream.registerConverter(new ParametersConverter(xStream.getMapper()));
       }
     }
   }
   return xStream;
 }
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    action = request.getParameter("action");
    jspPage = "/Home.jsp";
    boolean dispacher = true;

    if ((action == null) || action.length() < 1) {
      jspPage = "/Home.jsp";
      super.dispatch(jspPage, request, response);
    }
    if ("default".equals(action)) {
      jspPage = "/Home.jsp";

    } else if ("restricciones".equals(action)) {
      String idCliente = request.getParameter("cliente");
      RestriccionVOList list = sistema.getRestriccionesCliente(idCliente);
      XStream xstream = new XStream(new DomDriver());
      xstream.alias("restriccion", RestriccionVO.class);
      xstream.alias("restricciones", RestriccionVOList.class);
      xstream.addImplicitCollection(RestriccionVOList.class, "restricciones");

      String xml = xstream.toXML(list);
      response.setContentType("text/plain");
      response.setCharacterEncoding("UTF-8");
      response.getWriter().write(xml);
      dispacher = false;
    }

    if (dispacher) super.dispatch(jspPage, request, response);
  }
  static {
    XSTREAM = new XStream(new DomDriver());

    // Register aliases
    XSTREAM.alias("webapp-structure", WebappStructure.class);
    XSTREAM.alias("path-set", PathSet.class);
    XSTREAM.alias("dependency", Dependency.class);
  }
 public static PcRunEventLog xmlToObject(String xml) {
   XStream xstream = new XStream();
   xstream.alias("Record", PcRunEventLogRecord.class);
   xstream.alias("EventLog", PcRunEventLog.class);
   xstream.addImplicitCollection(PcRunEventLog.class, "RecordsList");
   xstream.setClassLoader(PcRunEventLog.class.getClassLoader());
   return (PcRunEventLog) xstream.fromXML(xml);
 }
 @Override
 protected void configureXStream(XStream xstream) {
   xstream.alias(ELEMENT_NAME_AGENT, OpenAcdAgentRestInfoFull.class);
   xstream.alias(ELEMENT_NAME_GROUP, OpenAcdAgentGroupRestInfo.class);
   xstream.alias(ELEMENT_NAME_SKILL, OpenAcdSkillRestInfo.class);
   xstream.alias(ELEMENT_NAME_QUEUE, OpenAcdQueueRestInfo.class);
   xstream.alias(ELEMENT_NAME_CLIENT, OpenAcdClientRestInfo.class);
 }
 @Override
 protected XStream createXStream() {
   XStream ret = super.createXStream();
   ret.alias("errors", Errors.class);
   ret.alias("error", Error.class);
   ret.addImplicitCollection(Error.Parameters.class, "parameters", "parameter", String.class);
   return ret;
 }
Exemple #16
0
  public OpenButton() {
    super("Open");
    st = new XStream(new DomDriver());
    st.alias("gate", Gate.class);
    st.alias("circuit", DigitalCircuit.class);

    this.addActionListener(this);
  }
  /**
   * This function makes the call to the XML database and retrieves all the file metadata for use in
   * ECGridToolkit. The data is first retrieved in a series of XML blocks, and then they are
   * converted into StudyEntry Objects and returned to the user
   *
   * @param userID - The ID of the user. This is used to check which files the user has submitted
   *     and thus has access to
   * @return The list of StudyEntry Objects taken from the file metadata in the XML database
   */
  public ArrayList<StudyEntry> getEntries(String userID) {
    ArrayList<StudyEntry> tempList = new ArrayList<StudyEntry>();

    try {

      // create first query to get the entire studyEntry block, the collection() XQuery function
      // does this across
      // all documents in the XML Collection

      //  The goal of this query is to find all the data we need for the StudyEntry object based on
      // which user submitted them.  For all the documents searched, the query looks to see
      //  if any files for that subject's ECG repository were submitted by that user.  If any files
      // were submitted, retrieve their metadata contained in the studyEntry block.
      String sQuery =
          studyBuilder.defaultFor()
              + studyBuilder.defaultWhere(userID)
              + studyBuilder.defaultOrderBy()
              + studyBuilder.defaultReturn();

      System.out.println("Query to be executed = " + sQuery);

      ResourceSet resultSet = executeQuery(sQuery);
      ResourceIterator iter = resultSet.getIterator();
      Resource selection = null;
      Resource fileSelection = null;
      int listIndex = 0;
      int subjectCount = 1;

      while (iter.hasMoreResources()) {
        selection = iter.nextResource();
        String studyEntryResult = (selection.getContent()).toString();

        // Now we will create an XStream object and then put that into our StudyEntry objects
        // the StudyEntry objects are de-serialized versions of the studyEntry blocks.
        XStream xmlStream = new XStream();

        xmlStream.alias("studyEntry", StudyEntry.class);
        xmlStream.alias("recordDetails", RecordDetails.class);
        xmlStream.alias("fileDetails", FileDetails.class);
        xmlStream.addImplicitCollection(RecordDetails.class, "fileDetails");

        StudyEntry newStudy = (StudyEntry) xmlStream.fromXML(studyEntryResult);

        // System.out.println(newStudy);

        // Add it to the return array
        tempList.add(newStudy);
      }
    } catch (Exception ex) {
      System.out.println(
          "StudyEntryUtility.getEntries():  AN EXCEPTION HAS BEEN CAUGHT!  IF A LIST IS RETURNED, IT WILL BE EMPTY!!!");
      ex.printStackTrace();
    }

    return tempList;
  }
  /**
   * Carica il bollettino valanghe.
   *
   * @return previsione caricata
   */
  public Bollettino caricaBollettino() {

    XStream xStream = new XStream();
    xStream.ignoreUnknownElements();
    xStream.alias("previsione", Bollettino.class);
    xStream.alias("giorno", Giorno.class);
    xStream.autodetectAnnotations(true);

    return loadXml(MeteoSettings.BOLLETTINO_VALANGHE_XML, xStream);
  }
Exemple #19
0
 private static XStream getJsonXstream() {
   XStream xstream = new XStream(new JettisonMappedXmlDriver());
   xstream.setMode(XStream.NO_REFERENCES);
   xstream.alias("config", ConfigurationHolder.class);
   xstream.addImplicitCollection(ConfigurationHolder.class, "messageParameters");
   xstream.alias("messages", MessageParameters.class);
   xstream.addImplicitCollection(MessageParameters.class, "plurals");
   xstream.alias("plurals", PluralDefinitions.class);
   return xstream;
 }
  public static XStream getConfiguredXStream(XStream xs) {
    xs.setMode(XStream.NO_REFERENCES);

    xs.alias("gwcQuotaConfiguration", DiskQuotaConfig.class);
    xs.alias("layerQuotas", List.class);
    xs.alias("LayerQuota", LayerQuota.class);
    xs.alias("Quota", Quota.class);
    xs.registerConverter(new QuotaXSTreamConverter());
    return xs;
  }
 public void configure(XStream xStream) {
   xStream.alias("profile", RulesProfile.class);
   xStream.alias("alert", Alert.class);
   xStream.alias("active-rule", ActiveRule.class);
   xStream.aliasField("active-rules", RulesProfile.class, "activeRules");
   xStream.aliasField("default-profile", RulesProfile.class, "defaultProfile");
   xStream.omitField(RulesProfile.class, "id");
   xStream.omitField(RulesProfile.class, "projects");
   xStream.registerConverter(getActiveRuleConverter());
   xStream.registerConverter(getAlertsConverter());
 }
Exemple #22
0
 public static void convertListUseAliasToFile() {
   XStream xs = new XStream();
   FileOutputStream fos = null;
   xs.alias("OrderForm", OrderForm.class);
   xs.alias("OrderFormDetail", OrderFormDetail.class);
   try {
     fos = getFileOSByName("OrderFormUseAlias.xml");
   } catch (IOException e) {
     e.printStackTrace();
   }
   xs.toXML(of, fos);
 }
  @Override
  public String getProducts() throws Exception {
    JAXBContext jaxbContext = JAXBContext.newInstance(Products.class);
    Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
    jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

    Products products = new Products();
    products.setProductsList(new ArrayList<Product>());
    PreparedStatement query = null;
    Connection conn = null;
    // List<Product> productList = new ArrayList<Product>();

    try {

      conn = MySQLDB.MySQLDBConn().getConnection();
      query =
          conn.prepareStatement(
              "select ProductID, ProductName, QuantityPerUnit, UnitPrice, UnitsInStock, "
                  + "UnitsOnOrder, ReorderLevel, Discontinued from products");

      ResultSet rs = query.executeQuery();
      while (rs.next()) {
        Product product = new Product();
        product.setProductId(rs.getInt("ProductID"));
        product.setProductName(rs.getString("ProductName"));
        product.setQuantityPerUnit(rs.getString("QuantityPerUnit"));
        product.setUnitPrice(rs.getDouble("UnitPrice"));
        product.setUnitsInStock(rs.getInt("UnitsInStock"));
        product.setRecorderLevel(rs.getInt("ReorderLevel"));
        product.setDiscontinued(rs.getBoolean("Discontinued"));
        products.getProductsList().add(product);
      }
      // jaxbMarshaller.marshal(products, System.out);
      jaxbMarshaller.marshal(products, new File("c:/temp/products.xml"));
      query.close();
    } catch (SQLException sqlError) {
      sqlError.printStackTrace();
      List<Product> emptyProductList = new ArrayList<Product>();
      return "Error occured";
    } finally {
      if (conn != null) conn.close();
    }

    // XStream xstream = new XStream();
    XStream xstream = new XStream(new DomDriver());
    xstream.alias("ListProducts", Products.class);
    xstream.alias("product", Product.class);
    System.out.println(xstream.toXML(products));

    return xstream.toXML(products);
  }
Exemple #24
0
 public static OrderForm getListUseAliasFromFile() {
   XStream xs = new XStream(new DomDriver());
   FileInputStream fis = null;
   xs.alias("OrderForm", OrderForm.class);
   xs.alias("OrderFormDetail", OrderFormDetail.class);
   try {
     fis = getFileISByName("OrderFormUseAlias.xml");
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   OrderForm orderForm = (OrderForm) xs.fromXML(fis);
   return orderForm;
 }
  private XStream configure(XStream x) {
    x.processAnnotations(PackageState.class);

    /* APPLICATION_VERSION */
    x.alias(
        StreamId.APPLICATION_VERSION.name(),
        AbstractSerializationTest.TestObjects.applicationVersion.getClass());
    PropertyDescriptor pd =
        SerializationAnnotationUtil.getStreamDescriptors(PackageState.class)
            .get(StreamId.APPLICATION_VERSION);
    x.registerLocalConverter(PackageState.class, pd.getName(), new ApplicationVersionConverter());

    /* DOMAIN_PROFILE_LIST */
    x.alias(
        StreamId.DOMAIN_PROFILE_LIST.name(),
        AbstractSerializationTest.TestObjects.domainProfileUris.getClass());
    pd =
        SerializationAnnotationUtil.getStreamDescriptors(PackageState.class)
            .get(StreamId.DOMAIN_PROFILE_LIST);
    x.registerLocalConverter(PackageState.class, pd.getName(), new DomainProfileUriListConverter());

    /* PACKAGE_METADATA */
    x.alias(
        StreamId.PACKAGE_METADATA.name(),
        AbstractSerializationTest.TestObjects.packageMetadata.getClass());
    pd =
        SerializationAnnotationUtil.getStreamDescriptors(PackageState.class)
            .get(StreamId.PACKAGE_METADATA);
    x.registerLocalConverter(PackageState.class, pd.getName(), new PackageMetadataConverter());

    /* PACKAGE_NAME */
    x.alias(
        StreamId.PACKAGE_NAME.name(), AbstractSerializationTest.TestObjects.packageName.getClass());
    pd =
        SerializationAnnotationUtil.getStreamDescriptors(PackageState.class)
            .get(StreamId.PACKAGE_NAME);
    x.registerLocalConverter(PackageState.class, pd.getName(), new PackageNameConverter());

    /* USER_SPECIFIED_PROPERTIES */
    x.alias(
        StreamId.USER_SPECIFIED_PROPERTIES.name(),
        AbstractSerializationTest.TestObjects.userProperties.getClass());
    pd =
        SerializationAnnotationUtil.getStreamDescriptors(PackageState.class)
            .get(StreamId.USER_SPECIFIED_PROPERTIES);
    x.registerLocalConverter(PackageState.class, pd.getName(), new UserPropertyConverter());

    return x;
  }
  public user parseXmlUser(InputStream is) {
    // use the magic of serialisation and seralise the xml data to the user object
    XStream xstream = new XStream(new DomDriver());
    xstream.autodetectAnnotations(true);

    // set the alias (by default xstream expects all the classes to be in the same package
    xstream.alias("user", user.class);
    xstream.alias("profile", profile.class);
    xstream.alias("membership", membership.class);
    xstream.alias("internationalisation", internationalisation.class);
    xstream.alias("link", link.class);

    user user = (user) xstream.fromXML(is);
    return user;
  }
Exemple #27
0
 static {
   XSTREAM.alias("fingerprint", Fingerprint.class);
   XSTREAM.alias("range", Range.class);
   XSTREAM.alias("ranges", RangeSet.class);
   XSTREAM.registerConverter(new HexBinaryConverter(), 10);
   XSTREAM.registerConverter(
       new RangeSet.ConverterImpl(
           new CollectionConverter(XSTREAM.getMapper()) {
             @Override
             protected Object createCollection(Class type) {
               return new ArrayList();
             }
           }),
       10);
 }
  private static XStream getSchemaParser() {
    XStream xstream = new XStream(new Dom4JDriver());

    xstream.alias("object-schema", ObjectSchema.class);

    xstream.alias("record", Record.class);
    xstream.aliasAttribute(Record.class, "type", "type");
    xstream.aliasAttribute(Record.class, "entityType", "entityType");
    xstream.addImplicitCollection(Record.class, "subRecords", "record", Record.class);

    xstream.alias("field", Field.class);
    xstream.addImplicitCollection(Record.class, "fields", "field", Field.class);

    return xstream;
  }
 public String toXML(boolean omitId) {
   XStream xs = new XStream();
   xs.alias("PedidoDeAbastecimiento", PedidoAbastecimientoVO.class);
   xs.alias("ocAsociada", OrdenDeCompraVO.class);
   xs.alias("Rodamiento", RodamientoVO.class);
   xs.alias("Proveedor", ProveedorVO.class);
   if (omitId) {
     xs.omitField(OrdenDeCompraVO.class, "idODV");
     xs.omitField(ProveedorVO.class, "id");
     xs.omitField(RodamientoVO.class, "id");
   }
   xs.omitField(PedidoAbastecimientoVO.class, "cantidadPendiente");
   xs.omitField(PedidoAbastecimientoVO.class, "ocAsociada");
   return xs.toXML(this);
 }
  private void configAgendaPlenario(XStream xstream) {
    xstream.alias("AgendaPlenario", AgendaPlenario.class);
    xstream.processAnnotations(Sessao.class);
    Materias.configXstream(xstream);
    xstream.alias("Materia", Proposicao.class);

    xstream.aliasField("Sessoes", AgendaPlenario.class, "sessoes");
    // xstream.aliasField("Materias", Sessao.class, "materias");

    xstream.aliasField("CodigoMateria", Proposicao.class, "idProposicao");
    xstream.aliasField("SiglaMateria", Proposicao.class, "tipo");
    xstream.aliasField("NumeroMateria", Proposicao.class, "numero");
    xstream.aliasField("AnoMateria", Proposicao.class, "ano");
    xstream.aliasField("Ementa", Proposicao.class, "ementa");
    xstream.aliasField("SequenciaOrdem", Proposicao.class, "seqOrdemPauta");
  }