/** {@inheritDoc} */ @Override public void run() { while (requests != null) { /* Not processing a request. */ currentRequest = null; /* Take a new request from the queue, waiting for one if none is available yet. */ try { currentRequest = requests.take(); } /* Interrupted? Well, try again! */ catch (InterruptedException ignored) { continue; } /* Process the request. */ try { ui.process(currentRequest.getRequest()); } /* Uncaught exception occurred during the request. */ catch (Throwable e) { e.initCause(currentRequest.getCause()); logger.err(e, "Unexpected error occurred."); } } }
/** * Make sure we have a theme set. Try to read a default value from the 'theme' property or use the * fallback. */ public static void initialize() { if (ShadeConfig.theme.isSet()) return; MyTheme theme = null; if (System.getProperty("theme") == null) theme = FALLBACK; else { try { theme = valueOf(System.getProperty("theme").trim().toUpperCase(java.util.Locale.ENGLISH)); } catch (IllegalArgumentException ignored) { /* No theme by the name given in the property 'theme'. */ } if (theme == null) { Color customColor = null; try { customColor = Color.decode(System.getProperty("theme").trim()); } catch (NumberFormatException e) { if (System.getProperty("theme").trim().length() > 0) Logger.get(MyTheme.class) .err(e, "err.invalidDefaultTheme", System.getProperty("theme").trim()); } if (customColor != null) { MyTheme.CUSTOM.getLookAndFeel().setBase(customColor); theme = CUSTOM; } else theme = FALLBACK; } } ShadeConfig.theme.set(theme.getLookAndFeel()); }
/** {@inheritDoc} */ @Override protected void configure() { // Services logger.dbg("Binding data services"); bind(InitDAO.class).to(InitDAOImpl.class); bind(IssueDAO.class).to(IssueDAOImpl.class); bind(MediaDAO.class).to(MediaDAOImpl.class); bind(SourceDAO.class).to(SourceDAOImpl.class); bind(TagDAO.class).to(TagDAOImpl.class); bind(UserDAO.class).to(UserDAOImpl.class); bind(SecurityDAO.class).to(SecurityDAOImpl.class); // Database logger.dbg("Binding persistence providers"); bind(ODB.class).toProvider(NeodatisProvider.class).in(Scopes.SINGLETON); bind(ObjectContainer.class).toProvider(Db4oProvider.class).in(Scopes.SINGLETON); }
/** * Add a request to the stack of requests to execute in the update thread. * * @param uiRequest The request to execute in the update thread. */ public void request(Request uiRequest) { UpdateRequest newRequest = new UpdateRequest( uiRequest, new RuntimeException( Locale.explain("err.originates") + Thread.currentThread().getName())); // $NON-NLS-1$ /* Don't process a request if the next pending or currently executing request is the same. */ if (newRequest.equals(currentRequest) || requests.contains(newRequest)) return; /* Add this request to the request list. */ synchronized (requests) { try { if (!requests.offer(newRequest, 500, TimeUnit.MILLISECONDS)) throw new InterruptedException("Maximum wait time elapsed."); } catch (InterruptedException e) { logger.err(e, "err.updateQueueFull", newRequest); } } }
/** * * * <h2>{@link DAOModule}<br> * <sub>[in short] (TODO).</sub></h2> * * <p>[description / usage]. * * <p><i>Jan 9, 2010</i> * * @author lhunath */ public class DAOModule extends AbstractModule { static final Logger logger = Logger.get(DAOModule.class); /** {@inheritDoc} */ @Override protected void configure() { // Services logger.dbg("Binding data services"); bind(InitDAO.class).to(InitDAOImpl.class); bind(IssueDAO.class).to(IssueDAOImpl.class); bind(MediaDAO.class).to(MediaDAOImpl.class); bind(SourceDAO.class).to(SourceDAOImpl.class); bind(TagDAO.class).to(TagDAOImpl.class); bind(UserDAO.class).to(UserDAOImpl.class); bind(SecurityDAO.class).to(SecurityDAOImpl.class); // Database logger.dbg("Binding persistence providers"); bind(ODB.class).toProvider(NeodatisProvider.class).in(Scopes.SINGLETON); bind(ObjectContainer.class).toProvider(Db4oProvider.class).in(Scopes.SINGLETON); } }
public static MPElementType forName(final String name) { for (final MPElementType type : values()) if (type.getName().equals(name)) return type; throw logger.bug("Element type not known: %s", name); }
/** * <i>07 04, 2012</i> * * @author lhunath */ public enum MPElementType { GeneratedMaximum( "Maximum Security Password", "Maximum", "20 characters, contains symbols.", MPElementTypeClass.Generated), GeneratedLong( "Long Password", "Long", "Copy-friendly, 14 characters, contains symbols.", MPElementTypeClass.Generated), GeneratedMedium( "Medium Password", "Medium", "Copy-friendly, 8 characters, contains symbols.", MPElementTypeClass.Generated), GeneratedShort( "Short Password", "Short", "Copy-friendly, 4 characters, no symbols.", MPElementTypeClass.Generated), GeneratedBasic( "Basic Password", "Basic", "8 characters, no symbols.", MPElementTypeClass.Generated), GeneratedPIN("PIN", "PIN", "4 numbers.", MPElementTypeClass.Generated), StoredPersonal( "Personal Password", "Personal", "AES-encrypted, exportable.", MPElementTypeClass.Stored, MPElementFeature.ExportContent), StoredDevicePrivate( "Device Private Password", "Private", "AES-encrypted, not exported.", MPElementTypeClass.Stored, MPElementFeature.DevicePrivate); static final Logger logger = Logger.get(MPElementType.class); private final MPElementTypeClass typeClass; private final Set<MPElementFeature> typeFeatures; private final String name; private final String shortName; private final String description; MPElementType( final String name, final String shortName, final String description, final MPElementTypeClass typeClass, final MPElementFeature... typeFeatures) { this.name = name; this.shortName = shortName; this.typeClass = typeClass; this.description = description; ImmutableSet.Builder<MPElementFeature> typeFeaturesBuilder = ImmutableSet.builder(); for (final MPElementFeature typeFeature : typeFeatures) typeFeaturesBuilder.add(typeFeature); this.typeFeatures = typeFeaturesBuilder.build(); } public MPElementTypeClass getTypeClass() { return typeClass; } public Set<MPElementFeature> getTypeFeatures() { return typeFeatures; } public String getName() { return name; } public String getShortName() { return shortName; } public String getDescription() { return description; } public static MPElementType forName(final String name) { for (final MPElementType type : values()) if (type.getName().equals(name)) return type; throw logger.bug("Element type not known: %s", name); } }
/** * * * <h2>{@link GalleryTabModels}<br> * <sub>Model provider for {@link GalleryTabPanel}.</sub></h2> * * <p><i>Mar 11, 2010</i> * * @author lhunath */ public class GalleryTabModels extends ModelProvider<GalleryTabModels, User> { static final Logger logger = Logger.get(GalleryTabModels.class); private final IModel<String> decoratedUsername; private final IModel<String> username; private final NewTagFormModels newTagForm; /** @param model A model providing the user whose gallery to show. */ @Inject public GalleryTabModels(final IModel<User> model) { super(model); decoratedUsername = new LoadableDetachableModel<String>() { @Override protected String load() { return getModelObject() == null ? null : getModelObject().toString(); } }; username = new LoadableDetachableModel<String>() { @Override protected String load() { return getModelObject() == null ? null : getModelObject().getUserName(); } }; newTagForm = new NewTagFormModels(); } /** * * * <h2>{@link NewTagFormModels}<br> * <sub>Model provider for the New Source form.</sub></h2> * * <p><i>Mar 12, 2010</i> * * @author lhunath */ public class NewTagFormModels extends EmptyModelProvider<NewTagFormModels> { private final IModel<List<SourceType>> types; private final IModel<SourceType> type; private final IModel<String> name; private final IModel<String> description; NewTagFormModels() { types = new LoadableDetachableModel<List<SourceType>>() { @Override protected List<SourceType> load() { return Arrays.asList(SourceType.values()); } }; type = new Model<SourceType>(); name = new Model<String>(); description = new Model<String>(); } // Accessors. /** @return A model that holds the user-selected {@link SourceType} which will provide media. */ public IModel<SourceType> type() { return type; } /** @return A model that provides a list of available {@link SourceType}s. */ public IModel<List<SourceType>> types() { return types; } /** @return A model that holds the user-specified name for the new tag. */ public IModel<String> name() { return name; } /** @return A model that holds the user-specified description for the new tag. */ public IModel<String> description() { return description; } } // Accessors. /** @return A model that provides a decorated version of the username of the gallery owner. */ public IModel<String> decoratedUsername() { return decoratedUsername; } /** @return A model that provides the username of the gallery owner. */ public IModel<String> username() { return username; } /** @return An object that provides models for the newTag form. */ public NewTagFormModels newTagForm() { return newTagForm; } }
/** * <i>{@link UpdateUi} - [in short] (TODO).</i><br> * <br> * [description / usage].<br> * <br> * * @author lhunath */ public class UpdateUi extends Thread { private static final Logger logger = Logger.get(UpdateUi.class); private final BlockingQueue<UpdateRequest> requests = new ArrayBlockingQueue<UpdateRequest>(20); private final AbstractUi ui; private UpdateRequest currentRequest; /** * Create a new {@link UpdateUi} instance. * * @param ui The user interface that will process the request. */ public UpdateUi(AbstractUi ui) { super("Update UI"); setDaemon(true); this.ui = ui; } /** * Add a request to the stack of requests to execute in the update thread. * * @param uiRequest The request to execute in the update thread. */ public void request(Request uiRequest) { UpdateRequest newRequest = new UpdateRequest( uiRequest, new RuntimeException( Locale.explain("err.originates") + Thread.currentThread().getName())); // $NON-NLS-1$ /* Don't process a request if the next pending or currently executing request is the same. */ if (newRequest.equals(currentRequest) || requests.contains(newRequest)) return; /* Add this request to the request list. */ synchronized (requests) { try { if (!requests.offer(newRequest, 500, TimeUnit.MILLISECONDS)) throw new InterruptedException("Maximum wait time elapsed."); } catch (InterruptedException e) { logger.err(e, "err.updateQueueFull", newRequest); } } } /** {@inheritDoc} */ @Override public void run() { while (requests != null) { /* Not processing a request. */ currentRequest = null; /* Take a new request from the queue, waiting for one if none is available yet. */ try { currentRequest = requests.take(); } /* Interrupted? Well, try again! */ catch (InterruptedException ignored) { continue; } /* Process the request. */ try { ui.process(currentRequest.getRequest()); } /* Uncaught exception occurred during the request. */ catch (Throwable e) { e.initCause(currentRequest.getCause()); logger.err(e, "Unexpected error occurred."); } } } private class UpdateRequest { private final Request request; private final Throwable cause; /** * Create a new {@link UpdateRequest} instance. * * @param request The request this stack element should make. * @param cause In case an exception gets thrown during the request, this will be set as the * exception's cause. */ UpdateRequest(Request request, Throwable cause) { this.request = request; this.cause = cause; } /** * Retrieve the request of this {@link UpdateRequest}. * * @return Guess. */ public Request getRequest() { return request; } /** * Retrieve the cause of this {@link UpdateRequest}. * * @return Guess. */ public Throwable getCause() { return cause; } /** {@inheritDoc} */ @Override public boolean equals(Object obj) { if (obj == this) return true; return obj instanceof UpdateRequest && request.equals(((UpdateRequest) obj).request); } /** {@inheritDoc} */ @Override public int hashCode() { return request.hashCode(); } /** {@inheritDoc} */ @Override public String toString() { return request.toString(); } } }
/** @author lhunath, 14-12-05 */ @XmlRootElement(name = "tests") public class MPWTests { public static final String ID_DEFAULT = "default"; @SuppressWarnings("UnusedDeclaration") private static final Logger logger = Logger.get(MPWTests.class); @XmlElement(name = "case") private List<Case> cases; @Nonnull public List<Case> getCases() { return checkNotNull(cases); } public Case getCase(String identifier) { for (Case testCase : getCases()) if (identifier.equals(testCase.getIdentifier())) return testCase; throw new IllegalArgumentException("No case for identifier: " + identifier); } @XmlRootElement(name = "case") public static class Case { @XmlAttribute(name = "id") private String identifier; @XmlAttribute private String parent; @XmlElement private String algorithm; @XmlElement private String fullName; @XmlElement private String masterPassword; @XmlElement private String keyID; @XmlElement private String siteName; @XmlElement private Integer siteCounter; @XmlElement private String siteType; @XmlElement private String siteVariant; @XmlElement private String siteContext; @XmlElement private String result; private transient Case parentCase; public void initializeParentHierarchy(MPWTests tests) { if (parent != null) { parentCase = tests.getCase(parent); parentCase.initializeParentHierarchy(tests); } algorithm = ifNotNullElse( algorithm, new NNSupplier<String>() { @Nonnull @Override public String get() { return checkNotNull(parentCase.algorithm); } }); fullName = ifNotNullElse( fullName, new NNSupplier<String>() { @Nonnull @Override public String get() { return checkNotNull(parentCase.fullName); } }); masterPassword = ifNotNullElse( masterPassword, new NNSupplier<String>() { @Nonnull @Override public String get() { return checkNotNull(parentCase.masterPassword); } }); keyID = ifNotNullElse( keyID, new NNSupplier<String>() { @Nonnull @Override public String get() { return checkNotNull(parentCase.keyID); } }); siteName = ifNotNullElse( siteName, new NNSupplier<String>() { @Nonnull @Override public String get() { return checkNotNull(parentCase.siteName); } }); siteCounter = ifNotNullElse( siteCounter, new NNSupplier<Integer>() { @Nonnull @Override public Integer get() { return checkNotNull(parentCase.siteCounter); } }); siteType = ifNotNullElse( siteType, new NNSupplier<String>() { @Nonnull @Override public String get() { return checkNotNull(parentCase.siteType); } }); siteVariant = ifNotNullElse( siteVariant, new NNSupplier<String>() { @Nonnull @Override public String get() { return checkNotNull(parentCase.siteVariant); } }); siteContext = ifNotNullElse( siteContext, new NNSupplier<String>() { @Nonnull @Override public String get() { return parentCase == null ? "" : checkNotNull(parentCase.siteContext); } }); result = ifNotNullElse( result, new NNSupplier<String>() { @Nonnull @Override public String get() { return parentCase == null ? "" : checkNotNull(parentCase.result); } }); } @Nonnull public String getIdentifier() { return identifier; } @Nullable public Case getParentCase() { return parentCase; } @Nonnull public MasterKey.Version getAlgorithm() { return MasterKey.Version.fromInt(ConversionUtils.toIntegerNN(algorithm)); } @Nonnull public String getFullName() { return checkNotNull(fullName); } @Nonnull public char[] getMasterPassword() { return checkNotNull(masterPassword).toCharArray(); } @Nonnull public String getKeyID() { return checkNotNull(keyID); } @Nonnull public String getSiteName() { return checkNotNull(siteName); } public int getSiteCounter() { return ifNotNullElse(siteCounter, 1); } @Nonnull public MPSiteType getSiteType() { return MPSiteType.forName(checkNotNull(siteType)); } @Nonnull public MPSiteVariant getSiteVariant() { return MPSiteVariant.forName(checkNotNull(siteVariant)); } @Nonnull public String getSiteContext() { return checkNotNull(siteContext); } @Nonnull public String getResult() { return checkNotNull(result); } @Override public String toString() { return identifier; } } }