Example usage for java.lang StringBuffer insert

List of usage examples for java.lang StringBuffer insert

Introduction

In this page you can find the example usage for java.lang StringBuffer insert.

Prototype

@Override
public StringBuffer insert(int offset, double d) 

Source Link

Usage

From source file:org.apache.ws.security.transform.STRTransform.java

/**
 * Method enginePerformTransform/* w  w w. jav  a2  s. c  o  m*/
 * 
 * @param input
 * @throws CanonicalizationException
 * @throws InvalidCanonicalizerException
 */
protected XMLSignatureInput enginePerformTransform(XMLSignatureInput input, Transform transformObject)
        throws IOException, CanonicalizationException, InvalidCanonicalizerException {
    doDebug = log.isDebugEnabled();

    if (doDebug) {
        log.debug("Beginning STRTransform..." + input.toString());
    }

    try {
        //
        // Get the main document, that is the complete SOAP request document
        //
        Document thisDoc = transformObject.getDocument();

        //
        // Here we get some information about the document that is being
        // processed, in particular the crypto implementation, and already
        // detected BST that may be used later during dereferencing.
        //
        wsDocInfo = WSDocInfoStore.lookup(thisDoc);
        if (wsDocInfo == null) {
            throw (new CanonicalizationException("no WSDocInfo found"));
        }
        //
        // According to the OASIS WS Specification "Web Services Security:
        // SOAP Message Security 1.0" Monday, 19 January 2004, chapter 8.3
        // describes that the input node set must be processed by the c14n
        // that is specified in the argument element of the STRTransform
        // element.
        // 
        // First step: Get the required c14n argument and get the specified
        // Canonicalizer
        //
        String canonAlgo = null;
        if (transformObject.length(WSConstants.WSSE_NS, "TransformationParameters") == 1) {
            Element tmpE = XMLUtils.selectNode(transformObject.getElement().getFirstChild(),
                    WSConstants.WSSE_NS, "TransformationParameters", 0);
            Element canonElem = (Element) WSSecurityUtil.getDirectChild(tmpE, "CanonicalizationMethod",
                    WSConstants.SIG_NS);
            canonAlgo = canonElem.getAttribute("Algorithm");
            if (doDebug) {
                log.debug("CanonAlgo: " + canonAlgo);
            }
        }
        Canonicalizer canon = Canonicalizer.getInstance(canonAlgo);

        ByteArrayOutputStream bos = null;
        byte[] buf = null;
        if (doDebug) {
            buf = input.getBytes();
            bos = new ByteArrayOutputStream(buf.length);
            bos.write(buf, 0, buf.length);
            log.debug("canon bos: " + bos.toString());
        }

        //
        // Get the input (node) to transform. Currently we support only an
        // Element as input format. If other formats are required we must
        // get it as bytes and probably reparse it into a DOM tree (How to
        // work with nodesets? how to select the right node from a nodeset?)
        //
        Element str = null;
        if (input.isElement()) {
            str = (Element) input.getSubNode();
        } else {
            throw new CanonicalizationException("Wrong input format - only element input supported");
        }

        if (doDebug) {
            log.debug("STR: " + str.toString());
        }
        //
        // The element to transform MUST be a SecurityTokenReference
        // element.
        //
        SecurityTokenReference secRef = new SecurityTokenReference(str);
        //
        // Third and forth step are performed by derefenceSTR()
        //
        Element dereferencedToken = STRTransformUtil.dereferenceSTR(thisDoc, secRef, wsDocInfo);
        //
        // C14n with specified algorithm. According to WSS Specification.
        //
        buf = canon.canonicalizeSubtree(dereferencedToken, "#default");
        if (doDebug) {
            bos = new ByteArrayOutputStream(buf.length);
            bos.write(buf, 0, buf.length);
            log.debug("after c14n: " + bos.toString());
        }

        //
        // Alert: Hacks ahead According to WSS spec an Apex node must
        // contain a default namespace. If none is availabe in the first
        // node of the c14n output (this is the apex element) then we do
        // some editing to insert an empty default namespace
        // 
        // TODO: Rework theses hacks after c14n was updated and can be
        // instructed to insert empty default namespace if required
        //
        // If the problem with c14n method is solved then just do:
        // return new XMLSignatureInput(buf);

        // start of HACK
        StringBuffer bf = new StringBuffer(new String(buf));
        String bf1 = bf.toString();

        //
        // Find start and end of first element <....>, this is the Apex node
        //
        int gt = bf1.indexOf(">");
        //
        // Lookup the default namespace
        //
        int idx = bf1.indexOf(XMLNS);
        //
        // If none found or if it is outside of this (Apex) element look for
        // first blank in, insert default namespace there (this is the
        // correct place according to c14n specification)
        //
        if (idx < 0 || idx > gt) {
            idx = bf1.indexOf(" ");
            bf.insert(idx + 1, "xmlns=\"\" ");
            bf1 = bf.toString();
        }
        if (doDebug) {
            log.debug("last result: ");
            log.debug(bf1);
        }
        return new XMLSignatureInput(bf1.getBytes());
    }
    // End of HACK
    catch (WSSecurityException ex) {
        log.debug(ex.getMessage(), ex);
        throw (new CanonicalizationException("c14n.Canonicalizer.Exception", ex));
    }
}

From source file:gsn.vsensor.ChartVirtualSensor.java

public String toString() {
    StringBuffer buffer = new StringBuffer();
    try {//from   ww  w . j av  a2  s. c  o m
        if (plotTitle != null)
            buffer.append("Plot-Title : ").append(plotTitle).append("\n");
        if (inputStreamName != null) {
            buffer.append("Input-Stream Name : ").append(inputStreamName).append("\n");
        }
        buffer.append("Width : ").append(width).append("\n");
        buffer.append("Height : ").append(height).append("\n");
        if (type != null)
            buffer.append("Type : ").append(type).append("\n");
        buffer.append("History-size : ").append(historySize).append("\n");
    } catch (Exception e) {
        buffer.insert(0,
                "ERROR : Till now the ChartVirtualSensor instance could understand the followings : \n");
    }
    return buffer.toString();
}

From source file:org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.java

/**
 * DOC Administrator Comment method "createLauncherFile".
 * //from w  w w  . j  av  a2  s.c o m
 * @param process
 * @param list
 * @param cmdPrimary
 * @param cmdSecondary
 * @param tmpFold
 */
private void createLauncherFile(ProcessItem process, List<URL> list, String cmd, String fileName,
        String tmpFold) {
    PrintWriter pw = null;
    try {
        String cmdPrimary = cmd;
        // add for bug TDI-24935, add a string on comPrimary's start position.
        if (cmdPrimary != null && UNIX_LAUNCHER.equals(fileName)) {
            StringBuffer strBuffer = new StringBuffer(cmdPrimary);
            strBuffer.insert(0, "#!/bin/sh\n");
            cmdPrimary = strBuffer.toString();
        }
        File file = new File(tmpFold, process.getProperty().getLabel() + "_" + fileName); //$NON-NLS-1$
        file.createNewFile();
        pw = new PrintWriter(new FileOutputStream(file));
        pw.print(cmdPrimary);
        pw.flush();
        list.add(file.toURL());
        pw.close();
    } catch (Exception e) {
        ExceptionHandler.process(e);
    } finally {
        try {
            if (pw != null) {
                pw.close();
            }
        } catch (Exception e) {
            // do nothing here
        }
    }
}

From source file:com.npower.dm.processor.ProfileReAssignmentProcessor.java

/**
 * caculate the nodePath.//from w w w.  j av  a 2s .c  om
 * If the node's name is null, will instead with Map of this.nameMaps.
 * The path will start with "./"
 * @return
 */
private String caculateNodePath(DDFNode node) {

    StringBuffer result = new StringBuffer();
    String name = node.getName();
    if (name == null) {
        if (this.nameMaps.containsKey(node)) {
            name = this.nameMaps.get(node);
        } else {
            name = this.generateNodeName(node);
        }
    }
    result.append(name);
    DDFNode parent = node.getParentDDFNode();
    while (parent != null) {
        result.insert(0, "/");
        name = parent.getName();
        if (name == null) {
            if (this.nameMaps.containsKey(parent)) {
                name = this.nameMaps.get(parent);
            } else {
                throw new RuntimeException("Parent node haven't been specified name.");
            }
        }
        result.insert(0, name);
        parent = parent.getParentDDFNode();
    }
    String path = result.toString();
    if (!path.startsWith("./")) {
        return "./" + path;
    } else {
        return path;
    }
}

From source file:com.appeligo.search.actions.ProgramAction.java

public String getQueryStringNoProgramId() {
    String queryString = getServletRequest().getQueryString();
    String[] params = queryString.split("&");
    StringBuffer sb = new StringBuffer();
    boolean first = true;
    for (String param : params) {
        if (!param.startsWith("programId=")) {
            if (!first) {
                sb.append("&");
            }/*from w w w . j  a v  a  2s . co  m*/
            sb.append(param);
            first = false;
        }
    }
    if (sb.length() > 0) {
        sb.insert(0, '?');
    }
    return sb.toString();
}

From source file:com.npower.dm.processor.ProfileAssignmentProcessor.java

/**
 * caculate the nodePath. If the node's name is null, will instead with Map of
 * this.nameMaps. The path will start with "./"
 * //w w w  . ja va 2s  . c  o m
 * @return
 */
private String getNodePath(DDFNode node) {

    StringBuffer result = new StringBuffer();
    String name = node.getName();
    if (name == null) {
        if (this.nameMaps.containsKey(node)) {
            name = this.nameMaps.get(node);
        } else {
            throw new RuntimeException("node haven't been specified name.");
        }
    }
    result.append(name);
    DDFNode parent = node.getParentDDFNode();
    while (parent != null) {
        result.insert(0, "/");
        name = parent.getName();
        if (name == null) {
            if (this.nameMaps.containsKey(parent)) {
                name = this.nameMaps.get(parent);
            } else {
                throw new RuntimeException("Parent node haven't been specified name.");
            }
        }
        result.insert(0, name);
        parent = parent.getParentDDFNode();
    }
    String path = result.toString();
    if (!path.startsWith("./")) {
        return "./" + path;
    } else {
        return path;
    }
}

From source file:javax.faces.webapp.UIComponentTag.java

/** Generate diagnostic output. */
private String getPathToComponent(UIComponent component) {
    StringBuffer buf = new StringBuffer();

    if (component == null) {
        buf.append("{Component-Path : ");
        buf.append("[null]}");
        return buf.toString();
    }//from w  w  w  .  j a  v a  2  s  .c o  m

    getPathToComponent(component, buf);

    buf.insert(0, "{Component-Path : ");
    buf.append("}");

    return buf.toString();
}

From source file:com.sfs.whichdoctor.analysis.AgedDebtorsAnalysisDAOImpl.java

/**
 * Builds the sql where statement.//from ww w . ja  va 2 s.c om
 *
 * @param analysis the analysis
 * @param peopleField the people field
 * @param organisationField the organisation field
 * @param prependAnd the flag to prepend the AND to the SQL where statement
 * @return the string
 */
private String buildSqlWhere(final AgedDebtorsAnalysisBean analysis, final String peopleField,
        final String organisationField, final boolean prependAnd) {

    StringBuffer sql = new StringBuffer();

    for (Integer guid : analysis.getPeople().keySet()) {
        if (sql.length() > 0) {
            sql.append(" OR ");
        }
        sql.append(peopleField);
        sql.append(" = ");
        sql.append(guid);
    }

    for (Integer guid : analysis.getOrganisations().keySet()) {
        if (sql.length() > 0) {
            sql.append(" OR ");
        }
        sql.append(organisationField);
        sql.append(" = ");
        sql.append(guid);
    }

    if (prependAnd && sql.length() > 0) {
        sql.insert(0, " AND (");
        sql.append(")");
    }

    return sql.toString();
}

From source file:com.sfs.whichdoctor.dao.AddressVerificationDAOImpl.java

/**
 * Load a collection of address verification beans that are capable of being
 * processed by WhichDoctor and are pending processing.
 *
 * @param count the requested number//from w  w  w.  j  ava  2s. c  om
 * @return the pending address verification beans
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
@SuppressWarnings("unchecked")
public final Collection<AddressVerificationBean> loadPending(final int count) throws WhichDoctorDaoException {

    Collection<AddressVerificationBean> addressVerifications = new ArrayList<AddressVerificationBean>();

    Collection<Object> parameters = new ArrayList<Object>();
    parameters.add(PENDING);

    StringBuffer sqlWHERE = new StringBuffer();

    Collection<String> codes = this.getProcessableReturnCodes();
    for (String code : codes) {
        if (sqlWHERE.length() > 0) {
            sqlWHERE.append(" OR ");
        }
        sqlWHERE.append("address_verification.ReturnCode LIKE ?");
        parameters.add(code + "%");
    }
    if (sqlWHERE.length() > 0) {
        sqlWHERE.insert(0, " AND (");
        sqlWHERE.append(")");
    }

    parameters.add(count);
    sqlWHERE.append(" LIMIT ?");

    String loadPending = this.getSQL().getValue("addressVerification/loadPending") + sqlWHERE.toString();

    try {
        addressVerifications = this.getJdbcTemplateReader().query(loadPending, parameters.toArray(),
                new RowMapper() {
                    public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                        return loadAddressVerification(rs);
                    }
                });

    } catch (IncorrectResultSizeDataAccessException ie) {
        dataLogger.debug("Could not find any pending addresses: " + ie.getMessage());
    }

    // Update the status of these pending records
    for (AddressVerificationBean av : addressVerifications) {
        // Update the process status to 'Processing' for these records
        updateProcessStatus(av.getAddressVerificationId(), PROCESSING, "");
    }

    return addressVerifications;
}

From source file:org.apache.myfaces.ov2021.view.facelets.compiler.UILeaf.java

private void getPathToComponent(UIComponent component, StringBuffer buf) {
    if (component == null) {
        return;//  w w  w. j  a  v a2 s.co  m
    }

    StringBuffer intBuf = new StringBuffer();

    intBuf.append("[Class: ");
    intBuf.append(component.getClass().getName());
    if (component instanceof UIViewRoot) {
        intBuf.append(",ViewId: ");
        intBuf.append(((UIViewRoot) component).getViewId());
    } else {
        intBuf.append(",Id: ");
        intBuf.append(component.getId());
    }
    intBuf.append("]");

    buf.insert(0, intBuf.toString());

    getPathToComponent(component.getParent(), buf);
}