Example usage for javax.xml.stream XMLStreamWriter close

List of usage examples for javax.xml.stream XMLStreamWriter close

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamWriter close.

Prototype

public void close() throws XMLStreamException;

Source Link

Document

Close this writer and free any resources associated with the writer.

Usage

From source file:org.exoplatform.services.jcr.ext.artifact.ArtifactManagingServiceImpl.java

protected File createSingleMetadata(String groupId, String artifactId, String version)
        throws FileNotFoundException {
    File temp = null;//w ww .  jav  a  2 s .com
    try {
        String filename = getUniqueFilename("maven-metadata.xml");
        temp = File.createTempFile(filename, null);

        OutputStream os = new FileOutputStream(temp);
        XMLOutputFactory factory = XMLOutputFactory.newInstance();
        XMLStreamWriter writer = factory.createXMLStreamWriter(os);
        try {
            writer.writeStartDocument("UTF-8", "1.0");
            writer.writeStartElement("metadata");

            writer.writeStartElement("groupId");
            writer.writeCharacters(groupId);
            writer.writeEndElement();

            writer.writeStartElement("artifactId");
            writer.writeCharacters(artifactId);
            writer.writeEndElement();

            writer.writeStartElement("version");
            writer.writeCharacters(version);
            writer.writeEndElement();

            writer.writeEndElement();
            writer.writeEndDocument();
        } finally {
            writer.flush();
            writer.close();
            os.close();
        }
    } catch (XMLStreamException e) {
        LOG.error("Error on creating metadata - XML", e);
    } catch (IOException e) {
        LOG.error("Error on creating metadata - FILE", e);
    }
    return (temp != null && temp.exists()) ? temp : null;
}

From source file:org.exoplatform.services.jcr.ext.artifact.ArtifactManagingServiceImpl.java

protected File createMultiMetadata(String groupId, String artifactId, String current_version,
        List<String> v_list) throws FileNotFoundException {
    File temp = null;//  ww w  .  j a  v  a 2  s. co  m
    try {
        String filename = getUniqueFilename("maven-metadata.xml");
        temp = File.createTempFile(filename, null);

        OutputStream os = new FileOutputStream(temp);
        XMLOutputFactory factory = XMLOutputFactory.newInstance();
        XMLStreamWriter writer = factory.createXMLStreamWriter(os);
        try {
            writer.writeStartDocument("UTF-8", "1.0");
            writer.writeStartElement("metadata");

            writer.writeStartElement("groupId");
            writer.writeCharacters(groupId);
            writer.writeEndElement();

            writer.writeStartElement("artifactId");
            writer.writeCharacters(artifactId);
            writer.writeEndElement();

            String elderVersion;
            if (v_list.size() > 0) {
                Collections.sort(v_list); // sort list
                elderVersion = v_list.get(0); // get first element
            } else
                elderVersion = current_version;
            v_list.add(current_version);

            writer.writeStartElement("version");
            writer.writeCharacters(elderVersion);
            writer.writeEndElement();

            writer.writeStartElement("versions");
            writer.writeStartElement("versioning");

            for (Iterator<String> iterator = v_list.iterator(); iterator.hasNext();) {
                writer.writeStartElement("version");
                writer.writeCharacters(iterator.next());
                writer.writeEndElement();
            }

            writer.writeEndElement();
            writer.writeEndElement();

            writer.writeEndElement();
            writer.writeEndDocument();
        } finally {
            writer.flush();
            writer.close();
            os.close();
        }
    } catch (XMLStreamException e) {
        LOG.error("Error on creating metadata - XML", e);
    } catch (IOException e) {
        LOG.error("Error on creating metadata - FILE", e);
    }
    return (temp != null && temp.exists()) ? temp : null;
}

From source file:org.flowable.bpmn.converter.BpmnXMLConverter.java

public byte[] convertToXML(BpmnModel model, String encoding) {
    try {/*ww  w  .  ja  v  a 2 s .c  o m*/

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

        XMLOutputFactory xof = XMLOutputFactory.newInstance();
        OutputStreamWriter out = new OutputStreamWriter(outputStream, encoding);

        XMLStreamWriter writer = xof.createXMLStreamWriter(out);
        XMLStreamWriter xtw = new IndentingXMLStreamWriter(writer);

        DefinitionsRootExport.writeRootElement(model, xtw, encoding);
        CollaborationExport.writePools(model, xtw);
        DataStoreExport.writeDataStores(model, xtw);
        SignalAndMessageDefinitionExport.writeSignalsAndMessages(model, xtw);

        for (Process process : model.getProcesses()) {

            if (process.getFlowElements().isEmpty() && process.getLanes().isEmpty()) {
                // empty process, ignore it
                continue;
            }

            ProcessExport.writeProcess(process, xtw);

            for (FlowElement flowElement : process.getFlowElements()) {
                createXML(flowElement, model, xtw);
            }

            for (Artifact artifact : process.getArtifacts()) {
                createXML(artifact, model, xtw);
            }

            // end process element
            xtw.writeEndElement();
        }

        BPMNDIExport.writeBPMNDI(model, xtw);

        // end definitions root element
        xtw.writeEndElement();
        xtw.writeEndDocument();

        xtw.flush();

        outputStream.close();

        xtw.close();

        return outputStream.toByteArray();

    } catch (Exception e) {
        LOGGER.error("Error writing BPMN XML", e);
        throw new XMLException("Error writing BPMN XML", e);
    }
}

From source file:org.flowable.cmmn.converter.CmmnXmlConverter.java

public byte[] convertToXML(CmmnModel model, String encoding) {
    try {//from ww w. j a v  a 2  s.  co  m

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

        XMLOutputFactory xof = XMLOutputFactory.newInstance();
        OutputStreamWriter out = new OutputStreamWriter(outputStream, encoding);

        XMLStreamWriter writer = xof.createXMLStreamWriter(out);
        XMLStreamWriter xtw = new IndentingXMLStreamWriter(writer);

        DefinitionsRootExport.writeRootElement(model, xtw, encoding);

        for (Case caseModel : model.getCases()) {

            if (caseModel.getPlanModel().getPlanItems().isEmpty()) {
                // empty case, ignore it
                continue;
            }

            CaseExport.writeCase(caseModel, xtw);

            Stage planModel = caseModel.getPlanModel();
            StageExport.writeStage(planModel, xtw);

            // end case element
            xtw.writeEndElement();
        }

        CmmnDIExport.writeCmmnDI(model, xtw);

        // end definitions root element
        xtw.writeEndElement();
        xtw.writeEndDocument();

        xtw.flush();

        outputStream.close();

        xtw.close();

        return outputStream.toByteArray();

    } catch (Exception e) {
        LOGGER.error("Error writing CMMN XML", e);
        throw new XMLException("Error writing CMMN XML", e);
    }
}

From source file:org.gluewine.trace.XMLTracer.java

@Override
public void close() {
    isSuppressed();/*  w ww .ja  va2s .com*/
    for (XMLStreamWriter writer : writers.values()) {
        try {
            writer.writeEndElement(); // Close the root.
            writer.writeEndDocument();
            writer.flush();
            writer.close();
        } catch (XMLStreamException e) {
            ErrorLogger.log(getClass(), e);
        }
    }

    writers.clear();
}

From source file:org.graphipedia.dataextract.ExtractData.java

@Override
public void run() {
    logger.info("Start extracting data...");
    long startTime = System.currentTimeMillis();

    DisambiguationPageExtractor dpExtractor = new DisambiguationPageExtractor(settings, this.language,
            dpRootCategory, checkpoint, loggerMessageSuffix);
    dpExtractor.start();/*ww w . jav a 2  s. com*/
    ExtractNamespaces nsExtractor = new ExtractNamespaces(settings, language, loggerMessageSuffix,
            new File(settings.wikipediaEditionDirectory(language), ExtractNamespaces.NAMESPACE_FILE),
            checkpoint);
    nsExtractor.start();
    InfoboxTemplatesExtractor itExtractor = new InfoboxTemplatesExtractor(settings, language, itRootCategory,
            checkpoint, loggerMessageSuffix);
    itExtractor.start();
    ExtractGeoTags geotagsExtractor = new ExtractGeoTags(settings, language, loggerMessageSuffix);
    geotagsExtractor.start();
    try {
        dpExtractor.join();
        nsExtractor.join();
        this.ns = nsExtractor.namespaces();
        itExtractor.join();
        geotagsExtractor.join();
        this.geotags = geotagsExtractor.getGeoTags();
    } catch (InterruptedException e) {
        logger.severe("Problems with the threads.");
        e.printStackTrace();
        System.exit(-1);
    }
    XMLOutputFactory outputFactory = XMLOutputFactory2.newInstance();
    File outputFile = new File(settings.wikipediaEditionDirectory(language), TEMPORARY_LINK_FILE);
    if (checkpoint.isLinksExtracted(this.language)) {
        logger.info("Using pages and links from a previous computation");
        return;
    }
    try {
        FileOutputStream fout = new FileOutputStream(outputFile.getAbsolutePath());
        BufferedOutputStream bos = new BufferedOutputStream(fout);
        CompressorOutputStream output = new CompressorStreamFactory()
                .createCompressorOutputStream(CompressorStreamFactory.BZIP2, bos);
        XMLStreamWriter writer = outputFactory.createXMLStreamWriter(output, "UTF-8");
        writer.writeStartDocument();
        writer.writeStartElement("d");

        LinkExtractor linkExtractor = new LinkExtractor(writer, logger, settings, language,
                dpExtractor.disambiguationPages(), itExtractor.infoboxTemplates(), this.ns);
        linkExtractor.parse(settings.getWikipediaXmlFile(language).getAbsolutePath());
        writer.writeEndElement();
        writer.writeEndDocument();
        output.close();
        fout.close();
        bos.close();
        writer.close();
        long elapsed = System.currentTimeMillis() - startTime;
        logger.info("Data extracted in " + ReadableTime.readableTime(elapsed));
    } catch (Exception e) {
        logger.severe("Error while parsing the XML file ");
        e.printStackTrace();
        System.exit(-1);
    }
    try {
        checkpoint.addLinksExtracted(this.language, true);
    } catch (IOException e) {
        logger.severe("Error while saving the checkpoint to file");
        e.printStackTrace();
        System.exit(-1);
    }
    settings.getWikipediaXmlFile(language).delete();
}

From source file:org.gtdfree.model.GTDDataXMLTools.java

static public void store(GTDModel model, OutputStream out, ActionFilter filter)
        throws IOException, XMLStreamException, FactoryConfigurationError {

    if (filter == null) {
        filter = new DummyFilter(true);
    }/*from w ww. j av  a  2  s.co  m*/
    XMLStreamWriter w = XMLOutputFactory.newInstance().createXMLStreamWriter(out, "UTF-8"); //$NON-NLS-1$

    w.writeStartDocument("UTF-8", "1.0"); //$NON-NLS-1$ //$NON-NLS-2$

    w.writeCharacters(EOL);
    w.writeCharacters(EOL);

    w.writeStartElement("gtd-data"); //$NON-NLS-1$
    w.writeAttribute("version", "2.2"); //$NON-NLS-1$ //$NON-NLS-2$
    w.writeAttribute("modified", ApplicationHelper.formatLongISO(new Date())); //$NON-NLS-1$
    w.writeAttribute("lastActionID", Integer.toString(model.getLastActionID())); //$NON-NLS-1$
    w.writeCharacters(EOL);
    w.writeCharacters(EOL);

    // Write folders

    Folder[] fn = model.toFoldersArray();
    w.writeStartElement("lists"); //$NON-NLS-1$
    w.writeCharacters(EOL);

    for (int i = 0; i < fn.length; i++) {
        Folder ff = fn[i];
        if (ff.isMeta() || !filter.isAcceptable(ff, null)) {
            continue;
        }
        w.writeCharacters(SKIP);
        w.writeStartElement("list"); //$NON-NLS-1$
        w.writeAttribute("id", String.valueOf(ff.getId())); //$NON-NLS-1$
        w.writeAttribute("name", ff.getName()); //$NON-NLS-1$
        w.writeAttribute("type", ff.getType().toString()); //$NON-NLS-1$
        w.writeAttribute("closed", Boolean.toString(ff.isClosed())); //$NON-NLS-1$
        if (ff.getCreated() != null)
            w.writeAttribute("created", Long.toString(ff.getCreated().getTime())); //$NON-NLS-1$
        if (ff.getModified() != null)
            w.writeAttribute("modified", Long.toString(ff.getModified().getTime())); //$NON-NLS-1$
        if (ff.getResolved() != null)
            w.writeAttribute("resolved", Long.toString(ff.getResolved().getTime())); //$NON-NLS-1$
        if (!ff.isInBucket() && ff.getDescription() != null) {
            w.writeAttribute("description", ApplicationHelper.escapeControls(ff.getDescription())); //$NON-NLS-1$
        }
        w.writeCharacters(EOL);

        for (Action a : ff) {

            if (!filter.isAcceptable(ff, a)) {
                continue;
            }

            w.writeCharacters(SKIPSKIP);
            w.writeStartElement("action"); //$NON-NLS-1$
            w.writeAttribute("id", Integer.toString(a.getId())); //$NON-NLS-1$
            w.writeAttribute("created", Long.toString(a.getCreated().getTime())); //$NON-NLS-1$
            w.writeAttribute("resolution", a.getResolution().toString()); //$NON-NLS-1$
            if (a.getResolved() != null)
                w.writeAttribute("resolved", Long.toString(a.getResolved().getTime())); //$NON-NLS-1$
            if (a.getModified() != null)
                w.writeAttribute("modified", Long.toString(a.getModified().getTime())); //$NON-NLS-1$
            if (a.getDescription() != null)
                w.writeAttribute("description", ApplicationHelper.escapeControls(a.getDescription())); //$NON-NLS-1$
            if (a.getStart() != null)
                w.writeAttribute("start", Long.toString(a.getStart().getTime())); //$NON-NLS-1$
            if (a.getRemind() != null)
                w.writeAttribute("remind", Long.toString(a.getRemind().getTime())); //$NON-NLS-1$
            if (a.getDue() != null)
                w.writeAttribute("due", Long.toString(a.getDue().getTime())); //$NON-NLS-1$
            if (a.getType() != null)
                w.writeAttribute("type", a.getType().toString()); //$NON-NLS-1$
            if (a.getUrl() != null)
                w.writeAttribute("url", a.getUrl().toString()); //$NON-NLS-1$
            if (a.isQueued())
                w.writeAttribute("queued", Boolean.toString(a.isQueued())); //$NON-NLS-1$
            if (a.getProject() != null)
                w.writeAttribute("project", a.getProject().toString()); //$NON-NLS-1$
            if (a.getPriority() != null)
                w.writeAttribute("priority", a.getPriority().toString()); //$NON-NLS-1$
            w.writeEndElement();
            w.writeCharacters(EOL);
        }
        w.writeCharacters(SKIP);
        w.writeEndElement();
        w.writeCharacters(EOL);
    }
    w.writeEndElement();
    w.writeCharacters(EOL);

    // Write projects
    Project[] pn = model.toProjectsArray();
    w.writeStartElement("projects"); //$NON-NLS-1$
    w.writeCharacters(EOL);

    for (int i = 0; i < pn.length; i++) {
        Project ff = pn[i];

        if (!filter.isAcceptable(ff, null)) {
            continue;
        }

        w.writeCharacters(SKIP);
        w.writeStartElement("project"); //$NON-NLS-1$
        w.writeAttribute("id", String.valueOf(ff.getId())); //$NON-NLS-1$
        w.writeAttribute("name", ff.getName()); //$NON-NLS-1$
        w.writeAttribute("closed", String.valueOf(ff.isClosed())); //$NON-NLS-1$
        if (ff.getCreated() != null)
            w.writeAttribute("created", Long.toString(ff.getCreated().getTime())); //$NON-NLS-1$
        if (ff.getModified() != null)
            w.writeAttribute("modified", Long.toString(ff.getModified().getTime())); //$NON-NLS-1$
        if (ff.getResolved() != null)
            w.writeAttribute("resolved", Long.toString(ff.getResolved().getTime())); //$NON-NLS-1$

        if (ff.getDescription() != null) {
            w.writeAttribute("description", ApplicationHelper.escapeControls(ff.getDescription())); //$NON-NLS-1$
        }

        StringBuilder sb = new StringBuilder();

        for (Action a : ff) {
            if (!filter.isAcceptable(ff, a)) {
                continue;
            }
            if (sb.length() > 0) {
                sb.append(","); //$NON-NLS-1$
            }
            sb.append(a.getId());
        }
        w.writeAttribute("actions", sb.toString()); //$NON-NLS-1$
        w.writeEndElement();
        w.writeCharacters(EOL);
    }
    w.writeEndElement();
    w.writeCharacters(EOL);

    // Write queue
    Folder f = model.getQueue();

    if (filter.isAcceptable(f, null)) {
        w.writeStartElement("queue"); //$NON-NLS-1$
        w.writeAttribute("id", String.valueOf(f.getId())); //$NON-NLS-1$
        w.writeAttribute("name", f.getName()); //$NON-NLS-1$

        StringBuilder sb = new StringBuilder();
        Iterator<Action> i = f.iterator();
        if (i.hasNext()) {
            sb.append(i.next().getId());
        }
        while (i.hasNext()) {
            sb.append(","); //$NON-NLS-1$
            sb.append(i.next().getId());
        }
        w.writeAttribute("actions", sb.toString()); //$NON-NLS-1$
        w.writeEndElement();
        w.writeCharacters(EOL);
    }

    // containers
    w.writeEndElement();
    w.writeEndDocument();

    w.flush();
    w.close();

    //changed=false;

}

From source file:org.intermine.api.xml.TagBindingTest.java

public void testMarshal() throws Exception {
    XMLUnit.setIgnoreWhitespace(true);//from w ww . java2  s. co  m
    StringWriter sw = new StringWriter();
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    try {
        XMLStreamWriter writer = factory.createXMLStreamWriter(sw);
        writer.writeStartElement("tags");
        List<Tag> tags = getTags();
        for (Tag tag : tags) {
            TagBinding.marshal(tag, writer);
        }
        writer.writeEndElement();
        writer.close();
    } catch (XMLStreamException e) {
        throw new RuntimeException(e);
    }

    InputStream is = getClass().getClassLoader().getResourceAsStream("TagBindingTest.xml");
    String expectedXml = IOUtils.toString(is);

    String actualXml = sw.toString().trim();
    System.out.println(normalise(actualXml));
    assertEquals("actual and expected XML should be the same", normalise(expectedXml), normalise(actualXml));
}

From source file:org.netbeans.jbatch.modeler.spec.core.Definitions.java

public static void unload(ModelerFile file, List<String> definitionIdList) {
    File savedFile = file.getFile();
    if (definitionIdList.isEmpty()) {
        return;//from ww w  .  j  a v  a  2s  . com
    }
    try {
        File cloneSavedFile = File.createTempFile("TMP", "job");
        FileUtils.copyFile(savedFile, cloneSavedFile);

        BufferedReader br = new BufferedReader(new FileReader(savedFile));
        String line = null;
        while ((line = br.readLine()) != null) {
            System.out.println("pre savedFile : " + line);
        }

        XMLOutputFactory xof = XMLOutputFactory.newFactory();
        XMLStreamWriter xsw = xof.createXMLStreamWriter(new FileWriter(savedFile));
        xsw.setDefaultNamespace("http://jbatchsuite.java.net");

        xsw.writeStartDocument();
        xsw.writeStartElement("jbatchnb", "root", "http://jbatchsuite.java.net");
        xsw.writeNamespace("jbatch", "http://xmlns.jcp.org/xml/ns/javaee");
        xsw.writeNamespace("jbatchnb", "http://jbatchsuite.java.net");
        xsw.writeNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
        xsw.writeNamespace("java", "http://jcp.org/en/jsr/detail?id=270");
        xsw.writeNamespace("nbm", "http://nbmodeler.java.net");

        if (cloneSavedFile.length() != 0) {
            try {
                XMLInputFactory xif = XMLInputFactory.newFactory();
                StreamSource xml = new StreamSource(cloneSavedFile);
                XMLStreamReader xsr = xif.createXMLStreamReader(xml);
                xsr.nextTag();
                while (xsr.getEventType() == XMLStreamConstants.START_ELEMENT) {
                    //                        Def   Y    N
                    //                        Tag   N(D) Y(D)
                    //                        ________________
                    //                              T    T
                    //                        ----------------
                    //
                    //                        Def   Y    N
                    //                        Tag   Y(S) N(S)
                    //                        ________________
                    //                              S    S
                    //                        ----------------
                    //
                    //                        Def   Y    N
                    //                        Tag   Y(D) N(S)
                    //                        ________________
                    //                              T    S
                    //                        ----------------
                    //
                    //                       (D) => Different
                    //                       (S) => Same
                    //                        Y => Id Exist
                    //                        N => Def Id is null
                    //                        T => Transform
                    //                        S => Skip

                    if (xsr.getLocalName().equals("definitions")) {
                        //                            if (definitionId == null) {
                        //                                if (xsr.getAttributeValue(null, "id") != null) {
                        //                                    transformXMLStream(xsr, xsw);
                        //                                }
                        //                            } else {
                        if (xsr.getAttributeValue(null, "id") == null) {
                            System.out.println("transformXMLStream " + null);
                            transformXMLStream(xsr, xsw);
                        } else {
                            if (!definitionIdList.contains(xsr.getAttributeValue(null, "id"))) {
                                System.out.println("transformXMLStream " + xsr.getAttributeValue(null, "id"));
                                transformXMLStream(xsr, xsw);
                            } else {
                                System.out.println("skipXMLStream " + xsr.getAttributeValue(null, "id"));
                                skipXMLStream(xsr);
                            }
                        }
                        //                            }
                    }
                    System.out.println(
                            "pre xsr.getEventType() : " + xsr.getEventType() + "  " + xsr.getLocalName());
                    xsr.nextTag();
                    System.out.println(
                            "post xsr.getEventType() : " + xsr.getEventType() + "  " + xsr.getLocalName());
                }
            } catch (XMLStreamException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
        xsw.writeEndDocument();
        xsw.close();

        br = new BufferedReader(new FileReader(savedFile));
        line = null;
        while ((line = br.readLine()) != null) {
            System.out.println("post savedFile : " + line);
        }

    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    } catch (XMLStreamException ex) {
        Exceptions.printStackTrace(ex);
    }
}

From source file:org.netbeans.jbatch.modeler.specification.model.job.util.JobUtil.java

public void saveModelerFile(ModelerFile modelerFile) {

    Definitions definitions = (Definitions) modelerFile.getDefinitionElement();

    try {// w w w  .  j  a v a2 s.  c  om
        updateBatchDiagram(modelerFile);
        List<String> closeDefinitionIdList = closeDiagram(modelerFile, definitions.getGarbageDefinitions());
        List<String> definitionIdList = new ArrayList<String>(closeDefinitionIdList);
        //            definitionIdList.addAll(definitions.getGarbageDefinitions());
        definitionIdList.add(definitions.getId());
        File savedFile = modelerFile.getFile();

        BufferedReader br = new BufferedReader(new FileReader(savedFile));
        String line = null;
        while ((line = br.readLine()) != null) {
            System.out.println("savedFile : " + line);
        }

        File cloneSavedFile = File.createTempFile("TMP", "job");
        FileUtils.copyFile(savedFile, cloneSavedFile);
        //            br = new BufferedReader(new FileReader(cloneSavedFile));
        //            line = null;
        //            while ((line = br.readLine()) != null) {
        //                System.out.println("line2 : " + line);
        //            }

        XMLOutputFactory xof = XMLOutputFactory.newFactory();
        XMLStreamWriter xsw = xof.createXMLStreamWriter(new FileWriter(savedFile));
        xsw.setDefaultNamespace("http://jbatchsuite.java.net");

        xsw.writeStartDocument();
        xsw.writeStartElement("jbatchnb", "root", "http://jbatchsuite.java.net");
        xsw.writeNamespace("jbatch", "http://xmlns.jcp.org/xml/ns/javaee");
        xsw.writeNamespace("jbatchnb", "http://jbatchsuite.java.net");
        xsw.writeNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
        xsw.writeNamespace("java", "http://jcp.org/en/jsr/detail?id=270");
        xsw.writeNamespace("nbm", "http://nbmodeler.java.net");

        //            br = new BufferedReader(new FileReader(savedFile));
        //            line = null;
        //            while ((line = br.readLine()) != null) {
        //                System.out.println("line3 : " + line);
        //            }
        if (cloneSavedFile.length() != 0) {
            try {
                XMLInputFactory xif = XMLInputFactory.newFactory();
                StreamSource xml = new StreamSource(cloneSavedFile);
                XMLStreamReader xsr = xif.createXMLStreamReader(xml);
                xsr.nextTag();
                while (xsr.getEventType() == XMLStreamConstants.START_ELEMENT) {
                    //                        Def   Y    N
                    //                        Tag   N(D) Y(D)
                    //                        ________________
                    //                              T    T
                    //                        ----------------
                    //
                    //                        Def   Y    N
                    //                        Tag   Y(S) N(S)
                    //                        ________________
                    //                              S    S
                    //                        ----------------
                    //
                    //                        Def   Y    N
                    //                        Tag   Y(D) N(S)
                    //                        ________________
                    //                              T    S
                    //                        ----------------
                    //
                    //                       (D) => Different
                    //                       (S) => Same
                    //                        Y => Id Exist
                    //                        N => Id is null
                    //                        T => Transform
                    //                        S => Skip

                    if (xsr.getLocalName().equals("definitions")) {
                        //                            if (definitions.getId() == null) {
                        //                                if (xsr.getAttributeValue(null, "id") != null) {
                        //                                    transformXMLStream(xsr, xsw);
                        //                                } else {
                        //                                    skipXMLStream(xsr);
                        //                                }
                        //                            } else {
                        if (xsr.getAttributeValue(null, "id") == null) {
                            if (definitions.getId() == null) {
                                skipXMLStream(xsr);
                            } else {
                                transformXMLStream(xsr, xsw);
                            }
                        } else {
                            if (!definitionIdList.contains(xsr.getAttributeValue(null, "id"))) {
                                transformXMLStream(xsr, xsw);
                            } else {
                                skipXMLStream(xsr);
                            }
                        }
                        //                            }
                    }
                    xsr.nextTag();
                }
            } catch (XMLStreamException ex) {
                Exceptions.printStackTrace(ex);
            }
        }

        JAXBElement<Definitions> je = new JAXBElement<Definitions>(
                new QName("http://jbatchsuite.java.net", "definitions", "jbatchnb"), Definitions.class,
                definitions);
        if (jobContext == null) {
            jobContext = JAXBContext.newInstance(new Class<?>[] { ShapeDesign.class, Definitions.class });
        }
        if (jobMarshaller == null) {
            jobMarshaller = jobContext.createMarshaller();
        }

        // output pretty printed
        jobMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        jobMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
        //          jobMarshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://www.omg.org/spec/Batch/20100524/MODEL http://www.omg.org/spec/Batch/2.0/20100501/Batch20.xsd");
        jobMarshaller.setEventHandler(new ValidateJAXB());
        jobMarshaller.marshal(je, System.out);
        jobMarshaller.marshal(je, xsw);

        //            xsw.writeEndElement();
        xsw.writeEndDocument();
        xsw.close();

        //            StringWriter sw = new StringWriter();
        //            jobMarshaller.marshal(file.getDefinitionElement(), sw);
        //            FileUtils.writeStringToFile(savedFile, sw.toString().replaceFirst("xmlns:ns[A-Za-z\\d]{0,3}=\"http://www.omg.org/spec/Batch/20100524/MODEL\"",
        //                    "xmlns=\"http://www.omg.org/spec/Batch/20100524/MODEL\""));
    } catch (JAXBException ex) {
        Exceptions.printStackTrace(ex);
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    } catch (XMLStreamException ex) {
        Exceptions.printStackTrace(ex);
    }

}