Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: https://svn.apache.org/repos/asf/karaf/webconsole/trunk@1243483 13f79535-47bb-0310-9956-ffa450edef68
- Loading branch information
Showing
12 changed files
with
389 additions
and
19 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
core/src/main/java/org/apache/karaf/webconsole/core/behavior/RemoveAttributeBehavior.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* 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.karaf.webconsole.core.behavior; | ||
|
||
import org.apache.wicket.Component; | ||
import org.apache.wicket.behavior.AbstractBehavior; | ||
import org.apache.wicket.markup.ComponentTag; | ||
|
||
/** | ||
* Simple behavior to remove some attributes from output markup. | ||
*/ | ||
public class RemoveAttributeBehavior extends AbstractBehavior { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
private String attribute; | ||
|
||
public RemoveAttributeBehavior(String attribute) { | ||
this.attribute = attribute; | ||
} | ||
|
||
public void onComponentTag(Component component, ComponentTag tag) { | ||
tag.getAttributes().remove(attribute); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...src/main/java/org/apache/karaf/webconsole/osgi/core/bundle/install/InstallBundlePage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* 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.karaf.webconsole.osgi.core.bundle.install; | ||
|
||
import static org.apache.wicket.model.Model.of; | ||
|
||
import org.apache.karaf.webconsole.osgi.core.bundle.list.BundlePage; | ||
import org.apache.karaf.webconsole.osgi.core.shared.OsgiPage; | ||
import org.apache.wicket.markup.html.form.Form; | ||
import org.apache.wicket.markup.html.link.BookmarkablePageLink; | ||
import org.apache.wicket.model.IModel; | ||
import org.ops4j.pax.wicket.api.PaxWicketMountPoint; | ||
|
||
/** | ||
* Page with bundle installation form. | ||
*/ | ||
@PaxWicketMountPoint(mountPoint = "/osgi/bundle/add") | ||
public class InstallBundlePage extends OsgiPage { | ||
|
||
public InstallBundlePage() { | ||
IModel<WicketInstallModel> model = of(new WicketInstallModel()); | ||
|
||
Form<WicketInstallModel> form = new Form<WicketInstallModel>("install", model); | ||
form.add(new InstallBundlePanel("bundle", model)); | ||
|
||
form.add(new InstallBundleSubmitLink("confirm")); | ||
form.add(new BookmarkablePageLink<BundlePage>("cancel", BundlePage.class)); | ||
|
||
add(form); | ||
} | ||
|
||
} |
90 changes: 90 additions & 0 deletions
90
...rc/main/java/org/apache/karaf/webconsole/osgi/core/bundle/install/InstallBundlePanel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* 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.karaf.webconsole.osgi.core.bundle.install; | ||
|
||
import static org.apache.wicket.model.Model.of; | ||
|
||
import org.apache.karaf.webconsole.core.behavior.RemoveAttributeBehavior; | ||
import org.apache.karaf.webconsole.core.form.LabelBorder; | ||
import org.apache.wicket.ajax.AjaxRequestTarget; | ||
import org.apache.wicket.ajax.markup.html.form.AjaxCheckBox; | ||
import org.apache.wicket.behavior.SimpleAttributeModifier; | ||
import org.apache.wicket.markup.html.form.CheckBox; | ||
import org.apache.wicket.markup.html.form.Form; | ||
import org.apache.wicket.markup.html.form.RequiredTextField; | ||
import org.apache.wicket.markup.html.form.TextField; | ||
import org.apache.wicket.markup.html.form.upload.FileUploadField; | ||
import org.apache.wicket.markup.html.panel.Panel; | ||
import org.apache.wicket.model.CompoundPropertyModel; | ||
import org.apache.wicket.model.IModel; | ||
|
||
/** | ||
* Bundle installation form wrapper. | ||
*/ | ||
public class InstallBundlePanel extends Panel { | ||
|
||
private static final long serialVersionUID = 1L; | ||
private TextField<String> location; | ||
private CheckBox upload; | ||
private FileUploadField file; | ||
|
||
public InstallBundlePanel(String id, IModel<WicketInstallModel> model) { | ||
super(id); | ||
|
||
Form<WicketInstallModel> form = new Form<WicketInstallModel>("form", new CompoundPropertyModel<WicketInstallModel>(model)); | ||
location = new RequiredTextField<String>("location"); | ||
location.setLabel(of("Bundle location")); | ||
LabelBorder border = new LabelBorder("locationGroup", location); | ||
form.add(border); | ||
|
||
upload = new AjaxCheckBox("upload") { | ||
private static final long serialVersionUID = 1L; | ||
|
||
@Override | ||
protected void onUpdate(AjaxRequestTarget target) { | ||
if (target != null) { | ||
if (upload.getModelObject()) { | ||
onChecked(); | ||
} else { | ||
onUnchecked(); | ||
} | ||
target.addComponent(file); | ||
} | ||
} | ||
}; | ||
upload.setLabel(of("Specify file to install")); | ||
border = new LabelBorder("uploadGroup", upload); | ||
form.add(border); | ||
|
||
file = new FileUploadField("file"); | ||
file.setLabel(of("Bundle file")); | ||
file.add(new SimpleAttributeModifier("disabled", "disabled")); | ||
file.setOutputMarkupId(true); | ||
border = new LabelBorder("fileGroup", file); | ||
form.add(border); | ||
|
||
add(form); | ||
} | ||
|
||
protected void onChecked() { | ||
file.add(new RemoveAttributeBehavior("disabled")); | ||
} | ||
|
||
protected void onUnchecked() { | ||
file.add(new SimpleAttributeModifier("disabled", "disabled")); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...in/java/org/apache/karaf/webconsole/osgi/core/bundle/install/InstallBundleSubmitLink.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* 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.karaf.webconsole.osgi.core.bundle.install; | ||
|
||
import org.apache.karaf.webconsole.osgi.core.bundle.list.BundlePage; | ||
import org.apache.wicket.RequestCycle; | ||
import org.apache.wicket.Session; | ||
import org.apache.wicket.markup.html.form.SubmitLink; | ||
import org.ops4j.pax.wicket.api.PaxWicketBean; | ||
import org.osgi.framework.BundleContext; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Bundle installation link. Requires form with {@link WicketInstallModel}. | ||
*/ | ||
public class InstallBundleSubmitLink extends SubmitLink { | ||
private static final long serialVersionUID = 1L; | ||
|
||
@PaxWicketBean(name = "blueprintBundleContext") | ||
private BundleContext context; | ||
|
||
private transient Logger logger = LoggerFactory.getLogger(InstallBundleSubmitLink.class); | ||
|
||
public InstallBundleSubmitLink(String id) { | ||
super(id); | ||
} | ||
|
||
@Override | ||
public void onSubmit() { | ||
WicketInstallModel modelObject = (WicketInstallModel) getForm().getModelObject(); | ||
|
||
try { | ||
if (modelObject.isUpload()) { | ||
context.installBundle(modelObject.getLocation(), modelObject.getInputStream()); | ||
} else { | ||
context.installBundle(modelObject.getLocation()); | ||
} | ||
Session.get().info("Bundle " + modelObject.getLocation() + " installed"); | ||
RequestCycle.get().setResponsePage(BundlePage.class); | ||
} catch (Exception e) { | ||
logger.error("Error during installation", e); | ||
Session.get().error("Can not install bundle " + e.getMessage()); | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...rc/main/java/org/apache/karaf/webconsole/osgi/core/bundle/install/WicketInstallModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* 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.karaf.webconsole.osgi.core.bundle.install; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.Serializable; | ||
|
||
import org.apache.wicket.markup.html.form.upload.FileUpload; | ||
|
||
/** | ||
* Model for installation form. | ||
*/ | ||
public class WicketInstallModel implements Serializable { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
private String location; | ||
private boolean upload = false; | ||
private FileUpload file; | ||
|
||
public String getLocation() { | ||
return location; | ||
} | ||
|
||
public void setLocation(String location) { | ||
this.location = location; | ||
} | ||
|
||
public boolean isUpload() { | ||
return upload; | ||
} | ||
|
||
public void setUpload(boolean upload) { | ||
this.upload = upload; | ||
} | ||
|
||
public void setFile(FileUpload file) { | ||
this.file = file; | ||
} | ||
|
||
public InputStream getInputStream() throws IOException { | ||
return file.getInputStream(); | ||
} | ||
|
||
} |
Oops, something went wrong.