Imports one or more CSV files containing i18n keys with their translations.

@param multiPart multipart data
@return status code 200, or 400 if the multipart is null
19487
@POST
    @Consumes("multipart/form-data")
    @RequiresPermissions(I18nPermissions.KEY_WRITE)
    public Response importTranslations(FormDataMultiPart multiPart) {
        WebAssertions.assertNotNull(multiPart, "Missing input file");

        int importedKeys = 0;
        for (BodyPart bodyPart : multiPart.getBodyParts()) {
            importedKeys += importFile(bodyPart);
        }

        String importedKeysMessage = String.format(LOADED_KEYS_MESSAGE, importedKeys);
        LOGGER.debug(importedKeysMessage);
        return Response.ok(importedKeysMessage, MediaType.TEXT_PLAIN_TYPE).build();
    }
827793
public static MultiLanguageText.Builder generateMultiLanguageTextBuilder(final String multiLanguageText) {
        return addMultiLanguageText(MultiLanguageText.newBuilder(), Locale.getDefault(), multiLanguageText);
    }
433153
public synchronized String addImportResult(List<CmsAliasImportResult> importResults) {

        String key = (new CmsUUID()).toString();
        m_entries.put(key, importResults);
        return key;
    }
751802
public TranslationMap doImport() {
        try {
            for (String locale : LOCALES) {
                TranslationHashMap trMap = new TranslationHashMap(getLocale(locale));
                trMap.doImport(TranslationMap.class.getResourceAsStream(locale + ".txt"));
                add(trMap);
            }
            postImportHook();
            return this;
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }
3068
public String getI18nPropertiesString() throws IOException {
    // Load all properties
    Properties i18nProps = new Properties();

    // add entries
    for (Entry<String, String> entry : properties.entrySet()) {
      String key = entry.getKey();
      String escapedKey = validName(key);
      i18nProps.put(escapedKey, entry.getValue());
    }

    try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) {
      i18nProps.store(outStream, null);
      // Property files are always ISO 8859 encoded
      return outStream.toString(CharEncoding.ISO_8859_1);
    }
  }
845144
@Override
    public ZipImporter importFrom(final InputStream stream) throws ArchiveImportException {
        return importFrom(stream, Filters.includeAll());
    }
242625
@Override
    public ZipImporter importFrom(InputStream stream, Filter<ArchivePath> filter) throws ArchiveImportException {
        Validate.notNull(stream, "Stream must be specified");
        Validate.notNull(filter, "Filter must be specified");

        try {
            // Wrap in ZipInputStream if we haven't been given one
            final ZipInputStream zipStream = new ZipInputStream(stream);

            ZipEntry entry;
            while ((entry = zipStream.getNextEntry()) != null) {
                // Get the name
                final String entryName = entry.getName();

                if(!filter.include(ArchivePaths.create(entryName))) {
                    zipStream.closeEntry();
                    continue;
                }

                // Get the archive
                final Archive<?> archive = this.getArchive();

                // Handle directories separately
                if (entry.isDirectory()) {
                    archive.addAsDirectory(entryName);
                    continue;
                }

                final ByteArrayOutputStream output = new ByteArrayOutputStream(8192);
                IOUtil.copy(zipStream, output);
                archive.add(new ByteArrayAsset(output.toByteArray()), entryName);
                zipStream.closeEntry();
            }
        } catch (IOException e) {
            throw new ArchiveImportException("Could not import stream", e);
        }
        return this;
    }
713548
public JCTree.JCCompilationUnit parseCompilationUnit() {
        Token firstToken = token;
        JCExpression pid = null;
        JCModifiers mods = null;
        boolean consumedToplevelDoc = false;
        boolean seenImport = false;
        boolean seenPackage = false;
        List<JCAnnotation> packageAnnotations = List.nil();
        if (token.kind == MONKEYS_AT)
            mods = modifiersOpt();

        if (token.kind == PACKAGE) {
            seenPackage = true;
            if (mods != null) {
                checkNoMods(mods.flags);
                packageAnnotations = mods.annotations;
                mods = null;
            }
            nextToken();
            pid = qualident(false);
            accept(SEMI);
        }
        ListBuffer<JCTree> defs = new ListBuffer<JCTree>();
        boolean checkForImports = true;
        boolean firstTypeDecl = true;
        // JSR 308: Add imports
        Collection<JCTree> commandImports = commandLineImports();
        for (JCTree commendImport : commandImports)
            defs.append(commendImport);
        while (token.kind != EOF) {
            if (token.pos > 0 && token.pos <= endPosTable.errorEndPos) {
                // error recovery
                skip(checkForImports, false, false, false);
                if (token.kind == EOF)
                    break;
            }
            if (checkForImports && mods == null && token.kind == IMPORT) {
                seenImport = true;
                defs.append(importDeclaration());
            } else {
                Comment docComment = token.comment(CommentStyle.JAVADOC);
                if (firstTypeDecl && !seenImport && !seenPackage) {
                    docComment = firstToken.comment(CommentStyle.JAVADOC);
                    consumedToplevelDoc = true;
                }
                JCTree def = typeDeclaration(mods, docComment);
                if (def instanceof JCExpressionStatement)
                    def = ((JCExpressionStatement)def).expr;
                defs.append(def);
                if (def instanceof JCClassDecl)
                    checkForImports = false;
                mods = null;
                firstTypeDecl = false;
            }
        }
        JCTree.JCCompilationUnit toplevel = F.at(firstToken.pos).TopLevel(packageAnnotations, pid, defs.toList());
        if (!consumedToplevelDoc)
            attach(toplevel, firstToken.comment(CommentStyle.JAVADOC));
        if (defs.isEmpty())
            storeEnd(toplevel, S.prevToken().endPos);
        if (keepDocComments)
            toplevel.docComments = docComments;
        if (keepLineMap)
            toplevel.lineMap = S.getLineMap();
        this.endPosTable.setParser(null); // remove reference to parser
        toplevel.endPositions = this.endPosTable;
        return toplevel;
    }
369294
private FileItem getHttpImportFileItem() {

        FileItem result = null;
        m_htmlimport.setHttpDir("");
        // get the file item from the multipart-request
        Iterator it = getMultiPartFileItems().iterator();
        FileItem fi = null;
        while (it.hasNext()) {
            fi = (FileItem)it.next();
            if (fi.getName() != null) {
                // found the file object, leave iteration
                break;
            } else {
                // this is no file object, check next item
                continue;
            }
        }

        if ((fi != null) && CmsStringUtil.isNotEmptyOrWhitespaceOnly(fi.getName())) {
            result = fi;
        }
        return result;
    }
1334007
static Map<String,Collection<String>> extractTextParts(Multipart multiPart) throws MessagingException, IOException {
        HashMap<String,Collection<String>> bodies = new HashMap<>();
        for(int i = 0; i < multiPart.getCount(); i++) {
            checkPartForTextType(bodies, multiPart.getBodyPart(i));
        }
        return bodies;
    }
260517
public static PmiModuleConfig getTranslatedStatsConfig(String statsType, Locale locale) {
        PmiModuleConfig aCfg = getConfig(locale, statsType);
        if (aCfg == null)
            aCfg = _getStatsConfig(statsType, true, locale);

        return aCfg;
    }
686713
private MultipartParsingResult parseRequest(HttpRequest request) throws MultipartException {
        String encoding = determineEncoding(request);
        FileUpload fileUpload = prepareFileUpload(encoding);
        try {
            RequestBody body = request.getBody();
            Assert.notNull(body, "The body cannot be null.");
            List<FileItem> fileItems = fileUpload.parseRequest(new BodyContext(body));
            return parseFileItems(fileItems, encoding);
        } catch (FileUploadBase.SizeLimitExceededException ex) {
            throw new MaxUploadSizeExceededException(fileUpload.getSizeMax(), ex);
        } catch (FileUploadBase.FileSizeLimitExceededException ex) {
            throw new MaxUploadSizeExceededException(fileUpload.getFileSizeMax(), ex);
        } catch (FileUploadException ex) {
            throw new MultipartException("Failed to parse multipart servlet request.", ex);
        }
    }
710893
public MultipartResourceRequest resolveMultipart(final ResourceRequest request) throws MultipartException {
        Assert.notNull(request, "Request must not be null");
        if (this.resolveLazily) {
            return new DefaultMultipartResourceRequest(request) {
                @Override
                protected void initializeMultipart() {
                    MultipartParsingResult parsingResult = parseRequest(request);
                    setMultipartFiles(parsingResult.getMultipartFiles());
                    setMultipartParameters(parsingResult.getMultipartParameters());
                    setMultipartParameterContentTypes(parsingResult.getMultipartParameterContentTypes());
                }
            };
        } else {
            MultipartParsingResult parsingResult = parseRequest(request);
            return new DefaultMultipartResourceRequest(request, parsingResult.getMultipartFiles(),
                    parsingResult.getMultipartParameters(), parsingResult.getMultipartParameterContentTypes());
        }
    }
1367954
@Deprecated
  public static ImmutableMultimap<String, String> loadStringMultimap(File multimapFile)
      throws IOException {
    return loadStringMultimap(Files.asCharSource(multimapFile, Charsets.UTF_8));
  }
688215
public static long importCSV(final File file, final Connection conn, final String insertSQL,
            final Try.BiConsumer<? super PreparedStatement, ? super String[], SQLException> stmtSetter) throws UncheckedSQLException, UncheckedIOException {
        return importCSV(file, 0, Long.MAX_VALUE, conn, insertSQL, 200, 0, stmtSetter);
    }
384463
private void importFile( FormattableContainer currentRule, final String name ) {
        String filename = name.trim();
        boolean isReference = reader.isReference();
        boolean isCss = false;
        boolean isLess = false;
        boolean isMultiple = reader.isMultiple();
        boolean isInline = false;
        boolean isOptional = false;
        if( filename.startsWith( "(" ) ) {
            int endIdx = filename.indexOf( ')', 1);
            if( endIdx > 0 ) {
                StringTokenizer tokenizer = new StringTokenizer( filename.substring( 1, endIdx ), "," );
                filename = name.substring( endIdx + 1 ).trim();
                while( tokenizer.hasMoreTokens() ) {
                    String keywordStr = tokenizer.nextToken().trim();
                    switch( keywordStr ) {
                        case "inline":
                            isInline = true;
                            break;
                        case "optional":
                            isOptional = true;
                            break;
                        case "once":
                            isMultiple = false;
                            break;
                        case "multiple":
                            isMultiple = true;
                            break;
                        case "less":
                            isLess = true;
                            isCss = false;
                            break;
                        case "css":
                            isCss = true;
                            isLess = false;
                            break;
                        case "reference":
                            isReference = true;
                            break;
                        default:
                            throw new LessException( "Unknown @import keyword: " + keywordStr );
                    }
                }
            }
        }

        Object[] old = { reader, baseURL, relativeURL }; //store on the heap to reduce the stack size
        try {
            int i;
            boolean isURL;
            if( filename.startsWith( "url(" ) ) {
                i = 4;
                isURL = true;
            } else {
                i = 0;
                isURL = false;
            }
            StringBuilder builder = cachesBuilder;
            String media = null;
            char quote = 0;
            LOOP:
            for( ; i < filename.length(); i++ ) {
                char ch = filename.charAt( i );
                switch(ch){
                    case '\"':
                    case '\'':
                        if( quote == 0 ) {
                            quote = ch;
                        } else {
                            quote = 0;
                            if( !isURL ) {
                                break LOOP;
                            }
                        }
                        break;
                    case '\\':
                        builder.append( filename.charAt( ++i ) );
                        break;
                    case ')':
                        if( quote == 0 ) {
                            break LOOP;
                        }
                        //$FALL-THROUGH$
                    default:
                        builder.append( ch );
                }
            }
            if( i < filename.length() - 1 ) {
                //additional content after url(...)
                media = filename.substring( i + 1 ).trim();
                Rule rule = new Rule( reader, currentRule, "@media " + media, null, null );
                currentRule.add( rule );
                currentRule = rule;
            }
            filename = trim( builder );

            if( filename.contains( "@{" ) ) { // filename with variable name, we need to parse later
                if( currentRule != this ) {
                    //import is inside of a mixin and will be process if the mixin will be process
                    currentRule.add( new CssAtRule( reader, "@import " + name + ';' ) );
                    return;
                }
                HashMap<String, Expression> importVariables = new DefaultedHashMap<>( variables );
                variables = new DefaultedHashMap<>( importVariables );
                Formattable lastRuleBefore = rules.size() == 0 ? null : rules.get( rules.size() - 1 );
                LazyImport lazy = new LazyImport( reader, baseURL, name, importVariables, lastRuleBefore );
                if( lazyImports == null ) {
                    lazyImports = new ArrayList<>();
                }
                lazyImports.add( lazy );
                return;
            }
            if( !isLess && !isInline && (isCss || filename.endsWith( "css" )) ) {
                // filenames ends with "css" will not be inline else a CSS @import directive is written
                currentRule.add( new CssAtRule( reader, "@import " + name + ';') );
                return;
            }
            baseURL = baseURL == null ? new URL( filename ) : new URL( baseURL, filename );
            if( !isLess && !isInline && baseURL.getPath().endsWith( "css" ) ) {
                // URL path ends with "css" will not be inline else a CSS @import directive is written
                currentRule.add( new CssAtRule( reader, "@import " + name + ';') );
                return;
            }
            if( "file".equals( baseURL.getProtocol() ) && filename.lastIndexOf( '.' ) <= filename.lastIndexOf( '/' ) ) {
                filename += ".less";
                baseURL = (URL)old[1];
                baseURL = baseURL == null ? new URL( filename ) : new URL( baseURL, filename );
            }
            relativeURL = new URL( relativeURL, filename );
            if( imports.add( baseURL ) || isMultiple ) {
                if( isReference != reader.isReference() ) {
                    add( new ReferenceInfo( isReference ) );
                }
                Reader importReader = readerFactory.create( baseURL );
                if( isInline ) {
                    Scanner scanner = new Scanner(importReader).useDelimiter( "\\A" );
                    if( scanner.hasNext() ) {
                        currentRule.add( new CssAtRule( reader, scanner.next() ) );
                    }
                } else {
                    reader = new LessLookAheadReader( importReader, filename, isReference, isMultiple );
                    parse( currentRule );
                    reader.close();
                }
            }
        } catch( LessException ex ) {
            throw ex;
        } catch( IOException ex ) {
            if( !isOptional ) {
                throw new LessException( ex );
            }
        } catch( Exception ex ) {
            throw new LessException( ex );
        } finally {
            reader = (LessLookAheadReader)old[0];
            baseURL = (URL)old[1];
            relativeURL = (URL)old[2];
            if( isReference != reader.isReference() ) {
                add( new ReferenceInfo( reader.isReference() ) );
            }
        }
    }
651966
private ServletRequest init() throws MultipartException, IOException {
		// retrieve multipart/form-data parameters
		if (Multipart.isMultipartContent(request)) {
			Multipart multipart = new Multipart();
			multipart.parse(request, new PartHandler() {

				@Override
				public void handleFormItem(String name, String value) {
					multipartParams.put( name, value );
				}

				@Override
				public void handleFileItem(String name, FileItem fileItem) {
					files.add(fileItem);
				}

			});
		}

		return this;
	}