use of com.twinsoft.convertigo.engine.admin.services.ServiceException in project convertigo by convertigo.
the class GetSourcePackage method writeResponseResult.
@Override
protected void writeResponseResult(HttpServletRequest request, HttpServletResponse response) throws Exception {
MobileResourceHelper mobileResourceHelper = new MobileResourceHelper(request, "mobile/www");
if (mobileResourceHelper.mobileApplication == null) {
throw new ServiceException("no such mobile application");
} else {
boolean bTpPrivateRole = Engine.authenticatedSessionManager.hasRole(request.getSession(), Role.TEST_PLATFORM_PRIVATE);
if (!bTpPrivateRole && mobileResourceHelper.mobileApplication.getAccessibility() == Accessibility.Private) {
throw new AuthenticationException("Authentication failure: user has not sufficient rights!");
}
}
File mobileArchiveFile = mobileResourceHelper.makeZipPackage();
try (FileInputStream archiveInputStream = new FileInputStream(mobileArchiveFile)) {
HeaderName.ContentDisposition.setHeader(response, "attachment; filename=\"" + mobileArchiveFile.getName() + "\"");
HeaderName.ContentLength.setHeader(response, Long.toString(mobileArchiveFile.length()));
response.setContentType(MimeType.OctetStream.value());
IOUtils.copy(archiveInputStream, response.getOutputStream());
}
}
use of com.twinsoft.convertigo.engine.admin.services.ServiceException in project convertigo by convertigo.
the class LaunchBuild method getServiceResult.
@Override
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
synchronized (buildLock) {
final MobileResourceHelper mobileResourceHelper = new MobileResourceHelper(request, "mobile/www");
MobileApplication mobileApplication = mobileResourceHelper.mobileApplication;
if (mobileApplication == null) {
throw new ServiceException("no such mobile application");
} else {
boolean bTpPrivateRole = Engine.authenticatedSessionManager.hasRole(request.getSession(), Role.TEST_PLATFORM_PRIVATE);
if (!bTpPrivateRole && mobileApplication.getAccessibility() == Accessibility.Private) {
throw new AuthenticationException("Authentication failure: user has not sufficient rights!");
}
}
String sResult = perform(mobileResourceHelper, request);
JSONObject jsonObject = new JSONObject(sResult);
Element statusElement = document.createElement("application");
statusElement.setAttribute("id", jsonObject.getString("id"));
document.getDocumentElement().appendChild(statusElement);
}
}
use of com.twinsoft.convertigo.engine.admin.services.ServiceException in project convertigo by convertigo.
the class MobileResourceHelper method prepareFiles.
public void prepareFiles(FileFilter fileFilterForCopy) throws ServiceException {
try {
String endPoint = this.endpoint + "/projects/" + project.getName();
String applicationID = mobileApplication.getComputedApplicationId();
if (!endPoint.endsWith("/")) {
endPoint += "/";
}
// Check forbidden characters in application ID (a-zA-Z0-9.-)
if (!Pattern.matches("[\\.\\w]*", applicationID)) {
throw new ServiceException("The application ID is not valid: '" + applicationID + "'.\nThe only valid characters are upper and lower letters (A-Z, a-z), " + "digits (0-9), a period (.) and a hyphen (-).");
}
// Delete no existing files
FileUtils.deleteQuietly(destDir);
for (File directory : mobileDir) {
currentMobileDir = directory;
if (directory.exists()) {
FileUtils.copyDirectory(directory, destDir, fileFilterForCopy, true);
}
}
currentMobileDir = null;
List<File> filesToDelete = new LinkedList<File>();
for (File htmlFile : FileUtils.listFiles(destDir, new String[] { "html" }, true)) {
String htmlContent = FileUtils.readFileToString(htmlFile, StandardCharsets.UTF_8);
StringBuffer sbIndexHtml = new StringBuffer();
BufferedReader br = new BufferedReader(new StringReader(htmlContent));
String includeChar = null;
String includeBuf = null;
for (String line = br.readLine(); line != null; line = br.readLine()) {
if (!line.contains("<!--")) {
if (includeChar == null && line.contains("<base ")) {
line = " <base href=\"./\">";
} else if (includeChar == null && line.contains("\"../../../../")) {
String file = line.replaceFirst(".*\"\\.\\./\\.\\./\\.\\./\\.\\./(.*?)\".*", "$1");
if (file.endsWith("c8o.cordova.js")) {
file = file.replace("c8o.cordova.js", "c8o.cordova.device.js");
}
File inFile = new File(Engine.WEBAPP_PATH + "/f" + file);
try (InputStream is = inFile.exists() ? new FileInputStream(inFile) : getClass().getResourceAsStream("res/" + inFile.getName())) {
if (is != null) {
file = file.replace("scripts/", "js/");
File outFile = new File(destDir, file);
if (!outFile.exists()) {
FileUtils.copyInputStreamToFile(is, outFile);
if (!inFile.exists()) {
outFile.setLastModified(0);
}
}
line = line.replaceFirst("\"\\.\\./\\.\\./\\.\\./\\.\\./.*?\"", "\"" + file + "\"");
if (inFile.exists()) {
handleJQMcssFolder(inFile, outFile);
}
if (file.matches(".*/jquery\\.mobilelib\\..*?js")) {
String sJs = FileUtils.readFileToString(outFile, StandardCharsets.UTF_8);
sJs = sJs.replaceAll(Pattern.quote("url : \"../../\""), "url : \"" + endPoint + "\"");
writeStringToFile(outFile, sJs);
} else if (file.matches(".*/c8o\\.core\\..*?js")) {
String sJs = FileUtils.readFileToString(outFile, StandardCharsets.UTF_8);
sJs = sJs.replaceAll(Pattern.quote("endpoint_url: \"\""), "endpoint_url: \"" + endPoint + "\"");
writeStringToFile(outFile, sJs);
}
if (file.matches(".*/flashupdate_.*?\\.css")) {
if (inFile.exists()) {
FileUtils.copyDirectory(new File(inFile.getParentFile(), "flashupdate_fonts"), new File(outFile.getParentFile(), "flashupdate_fonts"), defaultFilter, true);
FileUtils.copyDirectory(new File(inFile.getParentFile(), "flashupdate_images"), new File(outFile.getParentFile(), "flashupdate_images"), defaultFilter, true);
} else {
for (String path : Arrays.asList("flashupdate_fonts/fontfaceROBOTO.css", "flashupdate_fonts/GoogleAndroidLicense.txt", "flashupdate_fonts/Roboto-Bold-webfont.eot", "flashupdate_fonts/Roboto-Bold-webfont.svg", "flashupdate_fonts/Roboto-Bold-webfont.ttf", "flashupdate_fonts/Roboto-Bold-webfont.woff", "flashupdate_fonts/Roboto-Regular-webfont.eot", "flashupdate_fonts/Roboto-Regular-webfont.svg", "flashupdate_fonts/Roboto-Regular-webfont.ttf", "flashupdate_fonts/Roboto-Regular-webfont.woff", "flashupdate_images/bg_ios.jpg")) {
File outRes = new File(outFile.getParentFile(), path);
FileUtils.copyInputStreamToFile(getClass().getResourceAsStream("res/" + path), outRes);
outRes.setLastModified(0);
}
}
}
}
}
} else {
/**
* Handle multilines <script> and <link> urls for the resourceCompressorManager
*/
if (includeChar == null) {
Matcher mStart = Pattern.compile("(?:(?:<script .*?src)|(?:<link .*?href))\\s*=\\s*(\"|')(.*?)(\\1|$)").matcher(line);
if (mStart.find()) {
String end = mStart.group(3);
if (end.length() == 0) {
includeChar = mStart.group(1);
}
includeBuf = mStart.group(2);
} else {
includeBuf = null;
}
} else {
int index = line.indexOf(includeChar);
if (index != -1) {
includeBuf += line.substring(0, index);
includeChar = null;
} else {
includeBuf += line;
}
}
if (includeChar == null && includeBuf != null) {
String uri = includeBuf;
if (htmlFile.getAbsolutePath().startsWith(projectDir.getAbsolutePath())) {
uri = htmlFile.getParentFile().getAbsolutePath().substring(projectDir.getParentFile().getAbsolutePath().length() + 1) + "/" + uri;
}
ResourceBundle resourceBundle = Engine.theApp.minificationManager != null ? Engine.theApp.minificationManager.process(uri) : null;
if (resourceBundle != null) {
synchronized (resourceBundle) {
String prepend = "";
for (File file : resourceBundle.getFiles()) {
String filename = file.getName();
if (filename.matches("c8o\\.core\\..*?js")) {
prepend += "C8O.vars.endpoint_url=\"" + endPoint + "\";";
} else if (handleJQMcssFolder(file, resourceBundle.getVirtualFile())) {
}
}
if (prepend.isEmpty()) {
resourceBundle.writeFile();
} else {
resourceBundle.writeFile(prepend);
}
for (File file : resourceBundle.getFiles()) {
if (file.getPath().indexOf(projectDir.getPath()) == 0) {
filesToDelete.add(file);
}
}
}
}
}
}
}
sbIndexHtml.append(line + "\n");
}
htmlContent = sbIndexHtml.toString();
writeStringToFile(htmlFile, htmlContent);
}
for (File file : filesToDelete) {
FileUtils.deleteQuietly(file);
}
long latestFile = 0;
File lastFile = null;
for (File file : FileUtils.listFiles(destDir, TrueFileFilter.INSTANCE, FileFilterUtils.notFileFilter(FileFilterUtils.nameFileFilter("res")))) {
if (!file.getName().equals("config.xml") && !file.getName().equals("env.json")) {
long curFile = file.lastModified();
if (latestFile < curFile) {
latestFile = curFile;
lastFile = file;
}
}
}
Engine.logEngine.info("(MobileResourceHelper) prepareFiles, lastestFile is '" + latestFile + "' for " + lastFile);
destDir.setLastModified(latestFile);
} catch (ServiceException e) {
throw e;
} catch (Exception e) {
throw new ServiceException(e.getClass().getName(), e);
}
}
use of com.twinsoft.convertigo.engine.admin.services.ServiceException in project convertigo by convertigo.
the class MobileResourceHelper method getMobilePlatform.
private static MobilePlatform getMobilePlatform(String projectName, String platform) throws ServiceException, EngineException {
if (!Engine.theApp.databaseObjectsManager.existsProject(projectName)) {
throw new ServiceException("Unable to get resources of the application '" + projectName + "'; reason: the project does not exist");
}
Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName);
MobileApplication mobileApplication = project.getMobileApplication();
if (mobileApplication == null) {
throw new ServiceException("The application " + project.getName() + " doesn't contain a mobileApplication object.");
}
return mobileApplication.getMobilePlatformByName(platform);
}
use of com.twinsoft.convertigo.engine.admin.services.ServiceException in project convertigo by convertigo.
the class LogManager method setFilter.
public void setFilter(String filter) throws ServiceException {
if (filter == null) {
filter = "";
}
if (!this.filter.equals(filter)) {
this.filter = filter;
if (filter.length() != 0) {
Context js_context = Context.enter();
try {
js_and.reset(filter);
js_or.reset(js_and.replaceAll(" && "));
filter = js_or.replaceAll(" || ");
js_filter = js_context.compileString(filter, "filter", 0, null);
} catch (EvaluatorException e) {
throw new ServiceException("Failed to compile JS filter : " + e.getMessage(), e);
} finally {
Context.exit();
}
} else {
js_filter = null;
}
bContinue = false;
}
}
Aggregations