Example usage for org.apache.commons.lang3 StringUtils defaultString

List of usage examples for org.apache.commons.lang3 StringUtils defaultString

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils defaultString.

Prototype

public static String defaultString(final String str) 

Source Link

Document

Returns either the passed in String, or if the String is null , an empty String ("").

 StringUtils.defaultString(null)  = "" StringUtils.defaultString("")    = "" StringUtils.defaultString("bat") = "bat" 

Usage

From source file:de.micromata.genome.gwiki.controls.GWikiPageImporterActionBean.java

protected QueryResult query() {
    if (StringUtils.isBlank(tmpDirName) == true) {
        wikiContext.addValidationError("No data found");
        return null;
    }//from  w w  w . ja  v a2  s . c o m
    String searchExpr = "";
    try {
        List<GWikiElementInfo> elems = wikiContext.getWikiWeb().getStorage().loadPageInfos(tmpDirName);
        List<SearchResult> sr = new ArrayList<SearchResult>(elems.size());
        for (GWikiElementInfo wi : elems) {
            String oei = getPageIdNoTemp(wi);
            if (StringUtils.isNotBlank(targetDir) == true) {
                oei = FileNameUtils.join(targetDir, oei);
            }
            CompareStatus st = getCompareStatus(wikiContext, wi, oei);
            wi.getProps().setStringValue("IMPSTATUS", st.name());
            sr.add(new SearchResult(wi));
        }
        searchExpr = getSearchExpression();
        SearchQuery query = new SearchQuery(StringUtils.defaultString(searchExpr), false, sr);

        QueryResult qr = filter(query);
        return qr;
    } catch (Exception ex) {
        wikiContext.append(ex.getMessage() + " for " + searchExpr);
        return null;
    }
}

From source file:com.netsteadfast.greenstep.util.SystemFormUtils.java

public static String getJsonMessage(Map<String, String> resultMap) {
    return StringUtils.defaultString(resultMap.get("message"));
}

From source file:eionet.webq.web.controller.cdr.IntegrationWithCDRController.java

/**
 * Start new web form./*from ww  w .  j a  v  a 2 s  .c  o  m*/
 *
 * @param parameters cdr parameters
 * @param webform    project web form
 * @return redirect string
 * @throws FileNotAvailableException if remote file not available
 */
private String startNewForm(CdrRequest parameters, ProjectFile webform) throws FileNotAvailableException {
    int fileId = userFileService.saveBasedOnWebForm(userFileBasedOn(parameters),
            webFormService.findActiveWebFormById(webform.getId()));

    LOGGER.info("Received ADD NEW file request from CDR with parameters: " + parameters.toString()
            + "; sessionid=" + parameters.getSessionId());

    String webformPath = webformUrlProvider.getWebformPath(webform);

    String redirect = "redirect:" + webformPath + "fileId=" + fileId + "&base_uri="
            + parameters.getContextPath() + "&envelope="
            + StringUtils.defaultString(parameters.getEnvelopeUrl())
            + StringUtils.defaultString(parameters.getAdditionalParametersAsQueryString()) + "&sessionid="
            + parameters.getSessionId();

    LOGGER.info("Redirect to: " + redirect);

    return redirect;
}

From source file:com.netsteadfast.greenstep.util.SystemFormUtils.java

public static String getJsonSuccess(Map<String, String> resultMap) {
    return StringUtils.defaultString(resultMap.get("success"));
}

From source file:edu.usu.sdl.openstorefront.service.OrganizationServiceImpl.java

@Override
public List<OrgReference> findReferences(String organization, boolean onlyActive,
        boolean onlyApprovedComponents) {
    List<OrgReference> references = new ArrayList<>();

    if (StringUtils.isNotBlank(organization)) {
        Organization organizationEntity = persistenceService.findById(Organization.class, organization);
        if (organizationEntity == null) {
            organizationEntity = new Organization();
            organizationEntity.setName(organization);
            organizationEntity = organizationEntity.find();
        }//from   www .ja v  a  2s  . co m

        if (organizationEntity != null) {
            organization = organizationEntity.getName();
        } else {
            log.log(Level.WARNING,
                    MessageFormat.format("Unable to find organization with key or label:  {0}", organization));
            return references;
        }
    }

    references.addAll(findOrgReferences(new Component(), organization, (Component entity) -> {
        OrgReference reference = new OrgReference();
        reference.setActiveStatus(entity.getActiveStatus());
        reference.setComponentApproveStatus(entity.getApprovalState());
        reference.setReferenceId(entity.getComponentId());
        reference.setReferenceName(String.join(" ",
                StringUtils.defaultString(StringProcessor.enclose(entity.getSecurityMarkingType())),
                getComponentService().getComponentName(entity.getComponentId())));
        return reference;
    }));
    references.addAll(findOrgReferences(new ComponentContact(), organization, (ComponentContact entity) -> {
        OrgReference reference = new OrgReference();
        reference.setActiveStatus(entity.getActiveStatus());
        reference.setComponentId(entity.getComponentId());
        reference.setComponentName(getComponentService().getComponentName(entity.getComponentId()));
        reference.setComponentApproveStatus(
                getComponentService().getComponentApprovalStatus(entity.getComponentId()));
        reference.setReferenceId(entity.getContactId());
        reference.setReferenceName(String.join(" ",
                StringUtils.defaultString(StringProcessor.enclose(entity.getSecurityMarkingType())),
                StringUtils.defaultString(TranslateUtil.translate(ContactType.class, entity.getContactType())),
                StringUtils.defaultString(entity.getFirstName()),
                StringUtils.defaultString(entity.getLastName()), StringUtils.defaultString(entity.getEmail())));
        return reference;
    }));

    references.addAll(findOrgReferences(new ComponentReview(), organization, (ComponentReview entity) -> {
        OrgReference reference = new OrgReference();
        reference.setActiveStatus(entity.getActiveStatus());
        reference.setComponentId(entity.getComponentId());
        reference.setComponentName(getComponentService().getComponentName(entity.getComponentId()));
        reference.setComponentApproveStatus(
                getComponentService().getComponentApprovalStatus(entity.getComponentId()));
        reference.setReferenceId(entity.getComponentReviewId());
        reference.setReferenceName(String.join("-", StringUtils.defaultString(entity.getCreateUser()),
                StringUtils.defaultString(StringProcessor.enclose(entity.getSecurityMarkingType())),
                StringUtils.defaultString(
                        StringProcessor.ellipseString(entity.getTitle(), MAX_REFERENCE_NAME_DETAIL))));
        return reference;
    }));
    references.addAll(findOrgReferences(new ComponentQuestion(), organization, (ComponentQuestion entity) -> {
        OrgReference reference = new OrgReference();
        reference.setActiveStatus(entity.getActiveStatus());
        reference.setComponentId(entity.getComponentId());
        reference.setComponentName(getComponentService().getComponentName(entity.getComponentId()));
        reference.setComponentApproveStatus(
                getComponentService().getComponentApprovalStatus(entity.getComponentId()));
        reference.setReferenceId(entity.getQuestionId());
        reference.setReferenceName(String.join("-", StringUtils.defaultString(entity.getCreateUser()),
                String.join(" ",
                        StringUtils.defaultString(StringProcessor.enclose(entity.getSecurityMarkingType())),
                        StringUtils.defaultString(StringProcessor.ellipseString(entity.getQuestion(),
                                MAX_REFERENCE_NAME_DETAIL)))));
        return reference;
    }));
    references.addAll(findOrgReferences(new ComponentQuestionResponse(), organization,
            (ComponentQuestionResponse entity) -> {
                OrgReference reference = new OrgReference();
                reference.setActiveStatus(entity.getActiveStatus());
                reference.setComponentId(entity.getComponentId());
                reference.setComponentName(getComponentService().getComponentName(entity.getComponentId()));
                reference.setComponentApproveStatus(
                        getComponentService().getComponentApprovalStatus(entity.getComponentId()));
                reference.setReferenceId(entity.getResponseId());
                reference.setReferenceName(String.join("-", StringUtils.defaultString(entity.getCreateUser()),
                        String.join(" ",
                                StringUtils.defaultString(
                                        StringProcessor.enclose(entity.getSecurityMarkingType())),
                                StringUtils.defaultString(StringProcessor.ellipseString(entity.getResponse(),
                                        MAX_REFERENCE_NAME_DETAIL)))));
                return reference;
            }));
    references.addAll(findOrgReferences(new UserProfile(), organization, (UserProfile entity) -> {
        OrgReference reference = new OrgReference();
        reference.setActiveStatus(entity.getActiveStatus());
        reference.setReferenceId(entity.getUsername());
        reference.setReferenceName(String.join(" ", StringUtils.defaultString(entity.getFirstName()),
                StringUtils.defaultString(entity.getLastName()), StringUtils.defaultString(entity.getEmail())));
        return reference;
    }));

    if (onlyActive) {
        references = references.stream().filter(r -> StandardEntity.ACTIVE_STATUS.equals(r.getActiveStatus()))
                .collect(Collectors.toList());
    }

    if (onlyApprovedComponents) {
        references = references.stream()
                .filter(r -> r.getComponentApproveStatus() == null
                        || ApprovalStatus.APPROVED.equals(r.getComponentApproveStatus()))
                .collect(Collectors.toList());
    }

    return references;
}

From source file:com.xpn.xwiki.pdf.impl.PdfURLFactory.java

/**
 * Computes a safe identifier for an attachment, guaranteed to be collision-free.
 * /* ww w .j  a v a  2  s.c o  m*/
 * @param space the name of the owner document's space
 * @param name the name of the owner document
 * @param filename the name of the attachment
 * @param revision an optional attachment version
 * @return an identifier for this attachment
 */
private String getAttachmentKey(String space, String name, String filename, String revision) {
    try {
        return "attachment" + SEPARATOR + URLEncoder.encode(space, XWiki.DEFAULT_ENCODING) + SEPARATOR
                + URLEncoder.encode(name, XWiki.DEFAULT_ENCODING) + SEPARATOR
                + URLEncoder.encode(filename, XWiki.DEFAULT_ENCODING) + SEPARATOR
                + URLEncoder.encode(StringUtils.defaultString(revision), XWiki.DEFAULT_ENCODING);
    } catch (UnsupportedEncodingException ex) {
        // This should never happen, UTF-8 is always available
        return space + SEPARATOR + name + SEPARATOR + filename + SEPARATOR
                + StringUtils.defaultString(revision);
    }
}

From source file:com.netsteadfast.greenstep.bsc.util.WorkspaceUtils.java

private static String getCompomentRenderBody(WorkspaceCompomentVO compoment,
        Map<String, Object> templateParameters) throws Exception {
    Class<BaseWorkspaceCompoment> clazz = (Class<BaseWorkspaceCompoment>) Class
            .forName(compoment.getClassName());
    BaseWorkspaceCompoment compomentObj = clazz.newInstance();
    compomentObj.loadFromId(compoment.getCompId());
    compomentObj.getParameters().putAll(templateParameters);
    compomentObj.doRender();/*  w w w  .  jav a2s . c o m*/
    return StringUtils.defaultString(compomentObj.getBody());
}

From source file:net.sf.jsignpdf.SignerLogic.java

/**
 * Signs a single file.//  www .  j a v a 2  s  .  c  om
 * 
 * @return true when signing is finished succesfully, false otherwise
 */
public boolean signFile() {
    final String outFile = options.getOutFileX();
    if (!validateInOutFiles(options.getInFile(), outFile)) {
        LOGGER.info(RES.get("console.skippingSigning"));
        return false;
    }

    boolean finished = false;
    Throwable tmpException = null;
    FileOutputStream fout = null;
    try {
        SSLInitializer.init(options);

        final PrivateKeyInfo pkInfo = KeyStoreUtils.getPkInfo(options);
        final PrivateKey key = pkInfo.getKey();
        final Certificate[] chain = pkInfo.getChain();
        if (ArrayUtils.isEmpty(chain)) {
            // the certificate was not found
            LOGGER.info(RES.get("console.certificateChainEmpty"));
            return false;
        }
        LOGGER.info(RES.get("console.createPdfReader", options.getInFile()));
        PdfReader reader;
        try {
            reader = new PdfReader(options.getInFile(), options.getPdfOwnerPwdStrX().getBytes());
        } catch (Exception e) {
            try {
                reader = new PdfReader(options.getInFile(), new byte[0]);
            } catch (Exception e2) {
                // try to read without password
                reader = new PdfReader(options.getInFile());
            }
        }

        LOGGER.info(RES.get("console.createOutPdf", outFile));
        fout = new FileOutputStream(outFile);

        final HashAlgorithm hashAlgorithm = options.getHashAlgorithmX();

        LOGGER.info(RES.get("console.createSignature"));
        char tmpPdfVersion = '\0'; // default version - the same as input
        if (reader.getPdfVersion() < hashAlgorithm.getPdfVersion()) {
            // this covers also problems with visible signatures (embedded
            // fonts) in PDF 1.2, because the minimal version
            // for hash algorithms is 1.3 (for SHA1)
            if (options.isAppendX()) {
                // if we are in append mode and version should be updated
                // then return false (not possible)
                LOGGER.info(RES.get("console.updateVersionNotPossibleInAppendMode"));
                return false;
            }
            tmpPdfVersion = hashAlgorithm.getPdfVersion();
            LOGGER.info(RES.get("console.updateVersion",
                    new String[] { String.valueOf(reader.getPdfVersion()), String.valueOf(tmpPdfVersion) }));
        }

        final PdfStamper stp = PdfStamper.createSignature(reader, fout, tmpPdfVersion, null,
                options.isAppendX());
        if (!options.isAppendX()) {
            // we are not in append mode, let's remove existing signatures
            // (otherwise we're getting to troubles)
            final AcroFields acroFields = stp.getAcroFields();
            @SuppressWarnings("unchecked")
            final List<String> sigNames = acroFields.getSignatureNames();
            for (String sigName : sigNames) {
                acroFields.removeField(sigName);
            }
        }
        if (options.isAdvanced() && options.getPdfEncryption() != PDFEncryption.NONE) {
            LOGGER.info(RES.get("console.setEncryption"));
            final int tmpRight = options.getRightPrinting().getRight()
                    | (options.isRightCopy() ? PdfWriter.ALLOW_COPY : 0)
                    | (options.isRightAssembly() ? PdfWriter.ALLOW_ASSEMBLY : 0)
                    | (options.isRightFillIn() ? PdfWriter.ALLOW_FILL_IN : 0)
                    | (options.isRightScreanReaders() ? PdfWriter.ALLOW_SCREENREADERS : 0)
                    | (options.isRightModifyAnnotations() ? PdfWriter.ALLOW_MODIFY_ANNOTATIONS : 0)
                    | (options.isRightModifyContents() ? PdfWriter.ALLOW_MODIFY_CONTENTS : 0);
            switch (options.getPdfEncryption()) {
            case PASSWORD:
                stp.setEncryption(true, options.getPdfUserPwdStr(), options.getPdfOwnerPwdStrX(), tmpRight);
                break;
            case CERTIFICATE:
                final X509Certificate encCert = KeyStoreUtils
                        .loadCertificate(options.getPdfEncryptionCertFile());
                if (encCert == null) {
                    LOGGER.error(RES.get("console.pdfEncError.wrongCertificateFile",
                            StringUtils.defaultString(options.getPdfEncryptionCertFile())));
                    return false;
                }
                if (!KeyStoreUtils.isEncryptionSupported(encCert)) {
                    LOGGER.error(RES.get("console.pdfEncError.cantUseCertificate",
                            encCert.getSubjectDN().getName()));
                    return false;
                }
                stp.setEncryption(new Certificate[] { encCert }, new int[] { tmpRight },
                        PdfWriter.ENCRYPTION_AES_128);
                break;
            default:
                LOGGER.error(RES.get("console.unsupportedEncryptionType"));
                return false;
            }
        }

        final PdfSignatureAppearance sap = stp.getSignatureAppearance();
        sap.setCrypto(key, chain, null, PdfSignatureAppearance.WINCER_SIGNED);
        final String reason = options.getReason();
        if (StringUtils.isNotEmpty(reason)) {
            LOGGER.info(RES.get("console.setReason", reason));
            sap.setReason(reason);
        }
        final String location = options.getLocation();
        if (StringUtils.isNotEmpty(location)) {
            LOGGER.info(RES.get("console.setLocation", location));
            sap.setLocation(location);
        }
        final String contact = options.getContact();
        if (StringUtils.isNotEmpty(contact)) {
            LOGGER.info(RES.get("console.setContact", contact));
            sap.setContact(contact);
        }
        LOGGER.info(RES.get("console.setCertificationLevel"));
        sap.setCertificationLevel(options.getCertLevelX().getLevel());

        if (options.isVisible()) {
            // visible signature is enabled
            LOGGER.info(RES.get("console.configureVisible"));
            LOGGER.info(RES.get("console.setAcro6Layers", Boolean.toString(options.isAcro6Layers())));
            sap.setAcro6Layers(options.isAcro6Layers());

            final String tmpImgPath = options.getImgPath();
            if (tmpImgPath != null) {
                LOGGER.info(RES.get("console.createImage", tmpImgPath));
                final Image img = Image.getInstance(tmpImgPath);
                LOGGER.info(RES.get("console.setSignatureGraphic"));
                sap.setSignatureGraphic(img);
            }
            final String tmpBgImgPath = options.getBgImgPath();
            if (tmpBgImgPath != null) {
                LOGGER.info(RES.get("console.createImage", tmpBgImgPath));
                final Image img = Image.getInstance(tmpBgImgPath);
                LOGGER.info(RES.get("console.setImage"));
                sap.setImage(img);
            }
            LOGGER.info(RES.get("console.setImageScale"));
            sap.setImageScale(options.getBgImgScale());
            LOGGER.info(RES.get("console.setL2Text"));
            final String signer = PdfPKCS7.getSubjectFields((X509Certificate) chain[0]).getField("CN");
            final String timestamp = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss z")
                    .format(sap.getSignDate().getTime());
            if (options.getL2Text() != null) {
                final Map<String, String> replacements = new HashMap<String, String>();
                replacements.put(L2TEXT_PLACEHOLDER_SIGNER, StringUtils.defaultString(signer));
                replacements.put(L2TEXT_PLACEHOLDER_TIMESTAMP, timestamp);
                replacements.put(L2TEXT_PLACEHOLDER_LOCATION, StringUtils.defaultString(location));
                replacements.put(L2TEXT_PLACEHOLDER_REASON, StringUtils.defaultString(reason));
                replacements.put(L2TEXT_PLACEHOLDER_CONTACT, StringUtils.defaultString(contact));
                final String l2text = StrSubstitutor.replace(options.getL2Text(), replacements);
                sap.setLayer2Text(l2text);
            } else {
                final StringBuilder buf = new StringBuilder();
                buf.append(RES.get("default.l2text.signedBy")).append(" ").append(signer).append('\n');
                buf.append(RES.get("default.l2text.date")).append(" ").append(timestamp);
                if (StringUtils.isNotEmpty(reason))
                    buf.append('\n').append(RES.get("default.l2text.reason")).append(" ").append(reason);
                if (StringUtils.isNotEmpty(location))
                    buf.append('\n').append(RES.get("default.l2text.location")).append(" ").append(location);
                sap.setLayer2Text(buf.toString());
            }
            if (FontUtils.getL2BaseFont() != null) {
                sap.setLayer2Font(new Font(FontUtils.getL2BaseFont(), options.getL2TextFontSize()));
            }
            LOGGER.info(RES.get("console.setL4Text"));
            sap.setLayer4Text(options.getL4Text());
            LOGGER.info(RES.get("console.setRender"));
            RenderMode renderMode = options.getRenderMode();
            if (renderMode == RenderMode.GRAPHIC_AND_DESCRIPTION && sap.getSignatureGraphic() == null) {
                LOGGER.warn(
                        "Render mode of visible signature is set to GRAPHIC_AND_DESCRIPTION, but no image is loaded. Fallback to DESCRIPTION_ONLY.");
                LOGGER.info(RES.get("console.renderModeFallback"));
                renderMode = RenderMode.DESCRIPTION_ONLY;
            }
            sap.setRender(renderMode.getRender());
            LOGGER.info(RES.get("console.setVisibleSignature"));
            int page = options.getPage();
            if (page < 1 || page > reader.getNumberOfPages()) {
                page = reader.getNumberOfPages();
            }
            sap.setVisibleSignature(new Rectangle(options.getPositionLLX(), options.getPositionLLY(),
                    options.getPositionURX(), options.getPositionURY()), page, null);
        }

        LOGGER.info(RES.get("console.processing"));
        final PdfSignature dic = new PdfSignature(PdfName.ADOBE_PPKLITE, new PdfName("adbe.pkcs7.detached"));
        if (!StringUtils.isEmpty(reason)) {
            dic.setReason(sap.getReason());
        }
        if (!StringUtils.isEmpty(location)) {
            dic.setLocation(sap.getLocation());
        }
        if (!StringUtils.isEmpty(contact)) {
            dic.setContact(sap.getContact());
        }
        dic.setDate(new PdfDate(sap.getSignDate()));
        sap.setCryptoDictionary(dic);

        final Proxy tmpProxy = options.createProxy();

        final CRLInfo crlInfo = new CRLInfo(options, chain);

        // CRLs are stored twice in PDF c.f.
        // PdfPKCS7.getAuthenticatedAttributeBytes
        final int contentEstimated = (int) (Constants.DEFVAL_SIG_SIZE + 2L * crlInfo.getByteCount());
        final Map<PdfName, Integer> exc = new HashMap<PdfName, Integer>();
        exc.put(PdfName.CONTENTS, new Integer(contentEstimated * 2 + 2));
        sap.preClose(exc);

        PdfPKCS7 sgn = new PdfPKCS7(key, chain, crlInfo.getCrls(), hashAlgorithm.getAlgorithmName(), null,
                false);
        InputStream data = sap.getRangeStream();
        final MessageDigest messageDigest = MessageDigest.getInstance(hashAlgorithm.getAlgorithmName());
        byte buf[] = new byte[8192];
        int n;
        while ((n = data.read(buf)) > 0) {
            messageDigest.update(buf, 0, n);
        }
        byte hash[] = messageDigest.digest();
        Calendar cal = Calendar.getInstance();
        byte[] ocsp = null;
        if (options.isOcspEnabledX() && chain.length >= 2) {
            LOGGER.info(RES.get("console.getOCSPURL"));
            String url = PdfPKCS7.getOCSPURL((X509Certificate) chain[0]);
            if (StringUtils.isEmpty(url)) {
                // get from options
                LOGGER.info(RES.get("console.noOCSPURL"));
                url = options.getOcspServerUrl();
            }
            if (!StringUtils.isEmpty(url)) {
                LOGGER.info(RES.get("console.readingOCSP", url));
                final OcspClientBouncyCastle ocspClient = new OcspClientBouncyCastle((X509Certificate) chain[0],
                        (X509Certificate) chain[1], url);
                ocspClient.setProxy(tmpProxy);
                ocsp = ocspClient.getEncoded();
            }
        }
        byte sh[] = sgn.getAuthenticatedAttributeBytes(hash, cal, ocsp);
        sgn.update(sh, 0, sh.length);

        TSAClientBouncyCastle tsc = null;
        if (options.isTimestampX() && !StringUtils.isEmpty(options.getTsaUrl())) {
            LOGGER.info(RES.get("console.creatingTsaClient"));
            if (options.getTsaServerAuthn() == ServerAuthentication.PASSWORD) {
                tsc = new TSAClientBouncyCastle(options.getTsaUrl(),
                        StringUtils.defaultString(options.getTsaUser()),
                        StringUtils.defaultString(options.getTsaPasswd()));
            } else {
                tsc = new TSAClientBouncyCastle(options.getTsaUrl());

            }
            final String tsaHashAlg = options.getTsaHashAlgWithFallback();
            LOGGER.info(RES.get("console.settingTsaHashAlg", tsaHashAlg));
            tsc.setHashAlgorithm(tsaHashAlg);
            tsc.setProxy(tmpProxy);
            final String policyOid = options.getTsaPolicy();
            if (StringUtils.isNotEmpty(policyOid)) {
                LOGGER.info(RES.get("console.settingTsaPolicy", policyOid));
                tsc.setPolicy(policyOid);
            }
        }
        byte[] encodedSig = sgn.getEncodedPKCS7(hash, cal, tsc, ocsp);

        if (contentEstimated + 2 < encodedSig.length) {
            System.err.println(
                    "SigSize - contentEstimated=" + contentEstimated + ", sigLen=" + encodedSig.length);
            throw new Exception("Not enough space");
        }

        byte[] paddedSig = new byte[contentEstimated];
        System.arraycopy(encodedSig, 0, paddedSig, 0, encodedSig.length);

        PdfDictionary dic2 = new PdfDictionary();
        dic2.put(PdfName.CONTENTS, new PdfString(paddedSig).setHexWriting(true));
        LOGGER.info(RES.get("console.closeStream"));
        sap.close(dic2);
        fout.close();
        fout = null;
        finished = true;
    } catch (Exception e) {
        LOGGER.error(RES.get("console.exception"), e);
    } catch (OutOfMemoryError e) {
        LOGGER.fatal(RES.get("console.memoryError"), e);
    } finally {
        if (fout != null) {
            try {
                fout.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        LOGGER.info(RES.get("console.finished." + (finished ? "ok" : "error")));
        options.fireSignerFinishedEvent(tmpException);
    }
    return finished;
}

From source file:com.pidoco.juri.JURI.java

/**
 * Use {@link #urlEncode(String)} if you want to encode the scheme specific part, or the http-specific manipulation
 * methods provided by this class./*from w  ww. ja  v a  2  s  .c  o m*/
 *
 * <p>If no scheme is currently set the scheme will become 'unspecified'.</p>
 *
 * @param rawSchemeSpecificPart null or "" not allowed.
 */
public JURI setRawSchemeSpecificPart(String rawSchemeSpecificPart) {
    rawSchemeSpecificPart = StringUtils.defaultString(rawSchemeSpecificPart);

    String newUri;
    if (StringUtils.isBlank(getScheme())) {
        newUri = "unspecified:" + rawSchemeSpecificPart;
    } else {
        newUri = getScheme() + ":" + rawSchemeSpecificPart;
    }

    URI newUriObj;
    try {
        newUriObj = new URI(newUri);
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e);
    }

    currentUri = newUriObj;
    reset();
    return this;
}

From source file:com.xpn.xwiki.pdf.impl.FileSystemURLFactory.java

/**
 * Computes a safe identifier for an attachment, guaranteed to be collision-free.
 *
 * @param name the name of the owner document
 * @param filename the name of the attachment
 * @param revision an optional attachment version
 * @return an identifier for this attachment
 *//*from   www. jav  a2 s  . com*/
private String getAttachmentKey(List<String> spaceNames, String name, String filename, String revision) {
    StringBuilder builder = new StringBuilder();

    try {
        builder.append("attachment").append(SEPARATOR);
        for (String spaceName : spaceNames) {
            builder.append(URLEncoder.encode(spaceName, XWiki.DEFAULT_ENCODING));
            builder.append(SEPARATOR);
        }
        builder.append(URLEncoder.encode(name, XWiki.DEFAULT_ENCODING)).append(SEPARATOR);
        builder.append(URLEncoder.encode(filename, XWiki.DEFAULT_ENCODING)).append(SEPARATOR);
        builder.append(URLEncoder.encode(StringUtils.defaultString(revision), XWiki.DEFAULT_ENCODING));
        return builder.toString();
    } catch (UnsupportedEncodingException e) {
        // This should never happen, UTF-8 is always available
        throw new RuntimeException(String.format(
                "Failed to compute unique Attachment key for spaces [%s[, "
                        + "page [%s], filename [%s], revision [%s], while exporting.",
                StringUtils.join(spaceNames, ", "), name, filename, revision), e);
    }
}