Search in sources :

Example 6 with StringSubstitutionException

use of com.sun.enterprise.admin.servermgmt.stringsubs.StringSubstitutionException in project Payara by payara.

the class RadixTreeSubstitutionAlgo method substitute.

@Override
public void substitute(Substitutable substitutable) throws StringSubstitutionException {
    Reader reader = substitutable.getReader();
    Writer writer = substitutable.getWriter();
    RadixTreeSubstitution sub = new RadixTreeSubstitution(_tree);
    String output = null;
    char[] cbuffer = new char[8192];
    int count = 0;
    try {
        while ((count = reader.read(cbuffer)) > 0) {
            for (int i = 0; i < count; i++) {
                output = sub.substitute(cbuffer[i]);
                if (output != null) {
                    writer.write(output);
                }
            }
        }
        output = sub.substitute(null);
        if (output != null) {
            writer.write(output);
        }
        writer.flush();
    } catch (IOException e) {
        throw new StringSubstitutionException(_strings.get("errorInStringSubstitution", substitutable.getName()), e);
    }
}
Also used : StringSubstitutionException(com.sun.enterprise.admin.servermgmt.stringsubs.StringSubstitutionException) Reader(java.io.Reader) IOException(java.io.IOException) Writer(java.io.Writer)

Example 7 with StringSubstitutionException

use of com.sun.enterprise.admin.servermgmt.stringsubs.StringSubstitutionException in project Payara by payara.

the class TestStringSubstitutionParser method testParser.

/**
 * Test string subs XML parsing.
 */
@Test
public void testParser() {
    StringsubsDefinition def = null;
    try {
        def = StringSubstitutionParser.parse(_configStream);
    } catch (StringSubstitutionException e) {
        Assert.fail("Failed to parse xml : " + _stringSubsPath, e);
    }
    Assert.assertNotNull(def);
    Assert.assertNotNull(def.getComponent());
    Assert.assertNotNull(def.getVersion());
    Assert.assertFalse(def.getChangePair().isEmpty());
}
Also used : StringSubstitutionException(com.sun.enterprise.admin.servermgmt.stringsubs.StringSubstitutionException) StringsubsDefinition(com.sun.enterprise.admin.servermgmt.xml.stringsubs.StringsubsDefinition) Test(org.testng.annotations.Test)

Aggregations

StringSubstitutionException (com.sun.enterprise.admin.servermgmt.stringsubs.StringSubstitutionException)7 IOException (java.io.IOException)3 Reader (java.io.Reader)2 Writer (java.io.Writer)2 Substitutable (com.sun.enterprise.admin.servermgmt.stringsubs.Substitutable)1 SubstitutionAlgorithm (com.sun.enterprise.admin.servermgmt.stringsubs.SubstitutionAlgorithm)1 Archive (com.sun.enterprise.admin.servermgmt.xml.stringsubs.Archive)1 ChangePair (com.sun.enterprise.admin.servermgmt.xml.stringsubs.ChangePair)1 ChangePairRef (com.sun.enterprise.admin.servermgmt.xml.stringsubs.ChangePairRef)1 Component (com.sun.enterprise.admin.servermgmt.xml.stringsubs.Component)1 FileEntry (com.sun.enterprise.admin.servermgmt.xml.stringsubs.FileEntry)1 Group (com.sun.enterprise.admin.servermgmt.xml.stringsubs.Group)1 ModeType (com.sun.enterprise.admin.servermgmt.xml.stringsubs.ModeType)1 StringsubsDefinition (com.sun.enterprise.admin.servermgmt.xml.stringsubs.StringsubsDefinition)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBElement (javax.xml.bind.JAXBElement)1 JAXBException (javax.xml.bind.JAXBException)1 Unmarshaller (javax.xml.bind.Unmarshaller)1