Migrate ALL java files from /src to /src/main/java - OFBIZ-7790

This is the first of two steps in the above mentioned JIRA. This
first step changes the java source directory for every component
from /src to /src/main/java. The next step will be adding unit
tests to every component in /src/test/java

Thank you to Deepak Dixit for tips on how to use the SVN commands
to make the appropriate file moving.


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk/specialpurpose@1752838 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Taher A. Alkhateeb
2016-07-15 14:17:14 +00:00
parent 9008b981b5
commit 2963cd7188
138 changed files with 0 additions and 0 deletions
@@ -0,0 +1,160 @@
/*******************************************************************************
* 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.ofbiz.example;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintException;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.Copies;
import javax.print.attribute.standard.Sides;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.stream.StreamSource;
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.MimeConstants;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.GeneralException;
import org.ofbiz.entity.util.EntityUtilProperties;
import org.ofbiz.service.DispatchContext;
import org.ofbiz.service.ServiceUtil;
import org.ofbiz.webapp.view.ApacheFopWorker;
import org.ofbiz.widget.renderer.ScreenRenderer;
import org.ofbiz.widget.renderer.ScreenStringRenderer;
import org.ofbiz.widget.renderer.macro.MacroScreenRenderer;
import org.xml.sax.SAXException;
import freemarker.template.TemplateException;
public class ExamplePrintServices {
public static final String module = ExamplePrintServices.class.getName();
public static Map<String, Object> printReportPdf(DispatchContext dctx, Map<String, ? extends Object> context) {
String screenLocation = "component://example/widget/example/ExampleReportScreens.xml";
String reportScreenName = "ExampleReport";
Map<String, Object> workContext = new HashMap<String, Object>();
workContext.putAll(context);
// render a screen to get the XML document
Writer reportWriter = new StringWriter();
ScreenStringRenderer screenStringRenderer = null;
try {
screenStringRenderer = new MacroScreenRenderer(EntityUtilProperties.getPropertyValue("widget", "screen.name", dctx.getDelegator()),
EntityUtilProperties.getPropertyValue("widget", "screen.screenrenderer", dctx.getDelegator()));
} catch (TemplateException e) {
String errMsg = "General error rendering screen [" + screenLocation + "]: " + e.toString();
Debug.logError(e, errMsg, module);
return ServiceUtil.returnError(errMsg);
} catch (IOException e) {
String errMsg = "IO error rendering screen [" + screenLocation + "]: " + e.toString();
Debug.logError(e, errMsg, module);
return ServiceUtil.returnError(errMsg);
}
ScreenRenderer reportScreenRenderer = new ScreenRenderer(reportWriter, null, screenStringRenderer);
reportScreenRenderer.populateContextForService(dctx, workContext);
// put the exampleId in the screen context, is a parameter coming into the service
//reportScreenRenderer.getContext().put("exampleId", context.get("exampleId"));
try {
reportScreenRenderer.render(screenLocation, reportScreenName);
} catch (GeneralException e) {
String errMsg = "General error rendering screen [" + screenLocation + "]: " + e.toString();
Debug.logError(e, errMsg, module);
return ServiceUtil.returnError(errMsg);
} catch (IOException e) {
String errMsg = "IO error rendering screen [" + screenLocation + "]: " + e.toString();
Debug.logError(e, errMsg, module);
return ServiceUtil.returnError(errMsg);
} catch (SAXException e) {
String errMsg = "SAX (XML parse) error rendering screen [" + screenLocation + "]: " + e.toString();
Debug.logError(e, errMsg, module);
return ServiceUtil.returnError(errMsg);
} catch (ParserConfigurationException e) {
String errMsg = "Parser configuration error rendering screen [" + screenLocation + "]: " + e.toString();
Debug.logError(e, errMsg, module);
return ServiceUtil.returnError(errMsg);
}
// set the input source (XSL-FO) and generate the PDF
StreamSource src = new StreamSource(new StringReader(reportWriter.toString()));
// create the output stream for the generation
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
Fop fop = ApacheFopWorker.createFopInstance(out, MimeConstants.MIME_PDF);
ApacheFopWorker.transform(src, null, fop);
} catch (FOPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/*
// set the content type and length
response.setContentType("application/pdf");
response.setContentLength(out.size());
// write to the browser
try {
out.writeTo(response.getOutputStream());
response.getOutputStream().flush();
} catch (IOException e) {
throw new ViewHandlerException("Unable write to browser OutputStream", e);
}
*/
DocFlavor docFlavor = DocFlavor.BYTE_ARRAY.PDF;
Doc myDoc = new SimpleDoc(out.toByteArray(), docFlavor, null);
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(new Copies(1));
//aset.add(MediaSize.A4);
aset.add(Sides.ONE_SIDED);
PrintService[] services = PrintServiceLookup.lookupPrintServices(docFlavor, aset);
if (services.length > 0) {
DocPrintJob job = services[0].createPrintJob();
try {
job.print(myDoc, aset);
} catch (PrintException pe) {
String errMsg = "Unable to print PDF from XSL-FO: " + pe.toString();
Debug.logError(pe, errMsg, module);
return ServiceUtil.returnError(errMsg);
}
}
return ServiceUtil.returnSuccess();
}
}
@@ -0,0 +1,49 @@
/*******************************************************************************
* 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.ofbiz.example;
import java.io.IOException;
import java.util.Map;
import java.util.Set;
import javax.websocket.Session;
import org.ofbiz.base.util.Debug;
import org.ofbiz.service.DispatchContext;
import org.ofbiz.service.ServiceUtil;
public class ExampleServices {
public static final String module = ExampleServices.class.getName();
public static Map<String, Object> sendExamplePushNotifications(DispatchContext dctx, Map<String, ? extends Object> context) {
String exampleId = (String) context.get("exampleId");
String message = (String) context.get("message");
Set<Session> clients = (Set<Session>) ExampleWebSockets.getClients();
try {
synchronized (clients) {
for (Session client : clients) {
client.getBasicRemote().sendText(message + ": " + exampleId);
}
}
} catch (IOException e) {
Debug.logError(e.getMessage(), module);
}
return ServiceUtil.returnSuccess();
}
}
@@ -0,0 +1,79 @@
/*******************************************************************************
* 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.ofbiz.example;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import javax.websocket.OnClose;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
import org.ofbiz.base.util.Debug;
@ServerEndpoint("/ws/pushNotifications")
public class ExampleWebSockets {
public static final String module = ExampleWebSockets.class.getName();
private static Set<Session> clients = Collections.synchronizedSet(new HashSet<Session>());
@OnMessage
public void onMessage(Session session, String msg, boolean last) {
try {
if (session.isOpen()) {
synchronized (clients) {
for(Session client : clients){
if (!client.equals(session)){
client.getBasicRemote().sendText(msg);
}
}
}
}
} catch (IOException e) {
try {
session.close();
} catch (IOException ioe) {
Debug.logError(ioe.getMessage(), module);
}
}
}
@OnOpen
public void onOpen (Session session) {
// Add session to the connected sessions clients set
clients.add(session);
}
@OnClose
public void onClose (Session session) {
// Remove session from the connected sessions clients set
clients.remove(session);
}
public static Set<Session> getClients () {
return clients;
}
}
+20
View File
@@ -0,0 +1,20 @@
#####################################################################
# 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.
#####################################################################
All source code related to the component.