Ejemplo n.º 1
0
  private String statusList(Map<String, String> parameters) throws Exception {
    WorkflowStatus[] list =
        studioController.getWorkflowStatuses(sessionUid, Long.parseLong(parameters.get("uid")));
    WorkflowStatusDefinition[] results = new WorkflowStatusDefinition[list.length];
    int ind = 0;
    for (WorkflowStatus it : list) {
      WorkflowStatusDefinition n = new WorkflowStatusDefinition();
      n.setPosition(ind);
      n.setWorkflowStatus(it);
      WorkflowStatusManager[] mn =
          studioController.getWorkflowStatusManagers(sessionUid, it.getUid());
      n.setWorkflowStatusManagers(mn);
      results[ind] = n;
      ind++;
    }
    XStream xml = new XStream(new DomDriver());
    XStream xstream =
        new XStream(
            new JettisonMappedXmlDriver() {

              public HierarchicalStreamWriter createWriter(Writer writer) {
                return new JsonWriter(writer, "".toCharArray(), "", JsonWriter.DROP_ROOT_MODE);
              }
            });
    xstream.aliasField(
        "securityEntityName", WorkflowStatusManager.class, "localSecurityEntityName");
    xstream.aliasField(
        "securityEntitySource", WorkflowStatusManager.class, "localSecurityEntitySource");
    xstream.aliasField(
        "securityEntityType", WorkflowStatusManager.class, "localSecurityEntityType");
    xstream.aliasField("workflowStatusUid", WorkflowStatusManager.class, "localWorkflowStatusUid");
    xstream.setMode(XStream.NO_REFERENCES);
    String jsonResp = xstream.toXML(results);
    return jsonResp;
  }
  public XmlProjectDescriptorSerializer(boolean postProcess) {
    xstream = new XStream(new DomDriver());
    xstream.ignoreUnknownElements();
    xstream.omitField(ProjectDescriptor.class, "id"); // This field was deprecated
    xstream.omitField(ProjectDescriptor.class, "log");
    xstream.omitField(ProjectDescriptor.class, "classLoader");
    xstream.omitField(ProjectDescriptor.class, "projectFolder");
    xstream.omitField(Module.class, "properties"); // properties doesn't supported by rules.xml
    xstream.omitField(Module.class, "wildcardName"); // runtime properties
    xstream.omitField(Module.class, "wildcardRulesRootPath"); // runtime properties
    xstream.omitField(Module.class, "project"); // runtime properties

    xstream.setMode(XStream.NO_REFERENCES);

    xstream.aliasType(PROJECT_DESCRIPTOR_TAG, ProjectDescriptor.class);
    xstream.aliasType(MODULE_TAG, Module.class);
    xstream.aliasType(DEPENDENCY_TAG, ProjectDependencyDescriptor.class);
    xstream.aliasType(PATH_TAG, PathEntry.class);
    xstream.aliasType(PROPERTY_TAG, Property.class);
    xstream.aliasField(
        PROPERTIES_FILE_NAME_PATTERN, ProjectDescriptor.class, "propertiesFileNamePattern");
    xstream.aliasField(
        PROPERTIES_FILE_NAME_PROCESSOR, ProjectDescriptor.class, "propertiesFileNameProcessor");
    xstream.addDefaultImplementation(HashSet.class, Collection.class);
    xstream.alias("value", String.class);

    xstream.useAttributeFor(PathEntry.class, "path");
    xstream.aliasField("rules-root", Module.class, "rulesRootPath");
    xstream.aliasField(METHOD_FILTER_TAG, Module.class, "methodFilter");
    xstream.registerConverter(new StringValueConverter());

    this.postProcess = postProcess;
  }
Ejemplo n.º 3
0
  static {
    XSTREAM.alias("project", FreeStyleProject.class);
    XSTREAM.alias("matrix-project", MatrixProject.class);
    XSTREAM.alias("axis", Axis.class);
    XSTREAM.alias("matrix-config", MatrixConfiguration.class);

    // aliases for project properties.
    // TODO: think about migrating to xstream's annotations.
    XSTREAM.alias("base-property", BaseProjectProperty.class);
    XSTREAM.alias("external-property", ExternalProjectProperty.class);
    XSTREAM.alias("trigger-property", TriggerProjectProperty.class);
    XSTREAM.alias("integer-property", IntegerProjectProperty.class);
    XSTREAM.alias("boolean-property", BooleanProjectProperty.class);
    XSTREAM.alias("string-property", StringProjectProperty.class);
    XSTREAM.alias("log-rotator-property", LogRotatorProjectProperty.class);
    XSTREAM.alias("result-property", ResultProjectProperty.class);
    XSTREAM.alias("scm-property", SCMProjectProperty.class);

    XSTREAM.alias("copy-write-list-property", CopyOnWriteListProjectProperty.class);
    XSTREAM.alias("axis-list-property", AxisListProjectProperty.class);
    XSTREAM.alias("describable-list-property", DescribableListProjectProperty.class);
    XSTREAM.aliasField("cascading-job-properties", Job.class, "cascadingJobProperties");
    XSTREAM.aliasField("project-properties", Job.class, "jobProperties");
    XSTREAM.alias("appointed-node-property", AppointedNode.class);
  }
Ejemplo n.º 4
0
  public static void registerMapping(XStream xstream) {
    // In the XML the class is represented as a page - tag
    xstream.alias("page", CPNPage.class);

    xstream.useAttributeFor(CPNPage.class, "idattri");
    xstream.aliasAttribute(CPNPage.class, "idattri", "id");

    // In order not to display the places / transitions / arcs tag, but simply show
    // the page tags one after another.
    xstream.addImplicitCollection(CPNPage.class, "places", CPNPlace.class);
    xstream.addImplicitCollection(CPNPage.class, "transitions", CPNTransition.class);
    xstream.addImplicitCollection(CPNPage.class, "arcs", CPNArc.class);

    // Sometimes XStream cannot translate elements into a XML structure.
    // Therefore exists the possibility to create and register a converter for that element.
    xstream.registerConverter(new CPNTextConverter());

    // These instance variables are not needed for the mapping, that's why they are excluded
    xstream.omitField(CPNPage.class, "arcRelation");
    xstream.omitField(CPNPage.class, "nodePositions");

    // Giving all fields a concrete name for the XML
    xstream.aliasField("Aux", CPNPage.class, "auxtag");
    xstream.aliasField("group", CPNPage.class, "grouptag");
    xstream.aliasField("vguidelines", CPNPage.class, "vguidelines");
    xstream.aliasField("hguidelines", CPNPage.class, "hguidelines");

    CPNPageattr.registerMapping(xstream);
    CPNModellingThing.registerMapping(xstream);
    CPNPlace.registerMapping(xstream);
    CPNTransition.registerMapping(xstream);
    CPNArc.registerMapping(xstream);
    CPNLittleProperty.registerMapping(xstream);
  }
 @Override
 protected void configureXStream(XStream xstream) {
   xstream.omitField(BeanWithId.class, "m_id");
   xstream.alias("entry", PhonebookEntry.class);
   xstream.aliasField("first-name", PhonebookEntry.class, "firstName");
   xstream.aliasField("last-name", PhonebookEntry.class, "lastName");
   xstream.aliasField("contact-information", PhonebookEntry.class, "addressBookEntry");
   xstream.omitField(PhonebookEntry.class, "m_phonebook");
   xstream.omitField(AddressBookEntry.class, "m_useBranchAddress");
   xstream.omitField(AddressBookEntry.class, "m_branchOfficeAddress");
 }
Ejemplo n.º 6
0
 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());
 }
Ejemplo n.º 7
0
 private void doAlias(Class<?> c) {
   if (c.isAnnotationPresent(Alias.class)) {
     converter.alias(c.getAnnotation(Alias.class).value(), c);
   }
   for (Field f : c.getDeclaredFields()) {
     if (f.isAnnotationPresent(Alias.class)) {
       converter.aliasField(f.getAnnotation(Alias.class).value(), c, f.getName());
     }
   }
 }
Ejemplo n.º 8
0
  private void ustawAliasy(XStream _xstream) {
    _xstream.alias("Sygnał", Sygnal.class);

    // _xstream.aliasField("Parametry", Sygnal.class, "sygnal_parametry");

    _xstream.aliasField("typSygnału", Sygnal.class, "typ");
    _xstream.aliasField("amplituda", Sygnal.class, "A");
    _xstream.aliasField("czasPoczątkowy", Sygnal.class, "t1");
    _xstream.aliasField("czasTrwania", Sygnal.class, "d");
    _xstream.aliasField("okresPodstawowy", Sygnal.class, "T");
    _xstream.aliasField("współczynnikWypełnienia", Sygnal.class, "kw");
    _xstream.aliasField("punkty", Sygnal.class, "punktyY_wykres");
    _xstream.aliasField("kroczek", Sygnal.class, "kroczek");
    _xstream.aliasField("krok", Sygnal.class, "krok");

    if (this.sygnal.getrodzaj() == rodzaj_sygnalu.CIAGLY) {
      _xstream.omitField(Sygnal.class, "ts");
      _xstream.omitField(Sygnal.class, "krok");
      _xstream.omitField(Sygnal.class, "kroczek");
      _xstream.omitField(Sygnal.class, "punktyY_wykres");
      _xstream.omitField(Sygnal.class, "punktyY_probkowanie");
      _xstream.omitField(Sygnal.class, "punktyY_kwantyzacja");
      _xstream.omitField(Sygnal.class, "poziom_kwantyzacji_krok");
      _xstream.omitField(Sygnal.class, "poziomy_kwantyzacji");
      if (this.sygnal.gettyp() != 9 || this.sygnal.gettyp() != 10) {
        _xstream.omitField(Sygnal.class, "skok");
      }
    }

    if (this.sygnal.getrodzaj() == rodzaj_sygnalu.DYSKRETNY) {
      _xstream.omitField(Sygnal.class, "typ");
      _xstream.omitField(Sygnal.class, "A");
      _xstream.omitField(Sygnal.class, "skok");
      _xstream.omitField(Sygnal.class, "kroczek");
      _xstream.omitField(Sygnal.class, "kw");
      _xstream.omitField(Sygnal.class, "ts");
      _xstream.omitField(Sygnal.class, "T");
      _xstream.omitField(Sygnal.class, "punktyY_probkowanie");
      _xstream.omitField(Sygnal.class, "punktyY_kwantyzacja");
      _xstream.omitField(Sygnal.class, "poziom_kwantyzacji_krok");
      _xstream.omitField(Sygnal.class, "poziomy_kwantyzacji");
      if (this.sygnal.gettyp() != 9 || this.sygnal.gettyp() != 10) {
        _xstream.omitField(Sygnal.class, "skok");
      }
    }
  }
Ejemplo n.º 9
0
  public static void main(String[] args) {
    try {
      XStream xs = new XStream(new DomDriver());
      File dir = new File("src/com/ce/pcenter/xstream/test"); // 获取当前目录
      String strDir = dir.getCanonicalPath();
      FileInputStream fis = new FileInputStream(strDir + "/Config.xml");
      xs.aliasField("datasource-name", ConfigReader.class, "datasourcename");
      xs.alias("config", ConfigReader.class);
      ConfigReader r = (ConfigReader) xs.fromXML(fis);

      System.out.println(r.toString());
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 10
0
  public static void registerMapping(XStream xstream) {
    xstream.alias("color", CPNColor.class);

    xstream.aliasField("ml", CPNColor.class, "mltag");
    xstream.aliasField("alias", CPNColor.class, "alias");
    xstream.aliasField("id", CPNColor.class, "idattri");
    xstream.aliasField("id", CPNColor.class, "idtag");
    xstream.aliasField("bool", CPNColor.class, "booleantag");
    xstream.aliasField("string", CPNColor.class, "stringtag");
    xstream.aliasField("int", CPNColor.class, "integertag");
    xstream.aliasField("product", CPNColor.class, "producttag");
    xstream.aliasField("list", CPNColor.class, "listtag");
    xstream.aliasField("unit", CPNColor.class, "unittag");

    xstream.useAttributeFor(CPNColor.class, "idattri");

    CPNString.registerMapping(xstream);
    CPNProduct.registerMapping(xstream);
    CPNBoolean.registerMapping(xstream);
    CPNInteger.registerMapping(xstream);
    CPNList.registerMapping(xstream);
    CPNUnit.registerMapping(xstream);
  }
Ejemplo n.º 11
0
  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");
  }
Ejemplo n.º 12
0
 public DefaultExtJson(
     HttpServletResponse response, TypeNameExtractor extractor, ProxyInitializer initializer)
     throws IOException {
   xstream =
       new XStream(
           new JsonHierarchicalStreamDriver() {
             @Override
             public HierarchicalStreamWriter createWriter(Writer writer) {
               return new JsonWriter(writer, new char[0], "", JsonWriter.DROP_ROOT_MODE) {
                 @Override
                 public void addAttribute(String key, String value) {
                   if (!key.equals("class")) {
                     super.addAttribute(key, value);
                   }
                 }
               };
             }
           });
   xstream.aliasField("data", ExtJSWrapper.class, "list");
   serializer = new XStreamSerializer(xstream, response.getWriter(), extractor, initializer);
 }
  protected XStream configure(final XStream xs) {
    assert xs != null;

    //        xs.registerConverter(new RepositoryBaseResourceConverter(xs.getMapper(), xs
    //            .getReflectionProvider()), XStream.PRIORITY_VERY_HIGH);
    //        xs.registerConverter(new RepositoryResourceResponseConverter(xs.getMapper(), xs
    //            .getReflectionProvider()), XStream.PRIORITY_VERY_HIGH); // strips the
    // class="class.name" attribute from data
    //
    //        xs.registerConverter(new ScheduledServiceBaseResourceConverter(xs.getMapper(), xs
    //            .getReflectionProvider()), XStream.PRIORITY_VERY_HIGH);
    //        xs.registerConverter(new ScheduledServicePropertyResourceConverter(xs.getMapper(), xs
    //            .getReflectionProvider()), XStream.PRIORITY_VERY_HIGH);
    //        xs.registerConverter(new ScheduledServiceResourceResponseConverter(xs.getMapper(), xs
    //            .getReflectionProvider()), XStream.PRIORITY_VERY_HIGH); // strips the
    // class="class.name" attribute from data

    //        // Maven POM
    //        xs.alias("project", Model.class);
    //        // Maven model
    //        xs.omitField(Model.class, "modelEncoding");
    //        xs.omitField(ModelBase.class, "modelEncoding");
    //        xs.omitField(Scm.class, "modelEncoding");

    // omitting modelEncoding
    //        xs.omitField(ErrorResponse.class, "modelEncoding");
    //        xs.omitField(ErrorMessage.class, "modelEncoding");
    xs.alias("nexus-error", ErrorResponse.class);
    xs.alias("error", ErrorMessage.class);
    xs.registerLocalConverter(
        ErrorResponse.class, "errors", new AliasingListConverter(ErrorMessage.class, "error"));

    //        xs.omitField(ContentListResourceResponse.class, "modelEncoding");
    //        xs.omitField(ContentListResource.class, "modelEncoding");
    xs.alias("content", ContentListResourceResponse.class);
    xs.alias("content-item", ContentListResource.class);
    xs.registerLocalConverter(
        ContentListResourceResponse.class,
        "data",
        new AliasingListConverter(ContentListResource.class, "content-item"));

    //        xs.omitField(RepositoryResourceResponse.class, "modelEncoding");
    //        xs.omitField(RepositoryBaseResource.class, "modelEncoding");
    //        xs.omitField(RepositoryResource.class, "modelEncoding");
    //        xs.omitField(RepositoryProxyResource.class, "modelEncoding");
    //        xs.omitField(RepositoryShadowResource.class, "modelEncoding");
    //        xs.omitField(RepositoryResourceRemoteStorage.class, "modelEncoding");
    xs.alias("repository", RepositoryResourceResponse.class);

    //        xs.omitField(RepositoryListResourceResponse.class, "modelEncoding");
    //        xs.omitField(RepositoryListResource.class, "modelEncoding");
    xs.alias("repositories", RepositoryListResourceResponse.class);
    // xstream.alias( "repositories-item", RepositoryListResource.class);
    xs.registerLocalConverter(
        RepositoryListResourceResponse.class,
        "data",
        new AliasingListConverter(RepositoryListResource.class, "repositories-item"));

    xs.alias("repositoryTypes", NexusRepositoryTypeListResourceResponse.class);
    xs.registerLocalConverter(
        NexusRepositoryTypeListResourceResponse.class,
        "data",
        new AliasingListConverter(NexusRepositoryTypeListResource.class, "repositoryType"));

    //        xs.omitField(RepositoryStatusResourceResponse.class, "modelEncoding");
    //        xs.omitField(RepositoryStatusResource.class, "modelEncoding");
    xs.alias("repository-status", RepositoryStatusResourceResponse.class);

    //        xs.omitField(RepositoryStatusListResourceResponse.class, "modelEncoding");
    //        xs.omitField(RepositoryStatusListResource.class, "modelEncoding");
    xs.alias("repository-status-list", RepositoryStatusListResourceResponse.class);
    // xstream.alias( "repository-status-list-item", RepositoryStatusListResource.class);
    xs.registerLocalConverter(
        RepositoryStatusListResourceResponse.class,
        "data",
        new AliasingListConverter(
            RepositoryStatusListResource.class, "repository-status-list-item"));

    //        xs.omitField(RepositoryMetaResourceResponse.class, "modelEncoding");
    //        xs.omitField(RepositoryMetaResource.class, "modelEncoding");
    xs.alias("repository-meta-data", RepositoryMetaResourceResponse.class);

    //        xs.omitField(RepositoryGroupListResourceResponse.class, "modelEncoding");
    //        xs.omitField(RepositoryGroupListResource.class, "modelEncoding");
    xs.alias("repo-group-list", RepositoryGroupListResourceResponse.class);
    // xstream.alias( "repo-group-list-item", RepositoryGroupListResource.class);
    // xstream.alias( "repo-group-member", RepositoryGroupMemberRepository.class);
    xs.registerLocalConverter(
        RepositoryGroupListResource.class,
        "repositories",
        new AliasingListConverter(RepositoryGroupMemberRepository.class, "repo-group-member"));
    xs.registerLocalConverter(
        RepositoryGroupResource.class,
        "repositories",
        new AliasingListConverter(RepositoryGroupMemberRepository.class, "repo-group-member"));
    xs.registerLocalConverter(
        RepositoryGroupListResourceResponse.class,
        "data",
        new AliasingListConverter(RepositoryGroupListResource.class, "repo-group-list-item"));

    //        xs.omitField(RepositoryGroupResourceResponse.class, "modelEncoding");
    //        xs.omitField(RepositoryGroupResource.class, "modelEncoding");
    //        xs.omitField(RepositoryGroupMemberRepository.class, "modelEncoding");
    xs.alias("repo-group", RepositoryGroupResourceResponse.class);

    //        xs.omitField(RepositoryRouteListResourceResponse.class, "modelEncoding");
    //        xs.omitField(RepositoryRouteListResource.class, "modelEncoding");
    xs.alias("repo-routes-list", RepositoryRouteListResourceResponse.class);
    // xstream.alias( "repo-routes-list-item", RepositoryRouteListResource.class);
    // xstream.alias( "repo-routes-member", RepositoryRouteMemberRepository.class);
    xs.registerLocalConverter(
        RepositoryRouteListResourceResponse.class,
        "data",
        new AliasingListConverter(RepositoryRouteListResource.class, "repo-routes-list-item"));
    xs.registerLocalConverter(
        RepositoryRouteListResource.class,
        "repositories",
        new AliasingListConverter(RepositoryRouteMemberRepository.class, "repo-routes-member"));

    //        xs.omitField(RepositoryRouteResourceResponse.class, "modelEncoding");
    //        xs.omitField(RepositoryRouteResource.class, "modelEncoding");
    //        xs.omitField(RepositoryRouteMemberRepository.class, "modelEncoding");
    xs.alias("repo-route", RepositoryRouteResourceResponse.class);
    xs.registerLocalConverter(
        RepositoryRouteResource.class,
        "repositories",
        new AliasingListConverter(RepositoryRouteMemberRepository.class, "repository"));

    //        xs.omitField(GlobalConfigurationListResourceResponse.class, "modelEncoding");
    //        xs.omitField(GlobalConfigurationListResource.class, "modelEncoding");
    xs.alias("global-settings-list", GlobalConfigurationListResourceResponse.class);
    // xstream.alias( "global-settings-list-item", GlobalConfigurationListResource.class);
    xs.registerLocalConverter(
        GlobalConfigurationListResourceResponse.class,
        "data",
        new AliasingListConverter(
            GlobalConfigurationListResource.class, "global-settings-list-item"));

    //        xs.omitField(GlobalConfigurationResourceResponse.class, "modelEncoding");
    //        xs.omitField(GlobalConfigurationResource.class, "modelEncoding");
    //        xs.omitField(RemoteConnectionSettings.class, "modelEncoding");
    //        xs.omitField(RemoteHttpProxySettings.class, "modelEncoding");
    //        xs.omitField(RestApiSettings.class, "modelEncoding");
    //        xs.omitField(AuthenticationSettings.class, "modelEncoding");
    //        xs.omitField(SmtpSettings.class, "modelEncoding");
    //        xs.omitField(ErrorReportingSettings.class, "modelEncoding");
    xs.alias("global-settings", GlobalConfigurationResourceResponse.class);

    //        xs.omitField(WastebasketResource.class, "modelEncoding");
    //        xs.omitField(WastebasketResourceResponse.class, "modelEncoding");
    xs.alias("wastebasket", WastebasketResourceResponse.class);

    //        xs.omitField(LogsListResourceResponse.class, "modelEncoding");
    //        xs.omitField(LogsListResource.class, "modelEncoding");
    xs.alias("logs-list", LogsListResourceResponse.class);
    // xstream.alias( "logs-list-item", LogsListResource.class);
    xs.registerLocalConverter(
        LogsListResourceResponse.class,
        "data",
        new AliasingListConverter(LogsListResource.class, "logs-list-item"));

    //        xs.omitField(ConfigurationsListResourceResponse.class, "modelEncoding");
    //        xs.omitField(ConfigurationsListResource.class, "modelEncoding");
    xs.alias("configs-list", ConfigurationsListResourceResponse.class);
    // xstream.alias( "configs-list-tem", ConfigurationsListResource.class);
    xs.registerLocalConverter(
        ConfigurationsListResourceResponse.class,
        "data",
        new AliasingListConverter(ConfigurationsListResource.class, "configs-list-tem"));

    //        xs.omitField(FeedListResourceResponse.class, "modelEncoding");
    //        xs.omitField(FeedListResource.class, "modelEncoding");
    xs.alias("feeds-list", FeedListResourceResponse.class);
    // xstream.alias( "feeds-list-item", FeedListResource.class);
    xs.registerLocalConverter(
        FeedListResourceResponse.class,
        "data",
        new AliasingListConverter(FeedListResource.class, "feeds-list-item"));

    //        xs.omitField(SearchResponse.class, "modelEncoding");
    xs.alias("search-results", SearchResponse.class);
    xs.registerLocalConverter(
        SearchResponse.class, "data", new AliasingListConverter(NexusArtifact.class, "artifact"));

    //        xs.omitField(NexusResponse.class, "modelEncoding");
    //        xs.omitField(NexusArtifact.class, "modelEncoding");
    xs.alias("artifact", NexusArtifact.class);

    //        xs.omitField(AuthenticationLoginResourceResponse.class, "modelEncoding");
    //        xs.omitField(AuthenticationLoginResource.class, "modelEncoding");
    //        xs.omitField(AuthenticationClientPermissions.class, "modelEncoding");
    //        xs.omitField(NexusAuthenticationClientPermissions.class, "modelEncoding");

    // Look at NexusAuthenticationLoginResourceConverter, we are only converting the
    // clientPermissions field
    xs.alias("authentication-login", AuthenticationLoginResourceResponse.class);

    xs.registerLocalConverter(
        AuthenticationClientPermissions.class,
        "permissions",
        new AliasingListConverter(ClientPermission.class, "permission"));

    //        xs.omitField(ClientPermission.class, "modelEncoding");

    //        xs.omitField(StatusResource.class, "modelEncoding");
    //        xs.omitField(StatusResourceResponse.class, "modelEncoding");
    //        xs.omitField(StatusConfigurationValidationResponse.class, "modelEncoding");
    xs.alias("status", StatusResourceResponse.class);
    xs.registerLocalConverter(
        StatusConfigurationValidationResponse.class,
        "validationErrors",
        new AliasingListConverter(String.class, "error"));
    xs.registerLocalConverter(
        StatusConfigurationValidationResponse.class,
        "validationWarnings",
        new AliasingListConverter(String.class, "warning"));

    //        xs.omitField(ScheduledServiceListResource.class, "modelEncoding");
    //        xs.omitField(ScheduledServiceListResourceResponse.class, "modelEncoding");
    //        xs.omitField(ScheduledServiceBaseResource.class, "modelEncoding");
    //        xs.omitField(ScheduledServicePropertyResource.class, "modelEncoding");
    //        xs.omitField(ScheduledServiceOnceResource.class, "modelEncoding");
    //        xs.omitField(ScheduledServiceDailyResource.class, "modelEncoding");
    //        xs.omitField(ScheduledServiceAdvancedResource.class, "modelEncoding");
    //        xs.omitField(ScheduledServiceMonthlyResource.class, "modelEncoding");
    //        xs.omitField(ScheduledServiceWeeklyResource.class, "modelEncoding");
    //        xs.omitField(ScheduledServiceResourceResponse.class, "modelEncoding");
    //        xs.omitField(ScheduledServiceTypeResourceResponse.class, "modelEncoding");
    //        xs.omitField(ScheduledServiceTypeResource.class, "modelEncoding");
    //        xs.omitField(ScheduledServiceTypePropertyResource.class, "modelEncoding");
    //        xs.omitField(ScheduledServiceResourceStatus.class, "modelEncoding");
    //        xs.omitField(ScheduledServiceResourceStatusResponse.class, "modelEncoding");
    xs.alias("schedules-list", ScheduledServiceListResourceResponse.class);
    // xstream.alias( "schedules-list-item", ScheduledServiceListResource.class );
    xs.alias("scheduled-task", ScheduledServiceResourceResponse.class);
    // xstream.alias( "scheduled-task-property", ScheduledServicePropertyResource.class );
    xs.alias("schedule-types", ScheduledServiceTypeResourceResponse.class);
    xs.alias("schedule-type", ScheduledServiceTypeResource.class);
    // xstream.alias( "schedule-type-property", ScheduledServiceTypePropertyResource.class );
    xs.registerLocalConverter(
        ScheduledServiceBaseResource.class,
        "properties",
        new AliasingListConverter(
            ScheduledServicePropertyResource.class, "scheduled-task-property"));
    xs.registerLocalConverter(
        ScheduledServiceWeeklyResource.class,
        "recurringDay",
        new AliasingListConverter(String.class, "day"));
    xs.registerLocalConverter(
        ScheduledServiceTypeResourceResponse.class,
        "data",
        new AliasingListConverter(ScheduledServiceTypeResource.class, "schedule-type"));
    xs.registerLocalConverter(
        ScheduledServiceTypeResource.class,
        "properties",
        new AliasingListConverter(
            ScheduledServiceTypePropertyResource.class, "scheduled-task-property"));
    xs.registerLocalConverter(
        ScheduledServiceListResourceResponse.class,
        "data",
        new AliasingListConverter(ScheduledServiceListResource.class, "schedules-list-item"));

    //        xs.omitField(UserListResourceResponse.class, "modelEncoding");
    //        xs.omitField(UserResourceRequest.class, "modelEncoding");
    //        xs.omitField(UserResourceResponse.class, "modelEncoding");
    //        xs.omitField(UserResource.class, "modelEncoding");
    //        xs.omitField(UserForgotPasswordRequest.class, "modelEncoding");
    //        xs.omitField(UserForgotPasswordResource.class, "modelEncoding");
    //        xs.omitField(UserChangePasswordRequest.class, "modelEncoding");
    //        xs.omitField(UserChangePasswordResource.class, "modelEncoding");
    xs.alias("users-list", UserListResourceResponse.class);
    // xstream.alias( "users-list-item", UserResource.class );
    xs.alias("user-request", UserResourceRequest.class);
    xs.alias("user-response", UserResourceResponse.class);
    xs.alias("user-forgotpw", UserForgotPasswordRequest.class);
    xs.alias("user-changepw", UserChangePasswordRequest.class);
    xs.registerLocalConverter(
        UserResource.class, "roles", new AliasingListConverter(String.class, "role"));
    xs.registerLocalConverter(
        UserListResourceResponse.class,
        "data",
        new AliasingListConverter(UserResource.class, "users-list-item"));

    //        xs.omitField(RoleListResourceResponse.class, "modelEncoding");
    //        xs.omitField(RoleResource.class, "modelEncoding");
    //        xs.omitField(RoleResourceRequest.class, "modelEncoding");
    //        xs.omitField(RoleResourceResponse.class, "modelEncoding");
    xs.alias("roles-list", RoleListResourceResponse.class);
    // xstream.alias( "roles-list-item", RoleResource.class );
    xs.alias("role-request", RoleResourceRequest.class);
    xs.alias("role-response", RoleResourceResponse.class);
    xs.registerLocalConverter(
        RoleListResourceResponse.class,
        "data",
        new AliasingListConverter(RoleResource.class, "roles-list-item"));
    xs.registerLocalConverter(
        RoleResource.class, "roles", new AliasingListConverter(String.class, "role"));
    xs.registerLocalConverter(
        RoleResource.class, "privileges", new AliasingListConverter(String.class, "privilege"));

    //        xs.omitField(PrivilegeResourceRequest.class, "modelEncoding");
    //        xs.omitField(PrivilegeResource.class, "modelEncoding");
    //        xs.omitField(PrivilegeStatusResource.class, "modelEncoding");
    //        xs.omitField(PrivilegeListResourceResponse.class, "modelEncoding");
    //        xs.omitField(PrivilegeStatusResourceResponse.class, "modelEncoding");
    //        xs.omitField(PrivilegeProperty.class, "modelEncoding");
    //        xs.omitField(PrivilegeTypeResource.class, "modelEncoding");
    //        xs.omitField(PrivilegeTypePropertyResource.class, "modelEncoding");
    //        xs.omitField(PrivilegeTypeResourceResponse.class, "modelEncoding");
    xs.alias("privilege-request", PrivilegeResourceRequest.class);
    xs.alias("privilege-list-response", PrivilegeListResourceResponse.class);
    xs.alias("privilege-status-response", PrivilegeStatusResourceResponse.class);
    xs.alias("privilege-type-response", PrivilegeTypeResourceResponse.class);
    xs.aliasField("methods", PrivilegeResource.class, "method");
    xs.registerLocalConverter(
        PrivilegeListResourceResponse.class,
        "data",
        new AliasingListConverter(PrivilegeStatusResource.class, "privilege-item"));
    xs.registerLocalConverter(
        PrivilegeResource.class, "method", new AliasingListConverter(String.class, "method"));
    xs.registerLocalConverter(
        PrivilegeStatusResource.class,
        "properties",
        new AliasingListConverter(PrivilegeProperty.class, "privilege-property"));
    xs.registerLocalConverter(
        PrivilegeTypeResourceResponse.class,
        "data",
        new AliasingListConverter(PrivilegeTypeResource.class, "privilege-type"));
    xs.registerLocalConverter(
        PrivilegeTypeResource.class,
        "properties",
        new AliasingListConverter(PrivilegeTypePropertyResource.class, "privilege-type-property"));

    //        xs.omitField(NFCResourceResponse.class, "modelEncoding");
    //        xs.omitField(NFCResource.class, "modelEncoding");
    //        xs.omitField(NFCRepositoryResource.class, "modelEncoding");
    xs.alias("nfc-info", NFCResourceResponse.class);
    // xstream.alias( "nfc-repo-info", NFCRepositoryResource.class );
    xs.registerLocalConverter(
        NFCResource.class,
        "nfcContents",
        new AliasingListConverter(NFCRepositoryResource.class, "nfc-repo-info"));
    xs.registerLocalConverter(
        NFCRepositoryResource.class, "nfcPaths", new AliasingListConverter(String.class, "path"));

    //        xs.omitField(RepositoryTargetListResourceResponse.class, "modelEncoding");
    //        xs.omitField(RepositoryTargetListResource.class, "modelEncoding");
    //        xs.omitField(RepositoryTargetResourceResponse.class, "modelEncoding");
    //        xs.omitField(RepositoryTargetResource.class, "modelEncoding");
    xs.alias("repo-targets-list", RepositoryTargetListResourceResponse.class);
    // xstream.alias( "repo-targets-list-item", RepositoryTargetListResource.class );
    xs.alias("repo-target", RepositoryTargetResourceResponse.class);
    xs.registerLocalConverter(
        RepositoryTargetResource.class,
        "patterns",
        new AliasingListConverter(String.class, "pattern"));
    xs.registerLocalConverter(
        RepositoryTargetListResourceResponse.class,
        "data",
        new AliasingListConverter(RepositoryTargetListResource.class, "repo-targets-list-item"));

    //        xs.omitField(RepositoryContentClassListResourceResponse.class, "modelEncoding");
    //        xs.omitField(RepositoryContentClassListResource.class, "modelEncoding");
    xs.alias("repo-content-classes-list", RepositoryContentClassListResourceResponse.class);
    // xstream.alias( "repo-content-classes-list-item", RepositoryContentClassListResource.class );
    xs.registerLocalConverter(
        RepositoryContentClassListResourceResponse.class,
        "data",
        new AliasingListConverter(
            RepositoryContentClassListResource.class, "repo-content-classes-list-item"));

    //        xs.omitField(PlexusComponentListResourceResponse.class, "modelEncoding");
    //        xs.omitField(PlexusComponentListResource.class, "modelEncoding");
    xs.alias("components-list", PlexusComponentListResourceResponse.class);
    xs.alias("component", PlexusComponentListResource.class);
    xs.registerLocalConverter(
        PlexusComponentListResourceResponse.class,
        "data",
        new AliasingListConverter(PlexusComponentListResource.class, "component"));

    //        xs.omitField(UserToRoleResourceRequest.class, "modelEncoding");
    //        xs.omitField(UserToRoleResource.class, "modelEncoding");
    xs.alias("user-to-role", UserToRoleResourceRequest.class);
    xs.registerLocalConverter(
        UserToRoleResource.class, "roles", new AliasingListConverter(String.class, "role"));

    //        xs.omitField(PlexusUserResourceResponse.class, "modelEncoding");
    xs.alias("plexus-user", PlexusUserResourceResponse.class);
    //        xs.omitField(PlexusUserResource.class, "modelEncoding");
    xs.registerLocalConverter(
        PlexusUserResource.class,
        "roles",
        new AliasingListConverter(PlexusRoleResource.class, "plexus-role"));

    //        xs.omitField(PlexusRoleResource.class, "modelEncoding");
    xs.alias("plexus-role", PlexusRoleResource.class);

    //        xs.omitField(PlexusUserListResourceResponse.class, "modelEncoding");
    xs.alias("plexus-user-list", PlexusUserListResourceResponse.class);
    xs.registerLocalConverter(
        PlexusUserListResourceResponse.class,
        "data",
        new AliasingListConverter(PlexusUserResource.class, "plexus-user"));

    //        xs.omitField(ExternalRoleMappingResourceResponse.class, "modelEncoding");
    xs.alias("external-role-mapping", ExternalRoleMappingResourceResponse.class);
    xs.registerLocalConverter(
        ExternalRoleMappingResourceResponse.class,
        "data",
        new AliasingListConverter(ExternalRoleMappingResource.class, "mapping"));
    //        xs.omitField(ExternalRoleMappingResource.class, "modelEncoding");
    xs.alias("mapping", ExternalRoleMappingResource.class);
    xs.registerLocalConverter(
        ExternalRoleMappingResource.class,
        "mappedRoles",
        new AliasingListConverter(PlexusRoleResource.class, "plexus-role"));

    //        xs.omitField(PlexusRoleListResourceResponse.class, "modelEncoding");
    xs.alias("plexus-roles", PlexusRoleListResourceResponse.class);
    xs.registerLocalConverter(
        PlexusRoleListResourceResponse.class,
        "data",
        new AliasingListConverter(PlexusRoleResource.class, "plexus-role"));

    //        xs.omitField(PlexusUserSearchCriteriaResourceRequest.class, "modelEncoding");
    xs.alias("user-search", PlexusUserSearchCriteriaResourceRequest.class);
    //        xs.omitField(PlexusUserSearchCriteriaResource.class, "modelEncoding");

    //        xs.omitField(ErrorReportRequest.class, "modelEncoding");
    //        xs.omitField(ErrorReportRequestDTO.class, "modelEncoding");
    //        xs.omitField(ErrorReportResponse.class, "modelEncoding");
    //        xs.omitField(ErrorReportResponseDTO.class, "modelEncoding");

    xs.alias("error-report-request", ErrorReportRequest.class);
    xs.alias("error-report-response", ErrorReportResponse.class);

    //        xs.omitField(MirrorResourceListRequest.class, "modelEncoding");
    //        xs.omitField(MirrorResourceListResponse.class, "modelEncoding");
    //        xs.omitField(MirrorStatusResourceListResponse.class, "modelEncoding");
    //        xs.omitField(MirrorResource.class, "modelEncoding");
    //        xs.omitField(MirrorStatusResource.class, "modelEncoding");

    xs.alias("mirror-list-request", MirrorResourceListRequest.class);
    xs.alias("mirror-list-response", MirrorResourceListResponse.class);
    xs.alias("mirror-status-list-response", MirrorStatusResourceListResponse.class);

    xs.registerLocalConverter(
        MirrorResourceListRequest.class,
        "data",
        new AliasingListConverter(MirrorResource.class, "mirrorResource"));
    xs.registerLocalConverter(
        MirrorResourceListResponse.class,
        "data",
        new AliasingListConverter(MirrorResource.class, "mirrorResource"));
    xs.registerLocalConverter(
        MirrorStatusResourceListResponse.class,
        "data",
        new AliasingListConverter(MirrorStatusResource.class, "mirrorResource"));

    return xs;
  }
  /**
   * Configure the XStream instance with this marshaller's bean properties.
   *
   * @param xstream the {@code XStream} instance
   */
  protected void configureXStream(XStream xstream) {
    if (this.converters != null) {
      for (int i = 0; i < this.converters.length; i++) {
        if (this.converters[i] instanceof Converter) {
          xstream.registerConverter((Converter) this.converters[i], i);
        } else if (this.converters[i] instanceof SingleValueConverter) {
          xstream.registerConverter((SingleValueConverter) this.converters[i], i);
        } else {
          throw new IllegalArgumentException(
              "Invalid ConverterMatcher [" + this.converters[i] + "]");
        }
      }
    }

    if (this.marshallingStrategy != null) {
      xstream.setMarshallingStrategy(this.marshallingStrategy);
    }
    if (this.mode != null) {
      xstream.setMode(this.mode);
    }

    try {
      if (this.aliases != null) {
        Map<String, Class<?>> classMap = toClassMap(this.aliases);
        for (Map.Entry<String, Class<?>> entry : classMap.entrySet()) {
          xstream.alias(entry.getKey(), entry.getValue());
        }
      }
      if (this.aliasesByType != null) {
        Map<String, Class<?>> classMap = toClassMap(this.aliasesByType);
        for (Map.Entry<String, Class<?>> entry : classMap.entrySet()) {
          xstream.aliasType(entry.getKey(), entry.getValue());
        }
      }
      if (this.fieldAliases != null) {
        for (Map.Entry<String, String> entry : this.fieldAliases.entrySet()) {
          String alias = entry.getValue();
          String field = entry.getKey();
          int idx = field.lastIndexOf('.');
          if (idx != -1) {
            String className = field.substring(0, idx);
            Class<?> clazz = ClassUtils.forName(className, this.beanClassLoader);
            String fieldName = field.substring(idx + 1);
            xstream.aliasField(alias, clazz, fieldName);
          } else {
            throw new IllegalArgumentException("Field name [" + field + "] does not contain '.'");
          }
        }
      }
    } catch (ClassNotFoundException ex) {
      throw new IllegalStateException("Failed to load specified alias class", ex);
    }

    if (this.useAttributeForTypes != null) {
      for (Class<?> type : this.useAttributeForTypes) {
        xstream.useAttributeFor(type);
      }
    }
    if (this.useAttributeFor != null) {
      for (Map.Entry<?, ?> entry : this.useAttributeFor.entrySet()) {
        if (entry.getKey() instanceof String) {
          if (entry.getValue() instanceof Class) {
            xstream.useAttributeFor((String) entry.getKey(), (Class<?>) entry.getValue());
          } else {
            throw new IllegalArgumentException(
                "'useAttributesFor' takes Map<String, Class> when using a map key of type String");
          }
        } else if (entry.getKey() instanceof Class) {
          Class<?> key = (Class<?>) entry.getKey();
          if (entry.getValue() instanceof String) {
            xstream.useAttributeFor(key, (String) entry.getValue());
          } else if (entry.getValue() instanceof List) {
            @SuppressWarnings("unchecked")
            List<Object> listValue = (List<Object>) entry.getValue();
            for (Object element : listValue) {
              if (element instanceof String) {
                xstream.useAttributeFor(key, (String) element);
              }
            }
          } else {
            throw new IllegalArgumentException(
                "'useAttributesFor' property takes either Map<Class, String> "
                    + "or Map<Class, List<String>> when using a map key of type Class");
          }
        } else {
          throw new IllegalArgumentException(
              "'useAttributesFor' property takes either a map key of type String or Class");
        }
      }
    }

    if (this.implicitCollections != null) {
      for (Map.Entry<Class<?>, String> entry : this.implicitCollections.entrySet()) {
        String[] collectionFields = StringUtils.commaDelimitedListToStringArray(entry.getValue());
        for (String collectionField : collectionFields) {
          xstream.addImplicitCollection(entry.getKey(), collectionField);
        }
      }
    }
    if (this.omittedFields != null) {
      for (Map.Entry<Class<?>, String> entry : this.omittedFields.entrySet()) {
        String[] fields = StringUtils.commaDelimitedListToStringArray(entry.getValue());
        for (String field : fields) {
          xstream.omitField(entry.getKey(), field);
        }
      }
    }

    if (this.annotatedClasses != null) {
      xstream.processAnnotations(this.annotatedClasses);
    }
    if (this.autodetectAnnotations) {
      xstream.autodetectAnnotations(true);
    }
  }
  static {
    xstream.registerConverter(new JodaDateTimeXStreamConverter());
    xstream.addDefaultImplementation(ArrayList.class, List.class);

    xstream.addImplicitCollection(CHistoryItem.class, "attachments", CAttachment.class);
    xstream.alias("attachment", CAttachment.class);

    xstream.alias("organisation", COrganisation.class);
    xstream.alias("person", CPerson.class);

    xstream.alias("address", CAddress.class);
    xstream.alias("website", CWebsite.class);
    xstream.alias("email", CEmail.class);
    xstream.alias("phone", CPhone.class);

    xstream.alias("tags", CTags.class);
    xstream.aliasAttribute(CTags.class, "size", "size");
    xstream.addImplicitCollection(CTags.class, "tags", CTag.class);
    xstream.alias("tag", CTag.class);

    xstream.alias("tasks", CTasks.class);
    xstream.aliasAttribute(CTasks.class, "size", "size");
    xstream.addImplicitCollection(CTasks.class, "tasks", CTask.class);
    xstream.alias("task", CTask.class);

    xstream.alias("tracks", CTracks.class);
    xstream.addImplicitCollection(CTracks.class, "tracks", CTrack.class);
    xstream.alias("track", CTrack.class);

    xstream.alias("users", CUsers.class);
    xstream.addImplicitCollection(CUsers.class, "users", CUser.class);
    xstream.alias("user", CUser.class);

    xstream.alias("history", CHistory.class);
    xstream.aliasAttribute(CHistory.class, "size", "size");
    xstream.addImplicitCollection(CHistory.class, "historyItems", CHistoryItem.class);
    xstream.alias("historyItem", CHistoryItem.class);

    xstream.alias("parties", CParties.class);
    xstream.aliasAttribute(CParties.class, "size", "size");
    xstream.addImplicitCollection(CParties.class, "organisations", COrganisation.class);
    xstream.addImplicitCollection(CParties.class, "persons", CPerson.class);

    xstream.alias("customField", CCustomField.class);
    xstream.aliasField("boolean", CCustomField.class, "bool");
    xstream.alias("customFields", CCustomFields.class);
    xstream.aliasAttribute(CCustomFields.class, "size", "size");
    xstream.addImplicitCollection(CCustomFields.class, "customFields", CCustomField.class);

    xstream.alias("customFieldDefinition", CCustomFieldDefinition.class);
    xstream.alias("customFieldDefinitions", CCustomFieldDefinitions.class);
    xstream.addImplicitCollection(
        CCustomFieldDefinitions.class, "customFieldDefinitions", CCustomFieldDefinition.class);

    xstream.alias("opportunities", COpportunities.class);
    xstream.addImplicitCollection(COpportunities.class, "opportunities", COpportunity.class);
    xstream.alias("opportunity", COpportunity.class);

    xstream.alias("milestones", CMilestones.class);
    xstream.addImplicitCollection(CMilestones.class, "milestones", CMilestone.class);
    xstream.alias("milestone", CMilestone.class);
  }
Ejemplo n.º 16
0
  @Override
  protected Object doJob() {

    String message = "init";
    String xmlString = "init";
    FileOutputStream fileOutputStream = null;
    OutputStreamWriter writer = null;
    try {
      String header = "Удаление объекта";

      String[] uri = request.getRequestURI().split("/");
      String entityType = uri[uri.length - 2];
      String action = uri[uri.length - 1];

      String btnSubmitText = "Удалить";

      List<AlertInfo> alerts = new ArrayList<AlertInfo>();
      alerts.add(
          new AlertInfo(
              "alert-success",
              "<strong>Удален объект!</strong> Наименование <i class='name'></i>."));
      alerts.add(
          new AlertInfo(
              "alert-info",
              "<strong>Внимание!</strong> Объект не существует. Наименование <i class='name'></i>."));
      alerts.add(
          new AlertInfo(
              "alert-danger",
              "<strong>Ошибка!</strong> Объект не удален. Наименование <i class='name'></i>."));

      List<InputInfo> inputs = new ArrayList<InputInfo>();
      inputs.add(new InputInfo("text", "name", "Наименование", "required"));

      ActionPage actionPage =
          new ActionPage(header, action, entityType, btnSubmitText, alerts, inputs);

      String fullFileName =
          String.format(
              "D:/ROMzes/Development/Projects/ItemReg/web/WEB-INF/action-pages/%s/%s.xml",
              entityType, action);
      // String fileName = "/WEB-INF/itemreg.xml" ;
      // String fullFileName = servletContext.getRealPath(fileName);

      fileOutputStream = new FileOutputStream(fullFileName);
      writer = new OutputStreamWriter(fileOutputStream, Charset.forName("UTF-8"));
      XStream xstream = new XStream();
      xstream.alias("Input", InputInfo.class);
      xstream.alias("Alert", AlertInfo.class);
      xstream.alias("ActionPage", ActionPage.class);
      xstream.aliasField("Type", InputInfo.class, "_type");
      xstream.aliasField("Name", InputInfo.class, "_name");
      xstream.aliasField("Label", InputInfo.class, "_label");
      xstream.aliasField("Validation", InputInfo.class, "_validation");
      xstream.aliasField("CssClass", AlertInfo.class, "_cssClass");
      xstream.aliasField("Message", AlertInfo.class, "_message");
      xstream.aliasField("Header", ActionPage.class, "_header");
      xstream.aliasField("Action", ActionPage.class, "_action");
      xstream.aliasField("EntityType", ActionPage.class, "_entityType");
      xstream.aliasField("BtnSubmitText", ActionPage.class, "_btnSubmitText");
      xstream.aliasField("Alerts", ActionPage.class, "_alerts");
      xstream.aliasField("Inputs", ActionPage.class, "_inputs");
      xstream.toXML(actionPage, writer);

      message = "ok";
    } catch (Exception ex) {
      message = ex.getMessage();
    } finally {
      try {
        if (fileOutputStream != null) {
          fileOutputStream.close();
        }
        if (writer != null) {
          writer.close();
        }
      } catch (Exception innerEx) {
        message += "\ninner: " + innerEx.getMessage();
      }
    }
    return message;
  }
Ejemplo n.º 17
0
  public static XStream buildXStream() {
    XStream xstream =
        new XStream() {
          @Override
          protected MapperWrapper wrapMapper(MapperWrapper next) {
            return new MapperWrapper(next) {
              @Override
              public boolean shouldSerializeMember(Class definedIn, String fieldName) {
                return definedIn != Object.class
                    && super.shouldSerializeMember(definedIn, fieldName);
              }
            };
          }
        };

    // product
    xstream.alias("products", ShopifyProductGroup.class);
    xstream.alias("product", ShopifyProduct.class);
    xstream.aliasField("body-html", ShopifyProduct.class, "bodyHtml");
    xstream.aliasField("created-at", ShopifyProduct.class, "createdAt");
    xstream.aliasField("product-type", ShopifyProduct.class, "productType");
    xstream.aliasField("published-at", ShopifyProduct.class, "publishedAt");
    xstream.aliasField("template-suffix", ShopifyProduct.class, "templateSuffix");
    xstream.aliasField("updated-at", ShopifyProduct.class, "updatedAt");

    // product-variant
    xstream.alias("variant", ShopifyVariant.class);
    xstream.aliasField("compare-at-price", ShopifyVariant.class, "compareAtPrice");
    xstream.aliasField("created-at", ShopifyVariant.class, "createdAt");
    xstream.aliasField("fulfillment-service", ShopifyVariant.class, "fulfillmentService");
    xstream.aliasField("inventory-management", ShopifyVariant.class, "inventoryManagement");
    xstream.aliasField("inventory-policy", ShopifyVariant.class, "inventoryPolicy");
    xstream.aliasField("inventory-quantity", ShopifyVariant.class, "inventoryQuantity");
    xstream.aliasField("product-id", ShopifyVariant.class, "productId");
    xstream.aliasField("requires-shipping", ShopifyVariant.class, "requiresShipping");
    xstream.aliasField("updated-at", ShopifyVariant.class, "updatedAt");

    // product-image
    xstream.alias("image", ShopifyImage.class);
    xstream.aliasField("created-at", ShopifyImage.class, "createdAt");
    xstream.aliasField("product-id", ShopifyImage.class, "productId");
    xstream.aliasField("updated-at", ShopifyImage.class, "updatedAt");

    // product-option
    xstream.alias("option", ShopifyOption.class);

    // order
    xstream.alias("order", ShopifyOrder.class);
    xstream.aliasField("buyer-accepts-marketing", ShopifyOrder.class, "buyerAcceptsMarketing");
    xstream.aliasField("closed-at", ShopifyOrder.class, "closedAt");
    xstream.aliasField("created-at", ShopifyOrder.class, "createdAt");
    xstream.aliasField("financial-status", ShopifyOrder.class, "financialStatus");
    xstream.aliasField("fulfillment-status", ShopifyOrder.class, "fulfillmentStatus");
    xstream.aliasField("landing-site", ShopifyOrder.class, "landingSite");
    xstream.aliasField("referring-site", ShopifyOrder.class, "referringSite");
    xstream.aliasField("subtotal-price", ShopifyOrder.class, "subtotalPrice");
    xstream.aliasField("taxes-included", ShopifyOrder.class, "taxesIncluded");
    xstream.aliasField("total-discounts", ShopifyOrder.class, "totalDiscounts");
    xstream.aliasField("total-line-items-price", ShopifyOrder.class, "totalLineItemsPrice");
    xstream.aliasField("total-price", ShopifyOrder.class, "totalPrice");
    xstream.aliasField("total-tax", ShopifyOrder.class, "totalTax");
    xstream.aliasField("total-weight", ShopifyOrder.class, "totalWeight");
    xstream.aliasField("updated-at", ShopifyOrder.class, "updatedAt");
    xstream.aliasField("browser-ip", ShopifyOrder.class, "browserIp");
    xstream.aliasField("landing-site-ref", ShopifyOrder.class, "landingSiteRef");
    xstream.aliasField("order-number", ShopifyOrder.class, "orderNumber");
    xstream.aliasField("billing-address", ShopifyOrder.class, "billingAddress");
    xstream.aliasField("shipping-address", ShopifyOrder.class, "shippingAddress");
    xstream.aliasField("line-items", ShopifyOrder.class, "lineItems");
    xstream.aliasField("shipping-lines", ShopifyOrder.class, "shippingLines");
    xstream.aliasField("tax-lines", ShopifyOrder.class, "taxLines");
    xstream.aliasField("payment-details", ShopifyOrder.class, "paymentDetails");
    xstream.aliasField("shipping-line", ShopifyOrder.class, "shippingLine");
    xstream.aliasField("note-attributes", ShopifyOrder.class, "noteAttributes");

    // order-address
    xstream.aliasField("first-name", ShopifyAddress.class, "firstName");
    xstream.aliasField("last-name", ShopifyAddress.class, "lastName");
    xstream.aliasField("country-code", ShopifyAddress.class, "countryCode");
    xstream.aliasField("province-code", ShopifyAddress.class, "provinceCode");

    // order-lineitem
    xstream.alias("line-item", ShopifyLineItem.class);
    xstream.aliasField("fulfillment-service", ShopifyLineItem.class, "fulfillmentService");
    xstream.aliasField("fulfillment-status", ShopifyLineItem.class, "fulfillmentStatus");
    xstream.aliasField("product-id", ShopifyLineItem.class, "productId");
    xstream.aliasField("requires-shipping", ShopifyLineItem.class, "requiresShipping");
    xstream.aliasField("variant-id", ShopifyLineItem.class, "variantId");
    xstream.aliasField("variant-title", ShopifyLineItem.class, "variantTitle");

    // order-shipping/tax-line
    xstream.alias("shipping-line", ShopifyShippingLine.class);
    xstream.alias("tax-line", ShopifyTaxLine.class);
    xstream.aliasField("credit-card-number", ShopifyPaymentDetails.class, "creditCardNumber");
    xstream.aliasField("credit-card-company", ShopifyPaymentDetails.class, "creditCardCompany");

    // webhook
    xstream.alias("webhooks", List.class);
    xstream.alias("webhook", ShopifyWebhook.class);

    registerConverters(xstream);

    return xstream;
  }
  /**
   * REST API Response Representation wrapper for single or multiple items expexted
   *
   * @param media MediaType expected
   * @param representation service response representation
   * @param dataClass class expected for items of the Response object
   * @param isArray if true wrap the data property else wrap the item property
   * @return Response
   */
  public static Response getResponseOrderandUserstorage(
      MediaType media, Representation representation, Class<?> dataClass, boolean isArray) {
    try {
      if (!media.isCompatible(MediaType.APPLICATION_JSON)
          && !media.isCompatible(MediaType.APPLICATION_XML)) {
        Engine.getLogger(AbstractSitoolsTestCase.class.getName())
            .warning("Only JSON or XML supported in tests");
        return null;
      }

      XStream xstream = XStreamFactory.getInstance().getXStreamReader(media);
      xstream.autodetectAnnotations(false);
      xstream.alias("response", Response.class);

      // for order
      xstream.alias("order", Order.class);

      // for userstorage
      xstream.alias("userstorage", UserStorage.class);
      xstream.alias("diskStorage", DiskStorage.class);

      if (isArray) {
        xstream.alias("item", dataClass);
        xstream.alias("item", Object.class, dataClass);
        // xstream.omitField(Response.class, "data");
        if (media.isCompatible(MediaType.APPLICATION_JSON)) {
          xstream.addImplicitCollection(Response.class, "data", dataClass);
          xstream.addImplicitCollection(Order.class, "events", Event.class);
          xstream.addImplicitCollection(Order.class, "resourceCollection", String.class);
        }

      } else {
        xstream.alias("item", dataClass);
        xstream.alias("item", Object.class, dataClass);

        if (dataClass == Order.class) {
          xstream.aliasField("order", Response.class, "item");
          if (media.isCompatible(MediaType.APPLICATION_JSON)) {
            xstream.addImplicitCollection(Order.class, "events", Event.class);
            xstream.addImplicitCollection(Order.class, "resourceCollection", String.class);
          }
        }
        if (dataClass == UserStorage.class) {
          xstream.aliasField("userstorage", Response.class, "item");
        }
      }
      xstream.aliasField("data", Response.class, "data");

      SitoolsXStreamRepresentation<Response> rep =
          new SitoolsXStreamRepresentation<Response>(representation);
      rep.setXstream(xstream);

      if (media.isCompatible(getMediaTest())) {
        Response response = rep.getObject("response");

        return response;
      } else {
        Engine.getLogger(AbstractSitoolsTestCase.class.getName())
            .warning("Only JSON or XML supported in tests");
        return null; // TODO complete test with ObjectRepresentation
      }
    } finally {
      RIAPUtils.exhaust(representation);
    }
  }