Package org.zanata.util

Examples of org.zanata.util.TMXParseException


            while (reader.hasNext()
                    && reader.next() != XMLStreamConstants.START_ELEMENT) {
            }
            if (!reader.hasNext())
                throw new TMXParseException("No root element");
            if (!reader.getName().equals(tmx))
                throw new TMXParseException("Wrong root element: expected tmx");

            // At this point, event = START_ELEMENT and name = tmx
            while (reader.hasNext()) {
                int eventType = reader.next();
                if (eventType == XMLStreamConstants.START_ELEMENT) {
                    if (handledTUs > 0 && handledTUs % BATCH_SIZE == 0) {
                        commitBatch(handledTUs);
                    }
                    QName elemName = reader.getName();
                    if (elemName.equals(tu)) {
                        Element tuElem = ElementBuilder.buildElement(reader);
                        transMemoryAdapter
                                .processTransUnit(transMemory, tuElem);
                        handledTUs++;
                    } else if (elemName.equals(header)) {
                        Element headerElem =
                                ElementBuilder.buildElement(reader);
                        transMemoryAdapter.processHeader(transMemory,
                                headerElem);
                    }
                }
            }
            commitBatch(handledTUs); // A new transaction is needed for Seam to
                                     // commit it
        } catch (EntityExistsException e) {
            String msg =
                    "Possible duplicate TU (duplicate tuid or duplicate"
                            + "src content without tuid)";
            throw new TMXParseException(msg, e);
        } catch (XMLStreamException e) {
            throw new TMXParseException(e);
        } finally {
            log.info("parsing stopped for: {}, TU count={}",
                    transMemory.getSlug(), handledTUs);
        }
    }
View Full Code Here


            String srcLang = tu.getSourceLanguage();
            if (srcLang != null) {
                TransMemoryUnitVariant sourceVariant =
                        tu.getTransUnitVariants().get(srcLang);
                if (sourceVariant == null) {
                    throw new TMXParseException(
                            "Source variant cannot be determined for Translation unit with no tuid.");
                }
                return sourceVariant.getPlainTextSegmentHash();
            } else {
                throw new TMXParseException(
                        "Source language cannot be determined for Translation unit with no tuid. "
                                + "It must be defined either in the <tu> or the <header> element.");
            }
        }
    }
View Full Code Here

        Map<String, Object> metadata = buildMetadata(fromHeaderElem);
        String srclang = (String) metadata.remove(SRC_LANG);
        if (srclang != null) {
            toTransMemory.setSourceLanguage(getValidLang(srclang));
        } else {
            throw new TMXParseException("missing srclang in header");
        }
        setSharedMetadata(toTransMemory, metadata);
    }
View Full Code Here

        Map<String, Object> metadata = buildMetadata(fromTuvElem);
        String lang = (String) metadata.remove(XML_LANG);
        if (lang != null) {
            toTuv.setLanguage(getValidLang(lang));
        } else {
            throw new TMXParseException("missing xml:lang in tuv: "
                    + fromTuvElem.toXML());
        }
        setSharedMetadata(toTuv, metadata);
    }
View Full Code Here

TOP

Related Classes of org.zanata.util.TMXParseException

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.