Example usage for org.jdom2 Document Document

List of usage examples for org.jdom2 Document Document

Introduction

In this page you can find the example usage for org.jdom2 Document Document.

Prototype

public Document(List<? extends Content> content) 

Source Link

Document

This will create a new Document, with the supplied list of content, and a DocType declaration only if the content contains a DocType instance.

Usage

From source file:eus.ixa.ixa.pipe.ml.features.XMLFeatureDescriptor.java

License:Apache License

/**
 * Generate the XML feature descriptor from the TrainingParameters prop file.
 * @param params the properties file/*from   w  w  w.  j  a v  a2  s .  c o  m*/
 * @return the XML feature descriptor
 * @throws IOException if input output fails
 */
public static String createXMLFeatureDescriptor(TrainingParameters params) throws IOException {

    Element aggGenerators = new Element("generators");
    Document doc = new Document(aggGenerators);

    //<generators>
    //  <cache>
    //    <generators>
    Element cached = new Element("cache");
    Element generators = new Element("generators");
    //<window prevLength="2" nextLength="2">
    //  <token />
    //</window>
    if (Flags.isTokenFeature(params)) {
        setWindow(params);
        String tokenFeatureRange = Flags.getTokenFeaturesRange(params);
        Element tokenFeature = new Element("custom");
        tokenFeature.setAttribute("class", TokenFeatureGenerator.class.getName());
        tokenFeature.setAttribute("range", tokenFeatureRange);
        Element tokenWindow = new Element("window");
        tokenWindow.setAttribute("prevLength", Integer.toString(leftWindow));
        tokenWindow.setAttribute("nextLength", Integer.toString(rightWindow));
        tokenWindow.addContent(tokenFeature);
        generators.addContent(tokenWindow);
        System.err.println("-> Token features added!: Window range " + leftWindow + ":" + rightWindow);
    }
    if (Flags.isTokenClassFeature(params)) {
        setWindow(params);
        String tokenClassFeatureRange = Flags.getTokenClassFeaturesRange(params);
        Element tokenClassFeature = new Element("custom");
        tokenClassFeature.setAttribute("class", TokenClassFeatureGenerator.class.getName());
        tokenClassFeature.setAttribute("range", tokenClassFeatureRange);
        Element tokenClassWindow = new Element("window");
        tokenClassWindow.setAttribute("prevLength", Integer.toString(leftWindow));
        tokenClassWindow.setAttribute("nextLength", Integer.toString(rightWindow));
        tokenClassWindow.addContent(tokenClassFeature);
        generators.addContent(tokenClassWindow);
        System.err.println("-> Token Class Features added!: Window range " + leftWindow + ":" + rightWindow);
    }
    if (Flags.isWordShapeSuperSenseFeature(params)) {
        setWindow(params);
        Element wordShapeSuperSenseFeature = new Element("custom");
        wordShapeSuperSenseFeature.setAttribute("class", WordShapeSuperSenseFeatureGenerator.class.getName());
        Element wordShapeWindow = new Element("window");
        wordShapeWindow.setAttribute("prevLength", Integer.toString(leftWindow));
        wordShapeWindow.setAttribute("nextLength", Integer.toString(rightWindow));
        wordShapeWindow.addContent(wordShapeSuperSenseFeature);
        generators.addContent(wordShapeWindow);
        System.err.println(
                "-> Word Shape SuperSense Features added!: Window range " + leftWindow + ":" + rightWindow);
    }
    if (Flags.isOutcomePriorFeature(params)) {
        Element outcomePriorFeature = new Element("custom");
        outcomePriorFeature.setAttribute("class", OutcomePriorFeatureGenerator.class.getName());
        generators.addContent(outcomePriorFeature);
        System.err.println("-> Outcome Prior Features added!");
    }
    if (Flags.isPreviousMapFeature(params)) {
        Element previousMapFeature = new Element("custom");
        previousMapFeature.setAttribute("class", PreviousMapFeatureGenerator.class.getName());
        generators.addContent(previousMapFeature);
        System.err.println("-> Previous Map Features added!");
    }
    if (Flags.isSentenceFeature(params)) {
        String beginSentence = Flags.getSentenceFeaturesBegin(params);
        String endSentence = Flags.getSentenceFeaturesEnd(params);
        Element sentenceFeature = new Element("custom");
        sentenceFeature.setAttribute("class", SentenceFeatureGenerator.class.getName());
        sentenceFeature.setAttribute("begin", beginSentence);
        sentenceFeature.setAttribute("end", endSentence);
        generators.addContent(sentenceFeature);
        System.err.println("-> Sentence Features added!");
    }
    if (Flags.isPrefixFeature(params)) {
        String beginPrefix = Flags.getPrefixFeaturesBegin(params);
        String endPrefix = Flags.getPrefixFeaturesEnd(params);
        Element prefixFeature = new Element("custom");
        prefixFeature.setAttribute("class", PrefixFeatureGenerator.class.getName());
        prefixFeature.setAttribute("begin", beginPrefix);
        prefixFeature.setAttribute("end", endPrefix);
        generators.addContent(prefixFeature);
        System.err.println("-> Prefix Features added!");
    }
    if (Flags.isSuffixFeature(params)) {
        String beginSuffix = Flags.getSuffixFeaturesBegin(params);
        String endSuffix = Flags.getSuffixFeaturesEnd(params);
        Element suffixFeature = new Element("custom");
        suffixFeature.setAttribute("class", SuffixFeatureGenerator.class.getName());
        suffixFeature.setAttribute("begin", beginSuffix);
        suffixFeature.setAttribute("end", endSuffix);
        generators.addContent(suffixFeature);
        System.err.println("-> Suffix Features added!");
    }
    if (Flags.isBigramClassFeature(params)) {
        Element bigramFeature = new Element("custom");
        bigramFeature.setAttribute("class", BigramClassFeatureGenerator.class.getName());
        generators.addContent(bigramFeature);
        System.err.println("-> Bigram Class Features added!");
    }
    if (Flags.isTrigramClassFeature(params)) {
        Element trigramFeature = new Element("custom");
        trigramFeature.setAttribute("class", TrigramClassFeatureGenerator.class.getName());
        generators.addContent(trigramFeature);
        System.err.println("-> Trigram Class Features added!");
    }
    if (Flags.isFourgramClassFeature(params)) {
        Element fourgramFeature = new Element("custom");
        fourgramFeature.setAttribute("class", FourgramClassFeatureGenerator.class.getName());
        generators.addContent(fourgramFeature);
        System.err.println("-> Fourgram Class Features added!");
    }
    if (Flags.isFivegramClassFeature(params)) {
        Element fivegramFeature = new Element("custom");
        fivegramFeature.setAttribute("class", FivegramClassFeatureGenerator.class.getName());
        generators.addContent(fivegramFeature);
        System.err.println("-> Fivegram Class Features added!");
    }
    if (Flags.isCharNgramClassFeature(params)) {
        String charngramRange = Flags.getCharNgramFeaturesRange(params);
        String[] rangeArray = Flags.processNgramRange(charngramRange);
        Element charngramFeature = new Element("custom");
        charngramFeature.setAttribute("class", CharacterNgramFeatureGenerator.class.getName());
        charngramFeature.setAttribute("minLength", rangeArray[0]);
        charngramFeature.setAttribute("maxLength", rangeArray[1]);
        generators.addContent(charngramFeature);
        System.err.println("-> CharNgram Class Features added!");
    }
    //Dictionary Features
    if (Flags.isDictionaryFeatures(params)) {
        setWindow(params);
        String dictPath = Flags.getDictionaryFeatures(params);
        String seqCodec = Flags.getSequenceCodec(params);
        List<File> fileList = StringUtils.getFilesInDir(new File(dictPath));
        for (File dictFile : fileList) {
            Element dictFeatures = new Element("custom");
            dictFeatures.setAttribute("class", DictionaryFeatureGenerator.class.getName());
            dictFeatures.setAttribute("dict", IOUtils.normalizeLexiconName(dictFile.getName()));
            dictFeatures.setAttribute("seqCodec", seqCodec);
            Element dictWindow = new Element("window");
            dictWindow.setAttribute("prevLength", Integer.toString(leftWindow));
            dictWindow.setAttribute("nextLength", Integer.toString(rightWindow));
            dictWindow.addContent(dictFeatures);
            generators.addContent(dictWindow);
        }
        System.err.println("-> Dictionary Features added!");
    }
    //Brown clustering features
    if (Flags.isBrownFeatures(params)) {
        setWindow(params);
        //previous 2 maps features
        Element prev2MapFeature = new Element("custom");
        prev2MapFeature.setAttribute("class", Prev2MapFeatureGenerator.class.getName());
        //generators.addContent(prev2MapFeature);
        //previous map and token feature (in window)
        Element prevMapTokenFeature = new Element("custom");
        prevMapTokenFeature.setAttribute("class", PreviousMapTokenFeatureGenerator.class.getName());
        Element prevMapTokenWindow = new Element("window");
        prevMapTokenWindow.setAttribute("prevLength", Integer.toString(leftWindow));
        prevMapTokenWindow.setAttribute("nextLength", Integer.toString(rightWindow));
        prevMapTokenWindow.addContent(prevMapTokenFeature);
        //generators.addContent(prevMapTokenWindow);
        //brown clustering features
        String brownClusterPath = Flags.getBrownFeatures(params);
        List<File> brownClusterFiles = Flags.getClusterLexiconFiles(brownClusterPath);
        for (File brownClusterFile : brownClusterFiles) {
            //brown bigram class features
            Element brownBigramFeatures = new Element("custom");
            brownBigramFeatures.setAttribute("class", BrownBigramFeatureGenerator.class.getName());
            brownBigramFeatures.setAttribute("dict", IOUtils.normalizeLexiconName(brownClusterFile.getName()));
            generators.addContent(brownBigramFeatures);
            //brown token feature
            Element brownTokenFeature = new Element("custom");
            brownTokenFeature.setAttribute("class", BrownTokenFeatureGenerator.class.getName());
            brownTokenFeature.setAttribute("dict", IOUtils.normalizeLexiconName(brownClusterFile.getName()));
            Element brownTokenWindow = new Element("window");
            brownTokenWindow.setAttribute("prevLength", Integer.toString(leftWindow));
            brownTokenWindow.setAttribute("nextLength", Integer.toString(rightWindow));
            brownTokenWindow.addContent(brownTokenFeature);
            generators.addContent(brownTokenWindow);
            //brown token class feature
            Element brownTokenClassFeature = new Element("custom");
            brownTokenClassFeature.setAttribute("class", BrownTokenClassFeatureGenerator.class.getName());
            brownTokenClassFeature.setAttribute("dict",
                    IOUtils.normalizeLexiconName(brownClusterFile.getName()));
            Element brownTokenClassWindow = new Element("window");
            brownTokenClassWindow.setAttribute("prevLength", Integer.toString(leftWindow));
            brownTokenClassWindow.setAttribute("nextLength", Integer.toString(rightWindow));
            brownTokenClassWindow.addContent(brownTokenClassFeature);
            generators.addContent(brownTokenClassWindow);
        }
        System.err.println("-> Brown Cluster Features added!");
    }
    //Clark clustering features
    if (Flags.isClarkFeatures(params)) {
        setWindow(params);
        String clarkClusterPath = Flags.getClarkFeatures(params);
        List<File> clarkClusterFiles = Flags.getClusterLexiconFiles(clarkClusterPath);
        for (File clarkCluster : clarkClusterFiles) {
            Element clarkFeatures = new Element("custom");
            clarkFeatures.setAttribute("class", ClarkFeatureGenerator.class.getName());
            clarkFeatures.setAttribute("dict", IOUtils.normalizeLexiconName(clarkCluster.getName()));
            Element clarkWindow = new Element("window");
            clarkWindow.setAttribute("prevLength", Integer.toString(leftWindow));
            clarkWindow.setAttribute("nextLength", Integer.toString(rightWindow));
            clarkWindow.addContent(clarkFeatures);
            generators.addContent(clarkWindow);
        }
        System.err.println("-> Clark Cluster Features added!");
    }
    //word2vec clustering features
    if (Flags.isWord2VecClusterFeatures(params)) {
        setWindow(params);
        String word2vecClusterPath = Flags.getWord2VecClusterFeatures(params);
        List<File> word2vecClusterFiles = Flags.getClusterLexiconFiles(word2vecClusterPath);
        for (File word2vecFile : word2vecClusterFiles) {
            Element word2vecClusterFeatures = new Element("custom");
            word2vecClusterFeatures.setAttribute("class", Word2VecClusterFeatureGenerator.class.getName());
            word2vecClusterFeatures.setAttribute("dict", IOUtils.normalizeLexiconName(word2vecFile.getName()));
            Element word2vecClusterWindow = new Element("window");
            word2vecClusterWindow.setAttribute("prevLength", Integer.toString(leftWindow));
            word2vecClusterWindow.setAttribute("nextLength", Integer.toString(rightWindow));
            word2vecClusterWindow.addContent(word2vecClusterFeatures);
            generators.addContent(word2vecClusterWindow);
        }
        System.err.println("-> Word2Vec Clusters Features added!");
    }
    //Morphological features
    if (Flags.isPOSTagModelFeatures(params)) {
        setWindow(params);
        String posModelPath = Flags.getPOSTagModelFeatures(params);
        String posModelRange = Flags.getPOSTagModelFeaturesRange(params);
        Element posTagClassFeatureElement = new Element("custom");
        posTagClassFeatureElement.setAttribute("class", POSTagModelFeatureGenerator.class.getName());
        posTagClassFeatureElement.setAttribute("model",
                IOUtils.normalizeLexiconName(new File(posModelPath).getName()));
        posTagClassFeatureElement.setAttribute("range", posModelRange);
        Element posTagClassFeatureWindow = new Element("window");
        posTagClassFeatureWindow.setAttribute("prevLength", Integer.toString(leftWindow));
        posTagClassFeatureWindow.setAttribute("nextLength", Integer.toString(rightWindow));
        posTagClassFeatureWindow.addContent(posTagClassFeatureElement);
        generators.addContent(posTagClassFeatureWindow);
        System.err.println("-> POSTagModel Features added!");
    }
    if (Flags.isPOSDictionaryFeatures(params)) {
        setWindow(params);
        String posDictPath = Flags.getPOSDictionaryFeatures(params);
        Element posDictFeatures = new Element("custom");
        posDictFeatures.setAttribute("class", POSDictionaryFeatureGenerator.class.getName());
        posDictFeatures.setAttribute("dict", IOUtils.normalizeLexiconName(new File(posDictPath).getName()));
        Element posDictWindow = new Element("window");
        posDictWindow.setAttribute("prevLength", Integer.toString(leftWindow));
        posDictWindow.setAttribute("nextLength", Integer.toString(rightWindow));
        posDictWindow.addContent(posDictFeatures);
        generators.addContent(posDictWindow);
        System.err.println("-> POSDictionary Features added!");
    }
    if (Flags.isLemmaModelFeatures(params)) {
        setWindow(params);
        String lemmaModelPath = Flags.getLemmaModelFeatures(params);
        Element lemmaClassFeatureElement = new Element("custom");
        lemmaClassFeatureElement.setAttribute("class", LemmaModelFeatureGenerator.class.getName());
        lemmaClassFeatureElement.setAttribute("model",
                IOUtils.normalizeLexiconName(new File(lemmaModelPath).getName()));
        Element lemmaClassFeatureWindow = new Element("window");
        lemmaClassFeatureWindow.setAttribute("prevLength", Integer.toString(leftWindow));
        lemmaClassFeatureWindow.setAttribute("nextLength", Integer.toString(rightWindow));
        lemmaClassFeatureWindow.addContent(lemmaClassFeatureElement);
        generators.addContent(lemmaClassFeatureWindow);
        System.err.println("-> LemmaModel Features added!");
    }
    if (Flags.isLemmaDictionaryFeatures(params)) {
        setWindow(params);
        String lemmaDictPath = Flags.getLemmaDictionaryFeatures(params);
        String[] lemmaDictResources = Flags.getLemmaDictionaryResources(lemmaDictPath);
        Element lemmaClassFeatureElement = new Element("custom");
        lemmaClassFeatureElement.setAttribute("class", LemmaDictionaryFeatureGenerator.class.getName());
        lemmaClassFeatureElement.setAttribute("model",
                IOUtils.normalizeLexiconName(new File(lemmaDictResources[0]).getName()));
        lemmaClassFeatureElement.setAttribute("dict",
                IOUtils.normalizeLexiconName(new File(lemmaDictResources[1]).getName()));
        Element lemmaClassFeatureWindow = new Element("window");
        lemmaClassFeatureWindow.setAttribute("prevLength", Integer.toString(leftWindow));
        lemmaClassFeatureWindow.setAttribute("nextLength", Integer.toString(rightWindow));
        lemmaClassFeatureWindow.addContent(lemmaClassFeatureElement);
        generators.addContent(lemmaClassFeatureWindow);
        System.err.println("-> LemmaDictionary Features added!");
    }
    if (Flags.isMFSFeatures(params)) {
        setWindow(params);
        String mfsPath = Flags.getMFSFeatures(params);
        String[] mfsResources = Flags.getMFSResources(mfsPath);
        String mfsRange = Flags.getMFSFeaturesRange(params);
        String seqCodec = Flags.getSequenceCodec(params);
        Element mfsClassFeatureElement = new Element("custom");
        mfsClassFeatureElement.setAttribute("class", MFSFeatureGenerator.class.getName());
        mfsClassFeatureElement.setAttribute("model",
                IOUtils.normalizeLexiconName(new File(mfsResources[0]).getName()));
        mfsClassFeatureElement.setAttribute("dict",
                IOUtils.normalizeLexiconName(new File(mfsResources[1]).getName()));
        mfsClassFeatureElement.setAttribute("mfs",
                IOUtils.normalizeLexiconName(new File(mfsResources[2]).getName()));
        mfsClassFeatureElement.setAttribute("range", mfsRange);
        mfsClassFeatureElement.setAttribute("seqCodec", seqCodec);
        Element mfsClassFeatureWindow = new Element("window");
        mfsClassFeatureWindow.setAttribute("prevLength", Integer.toString(leftWindow));
        mfsClassFeatureWindow.setAttribute("nextLength", Integer.toString(rightWindow));
        mfsClassFeatureWindow.addContent(mfsClassFeatureElement);
        generators.addContent(mfsClassFeatureWindow);
        System.err.println("-> MFS Features added");
    }
    if (Flags.isSuperSenseFeatures(params)) {
        String mfsPath = Flags.getSuperSenseFeatures(params);
        String[] mfsResources = Flags.getSuperSenseResources(mfsPath);
        String mfsRange = Flags.getSuperSenseFeaturesRange(params);
        String seqCodec = Flags.getSequenceCodec(params);
        Element mfsClassFeatureElement = new Element("custom");
        mfsClassFeatureElement.setAttribute("class", SuperSenseFeatureGenerator.class.getName());
        mfsClassFeatureElement.setAttribute("model",
                IOUtils.normalizeLexiconName(new File(mfsResources[0]).getName()));
        mfsClassFeatureElement.setAttribute("dict",
                IOUtils.normalizeLexiconName(new File(mfsResources[1]).getName()));
        mfsClassFeatureElement.setAttribute("mfs",
                IOUtils.normalizeLexiconName(new File(mfsResources[2]).getName()));
        mfsClassFeatureElement.setAttribute("range", mfsRange);
        mfsClassFeatureElement.setAttribute("seqCodec", seqCodec);
        generators.addContent(mfsClassFeatureElement);
        System.err.println("-> SuperSense Features added!");
    }
    if (Flags.isPOSBaselineFeatures(params)) {
        String beginPrefix = Flags.getPrefixBegin(params);
        String endPrefix = Flags.getPrefixEnd(params);
        String beginSuffix = Flags.getSuffixBegin(params);
        String endSuffix = Flags.getSuffixEnd(params);
        Element posFeatureElement = new Element("custom");
        posFeatureElement.setAttribute("class", POSBaselineContextGenerator.class.getName());
        posFeatureElement.setAttribute("prefBegin", beginPrefix);
        posFeatureElement.setAttribute("prefEnd", endPrefix);
        posFeatureElement.setAttribute("sufBegin", beginSuffix);
        posFeatureElement.setAttribute("sufEnd", endSuffix);
        generators.addContent(posFeatureElement);
        System.err.println("-> POS Baseline Context Generator added!");
    }
    if (Flags.isLemmaBaselineFeatures(params)) {
        String beginPrefix = Flags.getPrefixBegin(params);
        String endPrefix = Flags.getPrefixEnd(params);
        String beginSuffix = Flags.getSuffixBegin(params);
        String endSuffix = Flags.getSuffixEnd(params);
        String posModel = Flags.getLemmaBaselineFeatures(params);
        String lemmaRange = Flags.getLemmaBaselineFeaturesRange(params);
        Element lemmaFeatureElement = new Element("custom");
        lemmaFeatureElement.setAttribute("class", LemmaBaselineContextGenerator.class.getName());
        lemmaFeatureElement.setAttribute("prefBegin", beginPrefix);
        lemmaFeatureElement.setAttribute("prefEnd", endPrefix);
        lemmaFeatureElement.setAttribute("sufBegin", beginSuffix);
        lemmaFeatureElement.setAttribute("sufEnd", endSuffix);
        lemmaFeatureElement.setAttribute("model", IOUtils.normalizeLexiconName(new File(posModel).getName()));
        lemmaFeatureElement.setAttribute("range", lemmaRange);
        generators.addContent(lemmaFeatureElement);
        System.err.println("-> Lemma Baseline Context Generator added!");
    }
    if (Flags.isChunkBaselineFeatures(params)) {
        String posModel = Flags.getChunkBaselineFeatures(params);
        Element chunkFeatureElement = new Element("custom");
        chunkFeatureElement.setAttribute("class", ChunkBaselineContextGenerator.class.getName());
        chunkFeatureElement.setAttribute("model", IOUtils.normalizeLexiconName(new File(posModel).getName()));
        generators.addContent(chunkFeatureElement);
        System.err.println("-> Chunk Baseline Context Generator added!");
    }

    if (Flags.isPredicateContextFeatures(params)) {
        String predicateContextFile = Flags.getPredicateContextFeatures(params);
        Element predicateContextFeatureElement = new Element("custom");
        predicateContextFeatureElement.setAttribute("class", PredicateContextFeatureGenerator.class.getName());
        predicateContextFeatureElement.setAttribute("dict",
                IOUtils.normalizeLexiconName(new File(predicateContextFile).getName()));
        generators.addContent(predicateContextFeatureElement);
        System.err.println("-> Predicate Context Generator added!");
    }

    aggGenerators.addContent(cached);
    cached.addContent(generators);

    XMLOutputter xmlOutput = new XMLOutputter();
    Format format = Format.getPrettyFormat();
    xmlOutput.setFormat(format);
    return xmlOutput.outputString(doc);

}

From source file:eus.ixa.ixa.pipe.nerc.features.XMLFeatureDescriptor.java

License:Apache License

/**
 * Generate the XML feature descriptor from the TrainingParameters prop file.
 * @param params the properties file//  ww w.  jav  a 2  s .  c  om
 * @return the XML feature descriptor
 * @throws IOException if input output fails
 */
public static String createXMLFeatureDescriptor(TrainingParameters params) throws IOException {

    Element aggGenerators = new Element("generators");
    Document doc = new Document(aggGenerators);

    //<generators>
    //  <cache>
    //    <generators>
    Element cached = new Element("cache");
    Element generators = new Element("generators");
    //<window prevLength="2" nextLength="2">
    //  <token />
    //</window>
    if (Flags.isTokenFeature(params)) {
        setWindow(params);
        Element tokenFeature = new Element("custom");
        tokenFeature.setAttribute("class", TokenFeatureGenerator.class.getName());
        Element tokenWindow = new Element("window");
        tokenWindow.setAttribute("prevLength", Integer.toString(leftWindow));
        tokenWindow.setAttribute("nextLength", Integer.toString(rightWindow));
        tokenWindow.addContent(tokenFeature);
        generators.addContent(tokenWindow);
        System.err.println("-> Token features added!: Window range " + leftWindow + ":" + rightWindow);
    }
    if (Flags.isTokenClassFeature(params)) {
        setWindow(params);
        Element tokenClassFeature = new Element("custom");
        tokenClassFeature.setAttribute("class", TokenClassFeatureGenerator.class.getName());
        Element tokenClassWindow = new Element("window");
        tokenClassWindow.setAttribute("prevLength", Integer.toString(leftWindow));
        tokenClassWindow.setAttribute("nextLength", Integer.toString(rightWindow));
        tokenClassWindow.addContent(tokenClassFeature);
        generators.addContent(tokenClassWindow);
        System.err.println("-> Token Class Features added!: Window range " + leftWindow + ":" + rightWindow);
    }
    if (Flags.isWordShapeSuperSenseFeature(params)) {
        setWindow(params);
        Element wordShapeSuperSenseFeature = new Element("custom");
        wordShapeSuperSenseFeature.setAttribute("class", WordShapeSuperSenseFeatureGenerator.class.getName());
        Element wordShapeWindow = new Element("window");
        wordShapeWindow.setAttribute("prevLength", Integer.toString(leftWindow));
        wordShapeWindow.setAttribute("nextLength", Integer.toString(rightWindow));
        wordShapeWindow.addContent(wordShapeSuperSenseFeature);
        generators.addContent(wordShapeWindow);
        System.err.println(
                "-> Word Shape SuperSense Features added!: Window range " + leftWindow + ":" + rightWindow);
    }
    if (Flags.isOutcomePriorFeature(params)) {
        Element outcomePriorFeature = new Element("custom");
        outcomePriorFeature.setAttribute("class", OutcomePriorFeatureGenerator.class.getName());
        generators.addContent(outcomePriorFeature);
        System.err.println("-> Outcome Prior Features added!");
    }
    if (Flags.isPreviousMapFeature(params)) {
        Element previousMapFeature = new Element("custom");
        previousMapFeature.setAttribute("class", PreviousMapFeatureGenerator.class.getName());
        generators.addContent(previousMapFeature);
        System.err.println("-> Previous Map Features added!");
    }
    if (Flags.isSentenceFeature(params)) {
        Element sentenceFeature = new Element("custom");
        sentenceFeature.setAttribute("class", SentenceFeatureGenerator.class.getName());
        sentenceFeature.setAttribute("begin", "true");
        sentenceFeature.setAttribute("end", "false");
        generators.addContent(sentenceFeature);
        System.err.println("-> Sentence Features added!");
    }
    if (Flags.isPrefixFeature(params)) {
        Element prefixFeature = new Element("custom");
        prefixFeature.setAttribute("class", Prefix34FeatureGenerator.class.getName());
        generators.addContent(prefixFeature);
        System.err.println("-> Prefix Features added!");
    }
    if (Flags.isSuffixFeature(params)) {
        Element suffixFeature = new Element("custom");
        suffixFeature.setAttribute("class", SuffixFeatureGenerator.class.getName());
        generators.addContent(suffixFeature);
        System.err.println("-> Suffix Features added!");
    }
    if (Flags.isBigramClassFeature(params)) {
        Element bigramFeature = new Element("custom");
        bigramFeature.setAttribute("class", BigramClassFeatureGenerator.class.getName());
        generators.addContent(bigramFeature);
        System.err.println("-> Bigram Class Features added!");
    }
    if (Flags.isTrigramClassFeature(params)) {
        Element trigramFeature = new Element("custom");
        trigramFeature.setAttribute("class", TrigramClassFeatureGenerator.class.getName());
        generators.addContent(trigramFeature);
        System.err.println("-> Trigram Class Features added!");
    }
    if (Flags.isFourgramClassFeature(params)) {
        Element fourgramFeature = new Element("custom");
        fourgramFeature.setAttribute("class", FourgramClassFeatureGenerator.class.getName());
        generators.addContent(fourgramFeature);
        System.err.println("-> Fourgram Class Features added!");
    }
    if (Flags.isFivegramClassFeature(params)) {
        Element fivegramFeature = new Element("custom");
        fivegramFeature.setAttribute("class", FivegramClassFeatureGenerator.class.getName());
        generators.addContent(fivegramFeature);
        System.err.println("-> Fivegram Class Features added!");
    }
    if (Flags.isCharNgramClassFeature(params)) {
        setNgramRange(params);
        Element charngramFeature = new Element("custom");
        charngramFeature.setAttribute("class", CharacterNgramFeatureGenerator.class.getName());
        charngramFeature.setAttribute("minLength", Integer.toString(minCharNgram));
        charngramFeature.setAttribute("maxLength", Integer.toString(maxCharNgram));
        generators.addContent(charngramFeature);
        System.err.println("-> CharNgram Class Features added!");
    }
    //Dictionary Features
    if (Flags.isDictionaryFeatures(params)) {
        setWindow(params);
        String dictPath = Flags.getDictionaryFeatures(params);
        String seqCodec = Flags.getSequenceCodec(params);
        List<File> fileList = StringUtils.getFilesInDir(new File(dictPath));
        for (File dictFile : fileList) {
            Element dictFeatures = new Element("custom");
            dictFeatures.setAttribute("class", DictionaryFeatureGenerator.class.getName());
            dictFeatures.setAttribute("dict", InputOutputUtils.normalizeLexiconName(dictFile.getName()));
            dictFeatures.setAttribute("seqCodec", seqCodec);
            Element dictWindow = new Element("window");
            dictWindow.setAttribute("prevLength", Integer.toString(leftWindow));
            dictWindow.setAttribute("nextLength", Integer.toString(rightWindow));
            dictWindow.addContent(dictFeatures);
            generators.addContent(dictWindow);
        }
        System.err.println("-> Dictionary Features added!");
    }
    //Brown clustering features
    if (Flags.isBrownFeatures(params)) {
        setWindow(params);
        //previous 2 maps features
        Element prev2MapFeature = new Element("custom");
        prev2MapFeature.setAttribute("class", Prev2MapFeatureGenerator.class.getName());
        generators.addContent(prev2MapFeature);
        //previous map and token feature (in window)
        Element prevMapTokenFeature = new Element("custom");
        prevMapTokenFeature.setAttribute("class", PreviousMapTokenFeatureGenerator.class.getName());
        Element prevMapTokenWindow = new Element("window");
        prevMapTokenWindow.setAttribute("prevLength", Integer.toString(leftWindow));
        prevMapTokenWindow.setAttribute("nextLength", Integer.toString(rightWindow));
        prevMapTokenWindow.addContent(prevMapTokenFeature);
        generators.addContent(prevMapTokenWindow);
        //brown clustering features
        String brownClusterPath = Flags.getBrownFeatures(params);
        List<File> brownClusterFiles = Flags.getClusterLexiconFiles(brownClusterPath);
        for (File brownClusterFile : brownClusterFiles) {
            //brown bigram class features
            Element brownBigramFeatures = new Element("custom");
            brownBigramFeatures.setAttribute("class", BrownBigramFeatureGenerator.class.getName());
            brownBigramFeatures.setAttribute("dict",
                    InputOutputUtils.normalizeLexiconName(brownClusterFile.getName()));
            generators.addContent(brownBigramFeatures);
            //brown token feature
            Element brownTokenFeature = new Element("custom");
            brownTokenFeature.setAttribute("class", BrownTokenFeatureGenerator.class.getName());
            brownTokenFeature.setAttribute("dict",
                    InputOutputUtils.normalizeLexiconName(brownClusterFile.getName()));
            Element brownTokenWindow = new Element("window");
            brownTokenWindow.setAttribute("prevLength", Integer.toString(leftWindow));
            brownTokenWindow.setAttribute("nextLength", Integer.toString(rightWindow));
            brownTokenWindow.addContent(brownTokenFeature);
            generators.addContent(brownTokenWindow);
            //brown token class feature
            Element brownTokenClassFeature = new Element("custom");
            brownTokenClassFeature.setAttribute("class", BrownTokenClassFeatureGenerator.class.getName());
            brownTokenClassFeature.setAttribute("dict",
                    InputOutputUtils.normalizeLexiconName(brownClusterFile.getName()));
            Element brownTokenClassWindow = new Element("window");
            brownTokenClassWindow.setAttribute("prevLength", Integer.toString(leftWindow));
            brownTokenClassWindow.setAttribute("nextLength", Integer.toString(rightWindow));
            brownTokenClassWindow.addContent(brownTokenClassFeature);
            generators.addContent(brownTokenClassWindow);
        }
        System.err.println("-> Brown Cluster Features added!");
    }
    //Clark clustering features
    if (Flags.isClarkFeatures(params)) {
        setWindow(params);
        String clarkClusterPath = Flags.getClarkFeatures(params);
        List<File> clarkClusterFiles = Flags.getClusterLexiconFiles(clarkClusterPath);
        for (File clarkCluster : clarkClusterFiles) {
            Element clarkFeatures = new Element("custom");
            clarkFeatures.setAttribute("class", ClarkFeatureGenerator.class.getName());
            clarkFeatures.setAttribute("dict", InputOutputUtils.normalizeLexiconName(clarkCluster.getName()));
            Element clarkWindow = new Element("window");
            clarkWindow.setAttribute("prevLength", Integer.toString(leftWindow));
            clarkWindow.setAttribute("nextLength", Integer.toString(rightWindow));
            clarkWindow.addContent(clarkFeatures);
            generators.addContent(clarkWindow);
        }
        System.err.println("-> Clark Cluster Features added!");
    }
    //word2vec clustering features
    if (Flags.isWord2VecClusterFeatures(params)) {
        setWindow(params);
        String word2vecClusterPath = Flags.getWord2VecClusterFeatures(params);
        List<File> word2vecClusterFiles = Flags.getClusterLexiconFiles(word2vecClusterPath);
        for (File word2vecFile : word2vecClusterFiles) {
            Element word2vecClusterFeatures = new Element("custom");
            word2vecClusterFeatures.setAttribute("class", Word2VecClusterFeatureGenerator.class.getName());
            word2vecClusterFeatures.setAttribute("dict",
                    InputOutputUtils.normalizeLexiconName(word2vecFile.getName()));
            Element word2vecClusterWindow = new Element("window");
            word2vecClusterWindow.setAttribute("prevLength", Integer.toString(leftWindow));
            word2vecClusterWindow.setAttribute("nextLength", Integer.toString(rightWindow));
            word2vecClusterWindow.addContent(word2vecClusterFeatures);
            generators.addContent(word2vecClusterWindow);
        }
        System.err.println("-> Word2Vec Clusters Features added!");
    }
    //Morphological features
    if (Flags.isMorphoFeatures(params)) {
        setWindow(params);
        String morphoPath = Flags.getMorphoFeatures(params);
        String[] morphoResources = Flags.getMorphoResources(morphoPath);
        String morphoRange = Flags.getMorphoFeaturesRange(params);
        Element morphoClassFeatureElement = new Element("custom");
        morphoClassFeatureElement.setAttribute("class", MorphoFeatureGenerator.class.getName());
        morphoClassFeatureElement.setAttribute("model",
                InputOutputUtils.normalizeLexiconName(new File(morphoResources[0]).getName()));
        morphoClassFeatureElement.setAttribute("dict",
                InputOutputUtils.normalizeLexiconName(new File(morphoResources[1]).getName()));
        morphoClassFeatureElement.setAttribute("range", morphoRange);
        Element morphoClassFeatureWindow = new Element("window");
        morphoClassFeatureWindow.setAttribute("prevLength", Integer.toString(leftWindow));
        morphoClassFeatureWindow.setAttribute("nextLength", Integer.toString(rightWindow));
        morphoClassFeatureWindow.addContent(morphoClassFeatureElement);
        generators.addContent(morphoClassFeatureWindow);
        System.err.println("-> Morphological Features added!");
    }
    if (Flags.isMFSFeatures(params)) {
        setWindow(params);
        String mfsPath = Flags.getMFSFeatures(params);
        String[] mfsResources = Flags.getMFSResources(mfsPath);
        String mfsRange = Flags.getMFSFeaturesRange(params);
        String seqCodec = Flags.getSequenceCodec(params);
        Element mfsClassFeatureElement = new Element("custom");
        mfsClassFeatureElement.setAttribute("class", MFSFeatureGenerator.class.getName());
        mfsClassFeatureElement.setAttribute("model",
                InputOutputUtils.normalizeLexiconName(new File(mfsResources[0]).getName()));
        mfsClassFeatureElement.setAttribute("dict",
                InputOutputUtils.normalizeLexiconName(new File(mfsResources[1]).getName()));
        mfsClassFeatureElement.setAttribute("mfs",
                InputOutputUtils.normalizeLexiconName(new File(mfsResources[2]).getName()));
        mfsClassFeatureElement.setAttribute("range", mfsRange);
        mfsClassFeatureElement.setAttribute("seqCodec", seqCodec);
        Element mfsClassFeatureWindow = new Element("window");
        mfsClassFeatureWindow.setAttribute("prevLength", Integer.toString(leftWindow));
        mfsClassFeatureWindow.setAttribute("nextLength", Integer.toString(rightWindow));
        mfsClassFeatureWindow.addContent(mfsClassFeatureElement);
        generators.addContent(mfsClassFeatureWindow);
        System.err.println("-> MFS Features added");
    }
    if (Flags.isSuperSenseFeatures(params)) {
        String mfsPath = Flags.getSuperSenseFeatures(params);
        String[] mfsResources = Flags.getSuperSenseResources(mfsPath);
        String mfsRange = Flags.getSuperSenseFeaturesRange(params);
        String seqCodec = Flags.getSequenceCodec(params);
        Element mfsClassFeatureElement = new Element("custom");
        mfsClassFeatureElement.setAttribute("class", SuperSenseFeatureGenerator.class.getName());
        mfsClassFeatureElement.setAttribute("model",
                InputOutputUtils.normalizeLexiconName(new File(mfsResources[0]).getName()));
        mfsClassFeatureElement.setAttribute("dict",
                InputOutputUtils.normalizeLexiconName(new File(mfsResources[1]).getName()));
        mfsClassFeatureElement.setAttribute("mfs",
                InputOutputUtils.normalizeLexiconName(new File(mfsResources[2]).getName()));
        mfsClassFeatureElement.setAttribute("range", mfsRange);
        mfsClassFeatureElement.setAttribute("seqCodec", seqCodec);
        generators.addContent(mfsClassFeatureElement);
        System.err.println("-> SuperSense Features added!");
    }

    aggGenerators.addContent(cached);
    cached.addContent(generators);

    XMLOutputter xmlOutput = new XMLOutputter();
    Format format = Format.getPrettyFormat();
    xmlOutput.setFormat(format);
    return xmlOutput.outputString(doc);

}

From source file:firstPackage.WorkWithFile.java

public WorkWithFile(WorkWithHashMap wwhm) {
    try {/*from   ww w .j  a v a  2  s. com*/
        doc = new Document(rootElement);
        fw = new FileWriter(new File(file));
        this.wwhm = wwhm;
    } catch (IOException ex) {
        Logger.getLogger(WorkWithFile.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:firstPackage.WorkWithFile.java

/**
 *
 *//*from w  w  w. j  a v  a 2 s.com*/
public void saveAppointmentsInFile() {

    try {
        Element root = new Element("appointments");
        Document doc = new Document(root);

        for (Map.Entry<String, Appointment> me : wwhm.mapOfAppointments.entrySet()) {
            Element node = new Element("apointment-data");
            root.addContent(node);
            Element name = new Element("Name");
            name.setText(me.getValue().getNameOfAppointment());
            node.addContent(name);
            Element description = new Element("Description");
            description.setText(me.getValue().getDescription());
            node.addContent(description);
            Element dateOfEditing = new Element("DateOfEditing");
            dateOfEditing.setText(me.getValue().getDateOfEditing());
            node.addContent(dateOfEditing);
            Element typeOfAppointment = new Element("DypeOfAppointment");
            typeOfAppointment.setText(me.getValue().getTypeOfAppointment().toString());
            node.addContent(typeOfAppointment);
        }

        XMLout.output(doc, fw);
    } catch (IOException ex) {
        Logger.getLogger(WorkWithFile.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:fr.ms.tomcat.manager.ContextFileUtils.java

License:Apache License

public static File creationFichierContextDocBase(final File fichierContext, final File webappDirectory)
        throws JDOMException, IOException {

    Element context = null;/*from  w  ww . j a  va  2 s . c  o  m*/
    Document document = null;

    if (fichierContext.exists()) {
        LOG.debug("Le fichier context existe dj dans la webapps : {}.", fichierContext.getAbsolutePath());
        final SAXBuilder sxb = new SAXBuilder();
        document = sxb.build(fichierContext);
        context = document.getRootElement();
    } else {
        LOG.debug("Le fichier context n'existe pas dans la webapps : {}.", fichierContext.getAbsolutePath());
        context = new Element("Context");
        document = new Document(context);
    }

    final Attribute docBase = new Attribute("docBase", webappDirectory.getAbsolutePath());
    final Attribute workDir = new Attribute("workDir", webappDirectory.getAbsolutePath() + "-workDir");
    context.setAttribute(docBase);
    context.setAttribute(workDir);

    final XMLOutputter xmlContextFile = new XMLOutputter(Format.getPrettyFormat());

    if (LOG.isDebugEnabled()) {
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        xmlContextFile.output(document, baos);

        LOG.debug(baos.toString());
    }

    final File fichierContextTemporaire = File.createTempFile("contextTomcat", ".xml");

    final FileOutputStream fichierContextTemporaireOutputStream = new FileOutputStream(
            fichierContextTemporaire);

    xmlContextFile.output(document, fichierContextTemporaireOutputStream);
    fichierContextTemporaireOutputStream.close();
    return fichierContextTemporaire;
}

From source file:fr.rt.acy.locapic.gps.TrackService.java

License:Open Source License

/**
 * Methode pour creer le document JDOM de base pour le fichier GPX
 * Prend en parametre des valeurs pour les metadonnees GPX (contenues dans la balise <metadata>)
 * @param name - Nom du fichier gpx (pour les metadonnees GPX)
 * @param desc - Description du fichier gpx (pour les metadonnees GPX)
 * @param authorsName - Nom de l'autheur de la trace (pour les metadonnees GPX)
 * @param authorsEmail - Email de l'autheur de la trace (pour les metadonnees GPX)
 * @param keywords - Mots-cle pour les metadonnees GPX
 * @return document - Le document JDOM servant de base GPX
 *//*from   ww w  .ja  v  a 2 s  .c o  m*/
public Document createGpxDocTree(String name, String desc, String authorsName, String authorsEmail,
        String keywords) {
    /* Pour la date */
    Calendar calendar = Calendar.getInstance();
    Date date = calendar.getTime();
    // Format de la date
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-ddHH:mm:ss");
    StringBuilder dateBuilder = new StringBuilder(dateFormat.format(date));
    // Pour le format GPX, T apres la date et avant l'heure, et Z a la fin
    dateBuilder.append("Z");
    dateBuilder.insert(10, "T");
    // Conversion builder => string
    String formattedDate = dateBuilder.toString();
    Log.v(TAG, "TIME => " + formattedDate);

    /* Pour le reste des metadonnees perso */
    String mailId;
    String mailDomain;
    if (name == null)
        name = "LocaPic track";
    if (desc == null)
        desc = "GPS track logged on an Android device with an application from a project by Samuel Beaurepaire &amp; Virgile Beguin for IUT of Annecy (Fr), RT departement.";
    if (authorsName == null)
        authorsName = "Samuel Beaurepaire";
    if (authorsEmail == null) {
        mailId = "sjbeaurepaire";
        mailDomain = "orange.fr";
    } else {
        String[] mail = authorsEmail.split("@", 2);
        mailId = mail[0];
        mailDomain = mail[1];
    }

    // xsi du namespace a indique seulement pour la racine (addNamespaceDeclaratin())
    Namespace XSI = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
    // Creation de la racine du fichier gpx (<gpx></gpx>) sous forme d'objet de classe Element avec le namespace gpx
    Element xml_gpx = new Element("gpx", ns);
    // Namespace XSI et attributs
    xml_gpx.addNamespaceDeclaration(XSI);
    xml_gpx.setAttribute(new Attribute("schemaLocation",
            "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd", XSI));
    xml_gpx.setAttribute(new Attribute("creator", "LocaPic"));
    xml_gpx.setAttribute(new Attribute("version", "1.1"));

    // On cree un nouveau Document JDOM base sur la racine que l'on vient de creer
    Document document = new Document(xml_gpx);
    // ~~~~~~~~~~~~~~~~ <metadata> ~~~~~~~~~~~~~~~~
    Element xml_metadata = new Element("metadata", ns);
    xml_gpx.addContent(xml_metadata);
    // ~~~~~~~~~~~~~~~~ <name> ~~~~~~~~~~~~~~~~
    Element xml_metadata_name = new Element("name", ns);
    xml_metadata_name.addContent(name);
    xml_metadata.addContent(xml_metadata_name);
    // ~~~~~~~~~~~~~~~~ <desc> ~~~~~~~~~~~~~~~~
    Element xml_metadata_desc = new Element("desc", ns);
    xml_metadata_desc.addContent(desc);
    xml_metadata.addContent(xml_metadata_desc);
    // ~~~~~~~~~~~~~~~~ <author> ~~~~~~~~~~~~~~~~
    Element xml_metadata_author = new Element("author", ns);
    // ~~~~~~~~~~~~~~~~ <author> ~~~~~~~~~~~~~~~~
    Element xml_metadata_author_name = new Element("name", ns);
    xml_metadata_author_name.addContent(authorsName);
    xml_metadata_author.addContent(xml_metadata_author_name);
    // ~~~~~~~~~~~~~~~~ <email> ~~~~~~~~~~~~~~~~
    Element xml_metadata_author_email = new Element("email", ns);
    xml_metadata_author_email.setAttribute("id", mailId);
    xml_metadata_author_email.setAttribute("domain", mailDomain);
    xml_metadata_author.addContent(xml_metadata_author_email);
    xml_metadata.addContent(xml_metadata_author);
    // ~~~~~~~~~~~~~~~~ <time> ~~~~~~~~~~~~~~~~
    Element xml_metadata_time = new Element("time", ns);
    xml_metadata_time.addContent(formattedDate);
    xml_metadata.addContent(xml_metadata_time);
    // ~~~~~~~~~~~~~~~~ <keywords> ~~~~~~~~~~~~~~~~
    if (keywords != null) {
        Element xml_keywords = new Element("keywords", ns);
        xml_keywords.addContent(keywords);
        xml_metadata.addContent(xml_keywords);
    }
    // ~~~~~~~~~~~~~~~~ <trk> ~~~~~~~~~~~~~~~~
    Element xml_trk = new Element("trk", ns);
    // ~~~~~~~~~~~~~~~~ <number> ~~~~~~~~~~~~~~~~
    Element xml_trk_number = new Element("number", ns);
    xml_trk_number.addContent("1");
    xml_trk.addContent(xml_trk_number);
    // ~~~~~~~~~~~~~~~~ <trkseg> ~~~~~~~~~~~~~~~~
    Element xml_trk_trkseg = new Element("trkseg", ns);
    xml_trk.addContent(xml_trk_trkseg);
    xml_gpx.addContent(xml_trk);

    return document;
}

From source file:fr.rt.acy.locapic.gps.TrackService.java

License:Open Source License

/**
 * Methode qui ajoute la localisation a partir de l'element JDOM passe en parametre
 * Utilise les attributs de classe FILE_DIRECTORY et FILE_NAME comme chemin pour le fichier a reecrire
 * @param loc - Element JDOM representant la nouvelle position
 * @return true//from  ww w  .  j a  v a  2 s . c o m
 */
public boolean addLocation(Element loc) {
    // Parsing
    SAXBuilder saxBuilder = new SAXBuilder();
    Document document = new Document(new Element("temp"));
    try {
        // On creer un nouveau document JDOM a partir du fichier GPX
        if (!FILE_EXT)
            document = saxBuilder.build(openFileInput(FILE_NAME));
        else
            document = saxBuilder.build(new FileInputStream(new File(EXT_FILES_DIR + FILE_NAME)));

        // On recupere la racine du document
        Element racine = document.getRootElement();
        // A partir de la racine, on recupere les tracks (<trk>)
        List<Element> trkList = racine.getChildren("trk", ns);
        // A partir de la derniere track, on recupere les segments de track (<trkseg>)
        List<Element> trksegList = trkList.get(trkList.size() - 1).getChildren("trkseg", ns);
        // On recupere le dernier segment de track (de la derniere track donc)
        Element trkseg = trksegList.get(trksegList.size() - 1);
        // On y ajoute la nouvelle position (Element loc)
        trkseg.addContent(loc);
    } catch (Exception e) {
        Log.e(TAG, e.getMessage());
    }
    // Partie enregistrement dans le Fichier
    XMLOutputter xmlOutput = new XMLOutputter(Format.getPrettyFormat());
    //Log.d(TAG, "addLocation : FILE_EXT = "+FILE_EXT);
    try {
        if (!FILE_EXT)
            xmlOutput.output(document, openFileOutput(FILE_NAME, MODE_WORLD_READABLE));
        else
            xmlOutput.output(document, new FileOutputStream(EXT_FILES_DIR + FILE_NAME));
    } catch (FileNotFoundException e) {
        Log.e(TAG, e.toString());
    } catch (IOException ioe) {
        Log.e(TAG, ioe.toString());
    }

    return true;
}

From source file:geosolutions.zoom.system.XMLConfiguration.java

public boolean saveXmlParametrosSystem() {
    Cripto cripto = new Cripto();

    Element root = new Element("cronos");

    root.setAttribute("sistema", "Sistema Cronos");
    //nodos hijos mayores
    Element servidor = new Element("servidor");
    Element cliente = new Element("cliente");
    Element otroServidor = new Element("otro_servidor");
    Element otros = new Element("otros");
    Element path = new Element("path");

    //servidor/*w ww . j a  va2 s . c o m*/
    Element itemDriver = new Element("driver");
    itemDriver.setText(ParametrosSystem.getDriverPostgres());
    servidor.addContent(itemDriver);

    Element itemUrl = new Element("url");
    itemUrl.setText(ParametrosSystem.getUrlPostgres());
    servidor.addContent(itemUrl);

    Element itemIpServidor = new Element("ip_servidor");
    itemIpServidor.setText(ParametrosSystem.getIpServidor());
    servidor.addContent(itemIpServidor);

    Element itemNombreDB = new Element("db");
    itemNombreDB.setText(ParametrosSystem.getBaseDatos());
    servidor.addContent(itemNombreDB);

    Element itemNombrePcServidor = new Element("nombre_servidor");
    itemNombrePcServidor.setText(ParametrosSystem.getNombrePcServidor());
    servidor.addContent(itemNombrePcServidor);

    Element itemPuerto = new Element("puerto");
    itemPuerto.setText(ParametrosSystem.getPuertoPostgres());
    servidor.addContent(itemPuerto);

    Element itemUsuario = new Element("usuario");
    itemUsuario.setText(ParametrosSystem.getUsuarioPostgres());
    servidor.addContent(itemUsuario);

    Element itemPassword = new Element("password");
    itemPassword.setText(cripto.Encriptar(ParametrosSystem.getPasswordPostgres(), 27));
    servidor.addContent(itemPassword);

    Element itemNickCronos = new Element("nick");
    itemNickCronos.setText(ParametrosSystem.getNickSistema());
    servidor.addContent(itemNickCronos);

    //cliente
    Element itemIpCliente = new Element("ip_cliente");
    itemIpCliente.setText(ParametrosSystem.getNombrePcCliente());
    cliente.addContent(itemIpCliente);

    Element itemNombrePcCliente = new Element("nombre_cliente");
    itemNombrePcCliente.setText(ParametrosSystem.getNombrePcCliente());
    cliente.addContent(itemNombrePcCliente);

    //otro servidor
    Element itemIpOtroServidor = new Element("otro_ip_servidor");
    itemIpOtroServidor.setText(ParametrosSystem.getOtroIpServidor());
    otroServidor.addContent(itemIpOtroServidor);

    Element itemOtroPuerto = new Element("otro_puerto");
    itemOtroPuerto.setText(ParametrosSystem.getOtroPuertoPostgres());
    otroServidor.addContent(itemOtroPuerto);

    Element itemOtroDB = new Element("otro_db");
    itemOtroDB.setText(ParametrosSystem.getOtroDB());
    otroServidor.addContent(itemOtroDB);

    //otros
    Element itemEsServidor = new Element("es_servidor");
    itemEsServidor.setText(ParametrosSystem.getEsServidor());
    otros.addContent(itemEsServidor);

    Element itemOcurrioInterrupcion = new Element("interrupcion");
    itemOcurrioInterrupcion.setText(ParametrosSystem.getInterrupcion());
    otros.addContent(itemOcurrioInterrupcion);

    Element itemHoraCierrePlanilla = new Element("hora_cierre_planilla");
    itemHoraCierrePlanilla.setText(ParametrosSystem.getHoraCierrePlanilla());
    otros.addContent(itemHoraCierrePlanilla);

    Element itemEsAuotorizadoCopia = new Element("es_autorizado_backup");
    itemEsAuotorizadoCopia.setText(ParametrosSystem.getEsAutorizado());
    otros.addContent(itemEsAuotorizadoCopia);

    //path
    Element itemPathReporte = new Element("path_reporte");
    itemPathReporte.setText(ParametrosSystem.getPathReport());
    path.addContent(itemPathReporte);

    Element itemPathPgDump = new Element("path_pg_dump");
    itemPathPgDump.setText(ParametrosSystem.getPathPgDumpPostgres());
    path.addContent(itemPathPgDump);

    Element itemPathBackup = new Element("path_backup");
    itemPathBackup.setText(ParametrosSystem.getPathBackup());
    path.addContent(itemPathBackup);

    //agregamos al root
    root.addContent(servidor);
    root.addContent(cliente);
    root.addContent(otroServidor);
    root.addContent(otros);
    root.addContent(path);

    // Realizamos lo mismo con los elementos restantes
    XMLOutputter outputter = new XMLOutputter();
    try {
        outputter.output(new Document(root), new FileOutputStream("cronos.xml"));
        return true;
    } catch (Exception e) {
        e.getMessage();
        return false;
    }
}

From source file:gestetu05.Client.java

static void LireXML(String NomFichier) {
    Element racine = new Element("repertoire");
    Document document = new Document(racine);

    //On cre une instance de SAXBuilder
    SAXBuilder sxb = new SAXBuilder();
    try {//  w  ww  . ja va  2  s .com
        //On cre un nouveau document JDOM avec en argument le fichier XML
        //Le parsing est termin ;)
        document = sxb.build(new File(NomFichier));
    } catch (JDOMException | IOException e) {
    }

    //On initialise un nouvel lment racine avec l'lment racine du document.
    racine = document.getRootElement();
    //On cre une List contenant tous les noeuds "utilisateur" de l'Element racine
    List listUtilisateurs = racine.getChildren("utilisateur");
    //On cre un Iterator sur notre liste
    Iterator i = listUtilisateurs.iterator();
    System.out.println("--------------------Fil d'actualit--------------------");
    while (i.hasNext()) {
        //On recre l'Element courant  chaque tour de boucle afin de
        //pouvoir utiliser les mthodes propres aux Element comme :
        //slectionner un nud fils, modifier du texte, etc...
        Element courant = (Element) i.next();
        //On affiche le nom de llment courant
        System.out.println("L'utilisateur " + courant.getChild("nom").getText());
        System.out.println(" est " + courant.getChild("Profession").getText());

    }
}

From source file:gestetu05.Client.java

static void ChercherInformation(String NomFichier, String recherche) {
    Element racine = new Element("repertoire");
    Document document = new Document(racine);
    //On cre une instance de SAXBuilder
    SAXBuilder sxb = new SAXBuilder();
    try {/* w  w w . ja va 2s. c o m*/
        //On cre un nouveau document JDOM avec en argument le fichier XML
        //Le parsing est termin ;)
        document = sxb.build(new File(NomFichier));
    } catch (JDOMException | IOException e) {
    }

    //On initialise un nouvel lment racine avec l'lment racine du document.
    racine = document.getRootElement();
    //On cre une List contenant tous les noeuds "utilisateur" de l'Element racine
    List listUtilisateurs = racine.getChildren("utilisateur");
    //On cre un Iterator sur notre liste
    Iterator i = listUtilisateurs.iterator();
    System.out.println("Rsultat de la recherche:\n");
    while (i.hasNext()) {
        //On recre l'Element courant  chaque tour de boucle afin de
        //pouvoir utiliser les mthodes propres aux Element comme :
        //slectionner un nud fils, modifier du texte, etc...
        Element courant = (Element) i.next();
        //On affiche le nom de llment courant
        if (courant.getChild("nom").getText().equals(recherche)
                || courant.getChild("Profession").getText().equals(recherche)) {
            System.out.println("Nom:" + courant.getChild("nom").getText());
            System.out.println("Profession:" + courant.getChild("Profession").getText() + "\n");
        }

    }
}