Package org.apache.commons.configuration

Examples of org.apache.commons.configuration.XMLConfiguration$XMLFileConfigurationDelegate


   */

  private ConfigDispayRules() {
    configPfad = this.helper.getGoobiConfigDirectory() + "goobi_metadataDisplayRules.xml";
    try {
      config = new XMLConfiguration(configPfad);
      config.setReloadingStrategy(new FileChangedReloadingStrategy());
      getDisplayItems();
    } catch (ConfigurationException e) {
      /*
       * no configuration file found, default configuration (textarea) will be used, nothing to do here
View Full Code Here


public class WebInterfaceConfig {

  public static List<String> getCredencials(String requestIp, String requestPassword) {
    ArrayList<String> allowed = new ArrayList<String>();
    try {
      XMLConfiguration config = new XMLConfiguration(new Helper().getGoobiConfigDirectory() +"goobi_webapi.xml");
      config.setListDelimiter('&');
      config.setReloadingStrategy(new FileChangedReloadingStrategy());

      int count = config.getMaxIndex("credentials");
      for (int i = 0; i <= count; i++) {
        String ip = config.getString("credentials(" + i + ")[@ip]");
        String password = config.getString("credentials(" + i + ")[@password]");
        if (requestIp.startsWith(ip) && requestPassword.equals(password)) {
          int countCommands = config.getMaxIndex("credentials(" + i + ").command");

          for (int j = 0; j <= countCommands; j++) {
            allowed.add(config.getString("credentials(" + i + ").command(" + j + ")[@name]"));
          }
        }
      }
    } catch (Exception e) {
      allowed = new ArrayList<String>();
View Full Code Here

    if (mySchritt.getProzess().isIstTemplate()) {
      return properties;
    }

    String path = new Helper().getGoobiConfigDirectory() + "goobi_processProperties.xml";
    XMLConfiguration config;
    try {
      config = new XMLConfiguration(path);
    } catch (ConfigurationException e) {
      logger.error(e);
      config = new XMLConfiguration();
    }
    config.setListDelimiter('&');
    config.setReloadingStrategy(new FileChangedReloadingStrategy());

    // run though all properties
    int countProperties = config.getMaxIndex("property");
    for (int i = 0; i <= countProperties; i++) {

      // general values for property
      ProcessProperty pp = new ProcessProperty();
      pp.setName(config.getString("property(" + i + ")[@name]"));
      pp.setContainer(config.getInt("property(" + i + ")[@container]"));

      // projects
      int count = config.getMaxIndex("property(" + i + ").project");
      for (int j = 0; j <= count; j++) {
        pp.getProjects().add(config.getString("property(" + i + ").project(" + j + ")"));
      }

      // project is configured
      if (pp.getProjects().contains("*") || pp.getProjects().contains(projectTitle)) {

        // showStep
        boolean containsCurrentStepTitle = false;
        count = config.getMaxIndex("property(" + i + ").showStep");
        for (int j = 0; j <= count; j++) {
          ShowStepCondition ssc = new ShowStepCondition();
          ssc.setName(config.getString("property(" + i + ").showStep(" + j + ")[@name]"));
          String access = config.getString("property(" + i + ").showStep(" + j + ")[@access]");
          boolean duplicate = config.getBoolean("property(" + i + ").showStep(" + j + ")[@duplicate]", false);
          ssc.setAccessCondition(AccessCondition.getAccessConditionByName(access));
          if (ssc.getName().equals(stepTitle)) {
            containsCurrentStepTitle = true;
            pp.setDuplicationAllowed(duplicate);
            pp.setCurrentStepAccessCondition(AccessCondition.getAccessConditionByName(access));
          }
         
          pp.getShowStepConditions().add(ssc);
        }

        // steptitle is configured
        if (containsCurrentStepTitle) {
          // showProcessGroupAccessCondition
          String groupAccess = config.getString("property(" + i + ").showProcessGroup[@access]");
          if (groupAccess != null) {
            pp.setShowProcessGroupAccessCondition(AccessCondition.getAccessConditionByName(groupAccess));
          } else {
            pp.setShowProcessGroupAccessCondition(AccessCondition.WRITE);
          }
         
          // validation expression
          pp.setValidation(config.getString("property(" + i + ").validation"));
          // type
          pp.setType(Type.getTypeByName(config.getString("property(" + i + ").type")));
          // (default) value
          pp.setValue(config.getString("property(" + i + ").defaultvalue"));

          // possible values
          count = config.getMaxIndex("property(" + i + ").value");
          for (int j = 0; j <= count; j++) {
            pp.getPossibleValues().add(config.getString("property(" + i + ").value(" + j + ")"));
          }
          properties.add(pp);
        }
      }
    }
View Full Code Here

    logger.trace("config 1");
    List<GoobiHotfolder> answer = new ArrayList<GoobiHotfolder>();
    logger.trace("config 2");

    try {
       XMLConfiguration config = new XMLConfiguration(new Helper().getGoobiConfigDirectory() + "goobi_hotfolder.xml");

      logger.trace("config 3");

      config.setListDelimiter('&');

      logger.trace("config 4");
      config.setReloadingStrategy(new FileChangedReloadingStrategy());
      logger.trace("config 5");

      int count = config.getMaxIndex("hotfolder");
      logger.trace("config 6");

      for (int i = 0; i <= count; i++) {

        logger.trace("config 7");
        String name = config.getString("hotfolder(" + i + ")[@name]");
        logger.trace("config 8");
        File folder = new File(config.getString("hotfolder(" + i + ")[@folder]"));
        logger.trace("config 9");
        Integer template = config.getInt("hotfolder(" + i + ")[@template]");
        logger.trace("config 10");

        String updateStrategy = config.getString("hotfolder(" + i + ")[@updateStrategy]");
        logger.trace("config 11");
        String collection = config.getString("hotfolder(" + i + ")[@collection]");
        logger.trace("config 12");
        if (name == null || name.equals("") || template == null) {
          logger.trace("config 13");
          break;
        }
View Full Code Here

        properties.add(pp);
      }
      return properties;
    }
    String path = new Helper().getGoobiConfigDirectory() + "goobi_processProperties.xml";
    XMLConfiguration config;
    try {
      config = new XMLConfiguration(path);
    } catch (ConfigurationException e) {
      logger.error(e);
      config = new XMLConfiguration();
    }
    config.setListDelimiter('&');
    config.setReloadingStrategy(new FileChangedReloadingStrategy());

    // run though all properties
    int countProperties = config.getMaxIndex("property");
    for (int i = 0; i <= countProperties; i++) {

      // general values for property
      ProcessProperty pp = new ProcessProperty();
      pp.setName(config.getString("property(" + i + ")[@name]"));
      pp.setContainer(config.getInt("property(" + i + ")[@container]"));

      // projects
      int count = config.getMaxIndex("property(" + i + ").project");
      for (int j = 0; j <= count; j++) {
        pp.getProjects().add(config.getString("property(" + i + ").project(" + j + ")"));
      }

      // project is configured
      if (pp.getProjects().contains("*") || pp.getProjects().contains(projectTitle)) {

        // validation expression
        pp.setValidation(config.getString("property(" + i + ").validation"));
        // type
        pp.setType(Type.getTypeByName(config.getString("property(" + i + ").type")));
        // (default) value
        pp.setValue(config.getString("property(" + i + ").defaultvalue"));

        // possible values
        count = config.getMaxIndex("property(" + i + ").value");
        for (int j = 0; j <= count; j++) {
          pp.getPossibleValues().add(config.getString("property(" + i + ").value(" + j + ")"));
        }
        logger.debug("add property A " + pp.getName() + " - " + pp.getValue() + " - " + pp.getContainer());
        properties.add(pp);

      }
View Full Code Here

 
  private void readConfigAsSample() {
    ArrayList<ProcessProperty> properties = new ArrayList<ProcessProperty>();

    String path = new Helper().getGoobiConfigDirectory() + "goobi_processProperties.xml";
    XMLConfiguration config;
    try {
      config = new XMLConfiguration(path);
    } catch (ConfigurationException e) {
      logger.error(e);
      config = new XMLConfiguration();
    }
    config.setListDelimiter('&');
    config.setReloadingStrategy(new FileChangedReloadingStrategy());

    // run though all properties
    int countProperties = config.getMaxIndex("property");
    for (int i = 0; i <= countProperties; i++) {

      // general values for property
      ProcessProperty pp = new ProcessProperty();
      pp.setName(config.getString("property(" + i + ")[@name]"));
      pp.setContainer(config.getInt("property(" + i + ")[@container]"));

      // projects
      int count = config.getMaxIndex("property(" + i + ").project");
      for (int j = 0; j <= count; j++) {
        pp.getProjects().add(config.getString("property(" + i + ").project(" + j + ")"));
      }

      // showStep
      count = config.getMaxIndex("property(" + i + ").showStep");
      for (int j = 0; j <= count; j++) {
        ShowStepCondition ssc = new ShowStepCondition();
        ssc.setName(config.getString("property(" + i + ").showStep(" + j + ")[@name]"));
        String access = config.getString("property(" + i + ").showStep(" + j + ")[@access]");
        boolean duplicate = config.getBoolean("property(" + i + ").showStep(" + j + ")[@duplicate]", false);
        ssc.setAccessCondition(AccessCondition.getAccessConditionByName(access));
        ssc.setDuplication(duplicate);
        pp.getShowStepConditions().add(ssc);
      }

      // showProcessGroupAccessCondition
      String groupAccess = config.getString("property(" + i + ").showProcessGroup[@access]");
      pp.setShowProcessGroupAccessCondition(AccessCondition.getAccessConditionByName(groupAccess));

      // validation expression
      pp.setValidation(config.getString("property(" + i + ").validation"));
      // type
      pp.setType(Type.getTypeByName(config.getString("property(" + i + ").type")));
      // (default) value
      pp.setValue(config.getString("property(" + i + ").defaultvalue"));

      // possible values
      count = config.getMaxIndex("property(" + i + ").value");
      for (int j = 0; j <= count; j++) {
        pp.getPossibleValues().add(config.getString("property(" + i + ").value(" + j + ")"));
      }
      properties.add(pp);
    }
  }
View Full Code Here

    HashMap<String, String> fields = new HashMap<String, String>();
    try {
      File file = new File(new Helper().getGoobiConfigDirectory() + "goobi_exportXml.xml");
      if (file.exists() && file.canRead()) {
        XMLConfiguration config = new XMLConfiguration(file);
        config.setListDelimiter('&');
        config.setReloadingStrategy(new FileChangedReloadingStrategy());

        int count = config.getMaxIndex(xmlpath);
        for (int i = 0; i <= count; i++) {
          String name = config.getString(xmlpath + "(" + i + ")[@name]");
          String value = config.getString(xmlpath + "(" + i + ")[@value]");
          fields.put(name, value);
        }
      }
    } catch (Exception e) {
      fields = new HashMap<String, String>();
View Full Code Here

  private HashMap<String, String> getNamespacesFromConfig() {
    HashMap<String, String> nss = new HashMap<String, String>();
    try {
      File file = new File(new Helper().getGoobiConfigDirectory() + "goobi_exportXml.xml");
      if (file.exists() && file.canRead()) {
        XMLConfiguration config = new XMLConfiguration(file);
        config.setListDelimiter('&');
        config.setReloadingStrategy(new FileChangedReloadingStrategy());

        int count = config.getMaxIndex("namespace");
        for (int i = 0; i <= count; i++) {
          String name = config.getString("namespace(" + i + ")[@name]");
          String value = config.getString("namespace(" + i + ")[@value]");
          nss.put(name, value);
        }
      }
    } catch (Exception e) {
      nss = new HashMap<String, String>();
View Full Code Here

        fc.addChoosableFileFilter(fnef);

        // Let the user chose a settings file
        if( fc.showDialog(this, "Load Processing Settings") == JFileChooser.APPROVE_OPTION ) {
            try {
                this.settings = new XMLConfiguration(fc.getSelectedFile());

                // Update the interface to show all saved settings
                this.inputFileFormatComboBox.setSelectedItem(this.settings.getProperty("config.input-file-processor"));
                this.outputFileFormatComboBox.setSelectedItem(this.settings.getProperty("config.output-file-processor"));
                this.ifEncodingComboBox.setSelectedItem(Charset.forName( (String) this.settings.getProperty("config.input-file-encoding") ));
View Full Code Here

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        XMLConfiguration config = new XMLConfiguration();

        Options options = new Options();
        options.addOption("h", "help", false, "Print Usage information");
        options.addOption("ifp", "input-file-processor", true, "Input File Processor Type" );
        options.addOption("ofp", "output-file-processor", true, "Output File Processor Type" );

        options.addOption("if", "input-file", true, "Name of Input File");
        options.addOption("of", "output-file", true, "Name of Output File");

        options.addOption("ife", "input-file-encoding", true, "Encoding of Input File");
        options.addOption("ofe", "output-file-encoding", true, "Encoding of Output File");

        options.addOption("ma", "map", true, "File containing the mappings");
        options.addOption("s", "settings", true, "File containing the settings for processing (CLI options override config settings)");

        options.addOption("v", "verbose", false, "Be verbose");
        options.addOption("p", "progress", false, "Print progress");

        options.addOption("le", "list-encodings", false, "List available encodings and exit" );
        options.addOption("lfp", "list-file-processors", false, "List available file-processors and exit" );
        options.addOption("lfpo", "list-file-processor-options", false, "List available options for a given file-processor (use -ifp or -ofp)" );

        options.addOption("m", "mode", true, "Select operating mode (c = conversion, m = mapping, x = xslt)" );
        options.addOption("cm", "conversion-mode", true, "Select conversion mode (only used for mode = c)\n1 = MARC21 to MARCXML\n2 = MARC21 to MODS\n3 = MARCXML to MODS\n4 = MARC21 to OLEF\n5 = MARCXML to OLEF\n6 = MODS to OLEF\n7 = refNum to OLEF\n8 = passthrough\n9 = DC to MODS\n10 = DC to OLEF");

        options.addOption( "iip", "input-id-prefix", true, "Prefix all input IDs with the given string, used to e.g. traverse down an XML tree." );
        options.addOption( "ct", "count-threshold", true, "Create new output file every <arg> entries." );

        CommandLineParser parser = new PosixParser();
        CommandLine cmd = null;
        try {
            cmd = parser.parse(options, args);

            if (args.length <= 0 || cmd.hasOption("h")) {
                HelpFormatter formatter = new HelpFormatter();
                formatter.printHelp("smt-cli", options);

                System.exit(1);
            }
            else if( cmd.hasOption( "lfp" ) ) {
                String[] availProc = ProcessorHandler.self().getProcessors();
                String availProcString = "";
                for( int i = 0; i < availProc.length; i++ ) {
                    availProcString += availProc[i] + "\n";
                }

                System.out.println( "Available File Processor:\n" + availProcString );
                System.exit(0);
            }
            else if( cmd.hasOption( "lfpo" ) ) {
                if( !cmd.hasOption( "ifp" ) && !cmd.hasOption( "ofp" ) ) {
                    System.err.println( "ERROR: Either specify ifp or ofp." );
                    System.exit(1);
                }
            }
            else if( cmd.hasOption( "le" ) ) {
                String availEncodings = "";
                SortedMap<String,Charset> availCharsets = Charset.availableCharsets();
                Iterator<Map.Entry<String,Charset>> it = availCharsets.entrySet().iterator();
                while( it.hasNext() ) {
                    Map.Entry<String,Charset> currEntry = it.next();

                    availEncodings += currEntry.getKey() + "\n";
                }

                System.out.println( "Available File Encodings:\n" + availEncodings );
                System.out.println( "NOTE: Not all encodings are compatible with all file processors!");
                System.exit(0);
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }

        // Check what conversion mode we are running in
        if( cmd.hasOption( "m" ) ) {
            switch( cmd.getOptionValue( "m" ).charAt(0) ) {
                // Conversion mode, invoke conversion function and wait for result
                case 'c':
                    try {
                        Charset inputEncoding = Charset.defaultCharset(), outputEncoding = Charset.defaultCharset();

                        if( cmd.hasOption( "ife" ) ) inputEncoding = Charset.forName( cmd.getOptionValue("ife") );
                        if( cmd.hasOption( "ofe" ) ) outputEncoding = Charset.forName( cmd.getOptionValue("ofe") );

                        Main.convertMode(Integer.parseInt(cmd.getOptionValue("cm")), cmd.getOptionValue("if"), cmd.getOptionValue("of"), inputEncoding, outputEncoding );
                        System.exit(1);
                    }
                    catch( Exception e ) {
                        System.err.println( "Error while running in convert Mode!\n");
                        e.printStackTrace();
                        System.exit(1);
                    }

                    break;
                // XSLT Mode
                case 'x':
                    try {
                        // Apply transformation
                        XSLTransformer.transform( new File( cmd.getOptionValue("if")), new File(cmd.getOptionValue("of")), new File(cmd.getOptionValue("map")) );
                        System.out.println( "XSL Transformation succesfully done!" );
                        System.exit(0);
                    }
                    catch( Exception e ) {
                        System.err.println( "Error while applying XSL transformation.\n");
                        e.printStackTrace();
                        System.exit(1);
                    }
                    break;
                // Mapping mode, just continue
                case 'm':
                    break;
                // Something went wrong here, mode given but not a valid one
                default:
                    System.err.println( "Invalid operating mode '" + cmd.getOptionValue("m") + "'" );
                    System.exit(0);
                    break;

            }
        }

        // Check if a settings file was given, if yes load it
        if( cmd.hasOption("s") ) {
            try {
                config = new XMLConfiguration(cmd.getOptionValue("s"));
            }
            catch( Exception e ) {
                e.printStackTrace();
                System.exit(0);
            }
        }

        // Override config file settings with any given command line settings
        if( cmd.hasOption("ifp") ) config.setProperty("config.input-file-processor", cmd.getOptionValue("ifp"));
        if( cmd.hasOption("ofp") ) config.setProperty("config.output-file-processor", cmd.getOptionValue("ofp"));
        if( cmd.hasOption("ife") ) config.setProperty("config.input-file-encoding", cmd.getOptionValue("ife"));
        if( cmd.hasOption("ofe") ) config.setProperty("config.output-file-encoding", cmd.getOptionValue("ofe"));
        if( cmd.hasOption("iip") ) config.setProperty("config.input-id-prefix", cmd.getOptionValue("iip"));
        if( cmd.hasOption("ct") ) config.setProperty("config.count-threshold", cmd.getOptionValue("ct"));

        //
        // LOAD MAPPINGS
        //
        try {
            String mapFileName = cmd.getOptionValue("map");
            MapFileHandler.self().loadFile(mapFileName);

            HashMap<String, HashMap<String, MappingRecord>> tempMappings = MapFileHandler.self().getMappings();
            HashMap<String, ArrayList<ManipulationRecord>> tempManipulations = MapFileHandler.self().getManipulations();

            // Clear Mappings-Handler
            MappingsHandler.Self().clear();
            // Clear Manipulations-Handler
            ManipulationsHandler.self().clear();

            // Re-Assign all manipulations
            ManipulationsHandler.self().setManipulations(tempManipulations);

            // Re-Run all mappings
            Iterator<Map.Entry<String, HashMap<String, MappingRecord>>> mapsIt = tempMappings.entrySet().iterator();
            while (mapsIt.hasNext()) {
                Map.Entry<String, HashMap<String, MappingRecord>> entry = (Map.Entry<String, HashMap<String, MappingRecord>>) mapsIt.next();
                HashMap<String, MappingRecord> mappingsList = entry.getValue();
                String outputFieldID = entry.getKey();
                //MappingFieldPanel currOutputMFP = null;

                Iterator<String> mplIt = mappingsList.keySet().iterator();
                while (mplIt.hasNext()) {
                    String inputFieldID = mplIt.next();

                    // Add mapping again
                    MappingsHandler.Self().addMapping(inputFieldID, outputFieldID);
                    // Set options of mapping
                    //MappingsHandler.self().manipulateMapping(selectedInputMFP.getFieldID(), selectedOutputMFP.getFieldID(), mappingsList.get(selectedInputMFP.getFieldID()).existsAction);
                    MappingRecord mr = MappingsHandler.Self().getMapping(inputFieldID, outputFieldID);
                    mr.existsAction = mappingsList.get(inputFieldID).existsAction;
                    mr.persistentMapping = mappingsList.get(inputFieldID).persistentMapping;
                    MappingsHandler.Self().setMapping(inputFieldID, outputFieldID, mr);
                }
            }
           
            // save skip filters
            MappingsHandler.Self().setSkipFilter(MapFileHandler.self().getSkipFilters());
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(2);
        }

        // Set input and output order (if provided by the config file)
        if( config.containsKey( "config.input-field-order" ) ) MappingsHandler.Self().setInputOrder( (ArrayList<String>) config.getProperty( "config.input-field-order") );;
        if( config.containsKey( "config.output-field-order" ) ) MappingsHandler.Self().setOutputOrder( (ArrayList<String>) config.getProperty( "config.output-field-order") );;

        //
        // START PROCESSING HERE
        //
        MappingProcess mp = new MappingProcess();
        try {
            if( cmd.hasOption( "v" ) ) System.out.println("Creating File Processors");

            FileProcessor ifp = ProcessorHandler.self().getProcessorForType((String) config.getProperty( "config.input-file-processor" ));
            FileProcessor ofp = ProcessorHandler.self().getProcessorForType((String) config.getProperty( "config.output-file-processor" ));

            System.out.println("Preparing & Initializing File Processors");

            mp.setProcessor(ifp, ofp);

            mp.setInputFile(cmd.getOptionValue("if"), Charset.forName((String) config.getProperty( "config.input-file-encoding" )));
            mp.setOutputFile(cmd.getOptionValue("of"), Charset.forName((String) config.getProperty( "config.output-file-encoding" )));

            // Set additional options
            if( config.containsKey("config.input-id-prefix") ) mp.setInputIDPrefix((String) config.getProperty("config.input-id-prefix"));
            if( config.containsKey("config.count-threshold") ) mp.setCountThreshold(Integer.valueOf((String) config.getProperty("config.count-threshold")) );

            if( cmd.hasOption( "v" ) ) System.out.println("Converting Mappings-Hash & Preparing Processors");

            try {
                mp.prepare();
View Full Code Here

TOP

Related Classes of org.apache.commons.configuration.XMLConfiguration$XMLFileConfigurationDelegate

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.