openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r1038005 - in /openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest: ExceptionFormatter.java HTMLDocument.java
Date Tue, 23 Nov 2010 07:28:46 GMT
Author: ppoddar
Date: Tue Nov 23 07:28:45 2010
New Revision: 1038005

URL: http://svn.apache.org/viewvc?rev=1038005&view=rev
Log:
OPENJPA-1851: Model HTML formatting.

Added:
    openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/ExceptionFormatter.java
  (with props)
    openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/HTMLDocument.java
  (with props)

Added: openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/ExceptionFormatter.java
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/ExceptionFormatter.java?rev=1038005&view=auto
==============================================================================
--- openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/ExceptionFormatter.java
(added)
+++ openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/ExceptionFormatter.java
Tue Nov 23 07:28:45 2010
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.openjpa.persistence.jest;
+
+import static org.apache.openjpa.persistence.jest.Constants.CSS_JEST;
+import static org.apache.openjpa.persistence.jest.Constants.ATTR_CLASS;
+import static org.apache.openjpa.persistence.jest.Constants.CSS_ERROR_HEADER;
+import static org.apache.openjpa.persistence.jest.Constants.CSS_ERROR_MESSSAGE;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import org.apache.openjpa.persistence.jest.HTMLElement.Tag;
+
+/**
+ * Formats error stack trace.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+class ExceptionFormatter {
+    /**
+     * Creates a HTML Document with given header and stack trace of the given error.
+     * @param header
+     * @param e
+     */
+    public HTMLDocument createHTML(String header, Throwable e) {
+        HTMLDocument html = new HTMLDocument();
+        html.getHead().add(CSS_JEST);
+        
+        StringWriter buf = new StringWriter();
+        e.printStackTrace(new PrintWriter(buf, true));
+        html.getBody()
+               .add(new HTMLElement(Tag.p).set(ATTR_CLASS, CSS_ERROR_HEADER).setBody(header),

+                    new HTMLElement(Tag.p).set(ATTR_CLASS, CSS_ERROR_MESSSAGE).setBody(e.getLocalizedMessage()),

+                    new HTMLElement(Tag.p).setBody("Error Stack Trace:"), 
+                    new HTMLElement(Tag.pre).setBody(buf.toString()));
+        return html;
+    }
+
+}

Propchange: openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/ExceptionFormatter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/HTMLDocument.java
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/HTMLDocument.java?rev=1038005&view=auto
==============================================================================
--- openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/HTMLDocument.java
(added)
+++ openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/HTMLDocument.java
Tue Nov 23 07:28:45 2010
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.openjpa.persistence.jest;
+
+
+/**
+ * A HTML document. 
+ * A document has only a head and a body element at construction. 
+ * No further element can be added.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+public class HTMLDocument extends HTMLElement {
+    private final HTMLElement _head;
+    private final HTMLElement _body;
+    
+    public HTMLDocument() {
+        this(false);
+    }
+    
+    public HTMLDocument(boolean open) {
+        super(Tag.html, open);
+        _head = new HTMLElement(Tag.head, open);
+        _body = new HTMLElement(Tag.body, open);
+        super.add(_head, _body);
+    }
+    
+    public HTMLElement getHead() {
+        return _head;
+    }
+    
+    public HTMLElement getBody() {
+        return _body;
+    }
+    //<title>, <base>, <link>, <meta>, <script>, and <style>.
+    
+    /**
+     * Prevents adding any child element. 
+     * 
+     * @throws UnsupportedOperationException.
+     */
+    @Override
+    public HTMLDocument add(HTMLElement...children) {
+        throw new UnsupportedOperationException();
+    }
+}

Propchange: openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/HTMLDocument.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message