Search in sources :

Example 26 with SerializationException

use of org.apache.pivot.serialization.SerializationException in project pivot by apache.

the class ExpenseServlet method init.

@SuppressWarnings({ "resource", "unchecked" })
@Override
public void init() throws ServletException {
    CSVSerializer expenseSerializer = new CSVSerializer(Expense.class);
    expenseSerializer.setKeys("date", "type", "amount", "description");
    // Load the initial expense data
    InputStream inputStream = ExpenseServlet.class.getResourceAsStream("expenses.csv");
    try {
        expenses = (List<Expense>) expenseSerializer.readObject(inputStream);
    } catch (IOException exception) {
        throw new ServletException(exception);
    } catch (SerializationException exception) {
        throw new ServletException(exception);
    }
    // Index the initial expenses
    for (Expense expense : expenses) {
        int id = nextID++;
        expense.setID(id);
        expenseMap.put(id, expense);
    }
}
Also used : ServletException(javax.servlet.ServletException) SerializationException(org.apache.pivot.serialization.SerializationException) InputStream(java.io.InputStream) IOException(java.io.IOException) CSVSerializer(org.apache.pivot.serialization.CSVSerializer)

Example 27 with SerializationException

use of org.apache.pivot.serialization.SerializationException in project pivot by apache.

the class ColorSchemeBuilderWindow method reloadContent.

private void reloadContent() {
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    try {
        Component sampleContent = (Component) bxmlSerializer.readObject(ColorSchemeBuilderWindow.class, "sample_content.bxml");
        sampleContentBorder.setContent(sampleContent);
    } catch (IOException exception) {
        throw new RuntimeException(exception);
    } catch (SerializationException exception) {
        throw new RuntimeException(exception);
    }
}
Also used : SerializationException(org.apache.pivot.serialization.SerializationException) IOException(java.io.IOException) Component(org.apache.pivot.wtk.Component) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 28 with SerializationException

use of org.apache.pivot.serialization.SerializationException in project pivot by apache.

the class ColorSchemeBuilderWindow method copyToClipboard.

private void copyToClipboard() {
    int numberOfPaletteColors = getNumberOfPaletteColors();
    ArrayList<String> colors = new ArrayList<>(numberOfPaletteColors);
    for (int i = 0; i < numberOfPaletteColors; i++) {
        ColorChooserButton colorChooserButton = colorChooserButtons.get(i);
        Color color = colorChooserButton.getSelectedColor();
        colors.add(ColorUtilities.toStringValue(color));
    }
    LocalManifest clipboardContent = new LocalManifest();
    try {
        clipboardContent.putText(JSONSerializer.toString(colors));
    } catch (SerializationException exception) {
        Prompt.prompt(exception.getMessage(), this);
    }
    Clipboard.setContent(clipboardContent);
}
Also used : SerializationException(org.apache.pivot.serialization.SerializationException) ColorChooserButton(org.apache.pivot.wtk.ColorChooserButton) Color(java.awt.Color) ArrayList(org.apache.pivot.collections.ArrayList) LocalManifest(org.apache.pivot.wtk.LocalManifest)

Example 29 with SerializationException

use of org.apache.pivot.serialization.SerializationException in project pivot by apache.

the class RESTDemoServlet method doPost.

@SuppressWarnings("resource")
@Override
protected URL doPost(Path path, Object value) throws QueryException {
    if (path.getLength() > 0 || value == null) {
        throw new QueryException(Query.Status.BAD_REQUEST);
    }
    // Write the value to a temp file
    File directory = new File(System.getProperty("java.io.tmpdir"));
    File file;
    try {
        file = File.createTempFile(getClass().getName(), null, directory);
        JSONSerializer jsonSerializer = new JSONSerializer();
        jsonSerializer.writeObject(value, new FileOutputStream(file));
    } catch (IOException exception) {
        throw new QueryException(Query.Status.INTERNAL_SERVER_ERROR);
    } catch (SerializationException exception) {
        throw new QueryException(Query.Status.INTERNAL_SERVER_ERROR);
    }
    // Return the location of the resource
    URL location;
    try {
        location = new URL(getLocation(), file.getName());
    } catch (MalformedURLException exception) {
        throw new QueryException(Query.Status.INTERNAL_SERVER_ERROR);
    }
    return location;
}
Also used : QueryException(org.apache.pivot.web.QueryException) MalformedURLException(java.net.MalformedURLException) SerializationException(org.apache.pivot.serialization.SerializationException) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) URL(java.net.URL) JSONSerializer(org.apache.pivot.json.JSONSerializer)

Example 30 with SerializationException

use of org.apache.pivot.serialization.SerializationException in project pivot by apache.

the class RESTDemoServlet method doPut.

@SuppressWarnings("resource")
@Override
protected boolean doPut(Path path, Object value) throws QueryException {
    if (path.getLength() != 1 || value == null) {
        throw new QueryException(Query.Status.BAD_REQUEST);
    }
    // Write the value to the temp file
    File directory = new File(System.getProperty("java.io.tmpdir"));
    File file = new File(directory, path.get(0));
    if (!file.exists()) {
        throw new QueryException(Query.Status.NOT_FOUND);
    }
    try {
        JSONSerializer jsonSerializer = new JSONSerializer();
        jsonSerializer.writeObject(value, new FileOutputStream(file));
    } catch (IOException exception) {
        throw new QueryException(Query.Status.INTERNAL_SERVER_ERROR);
    } catch (SerializationException exception) {
        throw new QueryException(Query.Status.INTERNAL_SERVER_ERROR);
    }
    return false;
}
Also used : QueryException(org.apache.pivot.web.QueryException) SerializationException(org.apache.pivot.serialization.SerializationException) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) JSONSerializer(org.apache.pivot.json.JSONSerializer)

Aggregations

SerializationException (org.apache.pivot.serialization.SerializationException)49 IOException (java.io.IOException)28 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)14 URL (java.net.URL)9 JSONSerializer (org.apache.pivot.json.JSONSerializer)9 ArrayList (org.apache.pivot.collections.ArrayList)8 Component (org.apache.pivot.wtk.Component)7 File (java.io.File)6 List (org.apache.pivot.collections.List)6 QueryException (org.apache.pivot.web.QueryException)6 ComponentMouseButtonListener (org.apache.pivot.wtk.ComponentMouseButtonListener)6 InputStream (java.io.InputStream)5 Sequence (org.apache.pivot.collections.Sequence)5 Button (org.apache.pivot.wtk.Button)5 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)5 Mouse (org.apache.pivot.wtk.Mouse)5 PushButton (org.apache.pivot.wtk.PushButton)5 MalformedURLException (java.net.MalformedURLException)4 ScriptException (javax.script.ScriptException)4 TextInput (org.apache.pivot.wtk.TextInput)4